Skip to content

CmdPal: Include basic SettingsManager in extension template#46028

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-settings-manager-template
Draft

CmdPal: Include basic SettingsManager in extension template#46028
Copilot wants to merge 2 commits intomainfrom
copilot/add-settings-manager-template

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

Adds a SettingsManager scaffold 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 SettingsManager following the same conventions used across all built-in extensions.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Helpers/SettingsManager.cs (new)

  • Extends JsonSettingsManager (already bundled in Microsoft.CommandPalette.Extensions)
  • Uses Utilities.BaseSettingsPath() for correct local-state path (packaged and unpackaged)
  • Includes commented-out ToggleSetting example illustrating the full add/register/expose cycle
  • Auto-saves via Settings.SettingsChanged event

TemplateCmdPalExtensionCommandsProvider.cs (updated)

  • Instantiates SettingsManager as a field
  • Sets Settings = _settingsManager.Settings to advertise settings to CmdPal
  • Exposes _settingsManager.Settings.SettingsPage in MoreCommands for in-app settings access
// Helpers/SettingsManager.cs
internal sealed partial class SettingsManager : JsonSettingsManager
{
    private static readonly string _namespace = "templatecmdpalextension";
    private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}";

    // TODO: Add your settings here. For example:
    // private readonly ToggleSetting _myToggle = new(
    //     Namespaced(nameof(MyToggle)), "My toggle setting", "Description", false);
    // public bool MyToggle => _myToggle.Value;

    public SettingsManager()
    {
        FilePath = SettingsJsonPath();
        // Settings.Add(_myToggle);
        LoadSettings();
        Settings.SettingsChanged += (_, _) => SaveSettings();
    }
}

// TemplateCmdPalExtensionCommandsProvider.cs
private readonly SettingsManager _settingsManager = new();

public TemplateCmdPalExtensionCommandsProvider()
{
    // ...
    _commands = [
        new CommandItem(new TemplateCmdPalExtensionPage())
        {
            Title = DisplayName,
            MoreCommands = [new CommandContextItem(_settingsManager.Settings.SettingsPage)],
        },
    ];
    Settings = _settingsManager.Settings;
}

The template wizard replaces "TemplateCmdPalExtension" throughout all files, so BaseSettingsPath and the namespace string will update automatically when scaffolding a new extension.

Validation Steps Performed

  • Verified SettingsManager pattern matches existing built-in extensions (ClipboardHistory, System, Registry)
  • No new package references required — JsonSettingsManager, ToggleSetting, and Utilities are all included in the existing Microsoft.CommandPalette.Extensions NuGet package
Original prompt

This section details on the original issue you should resolve

<issue_title>CmdPal: Include basic SettingsManager in Template</issue_title>
<issue_description>### Description of the new feature / enhancement

Include basic SettingsManager in template.

Scenario when this would be used?

I believe most extensions will require some form of configuration, so adding basic SettingsManager would be helpful.

Supporting information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 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.

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Copilot AI changed the title [WIP] Add basic SettingsManager to template CmdPal: Include basic SettingsManager in extension template Mar 10, 2026
@niels9001 niels9001 requested a review from Copilot March 10, 2026 08:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cs that extends JsonSettingsManager, loads/saves settings.json, and auto-saves on SettingsChanged.
  • Wires the template command provider to expose the settings UI via MoreCommands and to advertise settings via CommandProvider.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.

Comment on lines +12 to +14
private static readonly string _namespace = "templatecmdpalextension";

private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}";
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

internal sealed partial class SettingsManager : JsonSettingsManager
{
private static readonly string _namespace = "templatecmdpalextension";

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

templatecmdpalextension is not a recognized word. (unrecognized-spelling)
@github-actions
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (1)

templatecmdpalextension

These words are not needed and should be removed kbmcontrols mfalse mtrue

To 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
on the copilot/add-settings-manager-template branch (ℹ️ how do I use this?):

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 ⚠️ (1)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

⚠️ Warnings Count
⚠️ ignored-expect-variant 3

See ⚠️ Event descriptions for more information.

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.txt file 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 the patterns.txt file.

    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.

@jiripolasek jiripolasek added the Product-Command Palette Refers to the Command Palette utility label Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CmdPal: Include basic SettingsManager in Template

4 participants