Compare commits

...

1 Commits

Author SHA1 Message Date
Niels Laute
c3fb921bb4 It's working 2026-03-10 16:14:14 +01:00
4 changed files with 95 additions and 2 deletions

View File

@@ -41,6 +41,8 @@ public partial class ProviderSettingsViewModel : ObservableObject
BuildFallbackViewModels();
}
public string ProviderId => _provider.ProviderId;
public string DisplayName => _provider.DisplayName;
public string ExtensionName => _provider.Extension?.ExtensionDisplayName ?? Resources.builtin_extension_name;

View File

@@ -4,6 +4,7 @@
using CommunityToolkit.Mvvm.Messaging;
using ManagedCommon;
using Microsoft.CmdPal.UI.Messages;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CmdPal.UI.ViewModels.Settings;
@@ -127,9 +128,30 @@ internal sealed partial class CommandPaletteContextMenuFactory : IContextMenuFac
List<IContextItem> moreCommands = [];
var commandItem = topLevelItem.ItemViewModel;
// Replace settings content page context items with commands that
// open the settings window for this provider.
var providerId = providerContext.ProviderId;
for (var i = 0; i < contextItems.Count; i++)
{
if (contextItems[i] is ICommandContextItem cci)
{
try
{
if (cci.Command is IContentPage)
{
var replacement = new OpenExtensionSettingsCommand(providerId, cci);
contextItems[i] = new CommandContextItem(replacement);
}
}
catch
{
// Extension object may be unavailable
}
}
}
// Add pin/unpin commands for pinning items to the top-level or to
// the dock.
var providerId = providerContext.ProviderId;
if (_topLevelCommandManager.LookupProvider(providerId) is CommandProviderWrapper provider)
{
var providerSettings = _settingsModel.GetProviderSettings(provider);
@@ -321,4 +343,45 @@ internal sealed partial class CommandPaletteContextMenuFactory : IContextMenuFac
WeakReferenceMessenger.Default.Send(message);
}
}
private sealed partial class OpenExtensionSettingsCommand : InvokableCommand
{
private readonly string _providerId;
public OpenExtensionSettingsCommand(string providerId, ICommandContextItem original)
{
_providerId = providerId;
Name = "Settings";
Icon = new IconInfo("\uE713");
// Preserve original name and icon when available
try
{
if (!string.IsNullOrEmpty(original.Command?.Name))
{
Name = original.Command.Name;
}
}
catch
{
}
try
{
if (original.Command?.Icon is IconInfo icon)
{
Icon = icon;
}
}
catch
{
}
}
public override CommandResult Invoke()
{
WeakReferenceMessenger.Default.Send(new OpenSettingsMessage(_providerId));
return CommandResult.KeepOpen();
}
}
}

View File

@@ -281,7 +281,30 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
_settingsWindow.Activate();
_settingsWindow.BringToFront();
_settingsWindow.Navigate(pageTag);
// Check if pageTag is a provider ID for extension deep-linking
var topLevelCommandManager = App.Current.Services.GetService<TopLevelCommandManager>()!;
CommandProviderWrapper? matchingWrapper = null;
foreach (var provider in topLevelCommandManager.CommandProviders)
{
if (provider.ProviderId == pageTag)
{
matchingWrapper = provider;
break;
}
}
if (matchingWrapper is not null)
{
var settings = App.Current.Services.GetService<SettingsModel>()!;
var providerSettings = settings.GetProviderSettings(matchingWrapper);
var providerVM = new ProviderSettingsViewModel(matchingWrapper, providerSettings, settings);
_settingsWindow.NavigateToExtension(providerVM);
}
else
{
_settingsWindow.Navigate(pageTag);
}
}
public void Receive(ShowDetailsMessage message)

View File

@@ -159,6 +159,11 @@ public sealed partial class SettingsWindow : WindowEx,
}
}
internal void NavigateToExtension(ProviderSettingsViewModel extension)
{
NavFrame.Navigate(typeof(ExtensionPage), extension);
}
private void Navigate(ProviderSettingsViewModel extension)
{
NavFrame.Navigate(typeof(ExtensionPage), extension);