Skip to content

Commit

Permalink
Merge pull request #409 from L45eMy/master
Browse files Browse the repository at this point in the history
Restore previously activated document after closing active document
  • Loading branch information
Dirkster99 authored Dec 25, 2022
2 parents 4f47fe4 + 39b4b4f commit 9b56fe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,14 @@ private void AutoFixSelectedContent()
{
if (!_autoFixSelectedContent) return;
if (SelectedContentIndex >= ChildrenCount) SelectedContentIndex = Children.Count - 1;
if (SelectedContentIndex == -1 && ChildrenCount > 0) SetNextSelectedIndex();
if (SelectedContentIndex == -1 && ChildrenCount > 0) SetLastActivatedIndex();
}

/// <summary>Sets the current <see cref="SelectedContentIndex"/> to the last activated child with IsEnabled == true</summary>
private void SetLastActivatedIndex()
{
var lastActivatedDocument = Children.Where(c => c.IsEnabled).OrderByDescending(c => c.LastActivationTimeStamp.GetValueOrDefault()).FirstOrDefault();
SelectedContentIndex = Children.IndexOf(lastActivatedDocument);
}

private void OnParentChildrenCollectionChanged(object sender, EventArgs e) => RaisePropertyChanged(nameof(IsDirectlyHostedInFloatingWindow));
Expand Down
9 changes: 8 additions & 1 deletion source/Components/AvalonDock/Layout/LayoutDocumentPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void AutoFixSelectedContent()
{
if (!_autoFixSelectedContent) return;
if (SelectedContentIndex >= ChildrenCount) SelectedContentIndex = Children.Count - 1;
if (SelectedContentIndex == -1 && ChildrenCount > 0) SetNextSelectedIndex();
if (SelectedContentIndex == -1 && ChildrenCount > 0) SetLastActivatedIndex();
}

/// <summary>
Expand Down Expand Up @@ -223,6 +223,13 @@ internal void SetNextSelectedIndex()
}
}

/// <summary>Sets the current <see cref="SelectedContentIndex"/> to the last activated child with IsEnabled == true</summary>
private void SetLastActivatedIndex()
{
var lastActivatedDocument = Children.Where(c => c.IsEnabled).OrderByDescending(c => c.LastActivationTimeStamp.GetValueOrDefault()).FirstOrDefault();
SelectedContentIndex = Children.IndexOf(lastActivatedDocument);
}

/// <summary>Updates the <see cref="IsDirectlyHostedInFloatingWindow"/> property of this object.</summary>
internal void UpdateIsDirectlyHostedInFloatingWindow() => RaisePropertyChanged(nameof(IsDirectlyHostedInFloatingWindow));

Expand Down

0 comments on commit 9b56fe2

Please sign in to comment.