Fixes #2789. StatusItem should have a disabled attribute if it can't execute.

This commit is contained in:
BDisp
2023-08-06 23:46:47 +01:00
committed by Tig
parent 42fcc35154
commit 74aedd25bf
2 changed files with 81 additions and 6 deletions

View File

@@ -18,12 +18,13 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (Key.CtrlMask | Key.Q, si.Shortcut);
Assert.Equal ("~^Q~ Quit", si.Title);
Assert.Null (si.Action);
Assert.True (si.IsEnabled ());
si = new StatusItem (Key.CtrlMask | Key.Q, "~^Q~ Quit", () => { });
Assert.NotNull (si.Action);
}
[Fact]
public void StatusBar_Contructor_Default ()
public void StatusBar_Constructor_Default ()
{
var sb = new StatusBar ();
@@ -155,5 +156,43 @@ CTRL-O Open {Application.Driver.VLine} CTRL-Q Quit
Assert.Equal ("~^A~ Save As", sb.Items [1].Title);
Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
}
[Fact, AutoInitShutdown]
public void CanExecute_ProcessHotKey ()
{
Window win = null;
var statusBar = new StatusBar (new StatusItem [] {
new StatusItem (Key.CtrlMask | Key.N, "~^N~ New", New, CanExecuteNew),
new StatusItem (Key.CtrlMask | Key.C, "~^C~ Close", Close, CanExecuteClose)
});
var top = Application.Top;
top.Add (statusBar);
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.CtrlMask, new KeyModifiers () { Alt = true })));
Application.MainLoop.MainIteration ();
Assert.NotNull (win);
Assert.False (CanExecuteNew ());
Assert.True (CanExecuteClose ());
}
}
}