Skip to content

Commit

Permalink
Merge pull request #417 from Noisrev/NavigatorWindow-Deactivated
Browse files Browse the repository at this point in the history
Close and active selected item when NavigatorWindow is inactive
  • Loading branch information
Dirkster99 authored Jan 29, 2023
2 parents fd7b4b0 + 11043c9 commit bae1291
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 bae1291

Please sign in to comment.