mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 00:38:00 +01:00
* Added View.DefaultCommand etc... Started on dedicated scenario * Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc. * Fixed Key Bindings and HotKeys * Fixed Key Bindings and HotKeys * Label now correctly supports hotkey * Disabled unix hot keys because they are annoying and get in the way * Updated nuget. fixed warnings * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Changed TextChangingEventArgs to inherit from CancelEventArgs * TextChangingEventArgs -> TextEventArgs * Simplified Text events by having only on args class * Fixed unit tests fail * Simplified by removing TitleEventArgs * POC of Title being primary for hotkey. Label and Button hacked to work * POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass * Dropped Microsoft.NETFramework.ReferenceAssemblies * Fixed Dialogs scenario hotkeys * Fixed build warnings * Fixed Border Title render bug * Regiggering default command handling * Regiggering default command handling * Checkbox clean up * Added StateEventArgs POC * Command.Default -> Command.HotKey * Command.Default -> Command.HotKey - fixed TableView * Command.Default -> Command.HotKey - fixed TableView * Updated reactive example * Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't * WIP - broke * Finished impl of StateEventArgs * Deleted ToggleEventArgs.cs. Added StateEventArgs.cs * XML doc fix * Removed old code * Removed commented out code * Label.Clicked -> Label.Accept (missed this before) * Removed Labels as Buttons scenario as it's not really useful * Moved SubView tests to own file * Moved SubView tests to own file * Simplified Text test * Added OnAccept test * Deleted DefaultCommand * Modernized CheckBox * New button test * Cleaned up RadioGroup; added tests * KeyCode->Key in ListView * Added ListView unit tests * ListView now does Accept correctly * TreeView now does Accept correctly * Cleaned up some TextField tests * TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Removed un-needed using statement
140 lines
4.0 KiB
C#
140 lines
4.0 KiB
C#
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
|
|
public class ViewKeyBindingTests
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
public ViewKeyBindingTests (ITestOutputHelper output) { _output = output; }
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Focus_KeyBinding ()
|
|
{
|
|
var view = new ScopedKeyBindingView ();
|
|
var invoked = false;
|
|
view.InvokingKeyBindings += (s, e) => invoked = true;
|
|
|
|
Application.Top.Add (view);
|
|
Application.Begin (Application.Top);
|
|
|
|
Application.OnKeyDown (Key.A);
|
|
Assert.True (invoked);
|
|
|
|
invoked = false;
|
|
Application.OnKeyDown (Key.H);
|
|
Assert.True (invoked);
|
|
|
|
invoked = false;
|
|
Assert.False (view.HasFocus);
|
|
Application.OnKeyDown (Key.F);
|
|
Assert.False (invoked);
|
|
Assert.False (view.FocusedCommand);
|
|
|
|
invoked = false;
|
|
view.CanFocus = true;
|
|
view.SetFocus ();
|
|
Assert.True (view.HasFocus);
|
|
Application.OnKeyDown (Key.F);
|
|
Assert.True (invoked);
|
|
|
|
Assert.True (view.ApplicationCommand);
|
|
Assert.True (view.HotKeyCommand);
|
|
Assert.True (view.FocusedCommand);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Focus_KeyBinding_Negative ()
|
|
{
|
|
var view = new ScopedKeyBindingView ();
|
|
var invoked = false;
|
|
view.InvokingKeyBindings += (s, e) => invoked = true;
|
|
|
|
Application.Top.Add (view);
|
|
Application.Begin (Application.Top);
|
|
|
|
Application.OnKeyDown (Key.Z);
|
|
Assert.False (invoked);
|
|
Assert.False (view.ApplicationCommand);
|
|
Assert.False (view.HotKeyCommand);
|
|
Assert.False (view.FocusedCommand);
|
|
|
|
invoked = false;
|
|
Assert.False (view.HasFocus);
|
|
Application.OnKeyDown (Key.F);
|
|
Assert.False (invoked);
|
|
Assert.False (view.ApplicationCommand);
|
|
Assert.False (view.HotKeyCommand);
|
|
Assert.False (view.FocusedCommand);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void HotKey_KeyBinding ()
|
|
{
|
|
var view = new ScopedKeyBindingView ();
|
|
var invoked = false;
|
|
view.InvokingKeyBindings += (s, e) => invoked = true;
|
|
|
|
Application.Top.Add (view);
|
|
Application.Begin (Application.Top);
|
|
|
|
invoked = false;
|
|
Application.OnKeyDown (Key.H);
|
|
Assert.True (invoked);
|
|
Assert.True (view.HotKeyCommand);
|
|
|
|
view.HotKey = KeyCode.Z;
|
|
invoked = false;
|
|
view.HotKeyCommand = false;
|
|
Application.OnKeyDown (Key.H); // old hot key
|
|
Assert.False (invoked);
|
|
Assert.False (view.HotKeyCommand);
|
|
|
|
Application.OnKeyDown (Key.Z); // new hot key
|
|
Assert.True (invoked);
|
|
Assert.True (view.HotKeyCommand);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void HotKey_KeyBinding_Negative ()
|
|
{
|
|
var view = new ScopedKeyBindingView ();
|
|
var invoked = false;
|
|
view.InvokingKeyBindings += (s, e) => invoked = true;
|
|
|
|
Application.Top.Add (view);
|
|
Application.Begin (Application.Top);
|
|
|
|
Application.OnKeyDown (Key.Z);
|
|
Assert.False (invoked);
|
|
Assert.False (view.HotKeyCommand);
|
|
|
|
invoked = false;
|
|
Application.OnKeyDown (Key.F);
|
|
Assert.False (view.HotKeyCommand);
|
|
}
|
|
|
|
// tests that test KeyBindingScope.Focus and KeyBindingScope.HotKey (tests for KeyBindingScope.Application are in Application/KeyboardTests.cs)
|
|
|
|
public class ScopedKeyBindingView : View
|
|
{
|
|
public ScopedKeyBindingView ()
|
|
{
|
|
AddCommand (Command.Save, () => ApplicationCommand = true);
|
|
AddCommand (Command.HotKey, () => HotKeyCommand = true);
|
|
AddCommand (Command.Left, () => FocusedCommand = true);
|
|
|
|
KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Save);
|
|
HotKey = KeyCode.H;
|
|
KeyBindings.Add (Key.F, KeyBindingScope.Focused, Command.Left);
|
|
}
|
|
|
|
public bool ApplicationCommand { get; set; }
|
|
public bool FocusedCommand { get; set; }
|
|
public bool HotKeyCommand { get; set; }
|
|
}
|
|
}
|