feature: add a search(filter) keyword for commands in command palette (#1937)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-03-05 15:48:03 +08:00
parent b65f23575a
commit 30d5700f88
3 changed files with 27 additions and 20 deletions

View File

@@ -6,12 +6,14 @@ namespace SourceGit.ViewModels
public class RepositoryCommandPaletteCmd
{
public string Label { get; set; }
public string Keyword { get; set; }
public string Icon { get; set; }
public Action Action { get; set; }
public RepositoryCommandPaletteCmd(string label, string icon, Action action)
public RepositoryCommandPaletteCmd(string label, string keyword, string icon, Action action)
{
Label = label;
Keyword = keyword;
Icon = icon;
Action = action;
}
@@ -46,85 +48,85 @@ namespace SourceGit.ViewModels
_launcher = launcher;
_repo = repo;
_cmds.Add(new($"{App.Text("Blame")}...", "Blame", () =>
_cmds.Add(new($"{App.Text("Blame")}...", "blame", "Blame", () =>
{
var sub = new BlameCommandPalette(_launcher, _repo.FullPath);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new($"{App.Text("Checkout")}...", "Check", () =>
_cmds.Add(new($"{App.Text("Checkout")}...", "checkout", "Check", () =>
{
var sub = new CheckoutCommandPalette(_launcher, _repo);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new($"{App.Text("Compare.WithHead")}...", "Compare", () =>
_cmds.Add(new($"{App.Text("Compare.WithHead")}...", "compare", "Compare", () =>
{
var sub = new CompareCommandPalette(_launcher, _repo, _repo.CurrentBranch);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new($"{App.Text("FileHistory")}...", "Histories", () =>
_cmds.Add(new($"{App.Text("FileHistory")}...", "history", "Histories", () =>
{
var sub = new FileHistoryCommandPalette(_launcher, _repo.FullPath);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new($"{App.Text("Merge")}...", "Merge", () =>
_cmds.Add(new($"{App.Text("Merge")}...", "merge", "Merge", () =>
{
var sub = new MergeCommandPalette(_launcher, _repo);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new($"{App.Text("OpenFile")}...", "OpenWith", () =>
_cmds.Add(new($"{App.Text("OpenFile")}...", "open", "OpenWith", () =>
{
var sub = new OpenFileCommandPalette(_launcher, _repo.FullPath);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new($"{App.Text("Repository.NewBranch")}...", "Branch.Add", () =>
_cmds.Add(new($"{App.Text("Repository.NewBranch")}...", "create branch", "Branch.Add", () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
repo.CreateNewBranch();
}));
_cmds.Add(new($"{App.Text("CreateTag.Title")}...", "Tag.Add", () =>
_cmds.Add(new($"{App.Text("CreateTag.Title")}...", "create tag", "Tag.Add", () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
repo.CreateNewTag();
}));
_cmds.Add(new($"{App.Text("Fetch.Title")}...", "Fetch", async () =>
_cmds.Add(new($"{App.Text("Fetch.Title")}...", "fetch", "Fetch", async () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
await repo.FetchAsync(false);
}));
_cmds.Add(new($"{App.Text("Pull.Title")}...", "Pull", async () =>
_cmds.Add(new($"{App.Text("Pull.Title")}...", "pull", "Pull", async () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
await repo.PullAsync(false);
}));
_cmds.Add(new($"{App.Text("Push.Title")}...", "Push", async () =>
_cmds.Add(new($"{App.Text("Push.Title")}...", "push", "Push", async () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
await repo.PushAsync(false);
}));
_cmds.Add(new($"{App.Text("Stash.Title")}...", "Stashes.Add", async () =>
_cmds.Add(new($"{App.Text("Stash.Title")}...", "stash", "Stashes.Add", async () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
await repo.StashAllAsync(false);
}));
_cmds.Add(new($"{App.Text("Apply.Title")}...", "Diff", () =>
_cmds.Add(new($"{App.Text("Apply.Title")}...", "apply", "Diff", () =>
{
var repo = _repo;
_launcher.CancelCommandPalette();
@@ -171,7 +173,8 @@ namespace SourceGit.ViewModels
foreach (var cmd in _cmds)
{
if (cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase))
if (cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase) ||
cmd.Keyword.Contains(_filter, StringComparison.OrdinalIgnoreCase))
visible.Add(cmd);
}

View File

@@ -128,7 +128,7 @@
Background="Transparent"
IsVisible="{Binding CommandPalette, Converter={x:Static ObjectConverters.IsNotNull}}"
PointerPressed="OnCloseCommandPalette">
<Border Width="400" HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)">
<Border Width="420" HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)">
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="8">
<ContentControl Margin="16,10,16,12" Content="{Binding CommandPalette}">
<ContentControl.DataTemplates>

View File

@@ -85,13 +85,17 @@
<ListBox.ItemTemplate>
<DataTemplate DataType="vm:RepositoryCommandPaletteCmd">
<Grid ColumnDefinitions="Auto,*" Background="Transparent" Tapped="OnItemTapped">
<Grid ColumnDefinitions="Auto,*,Auto" Background="Transparent" Tapped="OnItemTapped">
<v:RepositoryCommandPaletteIcon Grid.Column="0" Width="12" Height="12" IsHitTestVisible="False"/>
<TextBlock Grid.Column="1"
<Border Grid.Column="1" Margin="8,0,0,0" IsHitTestVisible="False">
<TextBlock VerticalAlignment="Center" Text="{Binding Label, Mode=OneWay}"/>
</Border>
<TextBlock Grid.Column="2"
Margin="8,0,0,0"
VerticalAlignment="Center"
IsHitTestVisible="False"
Text="{Binding Label, Mode=OneWay}"/>
FontSize="12"
Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"
Text="{Binding Keyword, Mode=OneWay}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>