PowerControl: Allow to set Autostart Profile Settings

This commit is contained in:
Kamil Trzciński 2023-04-01 13:41:53 +02:00 committed by Kamil Trzcinski
parent acd33f2cb2
commit cf0de0ad8f
4 changed files with 51 additions and 4 deletions

View file

@ -155,10 +155,50 @@ namespace PowerControl.Menu
toolStripItem.DropDownItems.Add(item);
}
AddMenuItemsToModifyProfile(
PowerControl.Options.Profiles.Controller?.AutostartProfileSettings,
toolStripItem.DropDownItems
);
toolStripItem.Visible = Visible && Options.Count > 0;
};
}
private void AddMenuItemsToModifyProfile(Helper.ProfileSettings? profileSettings, ToolStripItemCollection dropDownItems)
{
if (profileSettings is null || PersistentKey is null)
return;
dropDownItems.Add(new ToolStripSeparator());
var headingItem = new ToolStripMenuItem(profileSettings.ProfileName + ": ");
dropDownItems.Add(headingItem);
var persistedValue = profileSettings.GetValue(PersistentKey);
foreach (var option in Options)
{
var item = new ToolStripMenuItem("Set: " + option);
item.Checked = option == persistedValue;
item.Click += delegate { profileSettings.SetValue(PersistentKey, option); };
headingItem.DropDownItems.Add(item);
}
if (persistedValue is not null)
{
headingItem.Text += persistedValue;
headingItem.Checked = true;
headingItem.DropDownItems.Add(new ToolStripSeparator());
var unsetItem = headingItem.DropDownItems.Add("Unset");
unsetItem.Click += delegate { profileSettings.DeleteKey(PersistentKey); };
}
else
{
headingItem.Text += "Not set";
}
}
private void SelectIndex(int index)
{
if (Options.Count == 0)