PowerControl: Provide ValueChanged event

This commit is contained in:
Kamil Trzciński 2022-12-19 23:45:44 +01:00
parent f6dbf3c199
commit 49b94e274c
3 changed files with 35 additions and 0 deletions

View file

@ -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)