From 3bf962d745cde563bcc4d4412102bb2daf04bbb3 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 6 Mar 2024 19:46:19 +0800 Subject: [PATCH] feature: remember last active tab index if restore tabs is enabled --- src/ViewModels/Launcher.cs | 6 ++++++ src/ViewModels/Preference.cs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 97877a6d..c2dedc50 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -30,6 +30,11 @@ namespace SourceGit.ViewModels { OpenRepositoryInTab(node, null); } + + var lastActiveIdx = Preference.Instance.LastActiveTabIdx; + if (lastActiveIdx >= 0 && lastActiveIdx < Pages.Count) { + ActivePage = Pages[lastActiveIdx]; + } } } @@ -42,6 +47,7 @@ namespace SourceGit.ViewModels { } } + Preference.Instance.LastActiveTabIdx = Pages.IndexOf(ActivePage); Preference.Save(); } diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index d711622e..60f88d90 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -178,6 +178,11 @@ namespace SourceGit.ViewModels { set; } = new List(); + public int LastActiveTabIdx { + get; + set; + } = 0; + public static void AddNode(RepositoryNode node, RepositoryNode to = null) { var collection = to == null ? _instance._repositoryNodes : to.SubNodes; var list = new List();