Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Restore previously activated document after closing active document #409

Merged
merged 2 commits into from
Dec 25, 2022
Merged
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
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