diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj
index df6e7031054..9d21d3618af 100644
--- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj
+++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj
@@ -304,6 +304,8 @@
+
+
@@ -486,6 +488,14 @@
MSBuild:Compile
Designer
+
+ Designer
+ Always
+
+
+ Designer
+ Always
+
MSBuild:Compile
Designer
diff --git a/src/DynamoCoreWpf/UI/SharedResourceDictionary.cs b/src/DynamoCoreWpf/UI/SharedResourceDictionary.cs
index 35f577e671a..599e3353f90 100644
--- a/src/DynamoCoreWpf/UI/SharedResourceDictionary.cs
+++ b/src/DynamoCoreWpf/UI/SharedResourceDictionary.cs
@@ -64,6 +64,8 @@ public static class SharedDictionaryManager
private static ResourceDictionary _connectorsDictionary;
private static ResourceDictionary _portsDictionary;
private static ResourceDictionary _sidebarGridDictionary;
+ private static ResourceDictionary outPortsDictionary;
+ private static ResourceDictionary inPortsDictionary;
public static string ThemesDirectory
{
@@ -119,6 +121,16 @@ public static Uri PortsDictionaryUri
get { return new Uri(Path.Combine(ThemesDirectory, "Ports.xaml")); }
}
+ public static Uri OutPortsDictionaryUri
+ {
+ get { return new Uri(Path.Combine(ThemesDirectory, "OutPorts.xaml")); }
+ }
+
+ public static Uri InPortsDictionaryUri
+ {
+ get { return new Uri(Path.Combine(ThemesDirectory, "InPorts.xaml")); }
+ }
+
public static Uri SidebarGridDictionaryUri
{
get { return new Uri(Path.Combine(ThemesDirectory, "SidebarGridStyleDictionary.xaml")); }
@@ -188,6 +200,7 @@ public static ResourceDictionary ConnectorsDictionary
}
}
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortsDictionary or OutPortsDictionary")]
public static ResourceDictionary PortsDictionary
{
get {
@@ -195,6 +208,22 @@ public static ResourceDictionary PortsDictionary
}
}
+ public static ResourceDictionary OutPortsDictionary
+ {
+ get
+ {
+ return outPortsDictionary ?? (outPortsDictionary = new ResourceDictionary() { Source = OutPortsDictionaryUri });
+ }
+ }
+
+ public static ResourceDictionary InPortsDictionary
+ {
+ get
+ {
+ return inPortsDictionary ?? (inPortsDictionary = new ResourceDictionary() { Source = InPortsDictionaryUri });
+ }
+ }
+
public static ResourceDictionary SidebarGrid
{
get
diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/InPorts.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/InPorts.xaml
new file mode 100644
index 00000000000..af0b5099e08
--- /dev/null
+++ b/src/DynamoCoreWpf/UI/Themes/Modern/InPorts.xaml
@@ -0,0 +1,375 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/OutPorts.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/OutPorts.xaml
new file mode 100644
index 00000000000..0f497f0a12e
--- /dev/null
+++ b/src/DynamoCoreWpf/UI/Themes/Modern/OutPorts.xaml
@@ -0,0 +1,338 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
index 166931e8ec7..82e57b21a52 100644
--- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
@@ -538,7 +538,7 @@ public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationMode
internal void SetGroupInputPorts()
{
InPorts.Clear();
- List newPortViewModels;
+ List newPortViewModels;
// we need to store the original ports here
// as we need those later for when we
@@ -561,7 +561,7 @@ internal void SetGroupInputPorts()
// visually add them to the group but they
// should still reference their NodeModel
// owner
- newPortViewModels = CreateProxyPorts(originalInPorts);
+ newPortViewModels = CreateProxyInPorts(originalInPorts);
if (newPortViewModels == null) return;
InPorts.AddRange(newPortViewModels);
@@ -575,7 +575,7 @@ internal void SetGroupInputPorts()
internal void SetGroupOutPorts()
{
OutPorts.Clear();
- List newPortViewModels;
+ List newPortViewModels;
// we need to store the original ports here
// as we need thoese later for when we
@@ -598,7 +598,7 @@ internal void SetGroupOutPorts()
// visually add them to the group but they
// should still reference their NodeModel
// owner
- newPortViewModels = CreateProxyPorts(originalOutPorts);
+ newPortViewModels = CreateProxyOutPorts(originalOutPorts);
if (newPortViewModels == null) return;
OutPorts.AddRange(newPortViewModels);
@@ -649,14 +649,31 @@ internal IEnumerable GetGroupOutPorts(IEnumerable ownerNod
);
}
- private List CreateProxyPorts(IEnumerable groupPortModels)
+ private List CreateProxyInPorts(IEnumerable groupPortModels)
{
var originalPortViewModels = WorkspaceViewModel.Nodes
- .SelectMany(x => x.InPorts.Concat(x.OutPorts))
+ .SelectMany(x => x.InPorts)
+ .Where(x => groupPortModels.Contains(x.PortModel))
+ .ToList();
+
+ var newPortViewModels = new List();
+ for (int i = 0; i < groupPortModels.Count(); i++)
+ {
+ var model = groupPortModels.ElementAt(i);
+ newPortViewModels.Add(originalPortViewModels[i].CreateProxyPortViewModel(model));
+ }
+
+ return newPortViewModels;
+ }
+
+ private List CreateProxyOutPorts(IEnumerable groupPortModels)
+ {
+ var originalPortViewModels = WorkspaceViewModel.Nodes
+ .SelectMany(x => x.OutPorts)
.Where(x => groupPortModels.Contains(x.PortModel))
.ToList();
- var newPortViewModels = new List();
+ var newPortViewModels = new List();
for (int i = 0; i < groupPortModels.Count(); i++)
{
var model = groupPortModels.ElementAt(i);
diff --git a/src/DynamoCoreWpf/ViewModels/Core/InPortViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/InPortViewModel.cs
new file mode 100644
index 00000000000..072eefc4e71
--- /dev/null
+++ b/src/DynamoCoreWpf/ViewModels/Core/InPortViewModel.cs
@@ -0,0 +1,270 @@
+using System;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls.Primitives;
+using System.Windows.Media;
+using Dynamo.Graph.Nodes;
+using Dynamo.Models;
+using Dynamo.UI.Commands;
+using Dynamo.Utilities;
+
+namespace Dynamo.ViewModels
+{
+ public partial class InPortViewModel : PortViewModel
+ {
+ #region Properties/Fields
+
+ private DelegateCommand useLevelsCommand;
+ private DelegateCommand keepListStructureCommand;
+ private DelegateCommand portMouseLeftButtonOnLevelCommand;
+
+ private bool showUseLevelMenu;
+
+ private static SolidColorBrush portValueMarkerColor = new SolidColorBrush(Color.FromArgb(255, 204, 204, 204));
+ private static SolidColorBrush PortValueMarkerBlue = new SolidColorBrush(Color.FromRgb(106, 192, 231));
+ private static SolidColorBrush PortValueMarkerRed = new SolidColorBrush(Color.FromRgb(235, 85, 85));
+
+ private static readonly SolidColorBrush PortBackgroundColorKeepListStructure = new SolidColorBrush(Color.FromRgb(83, 126, 145));
+ private static readonly SolidColorBrush PortBorderBrushColorKeepListStructure = new SolidColorBrush(Color.FromRgb(168, 181, 187));
+
+ ///
+ /// Returns whether this port has a default value that can be used.
+ ///
+ public bool DefaultValueEnabled => port.DefaultValue != null;
+
+ ///
+ /// Returns whether the port is using its default value, or whether this been disabled
+ ///
+ public bool UsingDefaultValue
+ {
+ get => port.UsingDefaultValue;
+ set
+ {
+ port.UsingDefaultValue = value;
+ }
+ }
+
+ ///
+ /// If should display Use Levels popup menu.
+ ///
+ public bool ShowUseLevelMenu
+ {
+ get => showUseLevelMenu;
+ set
+ {
+ showUseLevelMenu = value;
+ RaisePropertyChanged(nameof(ShowUseLevelMenu));
+ }
+ }
+
+ ///
+ /// If UseLevel is enabled on this port.
+ ///
+ public bool UseLevels => port.UseLevels;
+
+ ///
+ /// Determines whether or not the UseLevelsSpinner is visible on the port.
+ ///
+ public Visibility UseLevelSpinnerVisible
+ {
+ get
+ {
+ if (PortType == PortType.Output)
+ {
+ return Visibility.Collapsed;
+ }
+
+ if (UseLevels)
+ {
+ return Visibility.Visible;
+ }
+
+ return Visibility.Hidden;
+ }
+ }
+
+ ///
+ /// If should keep list structure on this port.
+ ///
+ public bool ShouldKeepListStructure => port.KeepListStructure;
+
+ ///
+ /// Levle of list.
+ ///
+ public int Level
+ {
+ get => port.Level;
+ set
+ {
+ ChangeLevel(value);
+ }
+ }
+
+ ///
+ /// The visibility of Use Levels menu.
+ ///
+ public Visibility UseLevelVisibility
+ {
+ get
+ {
+ if (node.ArgumentLacing != LacingStrategy.Disabled)
+ {
+ return Visibility.Visible;
+ }
+
+ return Visibility.Collapsed;
+ }
+ }
+
+ ///
+ /// Sets the color of the small rectangular marker on each input port.
+ ///
+ public SolidColorBrush PortValueMarkerColor
+ {
+ get => portValueMarkerColor;
+ set
+ {
+ portValueMarkerColor = value;
+ RaisePropertyChanged(nameof(PortValueMarkerColor));
+ }
+ }
+
+ #endregion
+
+ public InPortViewModel(NodeViewModel node, PortModel port) : base(node, port)
+ {
+ port.PropertyChanged += PortPropertyChanged;
+ }
+
+ public override void Dispose()
+ {
+ port.PropertyChanged -= PortPropertyChanged;
+ base.Dispose();
+ }
+
+ internal override PortViewModel CreateProxyPortViewModel(PortModel portModel)
+ {
+ return new InPortViewModel(node, portModel);
+ }
+
+ private void PortPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ switch (e.PropertyName)
+ {
+ case nameof(port.DefaultValue):
+ RaisePropertyChanged(nameof(port.DefaultValue));
+ break;
+ case nameof(UsingDefaultValue):
+ RaisePropertyChanged(nameof(UsingDefaultValue));
+ RefreshPortColors();
+ break;
+ case nameof(UseLevels):
+ RaisePropertyChanged(nameof(UseLevels));
+ break;
+ case nameof(Level):
+ RaisePropertyChanged(nameof(Level));
+ break;
+ case nameof(KeepListStructure):
+ RaisePropertyChanged(nameof(ShouldKeepListStructure));
+ RefreshPortColors();
+ break;
+ }
+ }
+
+ ///
+ /// UseLevels command
+ ///
+ public DelegateCommand UseLevelsCommand
+ {
+ get { return useLevelsCommand ?? (useLevelsCommand = new DelegateCommand(UseLevel, p => true)); }
+ }
+
+ private void UseLevel(object parameter)
+ {
+ var useLevel = (bool)parameter;
+ var command = new DynamoModel.UpdateModelValueCommand(
+ Guid.Empty, node.NodeLogic.GUID, "UseLevels", string.Format("{0}:{1}", port.Index, useLevel));
+
+ node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
+ RaisePropertyChanged(nameof(UseLevelSpinnerVisible));
+ }
+
+ ///
+ /// ShouldKeepListStructure command
+ ///
+ public DelegateCommand KeepListStructureCommand
+ {
+ get
+ {
+ return keepListStructureCommand ??
+ (keepListStructureCommand = new DelegateCommand(KeepListStructure, p => true));
+ }
+ }
+
+ private void KeepListStructure(object parameter)
+ {
+ var keepListStructure = (bool)parameter;
+ var command = new DynamoModel.UpdateModelValueCommand(
+ Guid.Empty, node.NodeLogic.GUID, "KeepListStructure", string.Format("{0}:{1}", port.Index, keepListStructure));
+
+ node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
+ }
+
+ private void ChangeLevel(int level)
+ {
+ var command = new DynamoModel.UpdateModelValueCommand(
+ Guid.Empty, node.NodeLogic.GUID, "ChangeLevel", string.Format("{0}:{1}", port.Index, level));
+
+ node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
+ }
+
+ ///
+ /// Handles the Mouse left button click on the node levels context menu button.
+ ///
+ public DelegateCommand MouseLeftButtonDownOnLevelCommand
+ {
+ get
+ {
+ return portMouseLeftButtonOnLevelCommand ?? (portMouseLeftButtonOnLevelCommand =
+ new DelegateCommand(OnMouseLeftButtonDownOnLevel, CanConnect));
+ }
+ }
+
+ ///
+ /// Handles the Mouse left button down on the level.
+ ///
+ ///
+ private void OnMouseLeftButtonDownOnLevel(object parameter)
+ {
+ ShowUseLevelMenu = true;
+ }
+
+ ///
+ /// Handles the logic for updating the PortBackgroundColor and PortBackgroundBrushColor
+ ///
+ protected override void RefreshPortColors()
+ {
+ // Special case for keeping list structure visual appearance
+ if (port.UseLevels && port.KeepListStructure && port.IsConnected)
+ {
+ PortValueMarkerColor = PortValueMarkerBlue;
+ PortBackgroundColor = PortBackgroundColorKeepListStructure;
+ PortBorderBrushColor = PortBorderBrushColorKeepListStructure;
+ }
+ // Port has a default value, shows blue marker
+ else if (UsingDefaultValue && DefaultValueEnabled)
+ {
+ PortValueMarkerColor = PortValueMarkerBlue;
+ PortBackgroundColor = PortBackgroundColorDefault;
+ PortBorderBrushColor = PortBorderBrushColorDefault;
+ }
+ // Port isn't connected and has no default value (or isn't using it)
+ else
+ {
+ PortValueMarkerColor = !port.IsConnected ? PortValueMarkerRed : PortValueMarkerBlue;
+ PortBackgroundColor = PortBackgroundColorDefault;
+ PortBorderBrushColor = PortBorderBrushColorDefault;
+ }
+ }
+ }
+}
diff --git a/src/DynamoCoreWpf/ViewModels/Core/NodeViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/NodeViewModel.cs
index c1ea8d03b9d..33dbf032e71 100644
--- a/src/DynamoCoreWpf/ViewModels/Core/NodeViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Core/NodeViewModel.cs
@@ -832,13 +832,13 @@ private void SetupInitialPortViewModels()
{
foreach (var item in nodeLogic.InPorts)
{
- PortViewModel inportViewModel = SubscribePortEvents(item);
+ PortViewModel inportViewModel = SubscribeInPortEvents(item);
InPorts.Add(inportViewModel);
}
foreach (var item in nodeLogic.OutPorts)
{
- PortViewModel outportViewModel = SubscribePortEvents(item);
+ PortViewModel outportViewModel = SubscribeOutPortEvents(item);
OutPorts.Add(outportViewModel);
}
}
@@ -1048,7 +1048,7 @@ private void inports_collectionChanged(object sender, NotifyCollectionChangedEve
//create a new port view model
foreach (var item in e.NewItems)
{
- PortViewModel inportViewModel = SubscribePortEvents(item as PortModel);
+ PortViewModel inportViewModel = SubscribeInPortEvents(item as PortModel);
InPorts.Add(inportViewModel);
}
}
@@ -1084,7 +1084,7 @@ private void outports_collectionChanged(object sender, NotifyCollectionChangedEv
//create a new port view model
foreach (var item in e.NewItems)
{
- PortViewModel outportViewModel = SubscribePortEvents(item as PortModel);
+ PortViewModel outportViewModel = SubscribeOutPortEvents(item as PortModel);
OutPorts.Add(outportViewModel);
}
}
@@ -1096,6 +1096,7 @@ private void outports_collectionChanged(object sender, NotifyCollectionChangedEv
{
PortViewModel portToRemove = UnSubscribePortEvents(OutPorts.ToList().First(x => x.PortModel == item));
OutPorts.Remove(portToRemove);
+ portToRemove.Dispose();
}
}
else if (e.Action == NotifyCollectionChangedAction.Reset)
@@ -1103,6 +1104,7 @@ private void outports_collectionChanged(object sender, NotifyCollectionChangedEv
foreach (var p in OutPorts)
{
UnSubscribePortEvents(p);
+ p.Dispose();
}
OutPorts.Clear();
}
@@ -1110,13 +1112,27 @@ private void outports_collectionChanged(object sender, NotifyCollectionChangedEv
///
- /// Registers the port events.
+ /// Registers the in port events.
+ ///
+ /// PortModel.
+ ///
+ protected virtual PortViewModel SubscribeInPortEvents(PortModel item)
+ {
+ InPortViewModel portViewModel = new InPortViewModel(this, item);
+ portViewModel.MouseEnter += OnRectangleMouseEnter;
+ portViewModel.MouseLeave += OnRectangleMouseLeave;
+ portViewModel.MouseLeftButtonDown += OnMouseLeftButtonDown;
+ return portViewModel;
+ }
+
+ ///
+ /// Registers the out port events.
///
/// PortModel.
///
- private PortViewModel SubscribePortEvents(PortModel item)
+ protected virtual PortViewModel SubscribeOutPortEvents(PortModel item)
{
- PortViewModel portViewModel = new PortViewModel(this, item);
+ OutPortViewModel portViewModel = new OutPortViewModel(this, item);
portViewModel.MouseEnter += OnRectangleMouseEnter;
portViewModel.MouseLeave += OnRectangleMouseLeave;
portViewModel.MouseLeftButtonDown += OnMouseLeftButtonDown;
diff --git a/src/DynamoCoreWpf/ViewModels/Core/OutPortViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/OutPortViewModel.cs
new file mode 100644
index 00000000000..fbc2637ca6d
--- /dev/null
+++ b/src/DynamoCoreWpf/ViewModels/Core/OutPortViewModel.cs
@@ -0,0 +1,257 @@
+using System;
+using System.Linq;
+using System.Windows;
+using Dynamo.Graph.Nodes;
+using Dynamo.UI.Commands;
+
+namespace Dynamo.ViewModels
+{
+ public partial class OutPortViewModel : PortViewModel
+ {
+ #region Properties/Fields
+
+ private DelegateCommand breakConnectionsCommand;
+ private DelegateCommand hideConnectionsCommand;
+ private DelegateCommand portMouseLeftButtonOnContextCommand;
+
+ private bool showContextMenu;
+ private bool areConnectorsHidden;
+ private string showHideWiresButtonContent = "";
+ private bool hideWiresButtonEnabled;
+
+ ///
+ /// Sets the condensed styling on Code Block output ports.
+ /// This is used to style the output ports on Code Blocks to be smaller.
+ ///
+ public bool IsPortCondensed => this.PortModel.Owner is CodeBlockNodeModel;
+
+ ///
+ /// If should display Use Levels popup menu.
+ ///
+ public bool ShowContextMenu
+ {
+ get => showContextMenu;
+ set
+ {
+ showContextMenu = value;
+ RaisePropertyChanged(nameof(ShowContextMenu));
+ }
+ }
+
+ ///
+ /// The visibility of Use Levels menu.
+ ///
+ public Visibility UseContextMenuVisibility
+ {
+ get
+ {
+ if (IsPortCondensed || PortName.Equals(">"))
+ {
+ return Visibility.Collapsed;
+ }
+
+ return Visibility.Visible;
+ }
+ }
+
+ ///
+ /// Determines whether the output port button says 'Hide Wires' or 'Show Wires'
+ ///
+ public string ShowHideWiresButtonContent
+ {
+ get => showHideWiresButtonContent;
+ set
+ {
+ showHideWiresButtonContent = value;
+ RaisePropertyChanged(nameof(ShowHideWiresButtonContent));
+ }
+ }
+
+ ///
+ /// Sets the visibility of the connectors from the port. This will overwrite the
+ /// individual visibility of the connectors. However when visibility is controlled
+ /// from the connector, that connector's visibility will overwrite its previous state.
+ /// In order to overwrite visibility of all connectors associated with a port, us this
+ /// flag again.
+ ///
+ public bool SetConnectorsVisibility
+ {
+ get => areConnectorsHidden;
+ set
+ {
+ areConnectorsHidden = value;
+ RaisePropertyChanged(nameof(SetConnectorsVisibility));
+ }
+ }
+
+ ///
+ /// Enables or disables the Hide Wires button on the node output port context menu.
+ ///
+ public bool HideWiresButtonEnabled
+ {
+ get => hideWiresButtonEnabled;
+ set
+ {
+ hideWiresButtonEnabled = value;
+ RaisePropertyChanged(nameof(HideWiresButtonEnabled));
+ }
+ }
+
+ ///
+ /// Takes care of the multiple UI concerns when dealing with the Unhide/Hide Wires button
+ /// on the output port's context menu.
+ ///
+ private void RefreshHideWiresButton()
+ {
+ HideWiresButtonEnabled = port.Connectors.Count > 0;
+ SetConnectorsVisibility = CheckIfConnectorsAreHidden();
+
+ ShowHideWiresButtonContent = SetConnectorsVisibility
+ ? Wpf.Properties.Resources.ShowWiresPopupMenuItem
+ : Wpf.Properties.Resources.HideWiresPopupMenuItem;
+
+ RaisePropertyChanged(nameof(ShowHideWiresButtonContent));
+ }
+
+ #endregion
+
+ public OutPortViewModel(NodeViewModel node, PortModel port) :base(node, port)
+ {
+ node.PropertyChanged += NodePropertyChanged;
+ port.PropertyChanged += PortPropertyChanged;
+ RefreshHideWiresButton();
+ }
+
+ public override void Dispose()
+ {
+ port.PropertyChanged -= PortPropertyChanged;
+ node.PropertyChanged -= NodePropertyChanged;
+ base.Dispose();
+ }
+
+ internal override PortViewModel CreateProxyPortViewModel(PortModel portModel)
+ {
+ return new OutPortViewModel(node, portModel);
+ }
+
+ private void NodePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ switch (e.PropertyName)
+ {
+ case nameof(NodeViewModel.ZIndex):
+ RefreshHideWiresButton();
+ break;
+ }
+ }
+
+ private void PortPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ switch (e.PropertyName)
+ {
+ case nameof(IsConnected):
+ RefreshHideWiresButton();
+ break;
+ }
+ }
+
+ ///
+ /// Used by the 'Break Connection' button in the node output context menu.
+ /// Removes any current connections this port has.
+ ///
+ public DelegateCommand BreakConnectionsCommand
+ {
+ get { return breakConnectionsCommand ?? (breakConnectionsCommand = new DelegateCommand(BreakConnections)); }
+ }
+
+ ///
+ /// Used by the 'Break Connection' button in the node output context menu.
+ /// Removes any current connections this port has.
+ ///
+ public DelegateCommand HideConnectionsCommand
+ {
+ get { return hideConnectionsCommand ?? (hideConnectionsCommand = new DelegateCommand(HideConnections)); }
+ }
+
+ ///
+ /// Used by the 'Break Connection' button in the node output context menu.
+ /// Removes any current connections this port has.
+ ///
+ ///
+ private void BreakConnections(object parameter)
+ {
+ for (var i = port.Connectors.Count - 1; i >= 0; i--)
+ {
+ // Attempting to get the relevant ConnectorViewModel via matching GUID
+ ConnectorViewModel connectorViewModel = node.WorkspaceViewModel.Connectors
+ .FirstOrDefault(x => x.ConnectorModel.GUID == port.Connectors[i].GUID);
+
+ if (connectorViewModel == null)
+ {
+ continue;
+ }
+
+ connectorViewModel.BreakConnectionCommand.Execute(null);
+ }
+ }
+
+ ///
+ /// Used by the 'Hide Wires' button in the node output context menu.
+ /// Turns of the visibility of any connections this port has.
+ ///
+ ///
+ private void HideConnections(object parameter)
+ {
+ for (var i = port.Connectors.Count - 1; i >= 0; i--)
+ {
+ // Attempting to get the relevant ConnectorViewModel via matching GUID
+ var connectorViewModel = node.WorkspaceViewModel.Connectors
+ .FirstOrDefault(x => x.ConnectorModel.GUID == port.Connectors[i].GUID);
+
+ if (connectorViewModel == null)
+ {
+ continue;
+ }
+
+ connectorViewModel.HideConnectorCommand.Execute(!SetConnectorsVisibility);
+ }
+ RefreshHideWiresButton();
+ }
+
+ ///
+ /// Returns true if they are hidden.
+ ///
+ ///
+ private bool CheckIfConnectorsAreHidden()
+ {
+ if (port.Connectors.Count < 1 || node.WorkspaceViewModel.Connectors.Count < 1) return false;
+
+ // Attempting to get a relevant ConnectorViewModel via matching NodeModel GUID
+ ConnectorViewModel connectorViewModel = node.WorkspaceViewModel.Connectors
+ .FirstOrDefault(x => x.Nodevm.NodeModel.GUID == port.Owner.GUID);
+
+ if (connectorViewModel == null)
+ {
+ return false;
+ }
+
+ return connectorViewModel.IsCollapsed;
+ }
+
+ ///
+ /// Handles the Mouse left button click on the node context menu button.
+ ///
+ public DelegateCommand MouseLeftButtonDownOnContextCommand
+ {
+ get
+ {
+ return portMouseLeftButtonOnContextCommand ?? (portMouseLeftButtonOnContextCommand =
+ new DelegateCommand(OnMouseLeftButtonDownOnContext, CanConnect));
+ }
+ }
+
+ private void OnMouseLeftButtonDownOnContext(object parameter)
+ {
+ ShowContextMenu = true;
+ }
+ }
+}
diff --git a/src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs
index 34c0b37cc74..0c6cba9bb19 100644
--- a/src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs
@@ -10,25 +10,6 @@
namespace Dynamo.ViewModels
{
- ///
- /// Proxy port view model, used for proxy ports under collapsed groups
- /// Certain features could behave differently e.g. Node AutoComplete is
- /// disabled for it.
- ///
- public class ProxyPortViewModel : PortViewModel
- {
- ///
- /// Constructor
- ///
- ///
- ///
- public ProxyPortViewModel(NodeViewModel node, PortModel port)
- : base(node, port)
- {
- // Do nothing for now.
- }
- }
-
///
/// Port View Model
///
@@ -36,37 +17,23 @@ public partial class PortViewModel : ViewModelBase
{
#region Properties/Fields
- private readonly PortModel _port;
- private readonly NodeViewModel _node;
- private DelegateCommand _useLevelsCommand;
- private DelegateCommand _keepListStructureCommand;
- private DelegateCommand _breakConnectionsCommand;
- private DelegateCommand _hideConnectionsCommand;
+ protected readonly PortModel port;
+ protected readonly NodeViewModel node;
+ private DelegateCommand useLevelsCommand;
+ private DelegateCommand keepListStructureCommand;
+ private bool showUseLevelMenu;
private const double autocompletePopupSpacing = 2.5;
- private SolidColorBrush portBorderBrushColor = new SolidColorBrush(Color.FromArgb(255, 204, 204, 204));
- private SolidColorBrush portValueMarkerColor = new SolidColorBrush(Color.FromArgb(255, 204, 204, 204));
- private SolidColorBrush portBackgroundColor = new SolidColorBrush(Color.FromArgb(0, 60, 60, 60));
internal bool inputPortDisconnectedByConnectCommand = false;
- private bool _showUseLevelMenu;
- private bool areConnectorsHidden;
- private string showHideWiresButtonContent = "";
- private bool hideWiresButtonEnabled;
-
- public static SolidColorBrush PortValueMarkerBlue = new SolidColorBrush(Color.FromRgb(106, 192, 231));
- public static SolidColorBrush PortValueMarkerRed = new SolidColorBrush(Color.FromRgb(235, 85, 85));
-
- public static SolidColorBrush PortBackgroundColorDefault = new SolidColorBrush(Color.FromRgb(60, 60, 60));
- public static SolidColorBrush PortBackgroundColorKeepListStructure = new SolidColorBrush(Color.FromRgb(83, 126, 145));
-
- public static SolidColorBrush PortBorderBrushColorDefault = new SolidColorBrush(Color.FromRgb(161, 161, 161));
- public static SolidColorBrush PortBorderBrushColorKeepListStructure = new SolidColorBrush(Color.FromRgb(168, 181, 187));
-
+ protected static readonly SolidColorBrush PortBackgroundColorDefault = new SolidColorBrush(Color.FromRgb(60, 60, 60));
+ protected static readonly SolidColorBrush PortBorderBrushColorDefault = new SolidColorBrush(Color.FromRgb(161, 161, 161));
+ private SolidColorBrush portBorderBrushColor = PortBorderBrushColorDefault;
+ private SolidColorBrush portBackgroundColor = PortBackgroundColorDefault;
///
/// Port model.
///
public PortModel PortModel
{
- get { return _port; }
+ get { return port; }
}
///
@@ -74,7 +41,7 @@ public PortModel PortModel
///
public string ToolTipContent
{
- get { return _port.ToolTip; }
+ get { return port.ToolTip; }
}
///
@@ -82,7 +49,7 @@ public string ToolTipContent
///
public string PortName
{
- get { return GetPortDisplayName(_port.Name); }
+ get { return GetPortDisplayName(port.Name); }
}
///
@@ -90,7 +57,7 @@ public string PortName
///
public PortType PortType
{
- get { return _port.PortType; }
+ get { return port.PortType; }
}
@@ -99,7 +66,7 @@ public PortType PortType
///
public bool IsSelected
{
- get { return _node.IsSelected; }
+ get { return node.IsSelected; }
}
///
@@ -107,7 +74,7 @@ public bool IsSelected
///
public bool IsConnected
{
- get => _port.IsConnected;
+ get => port.IsConnected;
}
///
@@ -127,7 +94,7 @@ public bool IsPortCondensed
///
public bool IsEnabled
{
- get { return _port.IsEnabled; }
+ get { return port.IsEnabled; }
}
///
@@ -135,7 +102,7 @@ public bool IsEnabled
///
public double Height
{
- get { return _port.Height; }
+ get { return port.Height; }
}
///
@@ -143,7 +110,7 @@ public double Height
///
public Point Center
{
- get { return _port.Center.AsWindowsType(); }
+ get { return port.Center.AsWindowsType(); }
}
///
@@ -151,26 +118,28 @@ public Point Center
///
public ElementState State
{
- get { return _node.State; }
+ get { return node.State; }
}
///
/// Returns whether this port has a default value that can be used.
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public bool DefaultValueEnabled
{
- get { return _port.DefaultValue != null; }
+ get { return port.DefaultValue != null; }
}
///
/// Returns whether the port is using its default value, or whether this been disabled
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public bool UsingDefaultValue
{
- get { return _port.UsingDefaultValue; }
+ get { return port.UsingDefaultValue; }
set
{
- _port.UsingDefaultValue = value;
+ port.UsingDefaultValue = value;
}
}
@@ -183,7 +152,7 @@ public bool UsingDefaultValue
///
public bool IsHitTestVisible
{
- get { return _node.WorkspaceViewModel.FirstActiveConnector != null; }
+ get { return node.WorkspaceViewModel.FirstActiveConnector != null; }
}
///
@@ -191,7 +160,7 @@ public bool IsHitTestVisible
///
public System.Windows.Thickness MarginThickness
{
- get { return _port.MarginThickness.AsWindowsType(); }
+ get { return port.MarginThickness.AsWindowsType(); }
}
public PortEventType EventType { get; set; }
@@ -199,54 +168,45 @@ public System.Windows.Thickness MarginThickness
///
/// If should display Use Levels popup menu.
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public bool ShowUseLevelMenu
{
get
{
- return _showUseLevelMenu;
+ return showUseLevelMenu;
}
set
{
- _showUseLevelMenu = value;
- RaisePropertyChanged("ShowUseLevelMenu");
+ showUseLevelMenu = value;
+ RaisePropertyChanged(nameof(ShowUseLevelMenu));
}
}
///
/// If UseLevel is enabled on this port.
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public bool UseLevels
{
- get { return _port.UseLevels; }
- }
-
- ///
- /// Determines whether or not the UseLevelsSpinner is visible on the port.
- ///
- public Visibility UseLevelSpinnerVisible
- {
- get
- {
- if (PortType == PortType.Output) return Visibility.Collapsed;
- if (UseLevels) return Visibility.Visible;
- return Visibility.Hidden;
- }
+ get { return port.UseLevels; }
}
///
/// If should keep list structure on this port.
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public bool ShouldKeepListStructure
{
- get { return _port.KeepListStructure; }
+ get { return port.KeepListStructure; }
}
///
/// Levle of list.
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public int Level
{
- get { return _port.Level; }
+ get { return port.Level; }
set
{
ChangeLevel(value);
@@ -256,11 +216,12 @@ public int Level
///
/// The visibility of Use Levels menu.
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public Visibility UseLevelVisibility
{
get
{
- if (_node.ArgumentLacing != LacingStrategy.Disabled)
+ if (node.ArgumentLacing != LacingStrategy.Disabled)
{
return Visibility.Visible;
}
@@ -273,101 +234,9 @@ public Visibility UseLevelVisibility
internal NodeViewModel NodeViewModel
{
- get => _node;
+ get => node;
}
- ///
- /// Shows or hides the Use Levels and Keep List Structure checkboxes
- /// in the node chevron popup menu.
- ///
- public bool UseLevelCheckBoxVisibility
- {
- get => _port.PortType == PortType.Input;
- }
-
- ///
- /// Shows or hides the Use Default Value checkbox in the node chevron popup menu.
- ///
- public bool UseDefaultValueCheckBoxVisibility
- {
- get => _port.PortType == PortType.Input && DefaultValueEnabled;
- }
-
- ///
- /// Shows or hides the Break Connections, Hide Wires and UnhideWires buttons in the node chevron popup menu.
- ///
- public bool OutputPortConnectionsButtonsVisible
- {
- get => _port.PortType == PortType.Output;
- }
-
- ///
- /// Enables or disables the Break Connections button on the node output port context menu.
- ///
- public bool OutputPortBreakConnectionsButtonEnabled
- {
- get => OutputPortConnectionsButtonsVisible && IsConnected;
- }
-
- ///
- /// Determines whether the output port button says 'Hide Wires' or 'Show Wires'
- ///
- public string ShowHideWiresButtonContent
- {
- get => showHideWiresButtonContent;
- set
- {
- showHideWiresButtonContent = value;
- RaisePropertyChanged(nameof(ShowHideWiresButtonContent));
- }
- }
-
- ///
- /// Sets the visibility of the connectors from the port. This will overwrite the
- /// individual visibility of the connectors. However when visibility is controlled
- /// from the connector, that connector's visibility will overwrite its previous state.
- /// In order to overwrite visibility of all connectors associated with a port, us this
- /// flag again.
- ///
- public bool SetConnectorsVisibility
- {
- get => areConnectorsHidden;
- set
- {
- areConnectorsHidden = value;
- RaisePropertyChanged(nameof(SetConnectorsVisibility));
- }
- }
-
- ///
- /// Enables or disables the Hide Wires button on the node output port context menu.
- ///
- public bool HideWiresButtonEnabled
- {
- get => hideWiresButtonEnabled;
- set
- {
- hideWiresButtonEnabled = value;
- RaisePropertyChanged(nameof(HideWiresButtonEnabled));
- }
- }
-
- ///
- /// Takes care of the multiple UI concerns when dealing with the Unhide/Hide Wires button
- /// on the output port's context menu.
- ///
- private void RefreshHideWiresButton()
- {
- HideWiresButtonEnabled = _port.Connectors.Count > 0;
- SetConnectorsVisibility = CheckIfConnectorsAreHidden();
-
- ShowHideWiresButtonContent = SetConnectorsVisibility
- ? Wpf.Properties.Resources.ShowWiresPopupMenuItem
- : Wpf.Properties.Resources.HideWiresPopupMenuItem;
-
- RaisePropertyChanged(nameof(ShowHideWiresButtonContent));
- }
-
///
/// Sets the color of the port's border brush
///
@@ -381,19 +250,6 @@ public SolidColorBrush PortBorderBrushColor
}
}
- ///
- /// Sets the color of the small rectangular marker on each input port.
- ///
- public SolidColorBrush PortValueMarkerColor
- {
- get => portValueMarkerColor;
- set
- {
- portValueMarkerColor = value;
- RaisePropertyChanged(nameof(PortValueMarkerColor));
- }
- }
-
///
/// Sets the color of the port's background - affected by multiple factors such as
/// MouseOver, IsConnected, Node States (active, inactie, frozen
@@ -408,20 +264,7 @@ public SolidColorBrush PortBackgroundColor
}
}
- ///
- /// Sets the color of the use levels popup in the input port context menu.
- /// This changes when the Keep List Structure option is activated and the port
- /// is connected, upon which it turns blue.
- ///
- public SolidColorBrush UseLevelsMenuColor
- {
- get
- {
- return ShouldKeepListStructure && _port.IsConnected
- ? new SolidColorBrush(Color.FromArgb(255, 60, 60, 60))
- : new SolidColorBrush(Color.FromArgb(255, 83, 83, 83));
- }
- }
+ internal bool IsProxyPort { get; set; } = false;
#endregion
@@ -434,27 +277,26 @@ public SolidColorBrush UseLevelsMenuColor
public PortViewModel(NodeViewModel node, PortModel port)
{
- _node = node;
- _port = port;
+ this.node = node;
+ this.port = port;
- _port.PropertyChanged += _port_PropertyChanged;
- _node.PropertyChanged += _node_PropertyChanged;
- _node.WorkspaceViewModel.PropertyChanged += Workspace_PropertyChanged;
+ this.port.PropertyChanged += PortPropertyChanged;
+ this.node.PropertyChanged += NodePropertyChanged;
+ this.node.WorkspaceViewModel.PropertyChanged += WorkspacePropertyChanged;
RefreshPortColors();
- RefreshHideWiresButton();
}
public override void Dispose()
{
- _port.PropertyChanged -= _port_PropertyChanged;
- _node.PropertyChanged -= _node_PropertyChanged;
- _node.WorkspaceViewModel.PropertyChanged -= Workspace_PropertyChanged;
+ port.PropertyChanged -= PortPropertyChanged;
+ node.PropertyChanged -= NodePropertyChanged;
+ node.WorkspaceViewModel.PropertyChanged -= WorkspacePropertyChanged;
}
- internal ProxyPortViewModel CreateProxyPortViewModel(PortModel portModel)
+ internal virtual PortViewModel CreateProxyPortViewModel(PortModel portModel)
{
- return new ProxyPortViewModel(_node, portModel);
+ return new PortViewModel(node, portModel){IsProxyPort = true};
}
///
@@ -463,16 +305,16 @@ internal ProxyPortViewModel CreateProxyPortViewModel(PortModel portModel)
/// Node autocomplete popup.
internal void SetupNodeAutocompleteWindowPlacement(Popup popup)
{
- _node.OnRequestAutoCompletePopupPlacementTarget(popup);
+ node.OnRequestAutoCompletePopupPlacementTarget(popup);
popup.CustomPopupPlacementCallback = PlaceAutocompletePopup;
}
private CustomPopupPlacement[] PlaceAutocompletePopup(Size popupSize, Size targetSize, Point offset)
{
- var zoom = _node.WorkspaceViewModel.Zoom;
+ var zoom = node.WorkspaceViewModel.Zoom;
double x;
- var scaledSpacing = autocompletePopupSpacing * targetSize.Width / _node.ActualWidth;
+ var scaledSpacing = autocompletePopupSpacing * targetSize.Width / node.ActualWidth;
if (PortModel.PortType == PortType.Input)
{
// Offset popup to the left by its width from left edge of node and spacing.
@@ -485,7 +327,7 @@ private CustomPopupPlacement[] PlaceAutocompletePopup(Size popupSize, Size targe
}
// Offset popup down from the upper edge of the node by the node header and corresponding to the respective port.
// Scale the absolute heights by the target height (passed to the callback) and the actual height of the node.
- var scaledHeight = targetSize.Height / _node.ActualHeight;
+ var scaledHeight = targetSize.Height / node.ActualHeight;
var absoluteHeight = NodeModel.HeaderHeight + PortModel.Index * PortModel.Height;
var y = absoluteHeight * scaledHeight;
@@ -494,80 +336,57 @@ private CustomPopupPlacement[] PlaceAutocompletePopup(Size popupSize, Size targe
return new[] { placement };
}
- private void Workspace_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ private void WorkspacePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "ActiveConnector":
- RaisePropertyChanged("IsHitTestVisible");
+ RaisePropertyChanged(nameof(IsHitTestVisible));
break;
}
}
- void _node_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ private void NodePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
- case "IsSelected":
- RaisePropertyChanged("IsSelected");
- break;
- case "State":
- RaisePropertyChanged("State");
+ case nameof(IsSelected):
+ RaisePropertyChanged(nameof(IsSelected));
break;
- case "ToolTipContent":
- RaisePropertyChanged("ToolTipContent");
+ case nameof(State):
+ RaisePropertyChanged(nameof(State));
break;
- case nameof(NodeViewModel.ZIndex):
- RefreshHideWiresButton();
+ case nameof(ToolTipContent):
+ RaisePropertyChanged(nameof(ToolTipContent));
break;
}
}
- void _port_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ private void PortPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "ToolTip":
- RaisePropertyChanged("ToolTipContent");
+ RaisePropertyChanged(nameof(ToolTipContent));
break;
- case "PortType":
- RaisePropertyChanged("PortType");
+ case nameof(PortType):
+ RaisePropertyChanged(nameof(PortType));
break;
- case "PortName":
- RaisePropertyChanged("PortName");
+ case nameof(PortName):
+ RaisePropertyChanged(nameof(PortName));
break;
- case "IsConnected":
+ case nameof(IsConnected):
RaisePropertyChanged(nameof(IsConnected));
- RaisePropertyChanged(nameof(OutputPortBreakConnectionsButtonEnabled));
- RefreshPortColors();
- RefreshHideWiresButton();
- break;
- case "IsEnabled":
- RaisePropertyChanged("IsEnabled");
- break;
- case "Center":
- RaisePropertyChanged("Center");
- break;
- case "DefaultValue":
- RaisePropertyChanged("DefaultValue");
- break;
- case "UsingDefaultValue":
- RaisePropertyChanged("UsingDefaultValue");
RefreshPortColors();
break;
- case "MarginThickness":
- RaisePropertyChanged("MarginThickness");
+ case nameof(IsEnabled):
+ RaisePropertyChanged(nameof(IsEnabled));
break;
- case "UseLevels":
- RaisePropertyChanged("UseLevels");
- RaisePropertyChanged(nameof(UseLevelsMenuColor));
+ case nameof(Center):
+ RaisePropertyChanged(nameof(Center));
break;
- case "Level":
- RaisePropertyChanged("Level");
- break;
- case "KeepListStructure":
- RaisePropertyChanged("ShouldKeepListStructure");
- RefreshPortColors();
+ case nameof(MarginThickness):
+ RaisePropertyChanged(nameof(MarginThickness));
break;
}
}
@@ -575,155 +394,52 @@ void _port_PropertyChanged(object sender, System.ComponentModel.PropertyChangedE
///
/// UseLevels command
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public DelegateCommand UseLevelsCommand
{
get
{
- if (_useLevelsCommand == null)
+ if (useLevelsCommand == null)
{
- _useLevelsCommand = new DelegateCommand(UseLevel, p => true);
+ useLevelsCommand = new DelegateCommand(null, p => true);
}
- return _useLevelsCommand;
+ return useLevelsCommand;
}
}
- private void UseLevel(object parameter)
- {
- var useLevel = (bool)parameter;
- var command = new DynamoModel.UpdateModelValueCommand(
- Guid.Empty, _node.NodeLogic.GUID, "UseLevels", string.Format("{0}:{1}", _port.Index, useLevel));
-
- _node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
- RaisePropertyChanged(nameof(UseLevelSpinnerVisible));
- }
-
///
/// ShouldKeepListStructure command
///
+ [Obsolete("This method will be removed in Dynamo 3.0 - please use the InPortViewModel")]
public DelegateCommand KeepListStructureCommand
{
get
{
- if (_keepListStructureCommand == null)
+ if (keepListStructureCommand == null)
{
- _keepListStructureCommand = new DelegateCommand(KeepListStructure, p => true);
+ keepListStructureCommand = new DelegateCommand(null, p => true);
}
- return _keepListStructureCommand;
+ return keepListStructureCommand;
}
}
- ///
- /// Used by the 'Break Connection' button in the node output context menu.
- /// Removes any current connections this port has.
- ///
- public DelegateCommand BreakConnectionsCommand
- {
- get
- {
- if (_breakConnectionsCommand == null)
- {
- _breakConnectionsCommand = new DelegateCommand(BreakConnections);
- }
- return _breakConnectionsCommand;
- }
- }
-
- ///
- /// Used by the 'Break Connection' button in the node output context menu.
- /// Removes any current connections this port has.
- ///
- public DelegateCommand HideConnectionsCommand
- {
- get
- {
- if (_hideConnectionsCommand == null)
- {
- _hideConnectionsCommand = new DelegateCommand(HideConnections);
- }
- return _hideConnectionsCommand;
- }
- }
-
- private void KeepListStructure(object parameter)
- {
- bool keepListStructure = (bool)parameter;
- var command = new DynamoModel.UpdateModelValueCommand(
- Guid.Empty, _node.NodeLogic.GUID, "KeepListStructure", string.Format("{0}:{1}", _port.Index, keepListStructure));
-
- _node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
- }
-
+ //Todo remove in 2.13
private void ChangeLevel(int level)
{
var command = new DynamoModel.UpdateModelValueCommand(
- Guid.Empty, _node.NodeLogic.GUID, "ChangeLevel", string.Format("{0}:{1}", _port.Index, level));
+ Guid.Empty, node.NodeLogic.GUID, "ChangeLevel", string.Format("{0}:{1}", port.Index, level));
- _node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
+ node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
}
- ///
- /// Used by the 'Break Connection' button in the node output context menu.
- /// Removes any current connections this port has.
- ///
- ///
- private void BreakConnections(object parameter)
- {
- for (int i = _port.Connectors.Count - 1; i >= 0; i--)
- {
- // Attempting to get the relevant ConnectorViewModel via matching GUID
- ConnectorViewModel connectorViewModel = _node.WorkspaceViewModel.Connectors
- .FirstOrDefault(x => x.ConnectorModel.GUID == _port.Connectors[i].GUID);
-
- if (connectorViewModel == null) continue;
-
- connectorViewModel.BreakConnectionCommand.Execute(null);
- }
- }
-
- ///
- /// Used by the 'Hide Wires' button in the node output context menu.
- /// Turns of the visibility of any connections this port has.
- ///
- ///
- private void HideConnections(object parameter)
- {
- for (int i = _port.Connectors.Count - 1; i >= 0; i--)
- {
- // Attempting to get the relevant ConnectorViewModel via matching GUID
- ConnectorViewModel connectorViewModel = _node.WorkspaceViewModel.Connectors
- .FirstOrDefault(x => x.ConnectorModel.GUID == _port.Connectors[i].GUID);
-
- if (connectorViewModel == null) continue;
-
- connectorViewModel.HideConnectorCommand.Execute(!SetConnectorsVisibility);
- }
- RefreshHideWiresButton();
- }
- ///
- /// Returns true if they are hidden.
- ///
- ///
- private bool CheckIfConnectorsAreHidden()
- {
- if (_port.Connectors.Count < 1 || _node.WorkspaceViewModel.Connectors.Count < 1) return false;
-
- // Attempting to get a relevant ConnectorViewModel via matching NodeModel GUID
- ConnectorViewModel connectorViewModel = _node.WorkspaceViewModel.Connectors
- .FirstOrDefault(x => x.Nodevm.NodeModel.GUID == _port.Owner.GUID);
-
- if (connectorViewModel == null) return false;
- return connectorViewModel.IsCollapsed;
- }
-
-
private void Connect(object parameter)
{
- DynamoViewModel dynamoViewModel = this._node.DynamoViewModel;
+ DynamoViewModel dynamoViewModel = this.node.DynamoViewModel;
WorkspaceViewModel workspaceViewModel = dynamoViewModel.CurrentSpaceViewModel;
workspaceViewModel.HandlePortClicked(this);
}
- private bool CanConnect(object parameter)
+ protected bool CanConnect(object parameter)
{
return true;
}
@@ -731,7 +447,7 @@ private bool CanConnect(object parameter)
// Handler to invoke node Auto Complete
private void AutoComplete(object parameter)
{
- var wsViewModel = _node.WorkspaceViewModel;
+ var wsViewModel = node.WorkspaceViewModel;
wsViewModel.NodeAutoCompleteSearchViewModel.PortViewModel = this;
// If the input port is disconnected by the 'Connect' command while triggering Node AutoComplete, undo the port disconnection.
@@ -747,15 +463,15 @@ private void AutoComplete(object parameter)
private bool CanAutoComplete(object parameter)
{
- DynamoViewModel dynamoViewModel = _node.DynamoViewModel;
+ DynamoViewModel dynamoViewModel = node.DynamoViewModel;
// If user trying to trigger Node AutoComplete from proxy ports, display notification
// telling user it is not available that way
- if (this is ProxyPortViewModel)
+ if (IsProxyPort)
{
dynamoViewModel.MainGuideManager.CreateRealTimeInfoWindow(Wpf.Properties.Resources.NodeAutoCompleteNotAvailableForCollapsedGroups);
}
// If the feature is enabled from Dynamo experiment setting and if user interaction is not on proxy ports.
- return dynamoViewModel.EnableNodeAutoComplete && !(this is ProxyPortViewModel);
+ return dynamoViewModel.EnableNodeAutoComplete && !(IsProxyPort);
}
///
@@ -806,41 +522,10 @@ private void OnMouseLeftUseLevel(object parameter)
///
/// Handles the logic for updating the PortBackgroundColor and PortBackgroundBrushColor
///
- private void RefreshPortColors()
+ protected virtual void RefreshPortColors()
{
- // The visual appearance of ports can be affected by many different logical states
- // Inputs have more display styles than outputs
- if (_port.PortType == PortType.Input)
- {
- // Special case for keeping list structure visual appearance
- if (_port.UseLevels && _port.KeepListStructure && _port.IsConnected)
- {
- PortValueMarkerColor = PortValueMarkerBlue;
- PortBackgroundColor = PortBackgroundColorKeepListStructure;
- PortBorderBrushColor = PortBorderBrushColorKeepListStructure;
- }
- // Port has a default value, shows blue marker
- else if (UsingDefaultValue && DefaultValueEnabled)
- {
- PortValueMarkerColor = PortValueMarkerBlue;
- PortBackgroundColor = PortBackgroundColorDefault;
- PortBorderBrushColor = PortBorderBrushColorDefault;
- }
- // Port isn't connected and has no default value (or isn't using it)
- else
- {
- PortValueMarkerColor = !_port.IsConnected ? PortValueMarkerRed : PortValueMarkerBlue;
- PortBackgroundColor = PortBackgroundColorDefault;
- PortBorderBrushColor = PortBorderBrushColorDefault;
- }
- }
- // It's an output port, which either displays a connected style or a disconnected style
- else
- {
- PortBackgroundColor = PortBackgroundColorDefault;
- PortBorderBrushColor = PortBorderBrushColorDefault;
- }
- RaisePropertyChanged(nameof(UseLevelsMenuColor));
+ PortBackgroundColor = PortBackgroundColorDefault;
+ PortBorderBrushColor = PortBorderBrushColorDefault;
}
///
@@ -857,9 +542,9 @@ private string GetPortDisplayName(string value)
{
return value as string;
}
- if (_node.ArgumentLacing != LacingStrategy.Disabled)
+ if (node.ArgumentLacing != LacingStrategy.Disabled)
{
- switch (_port.PortType)
+ switch (port.PortType)
{
case PortType.Input:
return Properties.Resources.InputPortAlternativeName;
diff --git a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs
index 3bce94f8739..fe79e753623 100644
--- a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs
+++ b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs
@@ -31,7 +31,8 @@ public AnnotationView()
Resources.MergedDictionaries.Add(SharedDictionaryManager.DynamoColorsAndBrushesDictionary);
Resources.MergedDictionaries.Add(SharedDictionaryManager.DataTemplatesDictionary);
Resources.MergedDictionaries.Add(SharedDictionaryManager.DynamoConvertersDictionary);
- Resources.MergedDictionaries.Add(SharedDictionaryManager.PortsDictionary);
+ Resources.MergedDictionaries.Add(SharedDictionaryManager.InPortsDictionary);
+ Resources.MergedDictionaries.Add(SharedDictionaryManager.OutPortsDictionary);
InitializeComponent();
Unloaded += AnnotationView_Unloaded;
diff --git a/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs b/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs
index 4d63e3368c0..395a7656c57 100644
--- a/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs
+++ b/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs
@@ -114,7 +114,8 @@ public NodeView()
Resources.MergedDictionaries.Add(SharedDictionaryManager.DynamoColorsAndBrushesDictionary);
Resources.MergedDictionaries.Add(SharedDictionaryManager.DataTemplatesDictionary);
Resources.MergedDictionaries.Add(SharedDictionaryManager.DynamoConvertersDictionary);
- Resources.MergedDictionaries.Add(SharedDictionaryManager.PortsDictionary);
+ Resources.MergedDictionaries.Add(SharedDictionaryManager.InPortsDictionary);
+ Resources.MergedDictionaries.Add(SharedDictionaryManager.OutPortsDictionary);
InitializeComponent();