From 01164b33eca5e22099472a707120055bbab372a7 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 5 Feb 2026 16:22:32 -0600 Subject: [PATCH] Add an API to allow _any_ command to be pinned --- .../doc/initial-sdk-spec/initial-sdk-spec.md | 1 + .../AllAppsCommandProvider.cs | 10 ++++++++++ .../ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs | 15 +++++++++++++++ .../CommandProvider.cs | 5 +++++ 4 files changed, 31 insertions(+) diff --git a/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md b/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md index 034269bb83..4142a78e8c 100644 --- a/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md +++ b/src/modules/cmdpal/doc/initial-sdk-spec/initial-sdk-spec.md @@ -2061,6 +2061,7 @@ bands via the new `DockBand` property on `ICommandProvider3`. interface ICommandProvider3 requires ICommandProvider2 { ICommandItem[] GetDockBands(); + ICommandItem GetCommandItemById(String id); }; ``` diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs index 317087847e..27922f9b7b 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsCommandProvider.cs @@ -188,4 +188,14 @@ public partial class AllAppsCommandProvider : CommandProvider { RaiseItemsChanged(0); } + + public override ICommandItem? GetCommandItemById(string id) + { + if (id == _listItem.Command.Id) + { + return _listItem; + } + + return _page.GetAppCommandItemById(id); + } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs index 2a264f70c2..8802522016 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AllAppsPage.cs @@ -205,4 +205,19 @@ public sealed partial class AllAppsPage : ListPage RaiseItemsChanged(0); } + + internal ICommandItem? GetAppCommandItemById(string id) + { + var items = this.GetItems(); + + foreach (var item in items) + { + if (item.Command.Id == id) + { + return item; + } + } + + return null; + } } diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs index 79f952dbe7..2afaff9e27 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/CommandProvider.cs @@ -56,6 +56,11 @@ public abstract partial class CommandProvider : return null; } + public virtual ICommandItem? GetCommandItemById(string id) + { + return null; + } + /// /// This is used to manually populate the WinRT type cache in CmdPal with /// any interfaces that might not follow a straight linear path of requires.