Skip to content

Commit 945c63c

Browse files
committed
ux: add badge for global custom actions (#1490)
Signed-off-by: leo <[email protected]>
1 parent 3a1827e commit 945c63c

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/Resources/Styles.axaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,15 @@
843843
<DataTemplate DataType="vm:FilterModeInGraph">
844844
<v:FilterModeInGraph/>
845845
</DataTemplate>
846+
847+
<DataTemplate DataType="vm:CustomActionContextMenuLabel">
848+
<StackPanel Orientation="Horizontal">
849+
<TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
850+
<Border Margin="4,0,0,0" Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center" IsVisible="{Binding IsGlobal}">
851+
<TextBlock Classes="primary" Text="GLOBAL" Margin="8,0" FontSize="10" Foreground="White"/>
852+
</Border>
853+
</StackPanel>
854+
</DataTemplate>
846855
</ContentPresenter.DataTemplates>
847856
</ContentPresenter>
848857

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SourceGit.ViewModels
2+
{
3+
public class CustomActionContextMenuLabel(string name, bool isGlobal)
4+
{
5+
public string Name { get; set; } = name;
6+
public bool IsGlobal { get; set; } = isGlobal;
7+
}
8+
}

src/ViewModels/Histories.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,10 @@ public ContextMenu MakeContextMenu(DataGrid list)
800800

801801
foreach (var action in actions)
802802
{
803-
var dup = action;
803+
var (dup, label) = action;
804804
var item = new MenuItem();
805805
item.Icon = App.CreateMenuIcon("Icons.Action");
806-
item.Header = dup.Name;
806+
item.Header = label;
807807
item.Click += (_, e) =>
808808
{
809809
_repo.ExecCustomAction(dup, commit);

src/ViewModels/Repository.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,20 +1077,20 @@ public void AbortMerge()
10771077
_workingCopy?.AbortMerge();
10781078
}
10791079

1080-
public List<Models.CustomAction> GetCustomActions(Models.CustomActionScope scope)
1080+
public List<(Models.CustomAction, CustomActionContextMenuLabel)> GetCustomActions(Models.CustomActionScope scope)
10811081
{
1082-
var actions = new List<Models.CustomAction>();
1082+
var actions = new List<(Models.CustomAction, CustomActionContextMenuLabel)>();
10831083

10841084
foreach (var act in Preferences.Instance.CustomActions)
10851085
{
10861086
if (act.Scope == scope)
1087-
actions.Add(act);
1087+
actions.Add((act, new CustomActionContextMenuLabel(act.Name, true)));
10881088
}
10891089

10901090
foreach (var act in _settings.CustomActions)
10911091
{
10921092
if (act.Scope == scope)
1093-
actions.Add(act);
1093+
actions.Add((act, new CustomActionContextMenuLabel(act.Name, false)));
10941094
}
10951095

10961096
return actions;
@@ -1748,10 +1748,10 @@ public ContextMenu CreateContextMenuForCustomAction()
17481748
{
17491749
foreach (var action in actions)
17501750
{
1751-
var dup = action;
1751+
var (dup, label) = action;
17521752
var item = new MenuItem();
17531753
item.Icon = App.CreateMenuIcon("Icons.Action");
1754-
item.Header = dup.Name;
1754+
item.Header = label;
17551755
item.Click += (_, e) =>
17561756
{
17571757
ExecCustomAction(dup, null);
@@ -2437,10 +2437,10 @@ public ContextMenu CreateContextMenuForTag(Models.Tag tag)
24372437

24382438
foreach (var action in actions)
24392439
{
2440-
var dup = action;
2440+
var (dup, label) = action;
24412441
var item = new MenuItem();
24422442
item.Icon = App.CreateMenuIcon("Icons.Action");
2443-
item.Header = dup.Name;
2443+
item.Header = label;
24442444
item.Click += (_, e) =>
24452445
{
24462446
ExecCustomAction(dup, tag);
@@ -2872,10 +2872,10 @@ private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.B
28722872

28732873
foreach (var action in actions)
28742874
{
2875-
var dup = action;
2875+
var (dup, label) = action;
28762876
var item = new MenuItem();
28772877
item.Icon = App.CreateMenuIcon("Icons.Action");
2878-
item.Header = dup.Name;
2878+
item.Header = label;
28792879
item.Click += (_, e) =>
28802880
{
28812881
ExecCustomAction(dup, branch);

0 commit comments

Comments
 (0)