Skip to content

Commit 133b69d

Browse files
committed
feature: supports to copy selected folder path in changes and rename searching by file to searching by path (#1470)
Signed-off-by: leo <[email protected]>
1 parent 1acf2a1 commit 133b69d

File tree

8 files changed

+85
-15
lines changed

8 files changed

+85
-15
lines changed

src/Commands/QueryCommits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public QueryCommits(string repo, string filter, Models.CommitSearchMethod method
4141

4242
search = argsBuilder.ToString();
4343
}
44-
else if (method == Models.CommitSearchMethod.ByFile)
44+
else if (method == Models.CommitSearchMethod.ByPath)
4545
{
4646
search += $"-- \"{filter}\"";
4747
}

src/Models/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum CommitSearchMethod
1212
ByAuthor,
1313
ByCommitter,
1414
ByMessage,
15-
ByFile,
15+
ByPath,
1616
ByContent,
1717
}
1818

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@
648648
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">Author</x:String>
649649
<x:String x:Key="Text.Repository.Search.ByCommitter" xml:space="preserve">Committer</x:String>
650650
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">Content</x:String>
651-
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">File</x:String>
652651
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
652+
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">Path</x:String>
653653
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>
654654
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">Current Branch</x:String>
655655
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">Show Submodules as Tree</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,8 @@
652652
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">作者</x:String>
653653
<x:String x:Key="Text.Repository.Search.ByCommitter" xml:space="preserve">提交者</x:String>
654654
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">变更内容</x:String>
655-
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">文件</x:String>
656655
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交信息</x:String>
656+
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">路径</x:String>
657657
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指纹</x:String>
658658
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">仅在当前分支中查找</x:String>
659659
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以树型结构展示</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,8 @@
652652
<x:String x:Key="Text.Repository.Search.ByAuthor" xml:space="preserve">作者</x:String>
653653
<x:String x:Key="Text.Repository.Search.ByCommitter" xml:space="preserve">提交者</x:String>
654654
<x:String x:Key="Text.Repository.Search.ByContent" xml:space="preserve">變更內容</x:String>
655-
<x:String x:Key="Text.Repository.Search.ByFile" xml:space="preserve">檔案</x:String>
656655
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交訊息</x:String>
656+
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">路徑</x:String>
657657
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交編號</x:String>
658658
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">僅搜尋目前分支</x:String>
659659
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以樹型結構展示</x:String>

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@ private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.B
28912891

28922892
private bool IsSearchingCommitsByFilePath()
28932893
{
2894-
return _isSearching && _searchCommitFilterType == (int)Models.CommitSearchMethod.ByFile;
2894+
return _isSearching && _searchCommitFilterType == (int)Models.CommitSearchMethod.ByPath;
28952895
}
28962896

28972897
private void CalcWorktreeFilesForSearching()

src/ViewModels/WorkingCopy.cs

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,19 @@ public ContextMenu CreateContextMenuForUnstagedChanges(string selectedSingleFold
594594
if (_selectedUnstaged.Count == 1)
595595
{
596596
var change = _selectedUnstaged[0];
597-
var path = Path.GetFullPath(Path.Combine(_repo.FullPath, change.Path));
597+
var path = Native.OS.GetAbsPath(_repo.FullPath, change.Path);
598598

599599
var explore = new MenuItem();
600600
explore.Header = App.Text("RevealFile");
601601
explore.Icon = App.CreateMenuIcon("Icons.Explore");
602602
explore.IsEnabled = File.Exists(path) || Directory.Exists(path);
603603
explore.Click += (_, e) =>
604604
{
605-
Native.OS.OpenInFileManager(path, true);
605+
if (string.IsNullOrEmpty(selectedSingleFolder))
606+
Native.OS.OpenInFileManager(path, true);
607+
else
608+
Native.OS.OpenInFileManager(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder), true);
609+
606610
e.Handled = true;
607611
};
608612
menu.Items.Add(explore);
@@ -982,7 +986,11 @@ public ContextMenu CreateContextMenuForUnstagedChanges(string selectedSingleFold
982986
copy.Icon = App.CreateMenuIcon("Icons.Copy");
983987
copy.Click += (_, e) =>
984988
{
985-
App.CopyText(change.Path);
989+
if (string.IsNullOrEmpty(selectedSingleFolder))
990+
App.CopyText(change.Path);
991+
else
992+
App.CopyText(selectedSingleFolder);
993+
986994
e.Handled = true;
987995
};
988996
menu.Items.Add(copy);
@@ -992,7 +1000,11 @@ public ContextMenu CreateContextMenuForUnstagedChanges(string selectedSingleFold
9921000
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
9931001
copyFullPath.Click += (_, e) =>
9941002
{
995-
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, change.Path));
1003+
if (string.IsNullOrEmpty(selectedSingleFolder))
1004+
App.CopyText(path);
1005+
else
1006+
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
1007+
9961008
e.Handled = true;
9971009
};
9981010
menu.Items.Add(copyFullPath);
@@ -1154,6 +1166,27 @@ public ContextMenu CreateContextMenuForUnstagedChanges(string selectedSingleFold
11541166

11551167
menu.Items.Add(new MenuItem() { Header = "-" });
11561168
menu.Items.Add(addToIgnore);
1169+
1170+
var copy = new MenuItem();
1171+
copy.Header = App.Text("CopyPath");
1172+
copy.Icon = App.CreateMenuIcon("Icons.Copy");
1173+
copy.Click += (_, e) =>
1174+
{
1175+
App.CopyText(selectedSingleFolder);
1176+
e.Handled = true;
1177+
};
1178+
1179+
var copyFullPath = new MenuItem();
1180+
copyFullPath.Header = App.Text("CopyPath");
1181+
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
1182+
copyFullPath.Click += (_, e) =>
1183+
{
1184+
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
1185+
e.Handled = true;
1186+
};
1187+
menu.Items.Add(new MenuItem() { Header = "-" });
1188+
menu.Items.Add(copy);
1189+
menu.Items.Add(copyFullPath);
11571190
}
11581191
}
11591192

