Leveraging the power of CanExecute feature.

This commit is contained in:
BDisp
2023-08-06 22:53:33 +01:00
committed by Tig
parent 63ceef5259
commit 754d7d6983
2 changed files with 56 additions and 12 deletions

View File

@@ -1747,5 +1747,45 @@ Edit
var exception = Record.Exception (() => menu.ProcessColdKey (new KeyEvent (Key.Space, new KeyModifiers ())));
Assert.Null (exception);
}
[Fact, AutoInitShutdown]
public void CanExecute_ProcessHotKey ()
{
Window win = null;
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem ("File", new MenuItem [] {
new MenuItem ("_New", "", New, CanExecuteNew),
new MenuItem ("_Close", "", Close, CanExecuteClose)
}),
});
var top = Application.Top;
top.Add (menu);
bool CanExecuteNew () => win == null;
void New ()
{
win = new Window ();
}
bool CanExecuteClose () => win != null;
void Close ()
{
win = null;
}
Application.Begin (top);
Assert.Null (win);
Assert.True (CanExecuteNew ());
Assert.False (CanExecuteClose ());
Assert.True (top.ProcessHotKey (new KeyEvent (Key.N | Key.AltMask, new KeyModifiers () { Alt = true })));
Application.MainLoop.MainIteration ();
Assert.NotNull (win);
Assert.False (CanExecuteNew ());
Assert.True (CanExecuteClose ());
}
}
}