enhance: supports search commits by changed file path like src/Commands/* or */Add.cs.

This commit is contained in:
leo 2024-06-07 18:43:37 +08:00
parent 89f2d3dd11
commit 6426da3289
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
5 changed files with 59 additions and 16 deletions

View file

@ -384,7 +384,9 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">ADD REMOTE</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">RESOLVE</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">Search Commit</x:String>
<x:String x:Key="Text.Repository.SearchTip" xml:space="preserve">Search Author/Committer/Message/SHA</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">Search By</x:String>
<x:String x:Key="Text.Repository.Search.ByBaseInfo" xml:space="preserve">Information</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">Statistics</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">SUBMODULES</x:String>
<x:String x:Key="Text.Repository.Submodules.Add" xml:space="preserve">ADD SUBMODULE</x:String>

View file

@ -387,7 +387,9 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">添加远程</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解决冲突</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">查找提交</x:String>
<x:String x:Key="Text.Repository.SearchTip" xml:space="preserve">支持搜索作者/提交者/主题/指纹</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">搜索途径</x:String>
<x:String x:Key="Text.Repository.Search.ByBaseInfo" xml:space="preserve">摘要</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">文件</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交统计</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模块列表</x:String>
<x:String x:Key="Text.Repository.Submodules.Add" xml:space="preserve">添加子模块</x:String>

View file

@ -387,7 +387,9 @@
<x:String x:Key="Text.Repository.Remotes.Add" xml:space="preserve">新增遠端</x:String>
<x:String x:Key="Text.Repository.Resolve" xml:space="preserve">解決衝突</x:String>
<x:String x:Key="Text.Repository.Search" xml:space="preserve">查詢提交</x:String>
<x:String x:Key="Text.Repository.SearchTip" xml:space="preserve">支援搜尋作者/提交者/主題/指紋</x:String>
<x:String x:Key="Text.Repository.Search.By" xml:space="preserve">查詢方式</x:String>
<x:String x:Key="Text.Repository.Search.ByBaseInfo" xml:space="preserve">摘要</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">檔案</x:String>
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交統計</x:String>
<x:String x:Key="Text.Repository.Submodules" xml:space="preserve">子模組列表</x:String>
<x:String x:Key="Text.Repository.Submodules.Add" xml:space="preserve">新增子模組</x:String>

View file

@ -185,6 +185,13 @@ namespace SourceGit.ViewModels
}
}
[JsonIgnore]
public int SearchCommitFilterType
{
get => _searchCommitFilterType;
set => SetProperty(ref _searchCommitFilterType, value);
}
[JsonIgnore]
public string SearchCommitFilter
{
@ -416,6 +423,9 @@ namespace SourceGit.ViewModels
return;
var visible = new List<Models.Commit>();
if (_searchCommitFilterType == 0)
{
foreach (var c in _histories.Commits)
{
if (c.SHA.Contains(_searchCommitFilter, StringComparison.OrdinalIgnoreCase)
@ -428,6 +438,11 @@ namespace SourceGit.ViewModels
visible.Add(c);
}
}
}
else
{
visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result();
}
SearchedCommits = visible;
}
@ -1508,6 +1523,7 @@ namespace SourceGit.ViewModels
private object _selectedView = null;
private bool _isSearching = false;
private int _searchCommitFilterType = 0;
private string _searchCommitFilter = string.Empty;
private List<Models.Commit> _searchedCommits = new List<Models.Commit>();

View file

@ -493,17 +493,17 @@
</Grid>
<!-- Left Search Mode -->
<Grid Grid.Column="0" RowDefinitions="32,*" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">
<Grid Grid.Column="0" RowDefinitions="32,32,*" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">
<!-- Search -->
<TextBox Grid.Row="0"
x:Name="txtSearchCommitsBox"
Margin="4,2"
Margin="4,2,4,0"
Height="24"
BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}"
Background="{DynamicResource Brush.Contents}"
CornerRadius="4"
Watermark="{DynamicResource Text.Repository.SearchTip}"
Watermark="{DynamicResource Text.Repository.Search}"
Text="{Binding SearchCommitFilter, Mode=TwoWay}"
VerticalContentAlignment="Center"
KeyDown="OnSearchKeyDown">
@ -529,7 +529,27 @@
</TextBox.InnerRightContent>
</TextBox>
<DataGrid Grid.Row="1"
<Grid Grid.Row="1" ColumnDefinitions="Auto,*" Margin="4,0">
<TextBlock Grid.Column="0"
Text="{DynamicResource Text.Repository.Search.By}"
Foreground="{DynamicResource Brush.FG2}"
Margin="2,0,0,0"/>
<ComboBox Grid.Column="1"
MinHeight="24" Height="24"
Padding="8,0"
Background="{DynamicResource Brush.Contents}"
BorderBrush="{DynamicResource Brush.Border2}"
HorizontalAlignment="Right"
SelectedIndex="{Binding SearchCommitFilterType, Mode=TwoWay}">
<ComboBox.Items>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByBaseInfo}" FontSize="12"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}" FontSize="12"/>
</ComboBox.Items>
</ComboBox>
</Grid>
<DataGrid Grid.Row="2"
ItemsSource="{Binding SearchedCommits}"
SelectionMode="Single"
SelectedItem="{Binding SearchResultSelectedCommit, Mode=OneWay}"
@ -544,6 +564,7 @@
BorderBrush="{DynamicResource Brush.Border2}"
Background="{DynamicResource Brush.Contents}"
Margin="4,0,4,4"
CornerRadius="4"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
SelectionChanged="OnSearchResultDataGridSelectionChanged">
@ -572,7 +593,7 @@
</DataGrid.Columns>
</DataGrid>
<Path Grid.Row="1"
<Path Grid.Row="2"
HorizontalAlignment="Center" VerticalAlignment="Center"
Width="48" Height="48"
Data="{StaticResource Icons.Empty}"