Skip to content
Open
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
40 changes: 37 additions & 3 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public WorkspaceView()

InitializeComponent();

Loaded += WorkspaceView_Loaded;
Unloaded += WorkspaceView_Unloaded;

DataContextChanged += OnWorkspaceViewDataContextChanged;

// view of items to drag
Expand Down Expand Up @@ -906,20 +909,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;

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 +1291,10 @@ private void OnGeometryScaling_Click(object sender, RoutedEventArgs e)
public void Dispose()
{
RemoveViewModelsubscriptions(ViewModel);

Loaded -= WorkspaceView_Loaded;
Unloaded -= WorkspaceView_Unloaded;

DataContextChanged -= OnWorkspaceViewDataContextChanged;
}
}
Expand Down
Loading