@@ -1205,15 +1238,19 @@ public ContextMenu CreateContextMenuForStagedChanges(string selectedSingleFolder
12051238
if (_selectedStaged.Count == 1)
12061239
{
12071240
var change = _selectedStaged[0];
1208-
var path = Path.GetFullPath(Path.Combine(_repo.FullPath, change.Path));
1241+
var path = Native.OS.GetAbsPath(_repo.FullPath, change.Path);
12091242

12101243
var explore = new MenuItem();
12111244
explore.IsEnabled = File.Exists(path) || Directory.Exists(path);
12121245
explore.Header = App.Text("RevealFile");
12131246
explore.Icon = App.CreateMenuIcon("Icons.Explore");
12141247
explore.Click += (_, e) =>
12151248
{
1216-
Native.OS.OpenInFileManager(path, true);
1249+
if (string.IsNullOrEmpty(selectedSingleFolder))
1250+
Native.OS.OpenInFileManager(path, true);
1251+
else
1252+
Native.OS.OpenInFileManager(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder), true);
1253+
12171254
e.Handled = true;
12181255
};
12191256

@@ -1391,7 +1428,11 @@ public ContextMenu CreateContextMenuForStagedChanges(string selectedSingleFolder
13911428
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
13921429
copyPath.Click += (_, e) =>
13931430
{
1394-
App.CopyText(change.Path);
1431+
if (string.IsNullOrEmpty(selectedSingleFolder))
1432+
App.CopyText(change.Path);
1433+
else
1434+
App.CopyText(selectedSingleFolder);
1435+
13951436
e.Handled = true;
13961437
};
13971438

@@ -1400,7 +1441,11 @@ public ContextMenu CreateContextMenuForStagedChanges(string selectedSingleFolder
14001441
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
14011442
copyFullPath.Click += (_, e) =>
14021443
{
1403-
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, change.Path));
1444+
if (string.IsNullOrEmpty(selectedSingleFolder))
1445+
App.CopyText(path);
1446+
else
1447+
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
1448+
14041449
e.Handled = true;
14051450
};
14061451

@@ -1480,6 +1525,31 @@ public ContextMenu CreateContextMenuForStagedChanges(string selectedSingleFolder
14801525
menu.Items.Add(new MenuItem() { Header = "-" });
14811526
menu.Items.Add(ai);
14821527
}
1528+
1529+
if (!string.IsNullOrEmpty(selectedSingleFolder))
1530+
{
1531+
var copyPath = new MenuItem();
1532+
copyPath.Header = App.Text("CopyPath");
1533+
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
1534+
copyPath.Click += (_, e) =>
1535+
{
1536+
App.CopyText(selectedSingleFolder);
1537+
e.Handled = true;
1538+
};
1539+
1540+
var copyFullPath = new MenuItem();
1541+
copyFullPath.Header = App.Text("CopyFullPath");
1542+
copyFullPath.Icon = App.CreateMenuIcon("Icons.Copy");
1543+
copyFullPath.Click += (_, e) =>
1544+
{
1545+
App.CopyText(Native.OS.GetAbsPath(_repo.FullPath, selectedSingleFolder));
1546+
e.Handled = true;
1547+
};
1548+
1549+
menu.Items.Add(new MenuItem() { Header = "-" });
1550+
menu.Items.Add(copyPath);
1551+
menu.Items.Add(copyFullPath);
1552+
}
14831553
}
14841554

14851555
return menu;

src/Views/Repository.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
<TextBlock Text="{DynamicResource Text.Repository.Search.ByAuthor}"/>
533533
<TextBlock Text="{DynamicResource Text.Repository.Search.ByCommitter}"/>
534534
<TextBlock Text="{DynamicResource Text.Repository.Search.ByMessage}"/>
535-
<TextBlock Text="{DynamicResource Text.Repository.Search.ByFile}"/>
535+
<TextBlock Text="{DynamicResource Text.Repository.Search.ByPath}"/>
536536
<TextBlock Text="{DynamicResource Text.Repository.Search.ByContent}"/>
537537
</ComboBox.Items>
538538
</ComboBox>

0 commit comments

Comments
 (0)