diff --git a/src/ViewModels/RepositoryCommandPalette.cs b/src/ViewModels/RepositoryCommandPalette.cs index da73191b..b5f7d8e7 100644 --- a/src/ViewModels/RepositoryCommandPalette.cs +++ b/src/ViewModels/RepositoryCommandPalette.cs @@ -5,13 +5,14 @@ namespace SourceGit.ViewModels { public class RepositoryCommandPaletteCmd { - public string Key { get; set; } + public string Label { get; set; } + public string Icon { get; set; } public Action Action { get; set; } - public string Label => $"{App.Text(Key)}..."; - public RepositoryCommandPaletteCmd(string key, Action action) + public RepositoryCommandPaletteCmd(string label, string icon, Action action) { - Key = key; + Label = label; + Icon = icon; Action = action; } } @@ -45,37 +46,37 @@ namespace SourceGit.ViewModels _launcher = launcher; _repo = repo; - _cmds.Add(new("Blame", () => + _cmds.Add(new($"{App.Text("Blame")}...", "Blame", () => { var sub = new BlameCommandPalette(_launcher, _repo.FullPath); _launcher.OpenCommandPalette(sub); })); - _cmds.Add(new("Checkout", () => + _cmds.Add(new($"{App.Text("Checkout")}...", "Check", () => { var sub = new CheckoutCommandPalette(_launcher, _repo); _launcher.OpenCommandPalette(sub); })); - _cmds.Add(new("Compare.WithHead", () => + _cmds.Add(new($"{App.Text("Compare.WithHead")}...", "Compare", () => { var sub = new CompareCommandPalette(_launcher, _repo, _repo.CurrentBranch); _launcher.OpenCommandPalette(sub); })); - _cmds.Add(new("FileHistory", () => + _cmds.Add(new($"{App.Text("FileHistory")}...", "Histories", () => { var sub = new FileHistoryCommandPalette(_launcher, _repo.FullPath); _launcher.OpenCommandPalette(sub); })); - _cmds.Add(new("Merge", () => + _cmds.Add(new($"{App.Text("Merge")}...", "Merge", () => { var sub = new MergeCommandPalette(_launcher, _repo); _launcher.OpenCommandPalette(sub); })); - _cmds.Add(new("OpenFile", () => + _cmds.Add(new($"{App.Text("OpenFile")}...", "OpenWith", () => { var sub = new OpenFileCommandPalette(_launcher, _repo.FullPath); _launcher.OpenCommandPalette(sub); @@ -120,8 +121,7 @@ namespace SourceGit.ViewModels foreach (var cmd in _cmds) { - if (cmd.Key.Contains(_filter, StringComparison.OrdinalIgnoreCase) || - cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase)) + if (cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase)) visible.Add(cmd); } diff --git a/src/Views/RepositoryCommandPalette.axaml b/src/Views/RepositoryCommandPalette.axaml index f1ea843d..7d57319b 100644 --- a/src/Views/RepositoryCommandPalette.axaml +++ b/src/Views/RepositoryCommandPalette.axaml @@ -86,12 +86,9 @@ - + diff --git a/src/Views/RepositoryCommandPaletteIcon.cs b/src/Views/RepositoryCommandPaletteIcon.cs new file mode 100644 index 00000000..102b2aab --- /dev/null +++ b/src/Views/RepositoryCommandPaletteIcon.cs @@ -0,0 +1,30 @@ +using System; + +using Avalonia.Controls; +using Avalonia.Controls.Shapes; +using Avalonia.Media; + +namespace SourceGit.Views +{ + public class RepositoryCommandPaletteIcon : Path + { + protected override Type StyleKeyOverride => typeof(Path); + + protected override void OnDataContextChanged(EventArgs e) + { + base.OnDataContextChanged(e); + + if (DataContext is ViewModels.RepositoryCommandPaletteCmd cmd && !string.IsNullOrEmpty(cmd.Icon)) + { + var geo = this.FindResource($"Icons.{cmd.Icon}") as StreamGeometry; + if (geo != null) + { + Data = geo; + return; + } + } + + Data = this.FindResource("Icon.Command") as StreamGeometry; + } + } +}