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

@ -85,6 +85,18 @@ namespace SourceGit {
} }
if (repo != null) Models.Watcher.Open(repo); if (repo != null) Models.Watcher.Open(repo);
} else {
var restore = Models.Preference.Instance.Restore;
var actived = null as Models.Repository;
if (restore.IsEnabled && restore.Opened.Count > 0) {
foreach (var path in restore.Opened) {
var repo = Models.Preference.Instance.FindRepository(path);
if (repo != null) Models.Watcher.Open(repo);
if (path == restore.Actived) actived = repo;
}
if (actived != null) Models.Watcher.Open(actived);
}
} }
// 检测更新 // 检测更新

View file

@ -135,6 +135,27 @@ namespace SourceGit.Models {
public Change.DisplayMode ChangeInCommitInfo { get; set; } = Change.DisplayMode.Tree; public Change.DisplayMode ChangeInCommitInfo { get; set; } = Change.DisplayMode.Tree;
} }
/// <summary>
/// 恢复上次打开的窗口
/// </summary>
public class RestoreTabs {
/// <summary>
/// 是否开启该功能
/// </summary>
public bool IsEnabled { get; set; } = false;
/// <summary>
/// 上次打开的仓库
/// </summary>
public List<string> Opened { get; set; } = new List<string>();
/// <summary>
/// 最后浏览的仓库
/// </summary>
public string Actived { get; set; } = null;
}
/// <summary> /// <summary>
/// 全局配置 /// 全局配置
/// </summary> /// </summary>
@ -163,6 +184,7 @@ namespace SourceGit.Models {
public WindowInfo Window { get; set; } = new WindowInfo(); public WindowInfo Window { get; set; } = new WindowInfo();
public List<Group> Groups { get; set; } = new List<Group>(); public List<Group> Groups { get; set; } = new List<Group>();
public List<Repository> Repositories { get; set; } = new List<Repository>(); public List<Repository> Repositories { get; set; } = new List<Repository>();
public RestoreTabs Restore { get; set; } = new RestoreTabs();
#endregion #endregion
#region LOAD_SAVE #region LOAD_SAVE

View file

@ -364,6 +364,7 @@
<sys:String x:Key="Text.Preference.UseDark">Use dark theme</sys:String> <sys:String x:Key="Text.Preference.UseDark">Use dark theme</sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">Check for update</sys:String> <sys:String x:Key="Text.Preference.CheckUpdate">Check for update</sys:String>
<sys:String x:Key="Text.Preference.AutoFetch">Fetch remotes automatically</sys:String> <sys:String x:Key="Text.Preference.AutoFetch">Fetch remotes automatically</sys:String>
<sys:String x:Key="Text.Preference.RestoreTabs">Restore windows</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT SETTING</sys:String> <sys:String x:Key="Text.Preference.Git">GIT SETTING</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">Install Path :</sys:String> <sys:String x:Key="Text.Preference.Git.Path">Install Path :</sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String> <sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String>

View file

@ -363,6 +363,7 @@
<sys:String x:Key="Text.Preference.UseDark">启用—暗色主题</sys:String> <sys:String x:Key="Text.Preference.UseDark">启用—暗色主题</sys:String>
<sys:String x:Key="Text.Preference.CheckUpdate">启用检测更新</sys:String> <sys:String x:Key="Text.Preference.CheckUpdate">启用检测更新</sys:String>
<sys:String x:Key="Text.Preference.AutoFetch">启用定时自动拉取远程更新</sys:String> <sys:String x:Key="Text.Preference.AutoFetch">启用定时自动拉取远程更新</sys:String>
<sys:String x:Key="Text.Preference.RestoreTabs">启动时恢复上次打开的仓库</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT配置</sys:String> <sys:String x:Key="Text.Preference.Git">GIT配置</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">安装路径 </sys:String> <sys:String x:Key="Text.Preference.Git.Path">安装路径 </sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String> <sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String>

View file

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

View file

@ -1,4 +1,5 @@
using System; using System;
using System.ComponentModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
@ -16,6 +17,31 @@ namespace SourceGit.Views {
tabs.Add(); 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 #region OPEN_REPO
private void OpenRepository(Models.Repository repo) { private void OpenRepository(Models.Repository repo) {
if (tabs.Goto(repo.Path)) return; 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="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="8"/> <RowDefinition Height="8"/>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -136,20 +137,26 @@
Content="{StaticResource Text.Preference.AutoFetch}" Content="{StaticResource Text.Preference.AutoFetch}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.AutoFetchRemotes, Mode=TwoWay}"/> 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 --> <!-- Git Group -->
<TextBlock <TextBlock
Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2"
Text="{StaticResource Text.Preference.Git}" Text="{StaticResource Text.Preference.Git}"
FontSize="16" FontWeight="DemiBold" FontSize="16" FontWeight="DemiBold"
Foreground="{StaticResource Brush.FG2}"/> Foreground="{StaticResource Brush.FG2}"/>
<!-- Git Executable Path --> <!-- Git Executable Path -->
<TextBlock <TextBlock
Grid.Row="8" Grid.Column="0" Grid.Row="9" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.Path}" Text="{StaticResource Text.Preference.Git.Path}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<Grid Grid.Row="8" Grid.Column="1"> <Grid Grid.Row="9" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
@ -172,11 +179,11 @@
<!-- Default Clone Dir --> <!-- Default Clone Dir -->
<TextBlock <TextBlock
Grid.Row="9" Grid.Column="0" Grid.Row="10" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.Dir}" Text="{StaticResource Text.Preference.Git.Dir}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<Grid Grid.Row="9" Grid.Column="1"> <Grid Grid.Row="10" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
@ -199,36 +206,36 @@
<!-- User --> <!-- User -->
<TextBlock <TextBlock
Grid.Row="10" Grid.Column="0" Grid.Row="11" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.User}" Text="{StaticResource Text.Preference.Git.User}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<controls:TextEdit <controls:TextEdit
Grid.Row="10" Grid.Column="1" Grid.Row="11" Grid.Column="1"
Height="24" Height="24"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}" Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
Placeholder="{StaticResource Text.Preference.Git.User.Placeholder}"/> Placeholder="{StaticResource Text.Preference.Git.User.Placeholder}"/>
<!-- Email --> <!-- Email -->
<TextBlock <TextBlock
Grid.Row="11" Grid.Column="0" Grid.Row="12" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.Email}" Text="{StaticResource Text.Preference.Git.Email}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<controls:TextEdit <controls:TextEdit
Grid.Row="11" Grid.Column="1" Grid.Row="12" Grid.Column="1"
Height="24" Height="24"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}" Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
Placeholder="{StaticResource Text.Preference.Git.Email.Placeholder}"/> Placeholder="{StaticResource Text.Preference.Git.Email.Placeholder}"/>
<!-- CRLF --> <!-- CRLF -->
<TextBlock <TextBlock
Grid.Row="12" Grid.Column="0" Grid.Row="13" Grid.Column="0"
Text="{StaticResource Text.Preference.Git.CRLF}" Text="{StaticResource Text.Preference.Git.CRLF}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<ComboBox <ComboBox
Grid.Row="12" Grid.Column="1" Grid.Row="13" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}" ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
SelectedValuePath="Value" SelectedValuePath="Value"
@ -245,19 +252,19 @@
<!-- Merge Tool Group --> <!-- Merge Tool Group -->
<TextBlock <TextBlock
Grid.Row="14" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="15" Grid.Column="0" Grid.ColumnSpan="2"
Text="{StaticResource Text.Preference.Merger}" Text="{StaticResource Text.Preference.Merger}"
FontSize="16" FontWeight="DemiBold" FontSize="16" FontWeight="DemiBold"
Foreground="{StaticResource Brush.FG2}"/> Foreground="{StaticResource Brush.FG2}"/>
<!-- Merge Tool Type --> <!-- Merge Tool Type -->
<TextBlock <TextBlock
Grid.Row="15" Grid.Column="0" Grid.Row="16" Grid.Column="0"
Text="{StaticResource Text.Preference.Merger.Type}" Text="{StaticResource Text.Preference.Merger.Type}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<ComboBox <ComboBox
Grid.Row="15" Grid.Column="1" Grid.Row="16" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}" ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
DisplayMemberPath="Name" DisplayMemberPath="Name"
@ -267,11 +274,11 @@
<!-- Merge Tool Executable Path --> <!-- Merge Tool Executable Path -->
<TextBlock <TextBlock
Grid.Row="16" Grid.Column="0" Grid.Row="17" Grid.Column="0"
Text="{StaticResource Text.Preference.Merger.Path}" Text="{StaticResource Text.Preference.Merger.Path}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<Grid Grid.Row="16" Grid.Column="1"> <Grid Grid.Row="17" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
@ -294,12 +301,12 @@
<!-- Merge Tool Command --> <!-- Merge Tool Command -->
<TextBlock <TextBlock
Grid.Row="17" Grid.Column="0" Grid.Row="18" Grid.Column="0"
Text="{StaticResource Text.Preference.Merger.Cmd}" Text="{StaticResource Text.Preference.Merger.Cmd}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<TextBlock <TextBlock
Grid.Row="17" Grid.Column="1" Grid.Row="18" Grid.Column="1"
x:Name="txtMergeCmd" x:Name="txtMergeCmd"
Text="{Binding ElementName=me, Path=MergeCmd}" Text="{Binding ElementName=me, Path=MergeCmd}"
Foreground="{StaticResource Brush.FG2}"/> Foreground="{StaticResource Brush.FG2}"/>