From c16bed1d9f357efa2a2afa2ddcfcf909fb7a5d03 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 9 Jul 2024 15:15:31 +0800 Subject: [PATCH] enhance: run commit search in background --- src/ViewModels/Repository.cs | 48 ++++++++++++++++++++++++------------ src/Views/Repository.axaml | 15 +++++++++-- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 1c087506..4f0ecfa1 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -259,6 +259,12 @@ namespace SourceGit.ViewModels } } + public bool IsSearchLoadingVisible + { + get => _isSearchLoadingVisible; + private set => SetProperty(ref _isSearchLoadingVisible, value); + } + public int SearchCommitFilterType { get => _searchCommitFilterType; @@ -533,29 +539,38 @@ namespace SourceGit.ViewModels if (_histories == null) return; - var visible = new List(); + IsSearchLoadingVisible = true; - if (_searchCommitFilterType == 0) + Task.Run(() => { - foreach (var c in _histories.Commits) + var visible = new List(); + + if (_searchCommitFilterType == 0) { - if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Subject.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) - || c.Committer.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)) + foreach (var c in _histories.Commits) { - visible.Add(c); + if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Subject.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Author.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Committer.Name.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Author.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase) + || c.Committer.Email.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)) + { + visible.Add(c); + } } } - } - else - { - visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result(); - } + else + { + visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result(); + } - SearchedCommits = visible; + Dispatcher.UIThread.Invoke(() => + { + SearchedCommits = visible; + IsSearchLoadingVisible = false; + }); + }); } public void ClearSearchBranchFilter() @@ -1948,6 +1963,7 @@ namespace SourceGit.ViewModels private object _selectedView = null; private bool _isSearching = false; + private bool _isSearchLoadingVisible = false; private int _searchCommitFilterType = 0; private string _searchCommitFilter = string.Empty; private List _searchedCommits = new List(); diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 569709a6..f6b1005a 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -633,8 +633,19 @@ HorizontalAlignment="Center" VerticalAlignment="Center" Width="48" Height="48" Data="{StaticResource Icons.Empty}" - Fill="{DynamicResource Brush.FG2}" - IsVisible="{Binding SearchedCommits.Count, Converter={x:Static c:IntConverters.IsZero}}"/> + Fill="{DynamicResource Brush.FG2}"> + + + + + + + + +