Added Application.QuitKey property to allow change the quitting application key. (#1450)

* Added Application.QuitKey property to allow change the quitting application key.

* Fixes QuitKey unit test by reseting his value.

* Locks timeouts until is added.
This commit is contained in:
BDisp
2021-09-29 22:22:43 +01:00
committed by GitHub
parent 84f79b2326
commit 23d4fa9016
3 changed files with 36 additions and 1 deletions

View File

@@ -148,6 +148,10 @@ namespace Terminal.Gui {
/// Alternative key to navigate backwards through all views. Shift+Ctrl+Tab is always used.
/// </summary>
public static Key AlternateBackwardKey { get; set; } = Key.PageUp | Key.CtrlMask;
/// <summary>
/// Gets or sets the key to quit the application.
/// </summary>
public static Key QuitKey { get; set; } = Key.Q | Key.CtrlMask;
/// <summary>
/// The <see cref="MainLoop"/> driver for the application

View File

@@ -294,7 +294,7 @@ namespace Terminal.Gui {
return true;
switch (ShortcutHelper.GetModifiersKey (keyEvent)) {
case Key.Q | Key.CtrlMask:
case Key k when k == Application.QuitKey:
// FIXED: stop current execution of this container
if (Application.MdiTop != null) {
Application.MdiTop.RequestStop ();

View File

@@ -1142,5 +1142,36 @@ namespace Terminal.Gui.Core {
Assert.False (Application.ShowChild (Application.Top));
Application.End (Application.Top);
}
[Fact]
[AutoInitShutdown]
public void QuitKey_Getter_Setter ()
{
var top = Application.Top;
var isQuiting = false;
top.Closing += (e) => {
isQuiting = true;
e.Cancel = true;
};
Application.Begin (top);
top.Running = true;
Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey);
Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
Assert.True (isQuiting);
isQuiting = false;
Application.QuitKey = Key.C | Key.CtrlMask;
Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
Assert.False (isQuiting);
Application.Driver.SendKeys ('c', ConsoleKey.C, false, false, true);
Assert.True (isQuiting);
// Reset the QuitKey to avoid throws errors on another tests
Application.QuitKey = Key.Q | Key.CtrlMask;
}
}
}