From b1457fe39d7dd777d23843784abe9b8d0fd9d965 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 6 Sep 2024 09:57:22 +0800 Subject: [PATCH] feature: supports filter submodules (#443) --- src/Resources/Locales/de_DE.axaml | 2 +- src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/fr_FR.axaml | 2 +- src/Resources/Locales/pt_BR.axaml | 2 +- src/Resources/Locales/zh_CN.axaml | 2 +- src/Resources/Locales/zh_TW.axaml | 2 +- src/ViewModels/Repository.cs | 63 +++++++++++++++++++++++-------- src/Views/Repository.axaml | 12 +++--- src/Views/Repository.axaml.cs | 2 +- 9 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 7f6a6a18..adc22a10 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -482,6 +482,7 @@ Repository Einstellungen WEITER Öffne im Datei-Browser + Suche Branches & Tags & Submodules GEFILTERT: LOKALE BRANCHES Zum HEAD wechseln @@ -499,7 +500,6 @@ Commit-Nachricht SHA Autor & Committer - Suche Branches & Tags Zeige Tags als Baum Statistiken SUBMODULE diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index a6938954..68957769 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -484,6 +484,7 @@ Configure this repository CONTINUE Open In File Browser + Search Branches & Tags & Submodules FILTERED BY: LOCAL BRANCHES Navigate To HEAD @@ -501,7 +502,6 @@ Message SHA Author & Committer - Search Branches & Tags Show Tags as Tree Statistics SUBMODULES diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 6209a100..57bf0569 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -481,6 +481,7 @@ Configure this repository CONTINUE Ouvrir dans l'explorateur Windows + Search Branches & Tags & Submodules FILTERED BY: LOCAL BRANCHES Navigate To HEAD @@ -498,7 +499,6 @@ Message SHA Author & Committer - Search Branches & Tags Show Tags as Tree Statistics SUBMODULES diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 1b3dc48f..d7e3456f 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -474,6 +474,7 @@ Configurar este repositório CONTINUAR Abrir no Navegador de Arquivos + Pesquisar Branches & Tags & Submódulos FILTRADO POR: BRANCHES LOCAIS Navegar para HEAD @@ -491,7 +492,6 @@ Mensagem SHA Autor & Committer - Pesquisar Branches & Tags Mostrar Tags como Árvore Estatísticas SUBMÓDULOS diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index d25ef88e..550750a6 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -486,6 +486,7 @@ 配置本仓库 下一步 在文件浏览器中打开 + 快速查找分支、标签、子模块 过滤规则 : 本地分支 定位HEAD @@ -503,7 +504,6 @@ 提交信息 提交指纹 作者及提交者 - 快速查找分支、标签 以树型结构展示 提交统计 子模块列表 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index b63b2365..279f63b0 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -487,6 +487,7 @@ 設定本存放庫 下一步 在檔案瀏覽器中開啟 + 快速搜尋分支、標籤、子模組 篩選規則: 本機分支 回到 HEAD @@ -504,7 +505,6 @@ 提交訊息 提交編號 作者及提交者 - 快速搜尋分支、標籤 以樹型結構展示 提交統計 子模組列表 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 62709b16..4f550ddd 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -83,17 +83,18 @@ namespace SourceGit.ViewModels } } - public string SearchBranchFilter + public string Filter { - get => _searchBranchFilter; + get => _filter; set { - if (SetProperty(ref _searchBranchFilter, value)) + if (SetProperty(ref _filter, value)) { var builder = BuildBranchTree(_branches, _remotes); LocalBranchTrees = builder.Locals; RemoteBranchTrees = builder.Remotes; VisibleTags = BuildVisibleTags(); + VisibleSubmodules = BuildVisibleSubmodules(); } } } @@ -152,6 +153,12 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _submodules, value); } + public List VisibleSubmodules + { + get => _visibleSubmodules; + private set => SetProperty(ref _visibleSubmodules, value); + } + public int LocalChangesCount { get => _localChangesCount; @@ -391,6 +398,7 @@ namespace SourceGit.ViewModels _tags.Clear(); _visibleTags.Clear(); _submodules.Clear(); + _visibleSubmodules.Clear(); _searchedCommits.Clear(); _revisionFiles.Clear(); @@ -525,6 +533,11 @@ namespace SourceGit.ViewModels PopupHost.ShowAndStartPopup(new Cleanup(this)); } + public void ClearFilter() + { + Filter = string.Empty; + } + public void ClearHistoriesFilter() { _settings.Filters.Clear(); @@ -582,11 +595,6 @@ namespace SourceGit.ViewModels }); } - public void ClearSearchBranchFilter() - { - SearchBranchFilter = string.Empty; - } - public void SetWatcherEnabled(bool enabled) { _watcher?.SetEnabled(enabled); @@ -811,7 +819,12 @@ namespace SourceGit.ViewModels { var submodules = new Commands.QuerySubmodules(_fullpath).Result(); _watcher?.SetSubmodules(submodules); - Dispatcher.UIThread.Invoke(() => Submodules = submodules); + + Dispatcher.UIThread.Invoke(() => + { + Submodules = submodules; + VisibleSubmodules = BuildVisibleSubmodules(); + }); } public void RefreshWorkingCopyChanges() @@ -1919,7 +1932,7 @@ namespace SourceGit.ViewModels var builder = new BranchTreeNode.Builder(); builder.SetFilters(_settings.Filters); - if (string.IsNullOrEmpty(_searchBranchFilter)) + if (string.IsNullOrEmpty(_filter)) { builder.CollectExpandedNodes(_localBranchTrees, true); builder.CollectExpandedNodes(_remoteBranchTrees, false); @@ -1930,7 +1943,7 @@ namespace SourceGit.ViewModels var visibles = new List(); foreach (var b in branches) { - if (b.FullName.Contains(_searchBranchFilter, StringComparison.OrdinalIgnoreCase)) + if (b.FullName.Contains(_filter, StringComparison.OrdinalIgnoreCase)) visibles.Add(b); } @@ -1943,7 +1956,7 @@ namespace SourceGit.ViewModels private List BuildVisibleTags() { var visible = new List(); - if (string.IsNullOrEmpty(_searchBranchFilter)) + if (string.IsNullOrEmpty(_filter)) { visible.AddRange(_tags); } @@ -1951,7 +1964,7 @@ namespace SourceGit.ViewModels { foreach (var t in _tags) { - if (t.Name.Contains(_searchBranchFilter, StringComparison.OrdinalIgnoreCase)) + if (t.Name.Contains(_filter, StringComparison.OrdinalIgnoreCase)) visible.Add(t); } } @@ -1959,6 +1972,24 @@ namespace SourceGit.ViewModels return visible; } + private List BuildVisibleSubmodules() + { + var visible = new List(); + if (string.IsNullOrEmpty(_filter)) + { + visible.AddRange(_submodules); + } + else + { + foreach (var s in _submodules) + { + if (s.Path.Contains(_filter, StringComparison.OrdinalIgnoreCase)) + visible.Add(s); + } + } + return visible; + } + private void UpdateCurrentRevisionFilesForSearchSuggestion() { _revisionFiles.Clear(); @@ -2002,8 +2033,7 @@ namespace SourceGit.ViewModels private bool _isSubmoduleGroupExpanded = false; private bool _isWorktreeGroupExpanded = false; - private string _searchBranchFilter = string.Empty; - + private string _filter = string.Empty; private List _remotes = new List(); private List _branches = new List(); private Models.Branch _currentBranch = null; @@ -2013,8 +2043,9 @@ namespace SourceGit.ViewModels private List _tags = new List(); private List _visibleTags = new List(); private List _submodules = new List(); - private bool _includeUntracked = true; + private List _visibleSubmodules = new List(); + private bool _includeUntracked = true; private InProgressContext _inProgressContext = null; private bool _hasUnsolvedConflicts = false; private Models.Commit _searchResultSelectedCommit = null; diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 7a8bd2a1..ba4ac133 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -128,15 +128,15 @@ - + leftHeight);