-
Notifications
You must be signed in to change notification settings - Fork 7.8k
CmdPal: Include basic SettingsManager in extension template #46028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright (c) Microsoft Corporation | ||
| // The Microsoft Corporation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.IO; | ||
| using Microsoft.CommandPalette.Extensions.Toolkit; | ||
|
|
||
| namespace TemplateCmdPalExtension; | ||
|
|
||
| internal sealed partial class SettingsManager : JsonSettingsManager | ||
| { | ||
| private static readonly string _namespace = "templatecmdpalextension"; | ||
|
|
||
| private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}"; | ||
|
Comment on lines
+12
to
+14
|
||
|
|
||
| // TODO: Add your settings here. For example: | ||
| // private readonly ToggleSetting _myToggle = new( | ||
| // Namespaced(nameof(MyToggle)), | ||
| // "My toggle setting", | ||
| // "Description of my toggle setting", | ||
| // false); | ||
|
|
||
| // TODO: Add accessors for each setting. For example: | ||
| // public bool MyToggle => _myToggle.Value; | ||
|
|
||
| internal static string SettingsJsonPath() | ||
| { | ||
| var directory = Utilities.BaseSettingsPath("TemplateCmdPalExtension"); | ||
| Directory.CreateDirectory(directory); | ||
|
|
||
| return Path.Combine(directory, "settings.json"); | ||
| } | ||
|
|
||
| public SettingsManager() | ||
| { | ||
| FilePath = SettingsJsonPath(); | ||
|
|
||
| // TODO: Register your settings here. For example: | ||
| // Settings.Add(_myToggle); | ||
|
|
||
| // Load settings from file upon initialization | ||
| LoadSettings(); | ||
|
|
||
| Settings.SettingsChanged += (_, _) => SaveSettings(); | ||
| } | ||
| } | ||
Check failure
Code scanning / check-spelling
Unrecognized Spelling Error