From 01584f33e1ce682be81e796a8e33fc70092097d4 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 16 Apr 2025 14:50:56 -0500 Subject: [PATCH] Update the settings form when ext settings are saved (#38851) This one was subtle - the Settings class in the toolkit didn't ever change the items for a SettingsContentPage. For the main settings window, this was problematic. It would only ever hang onto one instance of that CommandSettings.SettingsContentPage, and never re-retrieve the value from it. This fixes that issue, by making sure to raise an ItemsChanged in the settings changed handler, so that we automatically pull down the new settings forms. For settings that were added to commands, as a context item, this wasn't an issue. They were always returning new forms to the host, with the current settings values in it. Closes #38191 --- .../Microsoft.CommandPalette.Extensions.Toolkit/Settings.cs | 4 ++++ .../SettingsForm.cs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Settings.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Settings.cs index 39d3b1f855..7f877664bd 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Settings.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/Settings.cs @@ -118,6 +118,10 @@ public sealed partial class Settings : ICommandSettings _settings = settings; Name = "Settings"; Icon = new IconInfo("\uE713"); // Settings icon + + // When our settings change, make sure to let CmdPal know to + // retrieve the new forms + _settings.SettingsChanged += (s, e) => RaiseItemsChanged(); } } diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/SettingsForm.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/SettingsForm.cs index fa23cd8f0d..79f548bf56 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/SettingsForm.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/SettingsForm.cs @@ -24,6 +24,12 @@ public partial class SettingsForm : FormContent return CommandResult.KeepOpen(); } + // Re-render the current value of the settings to a card. The + // SettingsContentPage will raise an ItemsChanged in its own + // SettingsChange handler, so we need to be prepared to return the + // current settings value. + TemplateJson = _settings.ToFormJson(); + _settings.Update(inputs); _settings.RaiseSettingsChanged();