Skip to content

Commit afc4970

Browse files
authored
Cherry pick #12572 and #12565 (#12575)
* Hide All context menu in workspace when displaying node context menu (#12565) * Hide All context menu in workspace when displaying node context menu * Fix the crash for lacing menu * fix unit tests * Update Color (#12572)
1 parent b2edf3a commit afc4970

File tree

8 files changed

+56
-16
lines changed

8 files changed

+56
-16
lines changed

src/DynamoCore/Models/DynamoModelCommands.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,15 @@ private void UpdateModelValueImpl(UpdateModelValueCommand command)
597597
WorkspaceModel targetWorkspace = CurrentWorkspace;
598598
if (!command.WorkspaceGuid.Equals(Guid.Empty))
599599
targetWorkspace = Workspaces.FirstOrDefault(w => w.Guid.Equals(command.WorkspaceGuid));
600-
601-
if (targetWorkspace != null)
600+
try
602601
{
603-
targetWorkspace.UpdateModelValue(command.ModelGuids,
602+
targetWorkspace?.UpdateModelValue(command.ModelGuids,
604603
command.Name, command.Value);
605604
}
605+
catch (Exception ex)
606+
{
607+
Logger.LogError(ex.Message);
608+
}
606609
}
607610

608611
private void ConvertNodesToCodeImpl(ConvertNodesToCodeCommand command)

src/DynamoCoreWpf/Commands/WorkspaceCommands.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public partial class WorkspaceViewModel
2626
private DelegateCommand showHideAllGeometryPreviewCommand;
2727
private DelegateCommand showInCanvasSearchCommand;
2828
private DelegateCommand pasteCommand;
29+
private DelegateCommand hideAllPopupCommand;
2930

3031
#endregion
3132

@@ -214,6 +215,21 @@ public DelegateCommand ShowInCanvasSearchCommand
214215
return showInCanvasSearchCommand;
215216
}
216217
}
218+
219+
/// <summary>
220+
/// View Command to hide all popup in special cases
221+
/// </summary>
222+
[JsonIgnore]
223+
public DelegateCommand HideAllPopupCommand
224+
{
225+
get
226+
{
227+
if (hideAllPopupCommand == null)
228+
hideAllPopupCommand = new DelegateCommand(OnRequestHideAllPopup);
229+
230+
return hideAllPopupCommand;
231+
}
232+
}
217233
#endregion
218234

219235
#region Properties for Command Data Binding

src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ private void OnRequestShowInCanvasSearch(object param)
162162
RequestShowInCanvasSearch?.Invoke(flag);
163163
}
164164

165+
internal event Action<object> RequestHideAllPopup;
166+
private void OnRequestHideAllPopup(object param)
167+
{
168+
RequestHideAllPopup?.Invoke(param);
169+
}
170+
165171
internal event Action<ShowHideFlags> RequestNodeAutoCompleteSearch;
166172
internal event Action<ShowHideFlags, PortViewModel> RequestPortContextMenu;
167173

src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ private void DynamoView_Loaded(object sender, EventArgs e)
10051005
// will not work. Instead, we have to check if the Owner Window (DynamoView) is deactivated or not.
10061006
if (Application.Current == null)
10071007
{
1008-
this.Deactivated += (s, args) => { HidePopupWhenWindowDeactivated(); };
1008+
this.Deactivated += (s, args) => { HidePopupWhenWindowDeactivated(null); };
10091009
}
10101010
loaded = true;
10111011
}
@@ -1014,11 +1014,11 @@ private void DynamoView_Loaded(object sender, EventArgs e)
10141014
/// Close Popup when the Dynamo window is not in the foreground.
10151015
/// </summary>
10161016

1017-
private void HidePopupWhenWindowDeactivated()
1017+
private void HidePopupWhenWindowDeactivated(object obj)
10181018
{
10191019
var workspace = this.ChildOfType<WorkspaceView>();
10201020
if (workspace != null)
1021-
workspace.HidePopUp();
1021+
workspace.HideAllPopUp(obj);
10221022
}
10231023

10241024
private void TrackStartupAnalytics()
@@ -2368,7 +2368,7 @@ private void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs
23682368
//if original sender was scroll bar(i.e Thumb) don't close the popup.
23692369
if(!(e.OriginalSource is Thumb))
23702370
{
2371-
HidePopupWhenWindowDeactivated();
2371+
HidePopupWhenWindowDeactivated(sender);
23722372
}
23732373
}
23742374

