diff --git a/src/DynamoCore/Models/DynamoModelCommands.cs b/src/DynamoCore/Models/DynamoModelCommands.cs index 5e607c41bf0..ee1ee7d76d5 100644 --- a/src/DynamoCore/Models/DynamoModelCommands.cs +++ b/src/DynamoCore/Models/DynamoModelCommands.cs @@ -597,12 +597,15 @@ private void UpdateModelValueImpl(UpdateModelValueCommand command) WorkspaceModel targetWorkspace = CurrentWorkspace; if (!command.WorkspaceGuid.Equals(Guid.Empty)) targetWorkspace = Workspaces.FirstOrDefault(w => w.Guid.Equals(command.WorkspaceGuid)); - - if (targetWorkspace != null) + try { - targetWorkspace.UpdateModelValue(command.ModelGuids, + targetWorkspace?.UpdateModelValue(command.ModelGuids, command.Name, command.Value); } + catch (Exception ex) + { + Logger.LogError(ex.Message); + } } private void ConvertNodesToCodeImpl(ConvertNodesToCodeCommand command) diff --git a/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs b/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs index 364ba07953a..f01c91f058c 100644 --- a/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs +++ b/src/DynamoCoreWpf/Commands/WorkspaceCommands.cs @@ -26,6 +26,7 @@ public partial class WorkspaceViewModel private DelegateCommand showHideAllGeometryPreviewCommand; private DelegateCommand showInCanvasSearchCommand; private DelegateCommand pasteCommand; + private DelegateCommand hideAllPopupCommand; #endregion @@ -214,6 +215,21 @@ public DelegateCommand ShowInCanvasSearchCommand return showInCanvasSearchCommand; } } + + /// + /// View Command to hide all popup in special cases + /// + [JsonIgnore] + public DelegateCommand HideAllPopupCommand + { + get + { + if (hideAllPopupCommand == null) + hideAllPopupCommand = new DelegateCommand(OnRequestHideAllPopup); + + return hideAllPopupCommand; + } + } #endregion #region Properties for Command Data Binding diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index d35224e7651..e8dbea72f20 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -162,6 +162,12 @@ private void OnRequestShowInCanvasSearch(object param) RequestShowInCanvasSearch?.Invoke(flag); } + internal event Action RequestHideAllPopup; + private void OnRequestHideAllPopup(object param) + { + RequestHideAllPopup?.Invoke(param); + } + internal event Action RequestNodeAutoCompleteSearch; internal event Action RequestPortContextMenu; diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs index a83e4a57cd6..602e356a563 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs @@ -1005,7 +1005,7 @@ private void DynamoView_Loaded(object sender, EventArgs e) // will not work. Instead, we have to check if the Owner Window (DynamoView) is deactivated or not. if (Application.Current == null) { - this.Deactivated += (s, args) => { HidePopupWhenWindowDeactivated(); }; + this.Deactivated += (s, args) => { HidePopupWhenWindowDeactivated(null); }; } loaded = true; } @@ -1014,11 +1014,11 @@ private void DynamoView_Loaded(object sender, EventArgs e) /// Close Popup when the Dynamo window is not in the foreground. /// - private void HidePopupWhenWindowDeactivated() + private void HidePopupWhenWindowDeactivated(object obj) { var workspace = this.ChildOfType(); if (workspace != null) - workspace.HidePopUp(); + workspace.HideAllPopUp(obj); } private void TrackStartupAnalytics() @@ -2368,7 +2368,7 @@ private void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs //if original sender was scroll bar(i.e Thumb) don't close the popup. if(!(e.OriginalSource is Thumb)) { - HidePopupWhenWindowDeactivated(); + HidePopupWhenWindowDeactivated(sender); } } diff --git a/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs b/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs index 4ba69c41efa..6d5bf33a6f4 100644 --- a/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs @@ -735,6 +735,7 @@ private void StashNodeViewCustomizationMenuItems() private void DisplayNodeContextMenu(object sender, RoutedEventArgs e) { Guid nodeGuid = ViewModel.NodeModel.GUID; + ViewModel.WorkspaceViewModel.HideAllPopupCommand.Execute(sender); ViewModel.DynamoViewModel.ExecuteCommand( new DynCmd.SelectModelCommand(nodeGuid, Keyboard.Modifiers.AsDynamoType())); diff --git a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs index 8fe01b55c76..f7edb5d45d5 100644 --- a/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs @@ -124,16 +124,17 @@ void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) private void RemoveViewModelsubscriptions(WorkspaceViewModel ViewModel) { ViewModel.RequestShowInCanvasSearch -= ShowHideInCanvasControl; + ViewModel.RequestHideAllPopup -= HideAllPopUp; ViewModel.RequestNodeAutoCompleteSearch -= ShowHideNodeAutoCompleteControl; ViewModel.RequestPortContextMenu -= ShowHidePortContextMenu; ViewModel.DynamoViewModel.PropertyChanged -= ViewModel_PropertyChanged; - + ViewModel.ZoomChanged -= vm_ZoomChanged; ViewModel.RequestZoomToViewportCenter -= vm_ZoomAtViewportCenter; ViewModel.RequestZoomToViewportPoint -= vm_ZoomAtViewportPoint; ViewModel.RequestZoomToFitView -= vm_ZoomToFitView; ViewModel.RequestCenterViewOnElement -= CenterViewOnElement; - + ViewModel.RequestAddViewToOuterCanvas -= vm_RequestAddViewToOuterCanvas; ViewModel.WorkspacePropertyEditRequested -= VmOnWorkspacePropertyEditRequested; ViewModel.RequestSelectionBoxUpdate -= VmOnRequestSelectionBoxUpdate; @@ -151,6 +152,7 @@ private void RemoveViewModelsubscriptions(WorkspaceViewModel ViewModel) private void AttachViewModelsubscriptions(WorkspaceViewModel ViewModel) { ViewModel.RequestShowInCanvasSearch += ShowHideInCanvasControl; + ViewModel.RequestHideAllPopup += HideAllPopUp; ViewModel.RequestNodeAutoCompleteSearch += ShowHideNodeAutoCompleteControl; ViewModel.RequestPortContextMenu += ShowHidePortContextMenu; ViewModel.DynamoViewModel.PropertyChanged += ViewModel_PropertyChanged; @@ -172,7 +174,7 @@ private void AttachViewModelsubscriptions(WorkspaceViewModel ViewModel) } private void ShowHideNodeAutoCompleteControl(ShowHideFlags flag) - { + { ShowHidePopup(flag, NodeAutoCompleteSearchBar); } @@ -239,7 +241,7 @@ private void ShowHidePopup(ShowHideFlags flag, Popup popup) // If the dispatcher is not used in this scenario when switching // from inputPort context menu to Output port context menu, // the popup will display before the new content is fully rendered - this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() =>{ + this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => { popup.Child.Visibility = Visibility.Visible; popup.Child.UpdateLayout(); popup.IsOpen = displayPopup; @@ -253,15 +255,23 @@ private void ShowHidePopup(ShowHideFlags flag, Popup popup) } /// - /// Hides Context Menu as well as InCanvasControl (Right Click PopUp) + /// Hides all popups in the view, the amount of popup hidden will be different depending on + /// if the hide view command is triggered on node level or workspace level /// - public void HidePopUp() + public void HideAllPopUp(object sender) { + // First make sure workspace level popups are hidden if (InCanvasSearchBar.IsOpen || ContextMenuPopup.IsOpen) { ShowHideContextMenu(ShowHideFlags.Hide); ShowHideInCanvasControl(ShowHideFlags.Hide); } + // If triggered on node level, make sure node popups are also hidden + if(sender is NodeView && (PortContextMenu.IsOpen || NodeAutoCompleteSearchBar.IsOpen) ) + { + ShowHidePopup(ShowHideFlags.Hide, PortContextMenu); + ShowHidePopup(ShowHideFlags.Hide, NodeAutoCompleteSearchBar); + } } internal Point GetCenterPoint() diff --git a/test/DynamoCoreTests/CoreTests.cs b/test/DynamoCoreTests/CoreTests.cs index 450ca6bf668..a74775af528 100644 --- a/test/DynamoCoreTests/CoreTests.cs +++ b/test/DynamoCoreTests/CoreTests.cs @@ -431,7 +431,8 @@ public void UpdateModelValue_MissingNode_ThrowsException() CurrentDynamoModel.CurrentWorkspace.RemoveAndDisposeNode(addNode); var command = new DynCmd.UpdateModelValueCommand(Guid.Empty, addNode.GUID, "Code", ""); - Assert.Throws(() => CurrentDynamoModel.ExecuteCommand(command)); + Assert.Throws(() => CurrentDynamoModel.CurrentWorkspace.UpdateModelValue(command.ModelGuids, + command.Name, command.Value)); } [Test] @@ -439,7 +440,8 @@ public void UpdateModelValue_MissingNode_ThrowsException() public void UpdateModelValue_EmptyList_ThrowsException() { var command = new DynCmd.UpdateModelValueCommand(Guid.Empty, new Guid[] { }, "", ""); - Assert.Throws(() => CurrentDynamoModel.ExecuteCommand(command)); + Assert.Throws(() => CurrentDynamoModel.CurrentWorkspace.UpdateModelValue(command.ModelGuids, + command.Name, command.Value)); } [Test]