feature: supports to copy selected folder path in changes and rename searching by file to searching by path (#1470)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-06-28 12:38:03 +08:00
parent 1acf2a14df
commit 133b69de4a
8 changed files with 85 additions and 15 deletions

View File

@@ -41,7 +41,7 @@ namespace SourceGit.Commands
search = argsBuilder.ToString();
}
else if (method == Models.CommitSearchMethod.ByFile)
else if (method == Models.CommitSearchMethod.ByPath)
{
search += $"-- \"{filter}\"";
}

View File

@@ -12,7 +12,7 @@ namespace SourceGit.Models
ByAuthor,
ByCommitter,
ByMessage,
ByFile,
ByPath,
ByContent,
}

View File

@@ -648,8 +648,8 @@
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">Author</x:String>
<x:String x:Key="Text.Repository.Search.ByCommitter" xml:space="preserve">Committer</x:String>
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">Content</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">Path</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">Current Branch</x:String>
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">Show Submodules as Tree</x:String>

View File

@@ -652,8 +652,8 @@
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">作者</x:String>
<x:String x:Key="Text.Repository.Search.ByCommitter" xml:space="preserve">提交者</x:String>
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">变更内容</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">文件</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交信息</x:String>
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">路径</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指纹</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">仅在当前分支中查找</x:String>
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以树型结构展示</x:String>

View File

@@ -652,8 +652,8 @@
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">作者</x:String>
<x:String x:Key="Text.Repository.Search.ByCommitter" xml:space="preserve">提交者</x:String>
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">變更內容</x:String>
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">檔案</x:String>
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交訊息</x:String>
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">路徑</x:String>
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交編號</x:String>
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">僅搜尋目前分支</x:String>
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以樹型結構展示</x:String>

View File

@@ -2891,7 +2891,7 @@ namespace SourceGit.ViewModels
private bool IsSearchingCommitsByFilePath()
{
return _isSearching && _searchCommitFilterType == (int)Models.CommitSearchMethod.ByFile;
return _isSearching && _searchCommitFilterType == (int)Models.CommitSearchMethod.ByPath;
}
private void CalcWorktreeFilesForSearching()

View File

@@ -594,7 +594,7 @@ namespace SourceGit.ViewModels
if (_selectedUnstaged.Count == 1)
{
var change = _selectedUnstaged[0];
var path = Path.GetFullPath(Path.Combine(_repo.FullPath, change.Path));
var path = Native.OS.GetAbsPath(_repo.FullPath, change.Path);
var explore = new MenuItem();
explore.Header = App.Text("RevealFile");
@@ -602,7 +602,11 @@ namespace SourceGit.ViewModels
explore.IsEnabled = File.Exists(path) || Directory.Exists(path);
explore.Click += (_, e) =>
{
Native.OS.OpenInFileManager(path, true);
if (string.IsNullOrEmpty(selectedSingleFolder))
Native.OS.OpenInFileManager(path, true);
else
Native.OS.OpenInFileManager(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder), true);
e.Handled = true;
};
menu.Items.Add(explore);
@@ -982,7 +986,11 @@ namespace SourceGit.ViewModels
copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (_, e) =>
{
App.CopyText(change.Path);
if (string.IsNullOrEmpty(selectedSingleFolder))
App.CopyText(change.Path);
else
App.CopyText(selectedSingleFolder);
e.Handled = true;
};
menu.Items.Add(copy);
@@ -992,7 +1000,11 @@ namespace SourceGit.ViewModels
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyFullPath.Click += (_, e) =>
{
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, change.Path));
if (string.IsNullOrEmpty(selectedSingleFolder))
App.CopyText(path);
else
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
e.Handled = true;
};
menu.Items.Add(copyFullPath);
@@ -1154,6 +1166,27 @@ namespace SourceGit.ViewModels
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(addToIgnore);
var copy = new MenuItem();
copy.Header = App.Text("CopyPath");
copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (_, e) =>
{
App.CopyText(selectedSingleFolder);
e.Handled = true;
};
var copyFullPath = new MenuItem();
copyFullPath.Header = App.Text("CopyPath");
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyFullPath.Click += (_, e) =>
{
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
e.Handled = true;
};
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(copy);
menu.Items.Add(copyFullPath);
}
}
@@ -1205,7 +1238,7 @@ namespace SourceGit.ViewModels
if (_selectedStaged.Count == 1)
{
var change = _selectedStaged[0];
var path = Path.GetFullPath(Path.Combine(_repo.FullPath, change.Path));
var path = Native.OS.GetAbsPath(_repo.FullPath, change.Path);
var explore = new MenuItem();
explore.IsEnabled = File.Exists(path) || Directory.Exists(path);
@@ -1213,7 +1246,11 @@ namespace SourceGit.ViewModels
explore.Icon = App.CreateMenuIcon("Icons.Explore");
explore.Click += (_, e) =>
{
Native.OS.OpenInFileManager(path, true);
if (string.IsNullOrEmpty(selectedSingleFolder))
Native.OS.OpenInFileManager(path, true);
else
Native.OS.OpenInFileManager(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder), true);
e.Handled = true;
};
@@ -1391,7 +1428,11 @@ namespace SourceGit.ViewModels
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyPath.Click += (_, e) =>
{
App.CopyText(change.Path);
if (string.IsNullOrEmpty(selectedSingleFolder))
App.CopyText(change.Path);
else
App.CopyText(selectedSingleFolder);
e.Handled = true;
};
@@ -1400,7 +1441,11 @@ namespace SourceGit.ViewModels
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyFullPath.Click += (_, e) =>
{
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, change.Path));
if (string.IsNullOrEmpty(selectedSingleFolder))
App.CopyText(path);
else
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
e.Handled = true;
};
@@ -1480,6 +1525,31 @@ namespace SourceGit.ViewModels
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(ai);
}
if (!string.IsNullOrEmpty(selectedSingleFolder))
{
var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath");
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyPath.Click += (_, e) =>
{
App.CopyText(selectedSingleFolder);
e.Handled = true;
};
var copyFullPath = new MenuItem();
copyFullPath.Header = App.Text("CopyFullPath");
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
copyFullPath.Click += (_, e) =>
{
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
e.Handled = true;
};
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(copyPath);
menu.Items.Add(copyFullPath);
}
}
return menu;

View File

@@ -532,7 +532,7 @@
<TextBlock Text="{DynamicResource Text.Repository.Search.ByAuthor}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByCommitter}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByMessage}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByPath}"/>
<TextBlock Text="{DynamicResource Text.Repository.Search.ByContent}"/>
</ComboBox.Items>
</ComboBox>