Skip to content

Commit 3ec37a2

Browse files
committed
enhance: show command icon in command palette
Signed-off-by: leo <longshuang@msn.cn>
1 parent 5ffea60 commit 3ec37a2

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

src/ViewModels/RepositoryCommandPalette.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ namespace SourceGit.ViewModels
55
{
66
public class RepositoryCommandPaletteCmd
77
{
8-
public string Key { get; set; }
8+
public string Label { get; set; }
9+
public string Icon { get; set; }
910
public Action Action { get; set; }
10-
public string Label => $"{App.Text(Key)}...";
1111

12-
public RepositoryCommandPaletteCmd(string key, Action action)
12+
public RepositoryCommandPaletteCmd(string label, string icon, Action action)
1313
{
14-
Key = key;
14+
Label = label;
15+
Icon = icon;
1516
Action = action;
1617
}
1718
}
@@ -45,37 +46,37 @@ public RepositoryCommandPalette(Launcher launcher, Repository repo)
4546
_launcher = launcher;
4647
_repo = repo;
4748

48-
_cmds.Add(new("Blame", () =>
49+
_cmds.Add(new($"{App.Text("Blame")}...", "Blame", () =>
4950
{
5051
var sub = new BlameCommandPalette(_launcher, _repo.FullPath);
5152
_launcher.OpenCommandPalette(sub);
5253
}));
5354

54-
_cmds.Add(new("Checkout", () =>
55+
_cmds.Add(new($"{App.Text("Checkout")}...", "Check", () =>
5556
{
5657
var sub = new CheckoutCommandPalette(_launcher, _repo);
5758
_launcher.OpenCommandPalette(sub);
5859
}));
5960

60-
_cmds.Add(new("Compare.WithHead", () =>
61+
_cmds.Add(new($"{App.Text("Compare.WithHead")}...", "Compare", () =>
6162
{
6263
var sub = new CompareCommandPalette(_launcher, _repo, _repo.CurrentBranch);
6364
_launcher.OpenCommandPalette(sub);
6465
}));
6566

66-
_cmds.Add(new("FileHistory", () =>
67+
_cmds.Add(new($"{App.Text("FileHistory")}...", "Histories", () =>
6768
{
6869
var sub = new FileHistoryCommandPalette(_launcher, _repo.FullPath);
6970
_launcher.OpenCommandPalette(sub);
7071
}));
7172

72-
_cmds.Add(new("Merge", () =>
73+
_cmds.Add(new($"{App.Text("Merge")}...", "Merge", () =>
7374
{
7475
var sub = new MergeCommandPalette(_launcher, _repo);
7576
_launcher.OpenCommandPalette(sub);
7677
}));
7778

78-
_cmds.Add(new("OpenFile", () =>
79+
_cmds.Add(new($"{App.Text("OpenFile")}...", "OpenWith", () =>
7980
{
8081
var sub = new OpenFileCommandPalette(_launcher, _repo.FullPath);
8182
_launcher.OpenCommandPalette(sub);
@@ -120,8 +121,7 @@ private void UpdateVisible()
120121

121122
foreach (var cmd in _cmds)
122123
{
123-
if (cmd.Key.Contains(_filter, StringComparison.OrdinalIgnoreCase) ||
124-
cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase))
124+
if (cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase))
125125
visible.Add(cmd);
126126
}
127127

src/Views/RepositoryCommandPalette.axaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@
8686
<ListBox.ItemTemplate>
8787
<DataTemplate DataType="vm:RepositoryCommandPaletteCmd">
8888
<Grid ColumnDefinitions="Auto,*" Background="Transparent" Tapped="OnItemTapped">
89-
<Path Grid.Column="0"
90-
Width="12" Height="12"
91-
Data="{StaticResource Icons.Command}"
92-
IsHitTestVisible="False"/>
89+
<v:RepositoryCommandPaletteIcon Grid.Column="0" Width="12" Height="12" IsHitTestVisible="False"/>
9390
<TextBlock Grid.Column="1"
94-
Margin="6,0,0,0"
91+
Margin="8,0,0,0"
9592
VerticalAlignment="Center"
9693
IsHitTestVisible="False"
9794
Text="{Binding Label, Mode=OneWay}"/>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
using Avalonia.Controls;
4+
using Avalonia.Controls.Shapes;
5+
using Avalonia.Media;
6+
7+
namespace SourceGit.Views
8+
{
9+
public class RepositoryCommandPaletteIcon : Path
10+
{
11+
protected override Type StyleKeyOverride => typeof(Path);
12+
13+
protected override void OnDataContextChanged(EventArgs e)
14+
{
15+
base.OnDataContextChanged(e);
16+
17+
if (DataContext is ViewModels.RepositoryCommandPaletteCmd cmd && !string.IsNullOrEmpty(cmd.Icon))
18+
{
19+
var geo = this.FindResource($"Icons.{cmd.Icon}") as StreamGeometry;
20+
if (geo != null)
21+
{
22+
Data = geo;
23+
return;
24+
}
25+
}
26+
27+
Data = this.FindResource("Icon.Command") as StreamGeometry;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)