CmdPal: Include basic SettingsManager in extension template#46028
CmdPal: Include basic SettingsManager in extension template#46028
Conversation
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a basic settings scaffold to the CmdPal extension template so newly generated extensions have a pre-wired SettingsManager and an in-app entry point to the settings UI.
Changes:
- Introduces a new
Helpers/SettingsManager.csthat extendsJsonSettingsManager, loads/savessettings.json, and auto-saves onSettingsChanged. - Wires the template command provider to expose the settings UI via
MoreCommandsand to advertise settings viaCommandProvider.Settings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/TemplateCmdPalExtensionCommandsProvider.cs | Instantiates SettingsManager, sets Settings, and adds a settings page entry to MoreCommands. |
| src/modules/cmdpal/ExtensionTemplate/TemplateCmdPalExtension/TemplateCmdPalExtension/Helpers/SettingsManager.cs | Adds a settings manager scaffold that sets FilePath, loads settings, and saves on change. |
| private static readonly string _namespace = "templatecmdpalextension"; | ||
|
|
||
| private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}"; |
There was a problem hiding this comment.
The _namespace value is hard-coded to "templatecmdpalextension" and (unlike "TemplateCmdPalExtension" elsewhere) it likely won’t be updated by the template substitution. That means generated extensions will keep the same settings key prefix unless the developer notices and edits it, which can lead to confusing/duplicated setting IDs (especially if settings are ever stored in a shared JSON). Consider deriving this prefix from the project/assembly name (or using the same token/casing as the other template-replaced strings) so it stays consistent automatically.
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.Unrecognized words (1)templatecmdpalextension These words are not needed and should be removedkbmcontrols mfalse mtrueTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands... in a clone of the git@github.com:microsoft/PowerToys.git repository curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/c635c2f3f714eec2fcf27b643a1919b9a811ef2e/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/22889435079/attempts/2' &&
git commit -m 'Update check-spelling metadata'Warnings
|
| Count | |
|---|---|
| 3 |
See
If the flagged items are 🤯 false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it,
try adding it to thepatterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
Adds a
SettingsManagerscaffold to the CmdPal extension template so new extensions have a ready-to-use settings pattern out of the box.Summary of the Pull Request
Most extensions need configuration. The template previously had no settings infrastructure, leaving developers to discover the pattern from built-in extensions. This adds a wired-up
SettingsManagerfollowing the same conventions used across all built-in extensions.PR Checklist
Detailed Description of the Pull Request / Additional comments
Helpers/SettingsManager.cs(new)JsonSettingsManager(already bundled inMicrosoft.CommandPalette.Extensions)Utilities.BaseSettingsPath()for correct local-state path (packaged and unpackaged)ToggleSettingexample illustrating the full add/register/expose cycleSettings.SettingsChangedeventTemplateCmdPalExtensionCommandsProvider.cs(updated)SettingsManageras a fieldSettings = _settingsManager.Settingsto advertise settings to CmdPal_settingsManager.Settings.SettingsPageinMoreCommandsfor in-app settings accessThe template wizard replaces
"TemplateCmdPalExtension"throughout all files, soBaseSettingsPathand the namespace string will update automatically when scaffolding a new extension.Validation Steps Performed
SettingsManagerpattern matches existing built-in extensions (ClipboardHistory,System,Registry)JsonSettingsManager,ToggleSetting, andUtilitiesare all included in the existingMicrosoft.CommandPalette.ExtensionsNuGet packageOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.