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

DYN-7332: improvements after comments #15534

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
50 changes: 50 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/ConnectorPinViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Dynamo.UI.Commands;
using Dynamo.Wpf.ViewModels.Core;
using Newtonsoft.Json;
using Dynamo.Graph.Connectors;
using Dynamo.Selection;

namespace Dynamo.ViewModels
{
Expand Down Expand Up @@ -282,6 +284,9 @@ private void RemovePinFromGroupCommandExecute(object parameter)
{
WorkspaceViewModel.DynamoViewModel.UngroupModelCommand.Execute(null);
Analytics.TrackEvent(Actions.RemovedFrom, Categories.NodeContextMenuOperations, "ConnectorPin");

// Update the command's state after the pin is removed from the group
RemovePinFromGroupCommand.RaiseCanExecuteChanged();
}

/// <summary>
Expand Down Expand Up @@ -317,14 +322,24 @@ public ConnectorPinViewModel(WorkspaceViewModel workspaceViewModel, ConnectorPin
InitializeCommands();
model.PropertyChanged += OnPinPropertyChanged;
ZIndex = ++StaticZIndex; // places the pin on top of all nodes/notes

DynamoSelection.Instance.Selection.CollectionChanged += SelectionOnCollectionChanged;

AddPinToGroupIfConnectedNodesInSameGroup();
}

public override void Dispose()
{
model.PropertyChanged -= OnPinPropertyChanged;
DynamoSelection.Instance.Selection.CollectionChanged -= SelectionOnCollectionChanged;
base.Dispose();
}

private void SelectionOnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
RemovePinFromGroupCommand.RaiseCanExecuteChanged();
}

//respond to changes on the model's properties
void OnPinPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Expand All @@ -346,5 +361,40 @@ void OnPinPropertyChanged(object sender, System.ComponentModel.PropertyChangedEv
break;
}
}

/// <summary>
/// Adds the connector pin to a group if both connected nodes are part of the same group.
/// </summary>
private void AddPinToGroupIfConnectedNodesInSameGroup()
{
var workspace = WorkspaceViewModel.Model;
if (workspace == null)
{
return;
}

var groups = workspace.Annotations;
var connector = WorkspaceViewModel.Model.Connectors.FirstOrDefault(c => c.GUID == model.ConnectorId);
if (connector == null)
{
return;
}

// Get the start and end nodes of the connector associated with the pin
var startNode = connector.Start.Owner;
var endNode = connector.End.Owner;

foreach (var group in groups)
{
// Check if both nodes (start and end) are part of the same group
if (group.Nodes.Contains(startNode) && group.Nodes.Contains(endNode))
{
// If both nodes are part of the same group, add the pin to that group
group.AddToTargetAnnotationModel(model);
break;
}
}
}

}
}
16 changes: 16 additions & 0 deletions src/DynamoCoreWpf/Views/Core/ConnectorPinView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ private void OnPinMouseDown(object sender, MouseButtonEventArgs e)
private void OnPinRightMouseButtonDown(object sender, MouseButtonEventArgs e)
{
ViewModel.IsHoveredOver = true;

if (!ViewModel.Model.IsSelected)
{
if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
{
DynamoSelection.Instance.ClearSelection();
}
DynamoSelection.Instance.Selection.AddUnique(ViewModel.Model);
}
else
{
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{
DynamoSelection.Instance.Selection.Remove(ViewModel.Model);
}
}
}

private void OnPinRightMouseButtonUp(object sender, MouseButtonEventArgs e)
Expand Down
Loading