From 108cc408146ac92900351d0ce2819d31145b9cc9 Mon Sep 17 00:00:00 2001 From: L45eMy Date: Tue, 13 Dec 2022 18:10:55 +0100 Subject: [PATCH 1/2] Update LayoutDocumentPane.cs Restore previously activated document on close --- .../Components/AvalonDock/Layout/LayoutDocumentPane.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs b/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs index f51452f9..966e820f 100644 --- a/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs +++ b/source/Components/AvalonDock/Layout/LayoutDocumentPane.cs @@ -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(); } /// @@ -223,6 +223,13 @@ internal void SetNextSelectedIndex() } } + /// Sets the current to the last activated child with IsEnabled == true + private void SetLastActivatedIndex() + { + var lastActivatedDocument = Children.Where(c => c.IsEnabled).OrderByDescending(c => c.LastActivationTimeStamp.GetValueOrDefault()).FirstOrDefault(); + SelectedContentIndex = Children.IndexOf(lastActivatedDocument); + } + /// Updates the property of this object. internal void UpdateIsDirectlyHostedInFloatingWindow() => RaisePropertyChanged(nameof(IsDirectlyHostedInFloatingWindow)); From 39b4b4f7bcc904ca388a39a61a44472b5ad7ca0b Mon Sep 17 00:00:00 2001 From: L45eMy Date: Tue, 13 Dec 2022 18:31:12 +0100 Subject: [PATCH 2/2] Set last activated after close in anchorables --- .../Components/AvalonDock/Layout/LayoutAnchorablePane.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs b/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs index b8d6d3e6..72517f3f 100644 --- a/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs +++ b/source/Components/AvalonDock/Layout/LayoutAnchorablePane.cs @@ -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(); + } + + /// Sets the current to the last activated child with IsEnabled == true + 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));