src/DynamoCoreWpf/Views/Core/NodeView.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ private void StashNodeViewCustomizationMenuItems()
735735
private void DisplayNodeContextMenu(object sender, RoutedEventArgs e)
736736
{
737737
Guid nodeGuid = ViewModel.NodeModel.GUID;
738+
ViewModel.WorkspaceViewModel.HideAllPopupCommand.Execute(sender);
738739
ViewModel.DynamoViewModel.ExecuteCommand(
739740
new DynCmd.SelectModelCommand(nodeGuid, Keyboard.Modifiers.AsDynamoType()));
740741

src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,17 @@ void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
124124
private void RemoveViewModelsubscriptions(WorkspaceViewModel ViewModel)
125125
{
126126
ViewModel.RequestShowInCanvasSearch -= ShowHideInCanvasControl;
127+
ViewModel.RequestHideAllPopup -= HideAllPopUp;
127128
ViewModel.RequestNodeAutoCompleteSearch -= ShowHideNodeAutoCompleteControl;
128129
ViewModel.RequestPortContextMenu -= ShowHidePortContextMenu;
129130
ViewModel.DynamoViewModel.PropertyChanged -= ViewModel_PropertyChanged;
130-
131+
131132
ViewModel.ZoomChanged -= vm_ZoomChanged;
132133
ViewModel.RequestZoomToViewportCenter -= vm_ZoomAtViewportCenter;
133134
ViewModel.RequestZoomToViewportPoint -= vm_ZoomAtViewportPoint;
134135
ViewModel.RequestZoomToFitView -= vm_ZoomToFitView;
135136
ViewModel.RequestCenterViewOnElement -= CenterViewOnElement;
136-
137+
137138
ViewModel.RequestAddViewToOuterCanvas -= vm_RequestAddViewToOuterCanvas;
138139
ViewModel.WorkspacePropertyEditRequested -= VmOnWorkspacePropertyEditRequested;
139140
ViewModel.RequestSelectionBoxUpdate -= VmOnRequestSelectionBoxUpdate;
@@ -151,6 +152,7 @@ private void RemoveViewModelsubscriptions(WorkspaceViewModel ViewModel)
151152
private void AttachViewModelsubscriptions(WorkspaceViewModel ViewModel)
152153
{
153154
ViewModel.RequestShowInCanvasSearch += ShowHideInCanvasControl;
155+
ViewModel.RequestHideAllPopup += HideAllPopUp;
154156
ViewModel.RequestNodeAutoCompleteSearch += ShowHideNodeAutoCompleteControl;
155157
ViewModel.RequestPortContextMenu += ShowHidePortContextMenu;
156158
ViewModel.DynamoViewModel.PropertyChanged += ViewModel_PropertyChanged;
@@ -172,7 +174,7 @@ private void AttachViewModelsubscriptions(WorkspaceViewModel ViewModel)
172174
}
173175

174176
private void ShowHideNodeAutoCompleteControl(ShowHideFlags flag)
175-
{
177+
{
176178
ShowHidePopup(flag, NodeAutoCompleteSearchBar);
177179
}
178180

@@ -239,7 +241,7 @@ private void ShowHidePopup(ShowHideFlags flag, Popup popup)
239241
// If the dispatcher is not used in this scenario when switching
240242
// from inputPort context menu to Output port context menu,
241243
// the popup will display before the new content is fully rendered
242-
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() =>{
244+
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => {
243245
popup.Child.Visibility = Visibility.Visible;
244246
popup.Child.UpdateLayout();
245247
popup.IsOpen = displayPopup;
@@ -253,15 +255,23 @@ private void ShowHidePopup(ShowHideFlags flag, Popup popup)
253255
}
254256

255257
/// <summary>
256-
/// Hides Context Menu as well as InCanvasControl (Right Click PopUp)
258+
/// Hides all popups in the view, the amount of popup hidden will be different depending on
259+
/// if the hide view command is triggered on node level or workspace level
257260
/// </summary>
258-
public void HidePopUp()
261+
public void HideAllPopUp(object sender)
259262
{
263+
// First make sure workspace level popups are hidden
260264
if (InCanvasSearchBar.IsOpen || ContextMenuPopup.IsOpen)
261265
{
262266
ShowHideContextMenu(ShowHideFlags.Hide);
263267
ShowHideInCanvasControl(ShowHideFlags.Hide);
264268
}
269+
// If triggered on node level, make sure node popups are also hidden
270+
if(sender is NodeView && (PortContextMenu.IsOpen || NodeAutoCompleteSearchBar.IsOpen) )
271+
{
272+
ShowHidePopup(ShowHideFlags.Hide, PortContextMenu);
273+
ShowHidePopup(ShowHideFlags.Hide, NodeAutoCompleteSearchBar);
274+
}
265275
}
266276

267277
internal Point GetCenterPoint()

src/Libraries/CoreNodeModelsWpf/Controls/ElementSelectionControl.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
TextWrapping="Wrap"
2929
Grid.Row="1"
3030
Margin="5"
31-
MaxWidth="200" MaxHeight="200">
31+
MaxWidth="200"
32+
MaxHeight="200"
33+
Foreground="#F5F5F5">
3234
<TextBlock.ToolTip>
3335
<TextBlock Text="{Binding Model.Text}" MaxHeight="200" TextTrimming="WordEllipsis"/>
3436
</TextBlock.ToolTip>

test/DynamoCoreTests/CoreTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,17 @@ public void UpdateModelValue_MissingNode_ThrowsException()
431431
CurrentDynamoModel.CurrentWorkspace.RemoveAndDisposeNode(addNode);
432432

433433
var command = new DynCmd.UpdateModelValueCommand(Guid.Empty, addNode.GUID, "Code", "");
434-
Assert.Throws<InvalidOperationException>(() => CurrentDynamoModel.ExecuteCommand(command));
434+
Assert.Throws<InvalidOperationException>(() => CurrentDynamoModel.CurrentWorkspace.UpdateModelValue(command.ModelGuids,
435+
command.Name, command.Value));
435436
}
436437

437438
[Test]
438439
[Category("UnitTests")]
439440
public void UpdateModelValue_EmptyList_ThrowsException()
440441
{
441442
var command = new DynCmd.UpdateModelValueCommand(Guid.Empty, new Guid[] { }, "", "");
442-
Assert.Throws<ArgumentNullException>(() => CurrentDynamoModel.ExecuteCommand(command));
443+
Assert.Throws<ArgumentNullException>(() => CurrentDynamoModel.CurrentWorkspace.UpdateModelValue(command.ModelGuids,
444+
command.Name, command.Value));
443445
}
444446

445447
[Test]

0 commit comments

Comments
 (0)