From 918263130c4be81f26594599b5f18e2704287498 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 17 Oct 2022 10:12:59 +0800 Subject: [PATCH] feature: add sort supports --- src/Models/Preference.cs | 14 ++++++++++ src/Models/Repository.cs | 1 + src/Models/Watcher.cs | 1 + src/Resources/Icons.xaml | 2 +- src/Resources/Locales/en_US.xaml | 6 +++- src/Resources/Locales/zh_CN.xaml | 6 +++- src/Views/Launcher.xaml | 12 ++++---- src/Views/Launcher.xaml.cs | 6 ++++ src/Views/Widgets/Welcome.xaml | 42 ++++++++++------------------ src/Views/Widgets/Welcome.xaml.cs | 46 +++++++++++++++++++++++++++++++ 10 files changed, 101 insertions(+), 35 deletions(-) diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index bb16df69..04b7d70d 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -18,6 +18,15 @@ namespace SourceGit.Models { "preference_v4.json"); private static Preference instance = null; + /// + /// 起始页仓库列表排序方式 + /// + public enum SortMethod { + ByNameASC, + ByNameDESC, + ByRecentlyOpened, + } + /// /// 通用配置 /// @@ -68,6 +77,11 @@ namespace SourceGit.Models { /// 上一次检测的时间(用于控制每天仅第一次启动软件时,检测) /// public int LastCheckDay { get; set; } = 0; + + /// + /// 起始页仓库列表排序规则 + /// + public SortMethod SortBy { get; set; } = SortMethod.ByNameASC; } /// diff --git a/src/Models/Repository.cs b/src/Models/Repository.cs index 792e5b49..e0be31bf 100644 --- a/src/Models/Repository.cs +++ b/src/Models/Repository.cs @@ -28,6 +28,7 @@ namespace SourceGit.Models { public string Path { get; set; } = ""; public string GitDir { get; set; } = ""; public int Bookmark { get; set; } = 0; + public long LastOpenTime { get; set; } = 0; public List SubTrees { get; set; } = new List(); public List Filters { get; set; } = new List(); public List CommitMessages { get; set; } = new List(); diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index bbda2ed5..f2234a97 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -56,6 +56,7 @@ namespace SourceGit.Models { var watcher = new Watcher(); watcher.Start(repo.Path, repo.GitDir); all.Add(repo.Path, watcher); + repo.LastOpenTime = DateTime.Now.ToFileTime(); Opened?.Invoke(repo); } diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index d81bc0ac..6dfa506a 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -68,5 +68,5 @@ M683 537h-144v-142h-142V283H239a44 44 0 00-41 41v171a56 56 0 0014 34l321 321a41 41 0 0058 0l174-174a41 41 0 000-58zm-341-109a41 41 0 110-58a41 41 0 010 58zM649 284V142h-69v142h-142v68h142v142h69v-142h142v-68h-142z M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z - M597 256h85v85h213a43 43 0 0143 43v320L683 555l2 344 95-92L855 939H384a43 43 0 01-43-43v-213H256v-85h85V384a43 43 0 0143-43h213V256zm341 484V896a43 43 0 01-2 13l-84-145L939 740zM171 597v85H85v-85h85zm0-171v85H85v-85h85zm0-171v85H85V256h85zm0-171v85H85V85h85zm171 0v85H256V85h85zm171 0v85h-85V85h85zm171 0v85h-85V85h85z + M426.7 554.7v-85.3h341.3v85.3h-341.3m0 256v-85.3h170.7v85.3h-170.7m0-512V213.3h512v85.3H426.7M256 725.3h106.7L213.3 874.7 64 725.3H170.7V298.7H64L213.3 149.3 362.7 298.7H256v426.7z \ No newline at end of file diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index a1a1fd90..e3ee6da2 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -297,13 +297,13 @@ Into : Merge Option : - Free & open source GUI tool for git users Open Repository Open Terminal Clone Repository REPOSITORIES Delete Search Repositories ... + Sort Pull Pull (Fetch & Merge) @@ -509,6 +509,10 @@ Nov Dec + By Name + By Name Inversed + By Recently Opened + Git has NOT been configured. Please to go [Preference] and configure it first. Path[{0}] not exists! Can NOT locate bash.exe. Make sure bash.exe exists under the same folder with git.exe diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index f8ae2882..049c0aea 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -296,13 +296,13 @@ 目标分支 : 合并方式 : - 开源的轻量级Git图形客户端 打开本地仓库 打开GIT终端 克隆远程仓库 收藏/书签 删除 快速查找仓库 + 排序 拉回 拉回(拉取并合并) @@ -508,6 +508,10 @@ 11月 12月 + 按名称正序 + 按名称倒序 + 按最近访问 + GIT尚未配置。请打开【偏好设置】配置GIT路径。 路径({0})不存在或不可读取! 无法找到bash.exe,请确保其在git.exe同目录中! diff --git a/src/Views/Launcher.xaml b/src/Views/Launcher.xaml index ec5cc273..28a5a4c3 100644 --- a/src/Views/Launcher.xaml +++ b/src/Views/Launcher.xaml @@ -34,14 +34,16 @@ - + Click="ToggleMainMenu"> + + - - @@ -24,34 +22,15 @@ - - - - - - - + - + + + + - + @@ -116,7 +104,7 @@ - + @@ -191,6 +179,6 @@ - + diff --git a/src/Views/Widgets/Welcome.xaml.cs b/src/Views/Widgets/Welcome.xaml.cs index 33eea2be..8f2d4591 100644 --- a/src/Views/Widgets/Welcome.xaml.cs +++ b/src/Views/Widgets/Welcome.xaml.cs @@ -67,6 +67,40 @@ namespace SourceGit.Views.Widgets { if (MakeSureReady()) new Popups.Clone().Show(); } + private void FillSortMenu(ContextMenu menu, Models.Preference.SortMethod desired, string label) { + var item = new MenuItem(); + item.Header = App.Text(label); + item.Click += (s, ev) => { + Models.Preference.Instance.General.SortBy = desired; + UpdateVisibles(); + }; + + if (Models.Preference.Instance.General.SortBy == desired) { + var icon = new System.Windows.Shapes.Path(); + icon.Data = FindResource("Icon.Check") as Geometry; + icon.Fill = FindResource("Brush.FG1") as Brush; + icon.Width = 12; + item.Icon = icon; + } + + menu.Items.Add(item); + } + + private void OnSortMethodClicked(object sender, RoutedEventArgs e) { + var menu = new ContextMenu(); + menu.Placement = PlacementMode.Bottom; + menu.PlacementTarget = sender as Button; + menu.StaysOpen = false; + menu.Focusable = true; + + FillSortMenu(menu, Models.Preference.SortMethod.ByNameASC, "Sort.NameAsc"); + FillSortMenu(menu, Models.Preference.SortMethod.ByNameDESC, "Sort.NameDesc"); + FillSortMenu(menu, Models.Preference.SortMethod.ByRecentlyOpened, "Sort.RecentlyOpened"); + + menu.IsOpen = true; + e.Handled = true; + } + private void OnRemoveRepository(object sender, RoutedEventArgs e) { var repo = (sender as Button).DataContext as Models.Repository; if (repo == null) return; @@ -206,6 +240,18 @@ namespace SourceGit.Views.Widgets { } } + switch (Models.Preference.Instance.General.SortBy) { + case Models.Preference.SortMethod.ByNameASC: + visibles.Sort((l, r) => l.Name.CompareTo(r.Name)); + break; + case Models.Preference.SortMethod.ByNameDESC: + visibles.Sort((l, r) => r.Name.CompareTo(l.Name)); + break; + default: + visibles.Sort((l, r) => r.LastOpenTime.CompareTo(l.LastOpenTime)); + break; + } + repoList.ItemsSource = visibles; }