mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-21 06:03:52 +00:00
PowerControl: Provide ValueChanged event
This commit is contained in:
parent
f6dbf3c199
commit
49b94e274c
3 changed files with 35 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ namespace PowerControl
|
|||
|
||||
var contextMenu = new System.Windows.Forms.ContextMenuStrip(components);
|
||||
|
||||
rootMenu.Init();
|
||||
rootMenu.Visible = false;
|
||||
rootMenu.Update();
|
||||
rootMenu.CreateMenu(contextMenu);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ namespace PowerControl.Menu
|
|||
public Func<string, string?>? ApplyValue { get; set; }
|
||||
public Func<string?>? ResetValue { get; set; }
|
||||
|
||||
public event Action<MenuItemWithOptions, String?, String> ValueChanged;
|
||||
|
||||
private System.Windows.Forms.Timer delayTimer = new System.Windows.Forms.Timer();
|
||||
private ToolStripMenuItem toolStripItem = new ToolStripMenuItem();
|
||||
|
||||
|
|
@ -20,6 +22,8 @@ namespace PowerControl.Menu
|
|||
{
|
||||
this.Selectable = true;
|
||||
|
||||
ValueChanged += delegate { };
|
||||
|
||||
delayTimer.Tick += delegate (object? sender, EventArgs e)
|
||||
{
|
||||
if (delayTimer != null)
|
||||
|
|
@ -89,12 +93,17 @@ namespace PowerControl.Menu
|
|||
|
||||
private void FinalizeSet()
|
||||
{
|
||||
var wasOption = ActiveOption;
|
||||
|
||||
if (ApplyValue != null && SelectedOption != null)
|
||||
ActiveOption = ApplyValue(SelectedOption);
|
||||
else
|
||||
ActiveOption = SelectedOption;
|
||||
|
||||
SelectedOption = null;
|
||||
|
||||
if (wasOption != ActiveOption && ActiveOption != null)
|
||||
ValueChanged(this, wasOption, ActiveOption);
|
||||
}
|
||||
|
||||
public override void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMenu)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@ namespace PowerControl.Menu
|
|||
{
|
||||
public IList<MenuItem> Items { get; } = new List<MenuItem>();
|
||||
public MenuItem? Selected;
|
||||
|
||||
public event Action VisibleChanged;
|
||||
public event Action<MenuItemWithOptions, String?, String> ValueChanged;
|
||||
|
||||
public MenuRoot()
|
||||
{
|
||||
VisibleChanged += delegate { };
|
||||
ValueChanged += delegate { };
|
||||
}
|
||||
|
||||
public MenuItem? this[String name]
|
||||
|
|
@ -26,12 +29,34 @@ namespace PowerControl.Menu
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerable<MenuItemWithOptions> AllMenuItemOptions()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is MenuItemWithOptions)
|
||||
yield return (MenuItemWithOptions)item;
|
||||
}
|
||||
}
|
||||
|
||||
public override void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMenu)
|
||||
{
|
||||
foreach (var item in Items)
|
||||
item.CreateMenu(contextMenu);
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
foreach (var item in AllMenuItemOptions())
|
||||
{
|
||||
item.ValueChanged += MenuItem_ValueChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuItem_ValueChanged(MenuItemWithOptions item, String? was, String isNow)
|
||||
{
|
||||
ValueChanged(item, was, isNow);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue