enhance: run commit search in background

This commit is contained in:
leo 2024-07-09 15:15:31 +08:00
parent d3f7c31caf
commit c16bed1d9f
No known key found for this signature in database
2 changed files with 45 additions and 18 deletions

View file

@ -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<Models.Commit>();
IsSearchLoadingVisible = true;
if (_searchCommitFilterType == 0)
Task.Run(() =>
{
foreach (var c in _histories.Commits)
var visible = new List<Models.Commit>();
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<Models.Commit> _searchedCommits = new List<Models.Commit>();

View file

@ -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}">
<Path.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="SearchedCommits.Count" Converter="{x:Static c:IntConverters.IsZero}"/>
<Binding Path="IsSearchLoadingVisible" Converter="{x:Static BoolConverters.Not}"/>
</MultiBinding>
</Path.IsVisible>
</Path>
<v:LoadingIcon Grid.Row="2"
Width="48" Height="48"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsSearchLoadingVisible}"/>
</Grid>
</Grid>