Merge pull request #160 from workgroupengineering/feature/CopyFileName

feat: Allow Copy only file name with extension
This commit is contained in:
leo 2024-06-01 12:19:03 +08:00 committed by GitHub
commit 04e6ed45a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 2 deletions

View file

@ -114,6 +114,7 @@
<x:String x:Key="Text.Configure.User.Placeholder" xml:space="preserve">User name for this repository</x:String>
<x:String x:Key="Text.Copy" xml:space="preserve">Copy</x:String>
<x:String x:Key="Text.CopyPath" xml:space="preserve">Copy Path</x:String>
<x:String x:Key="Text.CopyFileName" xml:space="preserve">Copy File Name</x:String>
<x:String x:Key="Text.CreateBranch" xml:space="preserve">Create Branch</x:String>
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">Based On :</x:String>
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">Check out after created</x:String>

View file

@ -117,6 +117,7 @@
<x:String x:Key="Text.Configure.User.Placeholder" xml:space="preserve">应用于本仓库的用户名</x:String>
<x:String x:Key="Text.Copy" xml:space="preserve">复制</x:String>
<x:String x:Key="Text.CopyPath" xml:space="preserve">复制路径</x:String>
<x:String x:Key="Text.CopyFileName" xml:space="preserve">复制文件名</x:String>
<x:String x:Key="Text.CreateBranch" xml:space="preserve">新建分支</x:String>
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">新分支基于 </x:String>
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">完成后切换到新分支</x:String>

View file

@ -10,6 +10,7 @@ using Avalonia.Platform.Storage;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using SourceGit.Models;
namespace SourceGit.ViewModels
{
@ -218,7 +219,17 @@ namespace SourceGit.ViewModels
ev.Handled = true;
};
menu.Items.Add(copyPath);
var copyFileName = new MenuItem()
{
Header = App.Text("CopyFileName"),
Icon = App.CreateMenuIcon("Icon.Copy"),
};
copyFileName.Click += (_, e) =>
{
App.CopyText(Path.GetFileName(change.Path));
e.Handled = true;
};
menu.Items.Add(copyFileName);
return menu;
}
@ -284,12 +295,24 @@ namespace SourceGit.ViewModels
ev.Handled = true;
};
var copyFileName = new MenuItem()
{
Header = App.Text("CopyFileName"),
Icon = App.CreateMenuIcon("Icon.Copy"),
};
copyFileName.Click += (_, e) =>
{
App.CopyText(Path.GetFileName(file.Path));
e.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(history);
menu.Items.Add(blame);
menu.Items.Add(explore);
menu.Items.Add(saveAs);
menu.Items.Add(copyPath);
menu.Items.Add(copyFileName);
return menu;
}

View file

@ -183,6 +183,17 @@ namespace SourceGit.ViewModels
};
menu.Items.Add(copyPath);
var copyFileName = new MenuItem()
{
Header = App.Text("CopyFileName"),
Icon = App.CreateMenuIcon("Icon.Copy"),
};
copyFileName.Click += (_, e) =>
{
App.CopyText(Path.GetFileName(change.Path));
e.Handled = true;
};
menu.Items.Add(copyFileName);
return menu;
}

View file

@ -209,7 +209,7 @@ namespace SourceGit.ViewModels
_unstaged.Clear();
OnPropertyChanged(nameof(Unstaged));
}
if (_staged != null)
{
_staged.Clear();
@ -584,6 +584,17 @@ namespace SourceGit.ViewModels
e.Handled = true;
};
menu.Items.Add(copy);
var copyFileName = new MenuItem()
{
Header = App.Text("CopyFileName"),
Icon = App.CreateMenuIcon("Icon.Copy"),
};
copyFileName.Click += (_, e) =>
{
App.CopyText(Path.GetFileName(change.Path));
e.Handled = true;
};
menu.Items.Add(copyFileName);
}
else
{