feature<Launcher>: supports restore last opened tabs when startup

This commit is contained in:
leo 2021-07-06 09:58:36 +08:00
parent 2ddc61e162
commit f6c17e7d34
7 changed files with 90 additions and 20 deletions

View file

@ -13,7 +13,8 @@
MinWidth="1280" MinHeight="720"
Title="{StaticResource Text.About.Title}"
Width="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Width, Mode=TwoWay}"
Height="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Height, Mode=TwoWay}">
Height="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Height, Mode=TwoWay}"
Closing="OnClosing">
<controls:DragDropAdornerLayer>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>

View file

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
@ -16,6 +17,31 @@ namespace SourceGit.Views {
tabs.Add();
}
private void OnClosing(object sender, CancelEventArgs e) {
var restore = Models.Preference.Instance.Restore;
if (!restore.IsEnabled) return;
restore.Opened.Clear();
foreach (var tab in tabs.Tabs) {
if (tab.IsWelcomePage) continue;
// 仅支持恢复加入管理的仓库页Submodules等未加入管理的不支持
var repo = Models.Preference.Instance.FindRepository(tab.Id);
if (repo != null) restore.Opened.Add(tab.Id);
}
if (restore.Opened.Count > 0) {
if (restore.Opened.IndexOf(tabs.Current) >= 0) {
restore.Actived = tabs.Current;
} else {
restore.Actived = restore.Opened[0];
}
}
Models.Preference.Save();
}
#region OPEN_REPO
private void OpenRepository(Models.Repository repo) {
if (tabs.Goto(repo.Path)) return;

View file

@ -58,6 +58,7 @@
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="8"/>
<RowDefinition Height="36"/>
<RowDefinition Height="28"/>
@ -135,21 +136,27 @@
Grid.Row="5" Grid.Column="1"
Content="{StaticResource Text.Preference.AutoFetch}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.AutoFetchRemotes, Mode=TwoWay}"/>
<!-- Restore Windows -->
<CheckBox
Grid.Row="6" Grid.Column="1"
Content="{StaticResource Text.Preference.RestoreTabs}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Restore.IsEnabled, Mode=TwoWay}"/>
<!-- Git Group -->
<TextBlock
Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2"
Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2"
Text="{StaticResource Text.Preference.Git}"
FontSize="16" FontWeight="DemiBold"
Foreground="{StaticResource Brush.FG2}"/>
<!-- Git Executable Path -->
<TextBlock
Grid.Row="8" Grid.Column="0"
Grid.Row="9" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.Path}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<Grid Grid.Row="8" Grid.Column="1">
<Grid Grid.Row="9" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
@ -172,11 +179,11 @@
<!-- Default Clone Dir -->
<TextBlock
Grid.Row="9" Grid.Column="0"
Grid.Row="10" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.Dir}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<Grid Grid.Row="9" Grid.Column="1">
<Grid Grid.Row="10" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
@ -199,36 +206,36 @@
<!-- User -->
<TextBlock
Grid.Row="10" Grid.Column="0"
Grid.Row="11" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.User}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<controls:TextEdit
Grid.Row="10" Grid.Column="1"
Grid.Row="11" Grid.Column="1"
Height="24"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
Placeholder="{StaticResource Text.Preference.Git.User.Placeholder}"/>
<!-- Email -->
<TextBlock
Grid.Row="11" Grid.Column="0"
Grid.Row="12" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.Email}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<controls:TextEdit
Grid.Row="11" Grid.Column="1"
Grid.Row="12" Grid.Column="1"
Height="24"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
Placeholder="{StaticResource Text.Preference.Git.Email.Placeholder}"/>
<!-- CRLF -->
<TextBlock
Grid.Row="12" Grid.Column="0"
Grid.Row="13" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.CRLF}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<ComboBox
Grid.Row="12" Grid.Column="1"
Grid.Row="13" Grid.Column="1"
Height="24"
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
SelectedValuePath="Value"
@ -245,19 +252,19 @@
<!-- Merge Tool Group -->
<TextBlock
Grid.Row="14" Grid.Column="0" Grid.ColumnSpan="2"
Grid.Row="15" Grid.Column="0" Grid.ColumnSpan="2"
Text="{StaticResource Text.Preference.Merger}"
FontSize="16" FontWeight="DemiBold"
Foreground="{StaticResource Brush.FG2}"/>
<!-- Merge Tool Type -->
<TextBlock
Grid.Row="15" Grid.Column="0"
Grid.Row="16" Grid.Column="0"
Text="{StaticResource Text.Preference.Merger.Type}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<ComboBox
Grid.Row="15" Grid.Column="1"
Grid.Row="16" Grid.Column="1"
Height="24"
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
DisplayMemberPath="Name"
@ -267,11 +274,11 @@
<!-- Merge Tool Executable Path -->
<TextBlock
Grid.Row="16" Grid.Column="0"
Grid.Row="17" Grid.Column="0"
Text="{StaticResource Text.Preference.Merger.Path}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<Grid Grid.Row="16" Grid.Column="1">
<Grid Grid.Row="17" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
@ -294,12 +301,12 @@
<!-- Merge Tool Command -->
<TextBlock
Grid.Row="17" Grid.Column="0"
Grid.Row="18" Grid.Column="0"
Text="{StaticResource Text.Preference.Merger.Cmd}"
HorizontalAlignment="Right"
Margin="0,0,6,0"/>
<TextBlock
Grid.Row="17" Grid.Column="1"
Grid.Row="18" Grid.Column="1"
x:Name="txtMergeCmd"
Text="{Binding ElementName=me, Path=MergeCmd}"
Foreground="{StaticResource Brush.FG2}"/>