From 945c63c78a4e87d082924c7c27ce46ed2f3f807c Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 2 Jul 2025 16:24:48 +0800 Subject: [PATCH] ux: add badge for global custom actions (#1490) Signed-off-by: leo --- src/Resources/Styles.axaml | 9 +++++++++ .../CustomActionContextMenuLabel.cs | 8 ++++++++ src/ViewModels/Histories.cs | 4 ++-- src/ViewModels/Repository.cs | 20 +++++++++---------- 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 src/ViewModels/CustomActionContextMenuLabel.cs diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index a20bec81..e328cf26 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -843,6 +843,15 @@ + + + + + + + + + diff --git a/src/ViewModels/CustomActionContextMenuLabel.cs b/src/ViewModels/CustomActionContextMenuLabel.cs new file mode 100644 index 00000000..82804f09 --- /dev/null +++ b/src/ViewModels/CustomActionContextMenuLabel.cs @@ -0,0 +1,8 @@ +namespace SourceGit.ViewModels +{ + public class CustomActionContextMenuLabel(string name, bool isGlobal) + { + public string Name { get; set; } = name; + public bool IsGlobal { get; set; } = isGlobal; + } +} diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index a2656936..8d159419 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -800,10 +800,10 @@ namespace SourceGit.ViewModels foreach (var action in actions) { - var dup = action; + var (dup, label) = action; var item = new MenuItem(); item.Icon = App.CreateMenuIcon("Icons.Action"); - item.Header = dup.Name; + item.Header = label; item.Click += (_, e) => { _repo.ExecCustomAction(dup, commit); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 4bf5f6f5..8dbf7012 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1077,20 +1077,20 @@ namespace SourceGit.ViewModels _workingCopy?.AbortMerge(); } - public List GetCustomActions(Models.CustomActionScope scope) + public List<(Models.CustomAction, CustomActionContextMenuLabel)> GetCustomActions(Models.CustomActionScope scope) { - var actions = new List(); + var actions = new List<(Models.CustomAction, CustomActionContextMenuLabel)>(); foreach (var act in Preferences.Instance.CustomActions) { if (act.Scope == scope) - actions.Add(act); + actions.Add((act, new CustomActionContextMenuLabel(act.Name, true))); } foreach (var act in _settings.CustomActions) { if (act.Scope == scope) - actions.Add(act); + actions.Add((act, new CustomActionContextMenuLabel(act.Name, false))); } return actions; @@ -1748,10 +1748,10 @@ namespace SourceGit.ViewModels { foreach (var action in actions) { - var dup = action; + var (dup, label) = action; var item = new MenuItem(); item.Icon = App.CreateMenuIcon("Icons.Action"); - item.Header = dup.Name; + item.Header = label; item.Click += (_, e) => { ExecCustomAction(dup, null); @@ -2437,10 +2437,10 @@ namespace SourceGit.ViewModels foreach (var action in actions) { - var dup = action; + var (dup, label) = action; var item = new MenuItem(); item.Icon = App.CreateMenuIcon("Icons.Action"); - item.Header = dup.Name; + item.Header = label; item.Click += (_, e) => { ExecCustomAction(dup, tag); @@ -2872,10 +2872,10 @@ namespace SourceGit.ViewModels foreach (var action in actions) { - var dup = action; + var (dup, label) = action; var item = new MenuItem(); item.Icon = App.CreateMenuIcon("Icons.Action"); - item.Header = dup.Name; + item.Header = label; item.Click += (_, e) => { ExecCustomAction(dup, branch);