Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,11 @@ private void HidePopupWhenWindowDeactivated(object obj)
{
var workspace = this.ChildOfType<WorkspaceView>();
if (workspace != null)
{
workspace.HideAllPopUp(obj);
workspace.DestroyPortContextMenu();
}

}

private void TrackStartupAnalytics()
Expand Down
49 changes: 45 additions & 4 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public WorkspaceView()

InitializeComponent();

Loaded += WorkspaceView_Loaded;
Unloaded += WorkspaceView_Unloaded;

LostFocus += WorkspaceView_LostFocus;

DataContextChanged += OnWorkspaceViewDataContextChanged;

// view of items to drag
Expand All @@ -119,6 +124,11 @@ public WorkspaceView()
dictionaries.Add(SharedDictionaryManager.DataTemplatesDictionary);
}

private void WorkspaceView_LostFocus(object sender, RoutedEventArgs e)
{
DestroyPortContextMenu();
}

void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down Expand Up @@ -906,20 +916,47 @@ private void OnCanvasMouseDown(object sender, MouseButtonEventArgs e)
InCanvasSearchBar.IsOpen = false;
if (GeoScalingPopup != null)
GeoScalingPopup.IsOpen = false;
if(PortContextMenu.IsOpen) DestroyPortContextMenu();

if (PortContextMenu.IsOpen) DestroyPortContextMenu();

if (!ViewModel.IsConnecting && !ViewModel.IsPanning && e.MiddleButton == MouseButtonState.Pressed)
{
ViewModel.RequestTogglePanMode();
}
}

private void WorkspaceView_Loaded(object sender, RoutedEventArgs e)
{
var ownerWindow = Window.GetWindow(this);
if (ownerWindow != null)
{
ownerWindow.Deactivated += OwnerWindow_Deactivated;
}
}

private void WorkspaceView_Unloaded(object sender, RoutedEventArgs e)
{
var ownerWindow = Window.GetWindow(this);
if (ownerWindow != null)
{
ownerWindow.Deactivated -= OwnerWindow_Deactivated;
}
}

/// <summary>
/// When the Dynamo/Revit window loses focus, close the port context menu
/// so it doesn't float above other windows.
/// </summary>
private void OwnerWindow_Deactivated(object sender, EventArgs e)
{
DestroyPortContextMenu();
}

/// <summary>
/// Closes the port's context menu and sets its references to null.
/// </summary>
private void DestroyPortContextMenu() => PortContextMenu.IsOpen = false;
internal void DestroyPortContextMenu() => PortContextMenu.IsOpen = false;

private void OnMouseRelease(object sender, MouseButtonEventArgs e)
{
if (e == null) return; // in certain bizarre cases, e can be null
Expand Down Expand Up @@ -1261,6 +1298,10 @@ private void OnGeometryScaling_Click(object sender, RoutedEventArgs e)
public void Dispose()
{
RemoveViewModelsubscriptions(ViewModel);

Loaded -= WorkspaceView_Loaded;
Unloaded -= WorkspaceView_Unloaded;
LostFocus -= WorkspaceView_LostFocus;
DataContextChanged -= OnWorkspaceViewDataContextChanged;
}
}
Expand Down
Loading