Skip to content

Prevent node autocomplete from autohiding #11487

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

Merged
merged 3 commits into from
Feb 11, 2021
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
11 changes: 0 additions & 11 deletions src/DynamoCoreWpf/ViewModels/Core/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ internal void CancelActiveState()
stateMachine.CancelActiveState();
}

internal DateTime GetLastStateTimestamp()
{
return stateMachine.Timestamp;
}

internal void BeginDragSelection(Point2D mouseCursor)
{
// This represents the first mouse-move event after the mouse-down
Expand Down Expand Up @@ -444,11 +439,6 @@ private enum State
#endregion

#region Public Class Properties
/// <summary>
/// Optionally record the last time a particular state is updated.
/// Currently only used for Node AutoComplete feature.
/// </summary>
internal DateTime Timestamp { get; set; }

internal bool IsInIdleState
{
Expand Down Expand Up @@ -819,7 +809,6 @@ internal bool HandlePortClicked(PortViewModel portViewModel)
this.currentState = State.Connection;
owningWorkspace.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect);
owningWorkspace.IsCursorForced = false;
Timestamp = DateTime.Now;
return true;
}

Expand Down
21 changes: 12 additions & 9 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum CursorState
private double currentNodeCascadeOffset;
private Point inCanvasSearchPosition;
private List<DependencyObject> hitResultsList = new List<DependencyObject>();
private bool isAutoCompleteLoading;

public WorkspaceViewModel ViewModel
{
Expand Down Expand Up @@ -108,7 +109,6 @@ void OnWorkspaceViewLoaded(object sender, RoutedEventArgs e)
DynamoSelection.Instance.Selection.CollectionChanged += OnSelectionCollectionChanged;

ViewModel.RequestShowInCanvasSearch += ShowHideInCanvasControl;
ViewModel.RequestNodeAutoCompleteSearch += ShowHideNodeAutoCompleteControl;
ViewModel.DynamoViewModel.PropertyChanged += ViewModel_PropertyChanged;

infiniteGridView.AttachToZoomBorder(zoomBorder);
Expand Down Expand Up @@ -146,7 +146,6 @@ private void removeViewModelsubscriptions(WorkspaceViewModel ViewModel)
ViewModel.Model.RequestNodeCentered -= vm_RequestNodeCentered;
ViewModel.Model.RequestNodeCentered -= vm_RequestNodeCentered;
ViewModel.Model.CurrentOffsetChanged -= vm_CurrentOffsetChanged;
ViewModel.RequestNodeAutoCompleteSearch -= ShowHideNodeAutoCompleteControl;
}

void OnWorkspaceViewUnloaded(object sender, RoutedEventArgs e)
Expand All @@ -164,6 +163,14 @@ void OnWorkspaceViewUnloaded(object sender, RoutedEventArgs e)

private void ShowHideNodeAutoCompleteControl(ShowHideFlags flag)
{
// Prevents hiding the dialog from releasing the left mouse button
if (flag == ShowHideFlags.Hide && isAutoCompleteLoading)
{
isAutoCompleteLoading = false;
return;
}

isAutoCompleteLoading = flag == ShowHideFlags.Show && !NodeAutoCompleteSearchBar.IsOpen;
ShowHidePopup(flag, NodeAutoCompleteSearchBar);
}

Expand Down Expand Up @@ -214,13 +221,8 @@ public void HidePopUp()
}
if (NodeAutoCompleteSearchBar.IsOpen)
{
// Suppress the mouse action from last 0.2 second otherwise mouse button release
// in Dynamo window will forcefully shutdown all the open SearchBars
if ((new TimeSpan(DateTime.Now.Ticks - ViewModel.GetLastStateTimestamp().Ticks)).TotalSeconds > 0.2)
{
ShowHideNodeAutoCompleteControl(ShowHideFlags.Hide);
ViewModel.CancelActiveState();
}
ShowHideNodeAutoCompleteControl(ShowHideFlags.Hide);
ViewModel.CancelActiveState();
}
}

Expand Down Expand Up @@ -374,6 +376,7 @@ void OnWorkspaceViewDataContextChanged(object sender, DependencyPropertyChangedE
oldViewModel.RequestAddViewToOuterCanvas -= vm_RequestAddViewToOuterCanvas;
oldViewModel.WorkspacePropertyEditRequested -= VmOnWorkspacePropertyEditRequested;
oldViewModel.RequestSelectionBoxUpdate -= VmOnRequestSelectionBoxUpdate;
oldViewModel.RequestNodeAutoCompleteSearch -= ShowHideNodeAutoCompleteControl;
removeViewModelsubscriptions(oldViewModel);
}

Expand Down
3 changes: 3 additions & 0 deletions test/DynamoCoreWpfTests/NodeAutoCompleteSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public void NodeSuggestions_InputPortZeroTouchNode_AreCorrect()
Assert.IsTrue(currentWs.NodeAutoCompleteSearchBar.IsOpen);

// Hide Node AutoCompleteSearchBar
// Note the event handler needs to be called twice. The first one is ignore because it is
// assumed to come from releasing the left mouse button when popping up AutoCompleteSearchBar
ViewModel.CurrentSpaceViewModel.OnRequestNodeAutoCompleteSearch(ShowHideFlags.Hide);
ViewModel.CurrentSpaceViewModel.OnRequestNodeAutoCompleteSearch(ShowHideFlags.Hide);
Assert.IsFalse(currentWs.NodeAutoCompleteSearchBar.IsOpen);
}
Expand Down