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-6397 Fix crash when parent node is deleted while node autocomplete menu is displayed #14715

Merged
merged 33 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
56ba101
Fix PostDiff job
zeusongit Aug 11, 2023
dc250de
Merge branch 'master' of https://github.com/zeusongit/Dynamo
zeusongit Aug 11, 2023
1fecd29
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Aug 16, 2023
90a6c41
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Aug 28, 2023
64c202b
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Aug 29, 2023
d6ac751
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 5, 2023
255feeb
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 7, 2023
4e55f7f
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 8, 2023
1886669
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 8, 2023
8ac6b74
Merge branch 'master' of https://github.com/zeusongit/Dynamo
zeusongit Sep 12, 2023
41c461c
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 12, 2023
f9cf237
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 28, 2023
a0adaef
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 13, 2023
2ab3d49
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 17, 2023
558df01
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 20, 2023
efdb82b
Merge branch 'master' of https://github.com/zeusongit/Dynamo
zeusongit Oct 20, 2023
9b712f2
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 23, 2023
7c2dc1e
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 25, 2023
83bcb52
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Nov 1, 2023
30b861d
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Nov 3, 2023
71d23c2
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Dec 1, 2023
cd1c4f9
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Dec 1, 2023
0cae237
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Dec 6, 2023
a588d14
fix
zeusongit Dec 7, 2023
45eddb0
Revert different commit
zeusongit Dec 7, 2023
4cfc270
Merge branch 'master' of https://github.com/DynamoDS/Dynamo into node…
zeusongit Dec 8, 2023
579b3f1
comments
zeusongit Dec 8, 2023
fba8e45
add unsub
zeusongit Dec 8, 2023
f7c3fcd
add test
zeusongit Dec 8, 2023
69afd3e
Merge branch 'master' into nodeac-fix
QilongTang Dec 12, 2023
35d997b
Merge branch 'master' of https://github.com/DynamoDS/Dynamo into node…
zeusongit Dec 12, 2023
4636c6d
Merge branch 'nodeac-fix' of https://github.com/zeusongit/Dynamo into…
zeusongit Dec 12, 2023
e1dbf02
Update NodeAutoCompleteSearchControl.xaml.cs
zeusongit Dec 13, 2023
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
4 changes: 2 additions & 2 deletions src/DynamoCore/DynamoCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
<ItemGroup>
<Resource Include="BuiltInAndOperators\BuiltIn.Migrations.xml" />
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion src/DynamoCoreWpf/Controls/NodeAutoCompleteSearchControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.ZeroTouch;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
Expand Down Expand Up @@ -213,6 +214,19 @@ private void OnNodeAutoCompleteSearchControlVisibilityChanged(object sender, Dep
SearchTextBox.Focus();
ViewModel.PopulateAutoCompleteCandidates();
}), DispatcherPriority.Loaded);

ViewModel.ParentNodeRemoved += OnParentNodeRemoved;
}

//Removes nodeautocomplete menu when the associated parent node is removed.
private void OnParentNodeRemoved(NodeModel node)
{
NodeModel parent_node = ViewModel.PortViewModel?.PortModel.Owner;
if (node == parent_node)
{
OnRequestShowNodeAutoCompleteSearch(ShowHideFlags.Hide);
ViewModel.ParentNodeRemoved -= OnParentNodeRemoved;
}
}

private void OnMembersListBoxUpdated(object sender, DataTransferEventArgs e)
Expand Down Expand Up @@ -351,12 +365,13 @@ private void OnMoreInfoClicked(object sender, RoutedEventArgs e)

internal void CloseAutocompletionWindow(object sender, RoutedEventArgs e)
{
OnRequestShowNodeAutoCompleteSearch(ShowHideFlags.Hide);
CloseAutoCompletion();
}

internal void CloseAutoCompletion()
{
OnRequestShowNodeAutoCompleteSearch(ShowHideFlags.Hide);
ViewModel.OnNodeAutoCompleteWindowClosed();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Interfaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.PackageManager;
using Dynamo.PackageManager.UI;
Expand Down Expand Up @@ -2794,7 +2793,6 @@ internal bool CanDelete(object parameters)
return DynamoSelection.Instance.Selection.Count > 0;
}


public void SaveImage(object parameters)
{
OnRequestSaveImage(this, new ImageSaveEventArgs(parameters.ToString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public bool DisplayLowConfidence
}
}

internal event Action<NodeModel> ParentNodeRemoved;

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -530,6 +532,7 @@ internal void PopulateAutoCompleteCandidates()
{
if (PortViewModel == null) return;

dynamoViewModel.CurrentSpaceViewModel.Model.NodeRemoved += NodeViewModel_Removed;
Copy link
Contributor Author

@zeusongit zeusongit Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any place I can unsubscribe to this? I see that ViewModel has no property that can denote that the autocomplete menu is closed. May have to add it for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way is to pop the event all the way to DynamoViewModel level?

ResetAutoCompleteSearchViewState();

if (IsDisplayingMLRecommendation)
Expand Down Expand Up @@ -595,6 +598,16 @@ internal void PopulateDefaultAutoCompleteCandidates()
}
}

internal void OnNodeAutoCompleteWindowClosed()
{
dynamoViewModel.CurrentSpaceViewModel.Model.NodeRemoved -= NodeViewModel_Removed;
}

internal void NodeViewModel_Removed(NodeModel node)
{
ParentNodeRemoved?.Invoke(node);
}

/// <summary>
/// Returns a IEnumberable of NodeSearchElementViewModel for respective NodeSearchElements.
/// </summary>
Expand Down
31 changes: 31 additions & 0 deletions test/DynamoCoreWpfTests/NodeAutoCompleteSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,37 @@ public void SearchNodeAutocompletionSuggestions()
Assert.AreEqual(5 , searchViewModel.FilteredResults.Count());
}

[Test]
public void CloseNodeAutocompleteWhenParentNodeDeleted()
{
Open(@"UI\builtin_inputport_suggestion.dyn");

// Get the node view for a specific node in the graph
NodeView nodeView = NodeViewWithGuid(Guid.Parse("77aad5875f124bf59a4ece6b30813d3b").ToString());

var inPorts = nodeView.ViewModel.InPorts;
Assert.AreEqual(2, inPorts.Count());
var port = inPorts[0].PortModel;
var type = port.GetInputPortType();
Assert.AreEqual("DSCore.Color[]", type);

var searchViewModel = (ViewModel.CurrentSpaceViewModel.NodeAutoCompleteSearchViewModel as NodeAutoCompleteSearchViewModel);
searchViewModel.PortViewModel = inPorts[0];
searchViewModel.dynamoViewModel.PreferenceSettings.DefaultNodeAutocompleteSuggestion = NodeAutocompleteSuggestion.ObjectType;

// Get the matching node elements for the specific node port.
searchViewModel.PopulateAutoCompleteCandidates();
// Show Node AutoCompleteSearchBar
ViewModel.CurrentSpaceViewModel.OnRequestNodeAutoCompleteSearch(ShowHideFlags.Show);
//remove the parent node
searchViewModel.dynamoViewModel.CurrentSpaceViewModel.Model.RemoveAndDisposeNode(nodeView.ViewModel.NodeModel);

var currentWs = View.ChildOfType<WorkspaceView>();
//confirm if the AutoCompleteSearchBar is closed.
Assert.IsFalse(currentWs.NodeAutoCompleteSearchBar.IsOpen);

}

[Test]
public void NodeSuggestions_SkippedSuggestions()
{
Expand Down
Loading