From 21df028601cb10464d8eff622fa4e92df82d29c6 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 11 Aug 2021 14:16:43 +0800 Subject: [PATCH] optimize: do NOT restore tabs when app exited via closing the last tab --- src/Views/Launcher.xaml.cs | 1 + src/Views/Widgets/PageTabBar.xaml.cs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Views/Launcher.xaml.cs b/src/Views/Launcher.xaml.cs index 1b660132..a5617934 100644 --- a/src/Views/Launcher.xaml.cs +++ b/src/Views/Launcher.xaml.cs @@ -22,6 +22,7 @@ namespace SourceGit.Views { if (!restore.IsEnabled) return; restore.Opened.Clear(); + restore.Actived = null; foreach (var tab in tabs.Tabs) { if (tab.IsWelcomePage) continue; diff --git a/src/Views/Widgets/PageTabBar.xaml.cs b/src/Views/Widgets/PageTabBar.xaml.cs index f81a9ea7..37931b8f 100644 --- a/src/Views/Widgets/PageTabBar.xaml.cs +++ b/src/Views/Widgets/PageTabBar.xaml.cs @@ -140,16 +140,15 @@ namespace SourceGit.Views.Widgets { public void CloseCurrent() { var curTab = container.SelectedItem as Tab; - if (Tabs.Count == 1) { + var idx = container.SelectedIndex; + Tabs.Remove(curTab); + if (Tabs.Count == 0) { Application.Current.Shutdown(); } else { - var idx = container.SelectedIndex; - Tabs.Remove(curTab); - RaiseEvent(new TabEventArgs(TabClosedEvent, this, curTab.Id)); - var last = Tabs.Count - 1; var next = idx > last ? Tabs[last] : Tabs[idx]; container.SelectedItem = next; + RaiseEvent(new TabEventArgs(TabClosedEvent, this, curTab.Id)); RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id)); } } @@ -199,17 +198,18 @@ namespace SourceGit.Views.Widgets { var curTab = container.SelectedItem as Tab; if (curTab != null && tab.Id == curTab.Id) { - if (Tabs.Count > 1) { - var idx = Tabs.IndexOf(tab); - Tabs.Remove(tab); + var idx = Tabs.IndexOf(tab); + Tabs.Remove(tab); - var last = Tabs.Count - 1; - var next = idx > last ? Tabs[last] : Tabs[idx]; - container.SelectedItem = next; - RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id)); - } else { + if (Tabs.Count == 0) { Application.Current.Shutdown(); + return; } + + var last = Tabs.Count - 1; + var next = idx > last ? Tabs[last] : Tabs[idx]; + container.SelectedItem = next; + RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id)); } else { Tabs.Remove(tab); }