Skip to content

Commit

Permalink
Add a Deactivated event handler in the Navigator Window
Browse files Browse the repository at this point in the history
- Close the window when it is not active and activate the selected content
  • Loading branch information
Wenveo committed Dec 26, 2022
1 parent 1d4d30d commit 11043c9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions source/Components/AvalonDock/Controls/NavigatorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ internal NavigatorWindow(DockingManager manager)
DataContext = this;
Loaded += OnLoaded;
Unloaded += OnUnloaded;
Deactivated += OnDeactivated;
UpdateThemeResources();
}

Expand Down Expand Up @@ -380,11 +381,7 @@ protected override void OnKeyUp(KeyEventArgs e)
{
if (!(e.Key == Key.Tab || e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down))
{
Close();
if (SelectedDocument != null && SelectedDocument.ActivateCommand.CanExecute(null))
SelectedDocument.ActivateCommand.Execute(null);
if (SelectedDocument == null && SelectedAnchorable != null && SelectedAnchorable.ActivateCommand.CanExecute(null))
SelectedAnchorable.ActivateCommand.Execute(null);
CloseAndActiveSelected();
e.Handled = true;
}
base.OnKeyUp(e);
Expand Down Expand Up @@ -520,6 +517,21 @@ private void OnLoaded(object sender, RoutedEventArgs e)

private void OnUnloaded(object sender, RoutedEventArgs e) => Unloaded -= OnUnloaded;

private void OnDeactivated(object sender, EventArgs e)
{
CloseAndActiveSelected();
}

private void CloseAndActiveSelected()
{
Deactivated -= OnDeactivated;
Close();
if (SelectedDocument != null && SelectedDocument.ActivateCommand.CanExecute(null))
SelectedDocument.ActivateCommand.Execute(null);
if (SelectedDocument == null && SelectedAnchorable != null && SelectedAnchorable.ActivateCommand.CanExecute(null))
SelectedAnchorable.ActivateCommand.Execute(null);
}

private void FocusSelectedItem(ListBox list)
{
if (list.SelectedIndex >= 0)
Expand Down

0 comments on commit 11043c9

Please sign in to comment.