Files
PowerToys/src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleSettingsPage.cs
Mike Griese 2b5181b4c9 Rename the [Ee]xts dir to ext (#38852)
**WARNING:** This PR will probably blow up all in-flight PRs

at some point in the early days of CmdPal, two of us created seperate
`Exts` and `exts` dirs. Depending on what the casing was on the branch
that you checked one of those out from, it'd get stuck like that on your
PC forever.

Windows didn't care, so we never noticed.

But GitHub does care, and now browsing the source on GitHub is basically
impossible.

Closes #38081
2025-04-15 06:07:22 -05:00

60 lines
2.0 KiB
C#

// 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.Collections.Generic;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
namespace SamplePagesExtension;
internal sealed partial class SampleSettingsPage : ContentPage
{
private readonly Settings _settings = new();
private readonly List<ChoiceSetSetting.Choice> _choices = new()
{
new ChoiceSetSetting.Choice("The first choice in the list is the default choice", "0"),
new ChoiceSetSetting.Choice("Choices have titles and values", "1"),
new ChoiceSetSetting.Choice("Title", "Value"),
new ChoiceSetSetting.Choice("The options are endless", "3"),
new ChoiceSetSetting.Choice("So many choices", "4"),
};
public override IContent[] GetContent()
{
var s = _settings.ToContent();
return s;
}
public SampleSettingsPage()
{
Name = "Sample Settings";
Icon = new IconInfo(string.Empty);
_settings.Add(new ToggleSetting("onOff", true)
{
Label = "This is a toggle",
Description = "It produces a simple checkbox",
});
_settings.Add(new TextSetting("someText", "initial value")
{
Label = "This is a text box",
Description = "For some string of text",
});
_settings.Add(new ChoiceSetSetting("choiceSetExample", _choices)
{
Label = "It also has a label",
Description = "Describe your choice set setting here",
});
_settings.SettingsChanged += SettingsChanged;
}
private void SettingsChanged(object sender, Settings args)
{
/* Do something with the new settings here */
var onOff = _settings.GetSetting<bool>("onOff");
ExtensionHost.LogMessage(new LogMessage() { Message = $"SampleSettingsPage: Changed the value of onOff to {onOff}" });
}
}