From 84fda6a8db893e256f69542ad9f2b17fee274ee4 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 18 Sep 2024 21:35:33 +0800 Subject: [PATCH] feature: add property `RestoreOnStartup` property to `ViewModels.Workspace` (#488) --- src/Resources/Locales/de_DE.axaml | 3 +- src/Resources/Locales/en_US.axaml | 3 +- src/Resources/Locales/zh_CN.axaml | 3 +- src/Resources/Locales/zh_TW.axaml | 3 +- src/ViewModels/ConfigureWorkspace.cs | 5 +--- src/ViewModels/Launcher.cs | 2 +- src/ViewModels/Preference.cs | 42 +++++++++++++++++++++------- src/ViewModels/Workspace.cs | 11 ++++++-- src/Views/ConfigureWorkspace.axaml | 12 +++++--- 9 files changed, 59 insertions(+), 25 deletions(-) diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 586e2ed9..5cea52ce 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -150,8 +150,9 @@ Benutzername Benutzername für dieses Repository Arbeitsplätze - Name Farbe + Name + Zuletzt geöffnete Tabs beim Starten wiederherstellen Kopieren Kopiere gesamten Text COMMIT-NACHRICHT KOPIEREN diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 72a6a8ba..fec41bb4 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -149,8 +149,9 @@ User Name User name for this repository Workspaces - Name Color + Name + Restore tabs on startup Copy Copy All Text COPY MESSAGE diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 6c8739fe..0ae65f91 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -152,8 +152,9 @@ 用户名 应用于本仓库的用户名 工作区 - 名称 颜色 + 名称 + 启动时恢复打开的仓库 复制 复制全部文本 复制内容 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index defd33d1..c90893f7 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -152,8 +152,9 @@ 使用者名稱 用於本存放庫的使用者名稱 工作區 - 名稱 顏色 + 名稱 + 啟動時還原上次開啟的存放庫 複製 複製全部內容 複製內容 diff --git a/src/ViewModels/ConfigureWorkspace.cs b/src/ViewModels/ConfigureWorkspace.cs index 2c6c5595..23b0a1ae 100644 --- a/src/ViewModels/ConfigureWorkspace.cs +++ b/src/ViewModels/ConfigureWorkspace.cs @@ -36,10 +36,7 @@ namespace SourceGit.ViewModels public void Add() { - var workspace = new Workspace(); - workspace.Name = $"Unnamed {DateTime.Now:yyyy-MM-dd HH:mm:ss}"; - workspace.Color = 4278221015; - + var workspace = new Workspace() { Name = $"Unnamed {DateTime.Now:yyyy-MM-dd HH:mm:ss}" }; Preference.Instance.Workspaces.Add(workspace); Workspaces.Add(workspace); Selected = workspace; diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 6ed9cee1..15c22c16 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -81,7 +81,7 @@ namespace SourceGit.ViewModels } else { - ActiveWorkspace = new Workspace() { Name = "Unnamed", Color = 4278221015 }; + ActiveWorkspace = new Workspace() { Name = "Unnamed" }; foreach (var w in pref.Workspaces) w.IsActive = false; diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 2df40675..ef63d61e 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -22,15 +22,9 @@ namespace SourceGit.ViewModels _isLoading = false; } - if (!_instance.IsGitConfigured()) - _instance.GitInstallPath = Native.OS.FindGitExecutable(); - - if (_instance._shellOrTerminal == -1) - _instance.AutoSelectShellOrTerminal(); - - if (_instance.Workspaces.Count == 0) - _instance.Workspaces.Add(new Workspace() { Name = "Default", Color = 4278221015 }); - + _instance.PrepareGit(); + _instance.PrepareShellOrTerminal(); + _instance.PrepareWorkspaces(); return _instance; } } @@ -501,8 +495,18 @@ namespace SourceGit.ViewModels } } - private void AutoSelectShellOrTerminal() + private void PrepareGit() { + var path = Native.OS.GitExecutable; + if (string.IsNullOrEmpty(path) || !File.Exists(path)) + GitInstallPath = Native.OS.FindGitExecutable(); + } + + private void PrepareShellOrTerminal() + { + if (_shellOrTerminal >= 0) + return; + for (int i = 0; i < Models.ShellOrTerminal.Supported.Count; i++) { var shell = Models.ShellOrTerminal.Supported[i]; @@ -514,6 +518,24 @@ namespace SourceGit.ViewModels } } + private void PrepareWorkspaces() + { + if (Workspaces.Count == 0) + { + Workspaces.Add(new Workspace() { Name = "Default" }); + return; + } + + foreach (var workspace in Workspaces) + { + if (!workspace.RestoreOnStartup) + { + workspace.Repositories.Clear(); + workspace.ActiveIdx = 0; + } + } + } + private RepositoryNode FindNodeRecursive(string id, List collection) { foreach (var node in collection) diff --git a/src/ViewModels/Workspace.cs b/src/ViewModels/Workspace.cs index 4c7c288a..c1c586bc 100644 --- a/src/ViewModels/Workspace.cs +++ b/src/ViewModels/Workspace.cs @@ -43,6 +43,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _isActive, value); } + public bool RestoreOnStartup + { + get => _restoreOnStartup; + set => SetProperty(ref _restoreOnStartup, value); + } + [JsonIgnore] public IBrush Brush { @@ -57,8 +63,9 @@ namespace SourceGit.ViewModels } private string _name = string.Empty; - private uint _color = 0; + private uint _color = 4278221015; private bool _isActive = false; - private IBrush _brush = null; + private bool _restoreOnStartup = true; + private IBrush _brush = new SolidColorBrush(4278221015); } } diff --git a/src/Views/ConfigureWorkspace.axaml b/src/Views/ConfigureWorkspace.axaml index e245032e..582995b8 100644 --- a/src/Views/ConfigureWorkspace.axaml +++ b/src/Views/ConfigureWorkspace.axaml @@ -46,7 +46,7 @@ - + @@ -107,12 +107,16 @@ - + - - + + + +