optimize<PageTabBar>: do NOT restore tabs when app exited via closing the last tab

This commit is contained in:
leo 2021-08-11 14:16:43 +08:00
parent 3f2948dd06
commit 21df028601
2 changed files with 14 additions and 13 deletions

View file

@ -22,6 +22,7 @@ namespace SourceGit.Views {
if (!restore.IsEnabled) return; if (!restore.IsEnabled) return;
restore.Opened.Clear(); restore.Opened.Clear();
restore.Actived = null;
foreach (var tab in tabs.Tabs) { foreach (var tab in tabs.Tabs) {
if (tab.IsWelcomePage) continue; if (tab.IsWelcomePage) continue;

View file

@ -140,16 +140,15 @@ namespace SourceGit.Views.Widgets {
public void CloseCurrent() { public void CloseCurrent() {
var curTab = container.SelectedItem as Tab; var curTab = container.SelectedItem as Tab;
if (Tabs.Count == 1) {
Application.Current.Shutdown();
} else {
var idx = container.SelectedIndex; var idx = container.SelectedIndex;
Tabs.Remove(curTab); Tabs.Remove(curTab);
RaiseEvent(new TabEventArgs(TabClosedEvent, this, curTab.Id)); if (Tabs.Count == 0) {
Application.Current.Shutdown();
} else {
var last = Tabs.Count - 1; var last = Tabs.Count - 1;
var next = idx > last ? Tabs[last] : Tabs[idx]; var next = idx > last ? Tabs[last] : Tabs[idx];
container.SelectedItem = next; container.SelectedItem = next;
RaiseEvent(new TabEventArgs(TabClosedEvent, this, curTab.Id));
RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id)); RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id));
} }
} }
@ -199,17 +198,18 @@ namespace SourceGit.Views.Widgets {
var curTab = container.SelectedItem as Tab; var curTab = container.SelectedItem as Tab;
if (curTab != null && tab.Id == curTab.Id) { if (curTab != null && tab.Id == curTab.Id) {
if (Tabs.Count > 1) {
var idx = Tabs.IndexOf(tab); var idx = Tabs.IndexOf(tab);
Tabs.Remove(tab); Tabs.Remove(tab);
if (Tabs.Count == 0) {
Application.Current.Shutdown();
return;
}
var last = Tabs.Count - 1; var last = Tabs.Count - 1;
var next = idx > last ? Tabs[last] : Tabs[idx]; var next = idx > last ? Tabs[last] : Tabs[idx];
container.SelectedItem = next; container.SelectedItem = next;
RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id)); RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id));
} else {
Application.Current.Shutdown();
}
} else { } else {
Tabs.Remove(tab); Tabs.Remove(tab);
} }