mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user