From 1a4e97109248d2e5019cdf2df9594bda4894be85 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 18 Feb 2026 10:13:12 -0600 Subject: [PATCH] I think this is everything working now --- .../TopLevelItemPageContext.cs | 2 +- .../CommandPaletteContextMenuFactory.xaml.cs | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelItemPageContext.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelItemPageContext.cs index 90941ca115..5f21706fd3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelItemPageContext.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelItemPageContext.cs @@ -7,7 +7,7 @@ using Microsoft.CmdPal.Core.ViewModels; namespace Microsoft.CmdPal.UI.ViewModels; -internal partial class TopLevelItemPageContext : IPageContext +public partial class TopLevelItemPageContext : IPageContext { public TaskScheduler Scheduler { get; private set; } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/CommandPaletteContextMenuFactory.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/CommandPaletteContextMenuFactory.xaml.cs index a187b96f3b..5631d3c54e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/CommandPaletteContextMenuFactory.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/CommandPaletteContextMenuFactory.xaml.cs @@ -46,16 +46,27 @@ internal sealed partial class CommandPaletteContextMenuFactory : IContextMenuFac var alreadyPinnedToTopLevel = providerSettings.PinnedCommandIds.Contains(itemId); - var pinToTopLevelCommand = new PinToCommand( - commandId: itemId, - providerId: providerId, - pin: !alreadyPinnedToTopLevel, - PinLocation.TopLevel, - _settingsModel, - _topLevelCommandManager); + // Don't add pin/unpin commands for items displayed as + // TopLevelViewModels that aren't already pinned. + // + // We can't look up if this command item is in the top level + // items in the manager, because we are being called _before_ we + // get added to the manager's list of commands. + var isTopLevelItem = page is TopLevelItemPageContext; - var contextItem = new PinToContextItem(pinToTopLevelCommand, commandItem); - moreCommands.Add(contextItem); + if (!isTopLevelItem || alreadyPinnedToTopLevel) + { + var pinToTopLevelCommand = new PinToCommand( + commandId: itemId, + providerId: providerId, + pin: !alreadyPinnedToTopLevel, + PinLocation.TopLevel, + _settingsModel, + _topLevelCommandManager); + + var contextItem = new PinToContextItem(pinToTopLevelCommand, commandItem); + moreCommands.Add(contextItem); + } } }