mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-09 00:03:53 +00:00
PowerControl: Provide ValueChanged event
This commit is contained in:
parent
f6dbf3c199
commit
49b94e274c
3 changed files with 35 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue