Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to navigate to start and end nodes of a connector. #13429

Merged
merged 4 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3280,6 +3280,12 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="ContextMenuConnectionsShowAll" xml:space="preserve">
<value>Show All Wires</value>
</data>
<data name="ConnectorContextMenuHeaderStartNode" xml:space="preserve">
<value>Go to Start Node</value>
</data>
<data name="ConnectorContextMenuHeaderEndNode" xml:space="preserve">
<value>Go to End Node</value>
</data>
<data name="ContextMenuNodeConnections" xml:space="preserve">
<value>Node Connections</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,12 @@ You can manage this in Preferences -&gt; Security.</value>
<data name="ContextMenuConnectionsShowAll" xml:space="preserve">
<value>Show All Wires</value>
</data>
<data name="ConnectorContextMenuHeaderStartNode" xml:space="preserve">
<value>Go to Start Node</value>
</data>
<data name="ConnectorContextMenuHeaderEndNode" xml:space="preserve">
<value>Go to End Node</value>
</data>
<data name="ContextMenuNodeConnections" xml:space="preserve">
<value>Node Connections</value>
</data>
Expand Down
37 changes: 36 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
Expand All @@ -17,6 +17,7 @@
using System.Windows.Media;
using Dynamo.Graph;
using DynCmd = Dynamo.Models.DynamoModel;
using Dynamo.Models;

namespace Dynamo.ViewModels
{
Expand Down Expand Up @@ -666,6 +667,14 @@ model.Start.Owner is null||
/// Delegate command to trigger a construction of a ContextMenu.
/// </summary>
public DelegateCommand InstantiateContextMenuCommand { get; set; }
/// <summary>
/// Delegate command to focus the view on the start node
/// </summary>
public DelegateCommand GoToStartNodeCommand { get; set; }
/// <summary>
/// Delegate command to focus the view on the end node
/// </summary>
public DelegateCommand GoToEndNodeCommand { get; set; }

/// <summary>
/// When mouse hovers over connector, if the data coming through the connector is collection of 5 or more,
Expand Down Expand Up @@ -867,6 +876,30 @@ private void InstantiateContextMenuCommandExecute(object parameters)
CreateContextMenu();
}

private void GoToStartNodeCommandExecute(object parameters)
{
var startNodeID = ConnectorModel.Start.Owner.GUID;

//Select
var command = new DynCmd.SelectModelCommand(startNodeID, ModifierKeys.None);
workspaceViewModel.DynamoViewModel.ExecuteCommand(command);

//Focus the node
workspaceViewModel.DynamoViewModel.CurrentSpaceViewModel.FocusNodeCommand.Execute(startNodeID.ToString());
}

private void GoToEndNodeCommandExecute(object parameters)
{
var endNodeID = ConnectorModel.End.Owner.GUID;

//Select
var command = new DynCmd.SelectModelCommand(endNodeID, ModifierKeys.None);
workspaceViewModel.DynamoViewModel.ExecuteCommand(command);

//Focus the node
workspaceViewModel.DynamoViewModel.CurrentSpaceViewModel.FocusNodeCommand.Execute(endNodeID.ToString());
}

/// <summary>
/// Helper function ssed for placing (re-placing) connector
/// pins when a WatchNode is placed in the center of a connector.
Expand Down Expand Up @@ -909,6 +942,8 @@ private void InitializeCommands()
MouseUnhoverCommand = new DelegateCommand(MouseUnhoverCommandExecute, CanRunMouseUnhover);
PinConnectorCommand = new DelegateCommand(PinConnectorCommandExecute, x => true);
InstantiateContextMenuCommand = new DelegateCommand(InstantiateContextMenuCommandExecute, CanInstantiateContextMenu);
GoToStartNodeCommand = new DelegateCommand(GoToStartNodeCommandExecute, x => true);
GoToEndNodeCommand = new DelegateCommand(GoToEndNodeCommandExecute, x => true);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using Dynamo.Logging;
using Dynamo.UI.Commands;
Expand Down Expand Up @@ -96,13 +96,23 @@ public override void Dispose()
/// Alerts ConnectorViewModel to pin the connector
/// </summary>
public DelegateCommand PinConnectedSurrogateCommand { get; set; }
/// <summary>
/// Alerts ConnectorViewModel to focus the view on start node
/// </summary>
public DelegateCommand GoToStartNodeCommand { get; set; }
/// <summary>
/// Alerts ConnectorViewModel to focus the view on end node
/// </summary>
public DelegateCommand GoToEndNodeCommand { get; set; }

private void InitCommands()
{
HideConnectorSurrogateCommand = new DelegateCommand(HideConnectorSurrogateCommandExecute, x => true);
SelectConnectedSurrogateCommand = new DelegateCommand(SelectConnectedSurrogateCommandExecute, x => true);
BreakConnectionsSurrogateCommand = new DelegateCommand(BreakConnectionsSurrogateCommandExecute, x => true);
PinConnectedSurrogateCommand = new DelegateCommand(PinConnectedSurrogateCommandExecute, x => true);
GoToStartNodeCommand = new DelegateCommand(GoToStartNodeCommandExecute, x => true);
GoToEndNodeCommand = new DelegateCommand(GoToEndNodeCommandExecute, x => true);
}

/// <summary>
Expand Down Expand Up @@ -156,6 +166,24 @@ private void PinConnectedSurrogateCommandExecute(object obj)
Analytics.TrackEvent(Actions.Pin, Categories.ConnectorOperations, "PinWire");
}

/// <summary>
/// Executes the start node command on connector view model
/// </summary>
/// <param name="obj"></param>
private void GoToStartNodeCommandExecute(object obj)
{
ViewModel.GoToStartNodeCommand.Execute(null);
}

/// <summary>
/// Executes the end node command on connector view model
/// </summary>
/// <param name="obj"></param>
private void GoToEndNodeCommandExecute(object obj)
{
ViewModel.GoToEndNodeCommand.Execute(null);
}

#endregion


Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Views/Core/ConnectorContextMenuView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
</Style>
</MenuItem.Style>
</MenuItem>
<MenuItem x:Name="StartNode" Header="{x:Static props:Resources.ConnectorContextMenuHeaderStartNode}"
Command="{Binding GoToStartNodeCommand}"/>
<MenuItem x:Name="EndNode" Header="{x:Static props:Resources.ConnectorContextMenuHeaderEndNode}"
Command="{Binding GoToEndNodeCommand}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
Expand Down
32 changes: 31 additions & 1 deletion test/DynamoCoreWpfTests/ConnectorContextMenuTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
Expand Down Expand Up @@ -134,6 +134,36 @@ public void ShowAllConnectorFromWorkspaceContextMenuTest()
Assert.AreEqual(4, hiddenConnectors.Count());
}

[Test]
public void GoToStartNodeTest()
{
Open(@"UI/ConnectorContextMenuTestFile.dyn");

var connectorViewModel = this.ViewModel.CurrentSpaceViewModel.Connectors.First();
Assert.AreEqual(connectorViewModel.ConnectorModel.Start.Owner.IsSelected, false);

connectorViewModel.InstantiateContextMenuCommand.Execute(null);
var contextMenuViewModel = connectorViewModel.ConnectorContextMenuViewModel;
contextMenuViewModel.GoToStartNodeCommand.Execute(null);

Assert.AreEqual(connectorViewModel.ConnectorModel.Start.Owner.IsSelected, true);
}

[Test]
public void GoToEndNodeTest()
{
Open(@"UI/ConnectorContextMenuTestFile.dyn");

var connectorViewModel = this.ViewModel.CurrentSpaceViewModel.Connectors.First();
Assert.AreEqual(connectorViewModel.ConnectorModel.End.Owner.IsSelected, false);

connectorViewModel.InstantiateContextMenuCommand.Execute(null);
var contextMenuViewModel = connectorViewModel.ConnectorContextMenuViewModel;
contextMenuViewModel.GoToEndNodeCommand.Execute(null);

Assert.AreEqual(connectorViewModel.ConnectorModel.End.Owner.IsSelected, true);
}

/// <summary>
/// Helper method to select all (nodes) in the current Workspace
/// </summary>
Expand Down