From 16055c53b05418b929845810889a5ac31201a983 Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 22 Feb 2024 15:11:26 -0700 Subject: [PATCH] Fixes #3039. Fix View.HotKey (#3249) * 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 --- .github/workflows/dotnet-core.yml | 2 +- Example/Example.cs | 2 +- ReactiveExample/LoginView.cs | 30 +- ReactiveExample/LoginViewModel.cs | 15 +- Terminal.Gui/Application.cs | 3 +- .../CursesDriver/CursesDriver.cs | 2 +- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 2 +- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 3 +- .../FileServices/DefaultFileOperations.cs | 4 +- Terminal.Gui/Input/Command.cs | 19 +- Terminal.Gui/Input/Key.cs | 74 +- Terminal.Gui/Input/KeyBinding.cs | 26 +- .../Text/Autocomplete/AppendAutocomplete.cs | 6 +- .../Text/Autocomplete/AutocompleteBase.cs | 2 +- .../Text/Autocomplete/PopupAutocomplete.cs | 18 +- Terminal.Gui/Text/StringEventArgs.cs | 26 + Terminal.Gui/Text/TextFormatter.cs | 6 +- Terminal.Gui/View/Adornment/Border.cs | 56 +- Terminal.Gui/View/StateEventArgs.cs | 27 + Terminal.Gui/View/TitleEventArgs.cs | 23 - Terminal.Gui/View/ToggleEventArgs.cs | 20 - Terminal.Gui/View/View.cs | 161 ++- Terminal.Gui/View/ViewKeyboard.cs | 184 +-- Terminal.Gui/View/ViewText.cs | 47 +- Terminal.Gui/Views/Button.cs | 63 +- Terminal.Gui/Views/CheckBox.cs | 191 ++- Terminal.Gui/Views/ColorPicker.cs | 8 +- Terminal.Gui/Views/ComboBox.cs | 37 +- Terminal.Gui/Views/DateField.cs | 20 +- Terminal.Gui/Views/DatePicker.cs | 4 +- Terminal.Gui/Views/FileDialog.cs | 30 +- Terminal.Gui/Views/GraphView/GraphView.cs | 8 +- Terminal.Gui/Views/HexView.cs | 34 +- Terminal.Gui/Views/Label.cs | 83 +- Terminal.Gui/Views/ListView.cs | 38 +- Terminal.Gui/Views/Menu/Menu.cs | 20 +- Terminal.Gui/Views/Menu/MenuBar.cs | 75 +- Terminal.Gui/Views/MessageBox.cs | 2 +- Terminal.Gui/Views/RadioGroup.cs | 24 +- Terminal.Gui/Views/ScrollView.cs | 28 +- Terminal.Gui/Views/Slider.cs | 40 +- Terminal.Gui/Views/StatusBar.cs | 8 +- Terminal.Gui/Views/TabView.cs | 16 +- .../TableView/CheckBoxTableSourceWrapper.cs | 2 +- .../Views/TableView/TableSelection.cs | 2 +- Terminal.Gui/Views/TableView/TableView.cs | 53 +- Terminal.Gui/Views/TextChangedEventArgs.cs | 19 - Terminal.Gui/Views/TextChangingEventArgs.cs | 22 - Terminal.Gui/Views/TextField.cs | 140 +-- Terminal.Gui/Views/TextValidateField.cs | 36 +- Terminal.Gui/Views/TextView.cs | 170 ++- Terminal.Gui/Views/Tile.cs | 16 +- Terminal.Gui/Views/TileView.cs | 8 +- Terminal.Gui/Views/TimeField.cs | 21 +- Terminal.Gui/Views/ToplevelOverlapped.cs | 2 +- Terminal.Gui/Views/TreeView/TreeView.cs | 63 +- Terminal.Gui/Views/Wizard/Wizard.cs | 18 +- UICatalog/KeyBindingsDialog.cs | 6 +- UICatalog/Scenarios/ASCIICustomButton.cs | 6 +- UICatalog/Scenarios/Adornments.cs | 113 +- UICatalog/Scenarios/AllViewsTester.cs | 2 +- .../Scenarios/BackgroundWorkerCollection.cs | 4 +- UICatalog/Scenarios/Buttons.cs | 24 +- UICatalog/Scenarios/CharacterMap.cs | 19 +- UICatalog/Scenarios/ChineseUI.cs | 2 +- UICatalog/Scenarios/Clipping.cs | 2 +- UICatalog/Scenarios/ComboBoxIteration.cs | 4 +- UICatalog/Scenarios/ComputedLayout.cs | 8 +- UICatalog/Scenarios/ContextMenus.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 6 +- UICatalog/Scenarios/Dialogs.cs | 76 +- UICatalog/Scenarios/DynamicMenuBar.cs | 32 +- UICatalog/Scenarios/DynamicStatusBar.cs | 22 +- UICatalog/Scenarios/Editor.cs | 14 +- UICatalog/Scenarios/FileDialogExamples.cs | 2 +- UICatalog/Scenarios/HotKeys.cs | 138 +++ UICatalog/Scenarios/Images.cs | 2 +- UICatalog/Scenarios/InteractiveTree.cs | 4 +- UICatalog/Scenarios/InvertColors.cs | 2 +- UICatalog/Scenarios/LabelsAsButtons.cs | 386 ------- UICatalog/Scenarios/LineDrawing.cs | 2 +- UICatalog/Scenarios/ListColumns.cs | 6 +- UICatalog/Scenarios/ListViewWithSelection.cs | 13 +- UICatalog/Scenarios/ListsAndCombos.cs | 4 +- UICatalog/Scenarios/Localization.cs | 6 +- UICatalog/Scenarios/MenuBarScenario.cs | 6 +- UICatalog/Scenarios/MessageBoxes.cs | 2 +- UICatalog/Scenarios/MultiColouredTable.cs | 4 +- UICatalog/Scenarios/Progress.cs | 8 +- UICatalog/Scenarios/ProgressBarStyles.cs | 6 +- UICatalog/Scenarios/RunTExample.cs | 2 +- .../Scenarios/RuneWidthGreaterThanOne.cs | 12 +- UICatalog/Scenarios/Scrolling.cs | 6 +- UICatalog/Scenarios/SendKeys.cs | 2 +- UICatalog/Scenarios/SingleBackgroundWorker.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 10 +- UICatalog/Scenarios/Text.cs | 54 +- UICatalog/Scenarios/TextAlignments.cs | 4 +- UICatalog/Scenarios/Threading.cs | 16 +- UICatalog/Scenarios/TimeAndDate.cs | 2 +- UICatalog/Scenarios/VkeyPacketSimulator.cs | 4 +- UICatalog/Scenarios/WindowsAndFrameViews.cs | 4 +- UICatalog/Scenarios/WizardAsView.cs | 2 +- UICatalog/Scenarios/Wizards.cs | 6 +- UICatalog/UICatalog.cs | 4 +- UICatalog/UICatalog.csproj | 2 +- UnitTests/Application/KeyboardTests.cs | 98 +- UnitTests/Application/MainLoopTests.cs | 10 +- .../Configuration/ConfigurationMangerTests.cs | 24 +- UnitTests/Configuration/JsonConverterTests.cs | 4 - UnitTests/Configuration/SettingsScopeTests.cs | 12 +- .../ConsoleDrivers/ConsoleDriverTests.cs | 9 +- UnitTests/Dialogs/DialogTests.cs | 16 +- UnitTests/Dialogs/WizardTests.cs | 12 +- UnitTests/FileServices/FileDialogTests.cs | 14 +- UnitTests/Input/KeyBindingTests.cs | 88 +- UnitTests/Input/KeyTests.cs | 138 ++- UnitTests/Text/AutocompleteTests.cs | 28 +- UnitTests/UnitTests.csproj | 10 +- UnitTests/View/Adornment/BorderTests.cs | 3 +- UnitTests/View/HotKeyTests.cs | 95 +- UnitTests/View/KeyboardEventTests.cs | 22 +- UnitTests/View/Layout/DimTests.cs | 4 +- UnitTests/View/Layout/PosTests.cs | 4 +- UnitTests/View/NavigationTests.cs | 40 +- UnitTests/View/SubviewTests.cs | 333 ++++++ UnitTests/View/Text/AutoSizeTrueTests.cs | 112 +- UnitTests/View/Text/TextTests.cs | 27 +- UnitTests/View/TitleTests.cs | 20 +- UnitTests/View/ViewKeyBindingTests.cs | 28 +- UnitTests/View/ViewTests.cs | 452 ++------ UnitTests/Views/AllViewsTests.cs | 8 +- UnitTests/Views/AppendAutocompleteTests.cs | 8 +- UnitTests/Views/ButtonTests.cs | 110 +- UnitTests/Views/CheckBoxTests.cs | 188 +-- UnitTests/Views/ColorPickerTests.cs | 12 +- UnitTests/Views/ComboBoxTests.cs | 124 +- UnitTests/Views/ContextMenuTests.cs | 46 +- UnitTests/Views/DateFieldTests.cs | 50 +- UnitTests/Views/DatePickerTests.cs | 8 +- UnitTests/Views/HexViewTests.cs | 114 +- UnitTests/Views/LabelTests.cs | 126 +- UnitTests/Views/ListViewTests.cs | 119 +- UnitTests/Views/MenuBarTests.cs | 126 +- UnitTests/Views/RadioGroupTests.cs | 91 +- UnitTests/Views/ScrollBarViewTests.cs | 2 +- UnitTests/Views/ScrollViewTests.cs | 130 +-- UnitTests/Views/StatusBarTests.cs | 4 +- UnitTests/Views/TableViewTests.cs | 108 +- UnitTests/Views/TextFieldTests.cs | 376 +++--- UnitTests/Views/TextValidateFieldTests.cs | 114 +- UnitTests/Views/TextViewTests.cs | 1028 ++++++++--------- UnitTests/Views/TileViewTests.cs | 52 +- UnitTests/Views/TimeFieldTests.cs | 52 +- UnitTests/Views/ToplevelTests.cs | 106 +- UnitTests/Views/TreeTableSourceTests.cs | 12 +- UnitTests/Views/TreeViewTests.cs | 108 +- UnitTests/Views/WindowTests.cs | 8 +- 158 files changed, 4124 insertions(+), 3833 deletions(-) create mode 100644 Terminal.Gui/Text/StringEventArgs.cs create mode 100644 Terminal.Gui/View/StateEventArgs.cs delete mode 100644 Terminal.Gui/View/TitleEventArgs.cs delete mode 100644 Terminal.Gui/View/ToggleEventArgs.cs delete mode 100644 Terminal.Gui/Views/TextChangedEventArgs.cs delete mode 100644 Terminal.Gui/Views/TextChangingEventArgs.cs create mode 100644 UICatalog/Scenarios/HotKeys.cs delete mode 100644 UICatalog/Scenarios/LabelsAsButtons.cs create mode 100644 UnitTests/View/SubviewTests.cs diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index 308da12c3..4ca317ce0 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -17,7 +17,7 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0 + dotnet-version: 8.x dotnet-quality: 'ga' - name: Install dependencies diff --git a/Example/Example.cs b/Example/Example.cs index d9f3545f4..406675ad4 100644 --- a/Example/Example.cs +++ b/Example/Example.cs @@ -61,7 +61,7 @@ public class ExampleWindow : Window }; // When login button is clicked display a message popup - btnLogin.Clicked += (s, e) => + btnLogin.Accept += (s, e) => { if (UserNameText.Text == "admin" && passwordText.Text == "password") { diff --git a/ReactiveExample/LoginView.cs b/ReactiveExample/LoginView.cs index 4cf1b4368..4f057cb17 100644 --- a/ReactiveExample/LoginView.cs +++ b/ReactiveExample/LoginView.cs @@ -12,11 +12,11 @@ public class LoginView : Window, IViewFor public LoginView (LoginViewModel viewModel) { - Title = "Reactive Extensions Example"; + Title = $"Reactive Extensions Example - {Application.QuitKey} to Exit"; ViewModel = viewModel; Label usernameLengthLabel = UsernameLengthLabel (TitleLabel ()); TextField usernameInput = UsernameInput (usernameLengthLabel); - Label passwordLengthLabel = PasswordLengthLabel (usernameInput); + Label passwordLengthLabel = PasswordLengthLabel (usernameLengthLabel); TextField passwordInput = PasswordInput (passwordLengthLabel); Label validationLabel = ValidationLabel (passwordInput); Button loginButton = LoginButton (validationLabel); @@ -42,12 +42,12 @@ public class LoginView : Window, IViewFor { var clearButton = new Button { - X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Text = "Clear" + X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Text = "_Clear" }; clearButton .Events () - .Clicked + .Accept .InvokeCommand (ViewModel, x => x.Clear) .DisposeWith (_disposable); Add (clearButton); @@ -59,12 +59,12 @@ public class LoginView : Window, IViewFor { var loginButton = new Button { - X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Text = "Login" + X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Text = "_Login" }; loginButton .Events () - .Clicked + .Accept .InvokeCommand (ViewModel, x => x.Login) .DisposeWith (_disposable); Add (loginButton); @@ -79,7 +79,7 @@ public class LoginView : Window, IViewFor var loginProgressLabel = new Label { - X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Text = idle + AutoSize = false, X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Height = 1, Text = idle }; ViewModel @@ -97,7 +97,7 @@ public class LoginView : Window, IViewFor { var passwordInput = new TextField { - X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Text = ViewModel.Password + X = Pos.Right (previous) + 1, Y = Pos.Top (previous), Width = 40, Text = ViewModel.Password }; ViewModel @@ -119,11 +119,11 @@ public class LoginView : Window, IViewFor private Label PasswordLengthLabel (View previous) { - var passwordLengthLabel = new Label { X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40 }; + var passwordLengthLabel = new Label { X = Pos.Left (previous), Y = Pos.Top (previous) + 1, }; ViewModel .WhenAnyValue (x => x.PasswordLength) - .Select (length => $"Password ({length} characters)") + .Select (length => $"_Password ({length} characters):") .BindTo (passwordLengthLabel, x => x.Text) .DisposeWith (_disposable); Add (passwordLengthLabel); @@ -143,7 +143,7 @@ public class LoginView : Window, IViewFor { var usernameInput = new TextField { - X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Text = ViewModel.Username + X = Pos.Right (previous) + 1, Y = Pos.Top (previous), Width = 40, Text = ViewModel.Username }; ViewModel @@ -165,11 +165,11 @@ public class LoginView : Window, IViewFor private Label UsernameLengthLabel (View previous) { - var usernameLengthLabel = new Label { X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40 }; + var usernameLengthLabel = new Label { X = Pos.Left (previous), Y = Pos.Top (previous) + 1 }; ViewModel .WhenAnyValue (x => x.UsernameLength) - .Select (length => $"Username ({length} characters)") + .Select (length => $"_Username ({length} characters):") .BindTo (usernameLengthLabel, x => x.Text) .DisposeWith (_disposable); Add (usernameLengthLabel); @@ -179,12 +179,12 @@ public class LoginView : Window, IViewFor private Label ValidationLabel (View previous) { - var error = "Please, enter user name and password."; + var error = "Please enter a valid user name and password."; var success = "The input is valid!"; var validationLabel = new Label { - X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Text = error + X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Text = error }; ViewModel diff --git a/ReactiveExample/LoginViewModel.cs b/ReactiveExample/LoginViewModel.cs index e33796572..71816142e 100644 --- a/ReactiveExample/LoginViewModel.cs +++ b/ReactiveExample/LoginViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Reactive; using System.Reactive.Linq; using System.Runtime.Serialization; @@ -37,10 +38,10 @@ public class LoginViewModel : ReactiveObject _isValid = canLogin.ToProperty (this, x => x.IsValid); - Login = ReactiveCommand.CreateFromTask ( - e => Task.Delay (TimeSpan.FromSeconds (1)), - canLogin - ); + Login = ReactiveCommand.CreateFromTask ( + e => Task.Delay (TimeSpan.FromSeconds (1)), + canLogin + ); _usernameLength = this .WhenAnyValue (x => x.Username) @@ -52,7 +53,7 @@ public class LoginViewModel : ReactiveObject .Select (password => password.Length) .ToProperty (this, x => x.PasswordLength); - Clear = ReactiveCommand.Create (e => { }); + Clear = ReactiveCommand.Create (e => { }); Clear.Subscribe ( unit => @@ -64,13 +65,13 @@ public class LoginViewModel : ReactiveObject } [IgnoreDataMember] - public ReactiveCommand Clear { get; } + public ReactiveCommand Clear { get; } [IgnoreDataMember] public bool IsValid => _isValid.Value; [IgnoreDataMember] - public ReactiveCommand Login { get; } + public ReactiveCommand Login { get; } [Reactive] [DataMember] diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 103bb8a9b..918f1cd19 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1773,7 +1773,7 @@ public static partial class Application { foreach (View view in topLevel.Subviews.Where ( v => v.KeyBindings.TryGet ( - keyEvent.KeyCode, + keyEvent, KeyBindingScope.Application, out KeyBinding _ ) @@ -1781,7 +1781,6 @@ public static partial class Application { if (view.KeyBindings.TryGet (keyEvent.KeyCode, KeyBindingScope.Application, out KeyBinding _)) { - keyEvent.Scope = KeyBindingScope.Application; bool? handled = view.OnInvokingKeyBindings (keyEvent); if (handled is { } && (bool)handled) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 2dc72d167..688e21de5 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -567,7 +567,7 @@ internal class CursesDriver : ConsoleDriver } else { - key = new Key (KeyCode.Esc); + key = Key.Esc; } OnKeyDown (key); diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index 90527a263..0211593e8 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -318,7 +318,7 @@ public class FakeDriver : ConsoleDriver if (keyInfo.KeyChar != (uint)key) { - return ConsoleKeyMapping.MapToKeyCodeModifiers (keyInfo.Modifiers, (KeyCode)keyInfo.KeyChar); + return ConsoleKeyMapping.MapToKeyCodeModifiers (keyInfo.Modifiers, (KeyCode)keyInfo.Key); } if (keyInfo.Modifiers.HasFlag (ConsoleModifiers.Control) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index bb90b68ea..f3cf6bff5 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -1606,7 +1606,8 @@ internal class WindowsDriver : ConsoleDriver } } - return (KeyCode)keyInfo.KeyChar; + // Return the Key (not KeyChar!) + return (KeyCode)keyInfo.Key; } // Handle control keys whose VK codes match the related ASCII value (those below ASCII 33) like ESC diff --git a/Terminal.Gui/FileServices/DefaultFileOperations.cs b/Terminal.Gui/FileServices/DefaultFileOperations.cs index 25f5c2369..27c33dee6 100644 --- a/Terminal.Gui/FileServices/DefaultFileOperations.cs +++ b/Terminal.Gui/FileServices/DefaultFileOperations.cs @@ -135,14 +135,14 @@ public class DefaultFileOperations : IFileOperations var confirm = false; var btnOk = new Button { IsDefault = true, Text = Strings.btnOk }; - btnOk.Clicked += (s, e) => + btnOk.Accept += (s, e) => { confirm = true; Application.RequestStop (); }; var btnCancel = new Button { Text = Strings.btnCancel }; - btnCancel.Clicked += (s, e) => + btnCancel.Accept += (s, e) => { confirm = false; Application.RequestStop (); diff --git a/Terminal.Gui/Input/Command.cs b/Terminal.Gui/Input/Command.cs index 26eecf0b2..24ebdb407 100644 --- a/Terminal.Gui/Input/Command.cs +++ b/Terminal.Gui/Input/Command.cs @@ -6,8 +6,14 @@ namespace Terminal.Gui; /// Actions which can be performed by the application or bound to keys in a control. public enum Command { - /// The default command. For this focuses the view. - Default, + /// Invoked when the HotKey for the View has been pressed. + HotKey, + + /// Accepts the current state (e.g. list selection, button press, toggle, etc). + Accept, + + /// Selects an item (e.g. a list item or menu item) without necessarily accepting it. + Select, /// Moves down one item (cell, line, etc...). LineDown, @@ -131,12 +137,6 @@ public enum Command /// Open the selected item. OpenSelectedItem, - /// Toggle the checked state. - ToggleChecked, - - /// Accepts the current state (e.g. selection, button press etc). - Accept, - /// Toggles the Expanded or collapsed state of a a list or item (with subitems). ToggleExpandCollapse, @@ -263,9 +263,6 @@ public enum Command /// Creates a new document. New, - /// Moves selection to an item (e.g. highlighting a different menu item) without necessarily accepting it. - Select, - /// Shows context about the item (e.g. a context menu). ShowContextMenu } diff --git a/Terminal.Gui/Input/Key.cs b/Terminal.Gui/Input/Key.cs index 7cd2c5b6c..04777de66 100644 --- a/Terminal.Gui/Input/Key.cs +++ b/Terminal.Gui/Input/Key.cs @@ -78,6 +78,16 @@ public class Key : EventArgs, IEquatable /// The key public Key (KeyCode k) { KeyCode = k; } + /// + /// Copy constructor. + /// + /// The Key to copy + public Key (Key key) + { + KeyCode = key.KeyCode; + Handled = key.Handled; + } + /// Constructs a new from a char. /// /// @@ -144,12 +154,18 @@ public class Key : EventArgs, IEquatable /// public Rune AsRune => ToRune (KeyCode); + private bool _handled = false; + /// /// Indicates if the current Key event has already been processed and the driver should stop notifying any other - /// event subscriber. Its important to set this value to true specially when updating any View's layout from inside the + /// event subscriber. It's important to set this value to true specially when updating any View's layout from inside the /// subscriber method. /// - public bool Handled { get; set; } = false; + public bool Handled + { + get => _handled; + set => _handled = value; + } /// Gets a value indicating whether the Alt key was pressed (real or synthesized) /// if is alternate; otherwise, . @@ -182,6 +198,8 @@ public class Key : EventArgs, IEquatable /// public bool IsValid => this != Empty && NoAlt.NoShift.NoCtrl != Empty; + private readonly KeyCode _keyCode; + /// The encoded key value. /// /// IMPORTANT: Lowercase alpha keys are encoded (in ) as values between 65 and 90 @@ -190,7 +208,21 @@ public class Key : EventArgs, IEquatable /// for uppercase characters, these enum values represent *lowercase*, un-shifted characters. /// /// This property is the backing data for the . It is a enum value. - public KeyCode KeyCode { get; init; } + public KeyCode KeyCode + { + get => _keyCode; + init + { +#if DEBUG + if (GetIsKeyCodeAtoZ (value) && (value & KeyCode.Space) != 0) + { + throw new ArgumentException ($"Invalid KeyCode: {value} is invalid.", nameof (value)); + } + +#endif + _keyCode = value; + } + } /// /// Helper for removing a shift modifier from a . @@ -199,7 +231,7 @@ public class Key : EventArgs, IEquatable /// var AltDelete = ControlAltDelete.NoCtrl; /// /// - public Key NoAlt => new (KeyCode & ~KeyCode.AltMask); + public Key NoAlt => new (this) { KeyCode = KeyCode & ~KeyCode.AltMask }; /// /// Helper for removing a shift modifier from a . @@ -208,7 +240,7 @@ public class Key : EventArgs, IEquatable /// var AltDelete = ControlAltDelete.NoCtrl; /// /// - public Key NoCtrl => new (KeyCode & ~KeyCode.CtrlMask); + public Key NoCtrl => new (this) { KeyCode = KeyCode & ~KeyCode.CtrlMask }; /// /// Helper for removing a shift modifier from a . @@ -217,10 +249,7 @@ public class Key : EventArgs, IEquatable /// var AltDelete = ControlAltDelete.NoCtrl; /// /// - public Key NoShift => new (KeyCode & ~KeyCode.ShiftMask); - - /// Enables passing the key binding scope with the event. Default is . - public KeyBindingScope Scope { get; set; } = KeyBindingScope.Focused; + public Key NoShift => new (this) { KeyCode = KeyCode & ~KeyCode.ShiftMask }; /// /// Helper for specifying a shifted . @@ -228,7 +257,7 @@ public class Key : EventArgs, IEquatable /// var ControlAltDelete = new Key(Key.Delete).WithAlt.WithDel; /// /// - public Key WithAlt => new (KeyCode | KeyCode.AltMask); + public Key WithAlt => new (this) { KeyCode = KeyCode | KeyCode.AltMask }; /// /// Helper for specifying a shifted . @@ -236,7 +265,7 @@ public class Key : EventArgs, IEquatable /// var ControlAltDelete = new Key(Key.Delete).WithAlt.WithDel; /// /// - public Key WithCtrl => new (KeyCode | KeyCode.CtrlMask); + public Key WithCtrl => new (this) { KeyCode = KeyCode | KeyCode.CtrlMask }; /// /// Helper for specifying a shifted . @@ -244,7 +273,7 @@ public class Key : EventArgs, IEquatable /// var ControlAltDelete = new Key(Key.Delete).WithAlt.WithDel; /// /// - public Key WithShift => new (KeyCode | KeyCode.ShiftMask); + public Key WithShift => new (this) { KeyCode = KeyCode | KeyCode.ShiftMask }; /// /// Tests if a KeyCode represents a key in the range of to , @@ -369,7 +398,10 @@ public class Key : EventArgs, IEquatable public static implicit operator string (Key key) { return key.ToString (); } /// - public override bool Equals (object obj) { return obj is Key k && k.KeyCode == KeyCode; } + public override bool Equals (object obj) + { + return obj is Key k && k.KeyCode == KeyCode && k.Handled == Handled; + } bool IEquatable.Equals (Key other) { return Equals (other); } @@ -544,7 +576,7 @@ public class Key : EventArgs, IEquatable { if (string.IsNullOrEmpty (text)) { - key = new Key (KeyCode.Null); + key = Key.Empty; return true; } @@ -565,15 +597,15 @@ public class Key : EventArgs, IEquatable switch (parts [0]) { case "Ctrl": - key = new Key (KeyCode.CtrlMask); + key = KeyCode.CtrlMask; return true; case "Alt": - key = new Key (KeyCode.AltMask); + key = KeyCode.AltMask; return true; case "Shift": - key = new Key (KeyCode.ShiftMask); + key = KeyCode.ShiftMask; return true; } @@ -627,6 +659,10 @@ public class Key : EventArgs, IEquatable } } + if (GetIsKeyCodeAtoZ (keyCode) && (keyCode & KeyCode.Space) != 0) + { + keyCode = keyCode & ~KeyCode.Space; + } key = new Key (keyCode | modifiers); return true; @@ -643,6 +679,10 @@ public class Key : EventArgs, IEquatable return true; } + if (GetIsKeyCodeAtoZ (parsedKeyCode) && (parsedKeyCode & KeyCode.Space) != 0) + { + parsedKeyCode = parsedKeyCode & ~KeyCode.Space; + } key = new Key (parsedKeyCode | modifiers); return true; diff --git a/Terminal.Gui/Input/KeyBinding.cs b/Terminal.Gui/Input/KeyBinding.cs index 105dd2efb..b92eebc74 100644 --- a/Terminal.Gui/Input/KeyBinding.cs +++ b/Terminal.Gui/Input/KeyBinding.cs @@ -10,10 +10,11 @@ namespace Terminal.Gui; /// /// Key bindings are scoped to the most-focused view () by default. /// +[Flags] public enum KeyBindingScope { /// The key binding is scoped to just the view that has focus. - Focused = 0, + Focused = 1, /// /// The key binding is scoped to the View's SuperView and will be triggered even when the View does not have focus, as @@ -29,7 +30,7 @@ public enum KeyBindingScope /// /// /// - HotKey, + HotKey = 2, /// /// The key binding will be triggered regardless of which view has focus. This is typically used for global @@ -39,7 +40,7 @@ public enum KeyBindingScope /// Application-scoped key bindings are only invoked if the key down event was not handled by the focused view or /// any of its subviews, and if the key down event was not bound to a . /// - Application + Application = 4 } /// Provides a collection of objects that are scoped to . @@ -64,6 +65,7 @@ public class KeyBinding /// A class that provides a collection of objects bound to a . public class KeyBindings { + // TODO: Add a dictionary comparer that ignores Scope /// The collection of objects. public Dictionary Bindings { get; } = new (); @@ -92,16 +94,16 @@ public class KeyBindings /// public void Add (Key key, KeyBindingScope scope, params Command [] commands) { - if (commands.Length == 0) - { - throw new ArgumentException (@"At least one command must be specified", nameof (commands)); - } - if (key is null || !key.IsValid) { //throw new ArgumentException ("Invalid Key", nameof (commands)); return; } + + if (commands.Length == 0) + { + throw new ArgumentException (@"At least one command must be specified", nameof (commands)); + } if (TryGet (key, out KeyBinding _)) { @@ -149,8 +151,10 @@ public class KeyBindings /// public void Clear (params Command [] command) { - foreach (KeyValuePair kvp in Bindings.Where (kvp => kvp.Value.Commands.SequenceEqual (command)) - .ToArray ()) + var kvps = Bindings + .Where (kvp => kvp.Value.Commands.SequenceEqual (command)) + .ToArray (); + foreach (KeyValuePair kvp in kvps) { Bindings.Remove (kvp.Key); } @@ -243,7 +247,7 @@ public class KeyBindings { if (key.IsValid && Bindings.TryGetValue (key, out binding)) { - if (binding.Scope == scope) + if (scope.HasFlag (binding.Scope)) { return true; } diff --git a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs index dc6e6403c..887d09791 100644 --- a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs @@ -64,19 +64,19 @@ public class AppendAutocomplete : AutocompleteBase /// public override bool ProcessKey (Key a) { - KeyCode key = a.KeyCode; + Key key = a.KeyCode; if (key == SelectionKey) { return AcceptSelectionIfAny (); } - if (key == KeyCode.CursorUp) + if (key == Key.CursorUp) { return CycleSuggestion (1); } - if (key == KeyCode.CursorDown) + if (key == Key.CursorDown) { return CycleSuggestion (-1); } diff --git a/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs b/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs index af0252977..3dfe4955e 100644 --- a/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs +++ b/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs @@ -46,7 +46,7 @@ public abstract class AutocompleteBase : IAutocomplete // TODO: Update to use Key instead of KeyCode /// - public virtual KeyCode Reopen { get; set; } = KeyCode.Space | KeyCode.CtrlMask | KeyCode.AltMask; + public virtual KeyCode Reopen { get; set; } = (KeyCode)Key.Space.WithCtrl.WithAlt; /// public virtual AutocompleteContext Context { get; set; } diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index bf67d6321..dc6422ac7 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -169,11 +169,11 @@ public abstract partial class PopupAutocomplete : AutocompleteBase /// Handle key events before e.g. to make key events like up/down apply to the /// autocomplete control instead of changing the cursor position in the underlying text view. /// - /// The key event. + /// The key event. /// trueif the key can be handled falseotherwise. - public override bool ProcessKey (Key a) + public override bool ProcessKey (Key key) { - if (SuggestionGenerator.IsWordChar ((Rune)a)) + if (SuggestionGenerator.IsWordChar ((Rune)key)) { Visible = true; ManipulatePopup (); @@ -182,7 +182,7 @@ public abstract partial class PopupAutocomplete : AutocompleteBase return false; } - if (a.KeyCode == Reopen) + if (key == Reopen) { Context.Canceled = false; @@ -201,14 +201,14 @@ public abstract partial class PopupAutocomplete : AutocompleteBase return false; } - if (a.KeyCode == KeyCode.CursorDown) + if (key == Key.CursorDown) { MoveDown (); return true; } - if (a.KeyCode == KeyCode.CursorUp) + if (key == Key.CursorUp) { MoveUp (); @@ -227,12 +227,12 @@ public abstract partial class PopupAutocomplete : AutocompleteBase return false; }*/ - if (a.KeyCode == SelectionKey) + if (key == SelectionKey) { return Select (); } - if (a.KeyCode == CloseKey) + if (key == CloseKey) { Close (); Context.Canceled = true; @@ -249,7 +249,7 @@ public abstract partial class PopupAutocomplete : AutocompleteBase { if (!Context.Canceled && Suggestions.Count > 0 && !Visible && HostControl?.HasFocus == true) { - ProcessKey (new Key ((KeyCode)Suggestions [0].Title [0])); + ProcessKey (new Key (Suggestions [0].Title [0])); } else if (!Visible || HostControl?.HasFocus == false || Suggestions.Count == 0) { diff --git a/Terminal.Gui/Text/StringEventArgs.cs b/Terminal.Gui/Text/StringEventArgs.cs new file mode 100644 index 000000000..734f828b2 --- /dev/null +++ b/Terminal.Gui/Text/StringEventArgs.cs @@ -0,0 +1,26 @@ +using System.ComponentModel; + +namespace Terminal.Gui; + +/// Cancellable event args for string-based property change events. +public class StringEventArgs : CancelEventArgs +{ + /// + /// Initializes a new instance of + /// + public StringEventArgs () {} + + /// Initializes a new instance of + /// The old string. + /// The new string. + public StringEventArgs (string oldString, string newString) + { + OldValue = oldString; + NewValue = newString; + } + /// The new string. + public string NewValue { get; set; } + + /// The old string. + public string OldValue { get; set; } +} diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index 5dffabf2b..dbdabce43 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -216,7 +216,7 @@ public class TextFormatter /// Gets or sets whether the needs to format the text. /// /// If when Draw is called, the Draw call will be faster. - /// Used by + /// Used by /// Set to when any of the properties of are set. /// Set to when the text is formatted (if is accessed). /// @@ -2003,7 +2003,7 @@ public class TextFormatter if (string.IsNullOrEmpty (text) || hotKeySpecifier == (Rune)0xFFFF) { hotPos = -1; - hotKey = KeyCode.Null; + hotKey = Key.Empty; return false; } @@ -2072,6 +2072,8 @@ public class TextFormatter hotKey = newHotKey; + //hotKey.Scope = KeyBindingScope.HotKey; + return true; } } diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index cc5973fa1..e3484a13c 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -192,26 +192,7 @@ public class Border : Adornment Driver.Clip = savedClip; } - - /// Draws the title for a Window-style view. - /// Screen relative region where the title will be drawn. - /// The title. - public void DrawTitle (Rect region, string title) - { - int width = region.Width; - - if (!string.IsNullOrEmpty (title)) - { - Driver.Move (region.X + 2, region.Y); - - //Driver.AddRune (' '); - string str = title.EnumerateRunes ().Sum (r => Math.Max (r.GetColumns (), 1)) >= width - ? TextFormatter.Format (title, width, false, false) [0] - : title; - Driver.AddStr (str); - } - } - + /// public override void OnDrawContent (Rect contentArea) { @@ -259,10 +240,14 @@ public class Border : Adornment int titleY = borderBounds.Y; var titleBarsLength = 0; // the little vertical thingies - int maxTitleWidth = Math.Min ( - Parent.Title.GetColumns (), - Math.Min (screenBounds.Width - 4, borderBounds.Width - 4) - ); + int maxTitleWidth = Math.Max (0, + Math.Min ( + Parent.TitleTextFormatter.FormatAndGetSize ().Width, + Math.Min (screenBounds.Width - 4, borderBounds.Width - 4) + ) + ); + Parent.TitleTextFormatter.Size = new Size (maxTitleWidth, 1); + int sideLineLength = borderBounds.Height; bool canDrawBorder = borderBounds.Width > 0 && borderBounds.Height > 0; @@ -300,10 +285,9 @@ public class Border : Adornment if (canDrawBorder && Thickness.Top > 0 && maxTitleWidth > 0 && !string.IsNullOrEmpty (Parent?.Title)) { - Attribute prevAttr = Driver.GetAttribute (); - Driver.SetAttribute (Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor ()); - DrawTitle (new Rect (borderBounds.X, titleY, maxTitleWidth, 1), Parent?.Title); - Driver.SetAttribute (prevAttr); + Parent.TitleTextFormatter.Draw (new Rect (borderBounds.X + 2, titleY, maxTitleWidth, 1), + Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor (), + Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetHotNormalColor ()); } if (canDrawBorder && LineStyle != LineStyle.None) @@ -480,19 +464,9 @@ public class Border : Adornment // Redraw title if (drawTop && maxTitleWidth > 0 && !string.IsNullOrEmpty (Parent?.Title)) { - prevAttr = Driver.GetAttribute (); - - if (ColorScheme is { }) - { - Driver.SetAttribute (HasFocus ? GetHotNormalColor () : GetNormalColor ()); - } - else - { - Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ()); - } - - DrawTitle (new Rect (borderBounds.X, titleY, Parent.Title.GetColumns (), 1), Parent?.Title); - Driver.SetAttribute (prevAttr); + Parent.TitleTextFormatter.Draw (new Rect (borderBounds.X + 2, titleY, maxTitleWidth, 1), + Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor (), + Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor ()); } //Left diff --git a/Terminal.Gui/View/StateEventArgs.cs b/Terminal.Gui/View/StateEventArgs.cs new file mode 100644 index 000000000..10cb47886 --- /dev/null +++ b/Terminal.Gui/View/StateEventArgs.cs @@ -0,0 +1,27 @@ +#nullable enable +using System.ComponentModel; + +namespace Terminal.Gui; + +/// for events that convey state changes to a class. +/// +/// Events that use this class can be cancellable. The property should be set to +/// to prevent the state change from occurring. +/// +public class StateEventArgs : CancelEventArgs +{ + /// Creates a new instance of the class. + /// + /// + public StateEventArgs (T oldValue, T newValue) + { + OldValue = oldValue; + NewValue = newValue; + } + + /// The new state + public T NewValue { get; set; } + + /// The previous state + public T OldValue { get; } +} diff --git a/Terminal.Gui/View/TitleEventArgs.cs b/Terminal.Gui/View/TitleEventArgs.cs deleted file mode 100644 index 41c638595..000000000 --- a/Terminal.Gui/View/TitleEventArgs.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Terminal.Gui; - -/// Event arguments for Title change events. -public class TitleEventArgs : EventArgs -{ - /// Initializes a new instance of - /// The that is/has been replaced. - /// The new to be replaced. - public TitleEventArgs (string oldTitle, string newTitle) - { - OldTitle = oldTitle; - NewTitle = newTitle; - } - - /// Flag which allows canceling the Title change. - public bool Cancel { get; set; } - - /// The new Window Title. - public string NewTitle { get; set; } - - /// The old Window Title. - public string OldTitle { get; set; } -} diff --git a/Terminal.Gui/View/ToggleEventArgs.cs b/Terminal.Gui/View/ToggleEventArgs.cs deleted file mode 100644 index fa1386d4f..000000000 --- a/Terminal.Gui/View/ToggleEventArgs.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Terminal.Gui; - -/// for the event -public class ToggleEventArgs : EventArgs -{ - /// Creates a new instance of the class. - /// - /// - public ToggleEventArgs (bool? oldValue, bool? newValue) - { - OldValue = oldValue; - NewValue = newValue; - } - - /// The new checked state - public bool? NewValue { get; } - - /// The previous checked state - public bool? OldValue { get; } -} diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 1ec8d19b6..a59a06860 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -114,7 +114,6 @@ namespace Terminal.Gui; public partial class View : Responder, ISupportInitializeNotification { private bool _oldEnabled; - private string _title = string.Empty; /// Gets or sets whether a view is cleared if the property is . public bool ClearOnVisibleFalse { get; set; } = true; @@ -182,32 +181,6 @@ public partial class View : Responder, ISupportInitializeNotification /// The id should be unique across all Views that share a SuperView. public string Id { get; set; } = ""; - /// - /// The title to be displayed for this . The title will be displayed if . - /// is greater than 0. - /// - /// The title. - public string Title - { - get => _title; - set - { - if (!OnTitleChanging (_title, value)) - { - string old = _title; - _title = value; - SetNeedsDisplay (); -#if DEBUG - if (_title is { } && string.IsNullOrEmpty (Id)) - { - Id = _title; - } -#endif - OnTitleChanged (old, _title); - } - } - } - /// /// > public override bool Visible @@ -244,42 +217,9 @@ public partial class View : Responder, ISupportInitializeNotification /// public override void OnEnabledChanged () { EnabledChanged?.Invoke (this, EventArgs.Empty); } - /// Called when the has been changed. Invokes the event. - /// The that is/has been replaced. - /// The new to be replaced. - public virtual void OnTitleChanged (string oldTitle, string newTitle) - { - var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanged?.Invoke (this, args); - } - - /// - /// Called before the changes. Invokes the event, which can - /// be cancelled. - /// - /// The that is/has been replaced. - /// The new to be replaced. - /// `true` if an event handler canceled the Title change. - public virtual bool OnTitleChanging (string oldTitle, string newTitle) - { - var args = new TitleEventArgs (oldTitle, newTitle); - TitleChanging?.Invoke (this, args); - - return args.Cancel; - } - /// public override void OnVisibleChanged () { VisibleChanged?.Invoke (this, EventArgs.Empty); } - /// Event fired after the has been changed. - public event EventHandler TitleChanged; - - /// - /// Event fired when the is changing. Set to `true` - /// to cancel the Title change. - /// - public event EventHandler TitleChanging; - /// Pretty prints the View /// public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; } @@ -328,6 +268,101 @@ public partial class View : Responder, ISupportInitializeNotification return true; } + #region Title + + private string _title = string.Empty; + + /// Gets the used to format . + internal TextFormatter TitleTextFormatter { get; init; } = new (); + + /// + /// The title to be displayed for this . The title will be displayed if . + /// is greater than 0. The title can be used to set the + /// for the view by prefixing character with (e.g. "T_itle"). + /// + /// + /// + /// Set the to enable hotkey support. To disable Title-based hotkey support set + /// to (Rune)0xffff. + /// + /// + /// Only the first HotKey specifier found in is supported. + /// + /// + /// To cause the hotkey to be rendered with , + /// set View. to the desired character. + /// + /// + /// The title. + public string Title + { + get => _title; + set + { + if (value == _title) + { + return; + } + + if (!OnTitleChanging (_title, value)) + { + string old = _title; + _title = value; + TitleTextFormatter.Text = _title; + TitleTextFormatter.Size = new Size ( + TextFormatter.GetWidestLineLength (TitleTextFormatter.Text) + - (TitleTextFormatter.Text?.Contains ((char)HotKeySpecifier.Value) == true + ? Math.Max (HotKeySpecifier.GetColumns (), 0) + : 0), + 1); + SetHotKeyFromTitle (); + SetNeedsDisplay (); +#if DEBUG + if (_title is { } && string.IsNullOrEmpty (Id)) + { + Id = _title; + } +#endif // DEBUG + OnTitleChanged (old, _title); + } + } + } + + /// Called when the has been changed. Invokes the event. + /// The that is/has been replaced. + /// The new to be replaced. + public virtual void OnTitleChanged (string oldTitle, string newTitle) + { + StateEventArgs args = new (oldTitle, newTitle); + TitleChanged?.Invoke (this, args); + } + + /// + /// Called before the changes. Invokes the event, which can + /// be cancelled. + /// + /// The that is/has been replaced. + /// The new to be replaced. + /// `true` if an event handler canceled the Title change. + public virtual bool OnTitleChanging (string oldTitle, string newTitle) + { + StateEventArgs args = new (oldTitle, newTitle); + TitleChanging?.Invoke (this, args); + + return args.Cancel; + } + + /// Event fired after the has been changed. + public event EventHandler> TitleChanged; + + /// + /// Event fired when the is changing. Set to `true` + /// to cancel the Title change. + /// + public event EventHandler> TitleChanging; + + #endregion + #region Constructors and Initialization /// Initializes a new instance of . @@ -347,7 +382,9 @@ public partial class View : Responder, ISupportInitializeNotification /// public View () { - TextFormatter.HotKeyChanged += TextFormatter_HotKeyChanged; + HotKeySpecifier = (Rune)'_'; + TitleTextFormatter.HotKeyChanged += TitleTextFormatter_HotKeyChanged; + TextDirection = TextDirection.LeftRight_TopBottom; Text = string.Empty; @@ -434,8 +471,6 @@ public partial class View : Responder, ISupportInitializeNotification // These calls were moved from BeginInit as they access Bounds which is indeterminate until EndInit is called. UpdateTextDirection (TextDirection); UpdateTextFormatterText (); - SetHotKey (); - OnResizeNeeded (); if (_subviews is { }) diff --git a/Terminal.Gui/View/ViewKeyboard.cs b/Terminal.Gui/View/ViewKeyboard.cs index bac9ea093..095fb342d 100644 --- a/Terminal.Gui/View/ViewKeyboard.cs +++ b/Terminal.Gui/View/ViewKeyboard.cs @@ -1,40 +1,63 @@ -namespace Terminal.Gui; +using System.ComponentModel; + +namespace Terminal.Gui; public partial class View { private void AddCommands () { - // By default, the Default command is bound to the HotKey enabling focus - AddCommand ( - Command.Default, - () => - { - if (CanFocus) - { - SetFocus (); + // By default, the HotKey command sets the focus + AddCommand (Command.HotKey, OnHotKey); - return true; - } - - return false; - } - ); - - // By default the Accept command does nothing - AddCommand (Command.Accept, () => false); + // By default, the Accept command raises the Accept event + AddCommand (Command.Accept, OnAccept); } #region HotKey Support + /// + /// Called when the HotKey command () is invoked. Causes this view to be focused. + /// + /// If the command was canceled. + private bool? OnHotKey () + { + if (CanFocus) + { + SetFocus (); + + return true; + } + + return false; + } + + /// + /// Cancelable event fired when the command is invoked. Set + /// to cancel the event. + /// + public event EventHandler Accept; + + /// + /// Called when the command is invoked. Fires the + /// event. + /// + /// If the event was canceled. + public bool? OnAccept () + { + var args = new CancelEventArgs (); + Accept?.Invoke (this, args); + return args.Cancel; + } + /// Invoked when the is changed. public event EventHandler HotKeyChanged; private Key _hotKey = new (); - private void TextFormatter_HotKeyChanged (object sender, KeyChangedEventArgs e) { HotKeyChanged?.Invoke (this, e); } + private void TitleTextFormatter_HotKeyChanged (object sender, KeyChangedEventArgs e) { HotKeyChanged?.Invoke (this, e); } /// /// Gets or sets the hot key defined for this view. Pressing the hot key on the keyboard while this view has focus will - /// invoke the and commands. + /// invoke the and commands. /// causes the view to be focused and does nothing. By default, the HotKey is /// automatically set to the first character of that is prefixed with with /// . @@ -55,18 +78,18 @@ public partial class View /// /// /// By default, when the Hot Key is set, key bindings are added for both the base key (e.g. - /// ) and the Alt-shifted key (e.g. | - /// ). This behavior can be overriden by overriding + /// ) and the Alt-shifted key (e.g. . + /// ). This behavior can be overriden by overriding /// . /// /// - /// By default, when the HotKey is set to through key bindings will + /// By default, when the HotKey is set to through key bindings will /// be added for both the un-shifted and shifted versions. This means if the HotKey is , key /// bindings for Key.A and Key.A.WithShift will be added. This behavior can be overriden by /// overriding . /// /// If the hot key is changed, the event is fired. - /// Set to to disable the hot key. + /// Set to to disable the hot key. /// public virtual Key HotKey { @@ -84,7 +107,9 @@ public partial class View if (AddKeyBindingsForHotKey (_hotKey, value)) { // This will cause TextFormatter_HotKeyChanged to be called, firing HotKeyChanged - _hotKey = TextFormatter.HotKey = value; + // BUGBUG: _hotkey should be set BEFORE setting TextFormatter.HotKey + _hotKey = value; + TitleTextFormatter.HotKey = value; } } } @@ -95,8 +120,8 @@ public partial class View /// /// /// - /// By default key bindings are added for both the base key (e.g. ) and the Alt-shifted key - /// (e.g. Key.D3.WithAlt This behavior can be overriden by overriding . + /// By default, key bindings are added for both the base key (e.g. ) and the Alt-shifted key + /// (e.g. Key.D3.WithAlt) This behavior can be overriden by overriding . /// /// /// By default, when is through key bindings @@ -104,10 +129,6 @@ public partial class View /// key bindings for Key.A and Key.A.WithShift will be added. This behavior can be overriden by /// overriding . /// - /// - /// For each of the bound keys causes the view to be focused and - /// does nothing. - /// /// /// The HotKey is replacing. Key bindings for this key will be removed. /// The new HotKey. If bindings will be removed. @@ -115,7 +136,7 @@ public partial class View /// public virtual bool AddKeyBindingsForHotKey (Key prevHotKey, Key hotKey) { - if ((KeyCode)_hotKey == hotKey) + if (_hotKey == hotKey) { return false; } @@ -158,7 +179,7 @@ public partial class View KeyBindings.Remove (prevHotKey.WithAlt); } - if (_hotKey.KeyCode is >= KeyCode.A and <= KeyCode.Z) + if (_hotKey.IsKeyCodeAtoZ) { // Remove the shift version if (KeyBindings.TryGet (prevHotKey.WithShift, out _)) @@ -174,17 +195,17 @@ public partial class View } // Add the new - if (newKey != KeyCode.Null) + if (newKey != Key.Empty) { // Add the base and Alt key - KeyBindings.Add (newKey, KeyBindingScope.HotKey, Command.Default, Command.Accept); - KeyBindings.Add (newKey.WithAlt, KeyBindingScope.HotKey, Command.Default, Command.Accept); + KeyBindings.Add (newKey, KeyBindingScope.HotKey, Command.HotKey); + KeyBindings.Add (newKey.WithAlt, KeyBindingScope.HotKey, Command.HotKey); // If the Key is A..Z, add ShiftMask and AltMask | ShiftMask if (newKey.IsKeyCodeAtoZ) { - KeyBindings.Add (newKey.WithShift, KeyBindingScope.HotKey, Command.Default, Command.Accept); - KeyBindings.Add (newKey.WithShift.WithAlt, KeyBindingScope.HotKey, Command.Default, Command.Accept); + KeyBindings.Add (newKey.WithShift, KeyBindingScope.HotKey, Command.HotKey); + KeyBindings.Add (newKey.WithShift.WithAlt, KeyBindingScope.HotKey, Command.HotKey); } } @@ -199,37 +220,32 @@ public partial class View { get { - if (TextFormatter is { }) - { - return TextFormatter.HotKeySpecifier; - } - - return new Rune ('\xFFFF'); + return TitleTextFormatter.HotKeySpecifier; } set { - TextFormatter.HotKeySpecifier = value; - SetHotKey (); + TitleTextFormatter.HotKeySpecifier = value; + SetHotKeyFromTitle (); } } - private void SetHotKey () + private void SetHotKeyFromTitle () { - if (TextFormatter is null || HotKeySpecifier == new Rune ('\xFFFF')) + if (TitleTextFormatter == null || HotKeySpecifier == new Rune ('\xFFFF')) { return; // throw new InvalidOperationException ("Can't set HotKey unless a TextFormatter has been created"); } - if (TextFormatter.FindHotKey (_text, HotKeySpecifier, out _, out Key hk)) + if (TextFormatter.FindHotKey (_title, HotKeySpecifier, out _, out Key hk)) { - if (_hotKey.KeyCode != hk) + if (_hotKey != hk) { HotKey = hk; } } else { - HotKey = KeyCode.Null; + HotKey = Key.Empty; } } @@ -623,16 +639,15 @@ public partial class View /// public virtual bool? OnInvokingKeyBindings (Key keyEvent) { - // fire event - // BUGBUG: KeyEventArgs doesn't include scope, so the event never sees it. - if (keyEvent.Scope == KeyBindingScope.Application || keyEvent.Scope == KeyBindingScope.HotKey) + // fire event only if there's an app or hotkey binding for the key + if (KeyBindings.TryGet (keyEvent, KeyBindingScope.Application | KeyBindingScope.HotKey, out KeyBinding _)) { InvokingKeyBindings?.Invoke (this, keyEvent); - if (keyEvent.Handled) { return true; } + } // * If no key binding was found, `InvokeKeyBindings` returns `null`. @@ -653,16 +668,16 @@ public partial class View // Now, process any key bindings in the subviews that are tagged to KeyBindingScope.HotKey. foreach (View view in Subviews.Where ( v => v.KeyBindings.TryGet ( - keyEvent.KeyCode, + keyEvent, KeyBindingScope.HotKey, out KeyBinding _ ) )) { // TODO: I think this TryGet is not needed due to the one in the lambda above. Use `Get` instead? - if (view.KeyBindings.TryGet (keyEvent.KeyCode, KeyBindingScope.HotKey, out KeyBinding binding)) + if (view.KeyBindings.TryGet (keyEvent, KeyBindingScope.HotKey, out KeyBinding binding)) { - keyEvent.Scope = KeyBindingScope.HotKey; + //keyEvent.Scope = KeyBindingScope.HotKey; handled = view.OnInvokingKeyBindings (keyEvent); if (handled is { } && (bool)handled) @@ -682,19 +697,18 @@ public partial class View public event EventHandler InvokingKeyBindings; /// - /// Invokes any binding that is registered on this and matches the + /// Invokes any binding that is registered on this and matches the /// See for an overview of Terminal.Gui keyboard APIs. /// - /// The key event passed. + /// The key event passed. /// - /// if no command was bound the . if + /// if no command was bound the . if /// commands were invoked and at least one handled the command. if commands were invoked and at /// none handled the command. /// - protected bool? InvokeKeyBindings (Key keyEvent) + protected bool? InvokeKeyBindings (Key key) { bool? toReturn = null; - KeyCode key = keyEvent.KeyCode; if (!KeyBindings.TryGet (key, out KeyBinding binding)) { @@ -706,13 +720,7 @@ public partial class View if (!CommandImplementations.ContainsKey (command)) { throw new NotSupportedException ( - @$"A KeyBinding was set up for the command { - command - } ({ - keyEvent.KeyCode - }) but that command is not supported by this View ({ - GetType ().Name - })" + @$"A KeyBinding was set up for the command {command} ({key}) but that command is not supported by this View ({GetType ().Name})" ); } @@ -732,6 +740,42 @@ public partial class View return toReturn; } + /// + /// Invokes the specified commands. + /// + /// + /// + /// if no command was found. + /// if the command was invoked and it handled the command. + /// if the command was invoked and it did not handle the command. + /// + public bool? InvokeCommands (Command [] commands) + { + bool? toReturn = null; + + foreach (Command command in commands) + { + if (!CommandImplementations.ContainsKey (command)) + { + throw new NotSupportedException (@$"{command} is not supported by ({GetType ().Name})."); + } + + // each command has its own return value + bool? thisReturn = InvokeCommand (command); + + // if we haven't got anything yet, the current command result should be used + toReturn ??= thisReturn; + + // if ever see a true then that's what we will return + if (thisReturn ?? false) + { + toReturn = true; + } + } + + return toReturn; + } + /// Invokes the specified command. /// /// diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index d1d8e7cfd..b4221fba7 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -33,31 +33,48 @@ public partial class View /// The text will word-wrap to additional lines if it does not fit horizontally. If 's height /// is 1, the text will be clipped. /// - /// - /// Set the to enable hotkey support. To disable hotkey support set - /// to (Rune)0xffff. - /// /// If is true, the will be adjusted to fit the text. + /// When the text changes, the is fired. /// public virtual string Text { get => _text; set { + if (value == _text) + { + return; + } + + string old = _text; _text = value; - SetHotKey (); UpdateTextFormatterText (); OnResizeNeeded (); - #if DEBUG if (_text is { } && string.IsNullOrEmpty (Id)) { Id = _text; } #endif + OnTextChanged (old, Text); } } + /// + /// Called when the has changed. Fires the event. + /// + /// + /// + public void OnTextChanged (string oldValue, string newValue) + { + TextChanged?.Invoke (this, new StateEventArgs (oldValue, newValue)); + } + + /// + /// Text changed event, raised when the text has changed. + /// + public event EventHandler> TextChanged; + /// /// Gets or sets how the View's is aligned horizontally when drawn. Changing this property will /// redisplay the . @@ -156,7 +173,15 @@ public partial class View /// Gets the width or height of the characters in the /// property. /// - /// Only the first HotKey specifier found in is supported. + /// + /// + /// This is for , not . For to show the hotkey, + /// set View. to the desired character. + /// + /// + /// Only the first HotKey specifier found in is supported. + /// + /// /// /// If (the default) the width required for the HotKey specifier is returned. /// Otherwise the height is returned. @@ -170,13 +195,13 @@ public partial class View { if (isWidth) { - return TextFormatter.IsHorizontalDirection (TextDirection) && TextFormatter.Text?.Contains ((char)HotKeySpecifier.Value) == true - ? Math.Max (HotKeySpecifier.GetColumns (), 0) + return TextFormatter.IsHorizontalDirection (TextDirection) && TextFormatter.Text?.Contains ((char)TextFormatter.HotKeySpecifier.Value) == true + ? Math.Max (TextFormatter.HotKeySpecifier.GetColumns (), 0) : 0; } - return TextFormatter.IsVerticalDirection (TextDirection) && TextFormatter.Text?.Contains ((char)HotKeySpecifier.Value) == true - ? Math.Max (HotKeySpecifier.GetColumns (), 0) + return TextFormatter.IsVerticalDirection (TextDirection) && TextFormatter.Text?.Contains ((char)TextFormatter.HotKeySpecifier.Value) == true + ? Math.Max (TextFormatter.HotKeySpecifier.GetColumns (), 0) : 0; } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 0313c2f5b..7d7687895 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -7,17 +7,17 @@ namespace Terminal.Gui; -/// Button is a that provides an item that invokes raises the event. +/// Button is a that provides an item that invokes raises the event. /// /// -/// Provides a button showing text that raises the event when clicked on with a mouse or +/// Provides a button showing text that raises the event when clicked on with a mouse or /// when the user presses SPACE, ENTER, or the . The hot key is the first letter or digit /// following the first underscore ('_') in the button text. /// /// Use to change the hot key specifier from the default of ('_'). /// /// When the button is configured as the default () and the user presses the ENTER key, if -/// no other processes the key, the 's event will will +/// no other processes the key, the 's event will /// be fired. /// /// @@ -36,8 +36,6 @@ public class Button : View TextAlignment = TextAlignment.Centered; VerticalTextAlignment = VerticalTextAlignment.Middle; - HotKeySpecifier = new Rune ('_'); - _leftBracket = Glyphs.LeftBracket; _rightBracket = Glyphs.RightBracket; _leftDefault = Glyphs.LeftDefaultIndicator; @@ -50,18 +48,36 @@ public class Button : View AutoSize = true; // Override default behavior of View - // Command.Default sets focus - AddCommand ( - Command.Accept, - () => - { - OnClicked (); + AddCommand (Command.HotKey, () => + { + SetFocus (); + return !OnAccept (); + }); - return true; - } - ); - KeyBindings.Add (Key.Space, Command.Default, Command.Accept); - KeyBindings.Add (Key.Enter, Command.Default, Command.Accept); + KeyBindings.Add (Key.Space, Command.HotKey); + KeyBindings.Add (Key.Enter, Command.HotKey); + + TitleChanged += Button_TitleChanged; + } + + private void Button_TitleChanged (object sender, StateEventArgs e) + { + base.Text = e.NewValue; + TextFormatter.HotKeySpecifier = HotKeySpecifier; + } + + /// + public override string Text + { + get => base.Title; + set => base.Text = base.Title = value; + } + + /// + public override Rune HotKeySpecifier + { + get => base.HotKeySpecifier; + set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value; } /// Gets or sets whether the is the default action to activate in a dialog. @@ -83,16 +99,6 @@ public class Button : View /// public bool NoPadding { get; set; } - /// - /// The event fired when the user clicks the primary mouse button within the Bounds of this or - /// if the user presses the action key while this view is focused. (TODO: IsDefault) - /// - /// - /// Client code can hook up to this event, it is raised when the button is activated either with the mouse or the - /// keyboard. - /// - public event EventHandler Clicked; - /// public override bool MouseEvent (MouseEvent me) { @@ -107,7 +113,7 @@ public class Button : View Draw (); } - OnClicked (); + OnAccept (); } return true; @@ -116,9 +122,6 @@ public class Button : View return false; } - /// Virtual method to invoke the event. - public virtual void OnClicked () { Clicked?.Invoke (this, EventArgs.Empty); } - /// public override bool OnEnter (View view) { diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index eca870370..9f5f2aadb 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -1,4 +1,5 @@ -namespace Terminal.Gui; +#nullable enable +namespace Terminal.Gui; /// The shows an on/off toggle that the user can set public class CheckBox : View @@ -18,7 +19,6 @@ public class CheckBox : View _charNullChecked = Glyphs.NullChecked; _charChecked = Glyphs.Checked; _charUnChecked = Glyphs.UnChecked; - HotKeySpecifier = (Rune)'_'; // Ensures a height of 1 if AutoSize is set to false Height = 1; @@ -27,25 +27,33 @@ public class CheckBox : View AutoSize = true; // Things this view knows how to do - AddCommand (Command.ToggleChecked, () => ToggleChecked ()); - - AddCommand ( - Command.Accept, - () => - { - if (!HasFocus) - { - SetFocus (); - } - - ToggleChecked (); - - return true; - } - ); + AddCommand (Command.Accept, OnToggled); + AddCommand (Command.HotKey, OnToggled); // Default keybindings for this view - KeyBindings.Add (Key.Space, Command.ToggleChecked); + KeyBindings.Add (Key.Space, Command.Accept); + + TitleChanged += Checkbox_TitleChanged; + } + + private void Checkbox_TitleChanged (object? sender, StateEventArgs e) + { + base.Text = e.NewValue; + TextFormatter.HotKeySpecifier = HotKeySpecifier; + } + + /// + public override string Text + { + get => base.Title; + set => base.Text = base.Title = value; + } + + /// + public override Rune HotKeySpecifier + { + get => base.HotKeySpecifier; + set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value; } /// @@ -79,43 +87,6 @@ public class CheckBox : View } } - /// - public override Key HotKey - { - get => base.HotKey; - set - { - if (value is null) - { - throw new ArgumentException (nameof (value)); - } - - Key prev = base.HotKey; - - if (prev != value) - { - base.HotKey = TextFormatter.HotKey = value; - - // Also add Alt+HotKey - if (prev != Key.Empty && KeyBindings.TryGet (prev.WithAlt, out _)) - { - if (value.KeyCode == KeyCode.Null) - { - KeyBindings.Remove (prev.WithAlt); - } - else - { - KeyBindings.Replace (prev.WithAlt, value.WithAlt); - } - } - else if (value != Key.Empty) - { - KeyBindings.Add (value.WithAlt, Command.Accept); - } - } - } - } - /// public override bool MouseEvent (MouseEvent me) { @@ -124,9 +95,7 @@ public class CheckBox : View return false; } - ToggleChecked (); - - return true; + return OnToggled () == true; } /// @@ -138,17 +107,61 @@ public class CheckBox : View } /// Called when the property changes. Invokes the event. - public virtual void OnToggled (ToggleEventArgs e) { Toggled?.Invoke (this, e); } + /// + /// + /// If the event was canceled. + public bool? OnToggled () + { + StateEventArgs e = new (Checked, false); + + if (AllowNullChecked) + { + switch (Checked) + { + case null: + e.NewValue = true; + + break; + case true: + e.NewValue = false; + + break; + case false: + e.NewValue = null; + + break; + } + } + else + { + e.NewValue = !Checked; + } + + Toggled?.Invoke (this, e); + if (e.Cancel) + { + return e.Cancel; + } + + Checked = e.NewValue; + + SetNeedsDisplay (); + SetFocus (); + OnAccept (); + + return true; + } /// public override void PositionCursor () { Move (0, 0); } - /// Toggled event, raised when the is toggled. + /// Toggled event, raised when the is toggled. /// - /// Client code can hook up to this event, it is raised when the is activated either with - /// the mouse or the keyboard. The passed bool contains the previous state. + /// + /// This event can be cancelled. If cancelled, the will not change its state. + /// /// - public event EventHandler Toggled; + public event EventHandler>? Toggled; /// protected override void UpdateTextFormatterText () @@ -171,58 +184,20 @@ public class CheckBox : View private Rune GetCheckedState () { return Checked switch - { - true => _charChecked, - false => _charUnChecked, - var _ => _charNullChecked - }; + { + true => _charChecked, + false => _charUnChecked, + var _ => _charNullChecked + }; } private string GetFormatterText () { - if (AutoSize || string.IsNullOrEmpty (Text) || Frame.Width <= 2) + if (AutoSize || string.IsNullOrEmpty (Title) || Frame.Width <= 2) { return Text; } return Text [..Math.Min (Frame.Width - 2, Text.GetRuneCount ())]; } - - private bool ToggleChecked () - { - if (!HasFocus) - { - SetFocus (); - } - - bool? previousChecked = Checked; - - if (AllowNullChecked) - { - switch (previousChecked) - { - case null: - Checked = true; - - break; - case true: - Checked = false; - - break; - case false: - Checked = null; - - break; - } - } - else - { - Checked = !Checked; - } - - OnToggled (new ToggleEventArgs (previousChecked, Checked)); - SetNeedsDisplay (); - - return true; - } } diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs index 90ebfe650..23c1d022e 100644 --- a/Terminal.Gui/Views/ColorPicker.cs +++ b/Terminal.Gui/Views/ColorPicker.cs @@ -197,10 +197,10 @@ public class ColorPicker : View /// Add the KeyBindinds. private void AddKeyBindings () { - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.CursorDown, Command.LineDown); } /// Draw a box for one color. diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index d7251ccce..ea8b92ce1 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -6,6 +6,7 @@ // using System.Collections; +using System.ComponentModel; namespace Terminal.Gui; @@ -30,6 +31,7 @@ public class ComboBox : View _listview = new ComboListView (this, HideDropdownListOnClick) { CanFocus = true, TabStop = false }; _search.TextChanged += Search_Changed; + _search.Accept += Search_Accept; _listview.Y = Pos.Bottom (_search); _listview.OpenSelectedItem += (sender, a) => Selected (); @@ -66,7 +68,7 @@ public class ComboBox : View SetNeedsLayout (); SetNeedsDisplay (); - Search_Changed (this, new TextChangedEventArgs (Text)); + Search_Changed (this, new StateEventArgs (string.Empty, Text)); }; // Things this view knows how to do @@ -84,16 +86,16 @@ public class ComboBox : View AddCommand (Command.UnixEmulation, () => UnixEmulation ()); // Default keybindings for this view - KeyBindings.Add (KeyCode.Enter, Command.Accept); - KeyBindings.Add (KeyCode.F4, Command.ToggleExpandCollapse); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); - KeyBindings.Add (KeyCode.Home, Command.TopHome); - KeyBindings.Add (KeyCode.End, Command.BottomEnd); - KeyBindings.Add (KeyCode.Esc, Command.Cancel); - KeyBindings.Add (KeyCode.U | KeyCode.CtrlMask, Command.UnixEmulation); + KeyBindings.Add (Key.Enter, Command.Accept); + KeyBindings.Add (Key.F4, Command.ToggleExpandCollapse); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.PageUp, Command.PageUp); + KeyBindings.Add (Key.Home, Command.TopHome); + KeyBindings.Add (Key.End, Command.BottomEnd); + KeyBindings.Add (Key.Esc, Command.Cancel); + KeyBindings.Add (Key.U.WithCtrl, Command.UnixEmulation); } /// @@ -184,8 +186,8 @@ public class ComboBox : View if (SuperView is { } && SuperView.Subviews.Contains (this)) { SelectedItem = -1; - _search.Text = ""; - Search_Changed (this, new TextChangedEventArgs ("")); + _search.Text = string.Empty; + Search_Changed (this, new StateEventArgs (string.Empty, _search.Text)); SetNeedsDisplay (); } } @@ -651,11 +653,14 @@ public class ComboBox : View SetSearchSet (); } - private void Search_Changed (object sender, TextChangedEventArgs e) + // Tell TextField to handle Accept Command (Enter) + void Search_Accept (object sender, CancelEventArgs e) { e.Cancel = true; } + + private void Search_Changed (object sender, StateEventArgs e) { if (_source is null) { - // Object initialization + // Object initialization return; } @@ -714,7 +719,7 @@ public class ComboBox : View SetValue (_listview.SelectedItem > -1 ? _searchset [_listview.SelectedItem] : _text); _search.CursorPosition = _search.Text.GetColumns (); - Search_Changed (this, new TextChangedEventArgs (_search.Text)); + Search_Changed (this, new StateEventArgs (_search.Text, _search.Text)); OnOpenSelectedItem (); Reset (true); HideList (); diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 498015674..21059992c 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -183,15 +183,15 @@ public class DateField : TextField } } - private void DateField_Changing (object sender, TextChangingEventArgs e) + private void DateField_Changing (object sender, StateEventArgs e) { try { var spaces = 0; - for (var i = 0; i < e.NewText.Length; i++) + for (var i = 0; i < e.NewValue.Length; i++) { - if (e.NewText [i] == ' ') + if (e.NewValue [i] == ' ') { spaces++; } @@ -202,14 +202,14 @@ public class DateField : TextField } spaces += FormatLength; - string trimedText = e.NewText [..spaces]; + string trimedText = e.NewValue [..spaces]; spaces -= FormatLength; trimedText = trimedText.Replace (new string (' ', spaces), " "); var date = Convert.ToDateTime (trimedText).ToString (_format.Trim ()); - if ($" {date}" != e.NewText) + if ($" {date}" != e.NewValue) { - e.NewText = $" {date}".Replace (RightToLeftMark, ""); + e.NewValue = $" {date}".Replace (RightToLeftMark, ""); } AdjCursorPosition (CursorPosition); @@ -402,11 +402,10 @@ public class DateField : TextField AddCommand (Command.Right, () => MoveRight ()); // Default keybindings for this view - KeyBindings.Add (KeyCode.Delete, Command.DeleteCharRight); + KeyBindings.Add (Key.Delete, Command.DeleteCharRight); KeyBindings.Add (Key.D.WithCtrl, Command.DeleteCharRight); KeyBindings.Add (Key.Backspace, Command.DeleteCharLeft); - KeyBindings.Add (Key.D.WithAlt, Command.DeleteCharLeft); KeyBindings.Add (Key.Home, Command.LeftHome); KeyBindings.Add (Key.A.WithCtrl, Command.LeftHome); @@ -419,6 +418,11 @@ public class DateField : TextField KeyBindings.Add (Key.CursorRight, Command.Right); KeyBindings.Add (Key.F.WithCtrl, Command.Right); + +#if UNIX_KEY_BINDINGS + KeyBindings.Add (Key.D.WithAlt, Command.DeleteCharLeft); +#endif + } private bool SetText (Rune key) diff --git a/Terminal.Gui/Views/DatePicker.cs b/Terminal.Gui/Views/DatePicker.cs index e2920735d..833537fbf 100644 --- a/Terminal.Gui/Views/DatePicker.cs +++ b/Terminal.Gui/Views/DatePicker.cs @@ -222,7 +222,7 @@ public class DatePicker : View Text = GetBackButtonText () }; - _previousMonthButton.Clicked += (sender, e) => + _previousMonthButton.Accept += (sender, e) => { Date = _date.AddMonths (-1); CreateCalendar (); @@ -239,7 +239,7 @@ public class DatePicker : View Text = GetBackButtonText () }; - _nextMonthButton.Clicked += (sender, e) => + _nextMonthButton.Accept += (sender, e) => { Date = _date.AddMonths (1); CreateCalendar (); diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs index 0ec02269d..fe1269b21 100644 --- a/Terminal.Gui/Views/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialog.cs @@ -67,7 +67,7 @@ public class FileDialog : Dialog { Y = Pos.AnchorEnd (1), X = Pos.Function (CalculateOkButtonPosX), IsDefault = true, Text = Style.OkButtonText }; - _btnOk.Clicked += (s, e) => Accept (true); + _btnOk.Accept += (s, e) => Accept (true); _btnOk.KeyDown += (s, k) => { @@ -83,19 +83,19 @@ public class FileDialog : Dialog NavigateIf (k, KeyCode.CursorUp, _tableView); NavigateIf (k, KeyCode.CursorRight, _btnOk); }; - _btnCancel.Clicked += (s, e) => { Application.RequestStop (); }; + _btnCancel.Accept += (s, e) => { Application.RequestStop (); }; _btnUp = new Button { X = 0, Y = 1, NoPadding = true }; _btnUp.Text = GetUpButtonText (); - _btnUp.Clicked += (s, e) => _history.Up (); + _btnUp.Accept += (s, e) => _history.Up (); _btnBack = new Button { X = Pos.Right (_btnUp) + 1, Y = 1, NoPadding = true }; _btnBack.Text = GetBackButtonText (); - _btnBack.Clicked += (s, e) => _history.Back (); + _btnBack.Accept += (s, e) => _history.Back (); _btnForward = new Button { X = Pos.Right (_btnBack) + 1, Y = 1, NoPadding = true }; _btnForward.Text = GetForwardButtonText (); - _btnForward.Clicked += (s, e) => _history.Forward (); + _btnForward.Accept += (s, e) => _history.Forward (); _tbPath = new TextField { Width = Dim.Fill (), CaptionColor = new Color (Color.Black) }; @@ -128,7 +128,7 @@ public class FileDialog : Dialog FullRowSelect = true, CollectionNavigator = new FileDialogCollectionNavigator (this) }; - _tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + _tableView.KeyBindings.Add (Key.Space, Command.Select); _tableView.MouseClick += OnTableViewMouseClick; _tableView.Style.InvertSelectedCellFirstCharacter = true; Style.TableStyle = _tableView.Style; @@ -184,7 +184,7 @@ public class FileDialog : Dialog _btnToggleSplitterCollapse = new Button { Y = Pos.AnchorEnd (1), Text = GetToggleSplitterText (false) }; - _btnToggleSplitterCollapse.Clicked += (s, e) => + _btnToggleSplitterCollapse.Accept += (s, e) => { Tile tile = _splitContainer.Tiles.ElementAt (0); @@ -200,7 +200,7 @@ public class FileDialog : Dialog CaptionColor = new Color (Color.Black), Width = 30, Y = Pos.AnchorEnd (1), - HotKey = KeyCode.F | KeyCode.AltMask + HotKey = Key.F.WithAlt }; _spinnerView = new SpinnerView { X = Pos.Right (_tbFind) + 1, Y = Pos.AnchorEnd (1), Visible = false }; @@ -248,10 +248,10 @@ public class FileDialog : Dialog _tableView.KeyUp += (s, k) => k.Handled = TableView_KeyUp (k); _tableView.SelectedCellChanged += TableView_SelectedCellChanged; - _tableView.KeyBindings.Add (KeyCode.Home, Command.TopHome); - _tableView.KeyBindings.Add (KeyCode.End, Command.BottomEnd); - _tableView.KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask, Command.TopHomeExtend); - _tableView.KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask, Command.BottomEndExtend); + _tableView.KeyBindings.Add (Key.Home, Command.TopHome); + _tableView.KeyBindings.Add (Key.End, Command.BottomEnd); + _tableView.KeyBindings.Add (Key.Home.WithShift, Command.TopHomeExtend); + _tableView.KeyBindings.Add (Key.End.WithShift, Command.BottomEndExtend); _treeView.KeyDown += (s, k) => { @@ -657,7 +657,7 @@ public class FileDialog : Dialog ApplySort (); } - private void Accept (IEnumerable toMultiAccept) + private new void Accept (IEnumerable toMultiAccept) { if (!AllowsMultipleSelection) { @@ -676,7 +676,7 @@ public class FileDialog : Dialog FinishAccept (); } - private void Accept (IFileInfo f) + private new void Accept (IFileInfo f) { if (!IsCompatibleWithOpenMode (f.FullName, out string reason)) { @@ -696,7 +696,7 @@ public class FileDialog : Dialog FinishAccept (); } - private void Accept (bool allowMulti) + private new void Accept (bool allowMulti) { if (allowMulti && TryAcceptMulti ()) { diff --git a/Terminal.Gui/Views/GraphView/GraphView.cs b/Terminal.Gui/Views/GraphView/GraphView.cs index c28c0f329..4061462af 100644 --- a/Terminal.Gui/Views/GraphView/GraphView.cs +++ b/Terminal.Gui/Views/GraphView/GraphView.cs @@ -73,10 +73,10 @@ public class GraphView : View } ); - KeyBindings.Add (KeyCode.CursorRight, Command.ScrollRight); - KeyBindings.Add (KeyCode.CursorLeft, Command.ScrollLeft); - KeyBindings.Add (KeyCode.CursorUp, Command.ScrollUp); - KeyBindings.Add (KeyCode.CursorDown, Command.ScrollDown); + KeyBindings.Add (Key.CursorRight, Command.ScrollRight); + KeyBindings.Add (Key.CursorLeft, Command.ScrollLeft); + KeyBindings.Add (Key.CursorUp, Command.ScrollUp); + KeyBindings.Add (Key.CursorDown, Command.ScrollDown); // Not bound by default (preserves backwards compatibility) //KeyBindings.Add (Key.PageUp, Command.PageUp); diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index d9dfd690f..c2b58c1c9 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -54,7 +54,7 @@ public class HexView : View AddCommand (Command.Right, () => MoveRight ()); AddCommand (Command.LineDown, () => MoveDown (bytesPerLine)); AddCommand (Command.LineUp, () => MoveUp (bytesPerLine)); - AddCommand (Command.ToggleChecked, () => ToggleSide ()); + AddCommand (Command.Accept, () => ToggleSide ()); AddCommand (Command.PageUp, () => MoveUp (bytesPerLine * Frame.Height)); AddCommand (Command.PageDown, () => MoveDown (bytesPerLine * Frame.Height)); AddCommand (Command.TopHome, () => MoveHome ()); @@ -69,24 +69,24 @@ public class HexView : View ); // Default keybindings for this view - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.Enter, Command.ToggleChecked); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.Enter, Command.Accept); - KeyBindings.Add ('v' + KeyCode.AltMask, Command.PageUp); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); + KeyBindings.Add (Key.V.WithAlt, Command.PageUp); + KeyBindings.Add (Key.PageUp, Command.PageUp); - KeyBindings.Add (KeyCode.V | KeyCode.CtrlMask, Command.PageDown); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); + KeyBindings.Add (Key.V.WithCtrl, Command.PageDown); + KeyBindings.Add (Key.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.Home, Command.TopHome); - KeyBindings.Add (KeyCode.End, Command.BottomEnd); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.CtrlMask, Command.StartOfLine); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.CtrlMask, Command.EndOfLine); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.CtrlMask, Command.StartOfPage); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.CtrlMask, Command.EndOfPage); + KeyBindings.Add (Key.Home, Command.TopHome); + KeyBindings.Add (Key.End, Command.BottomEnd); + KeyBindings.Add (Key.CursorLeft.WithCtrl, Command.StartOfLine); + KeyBindings.Add (Key.CursorRight.WithCtrl, Command.EndOfLine); + KeyBindings.Add (Key.CursorUp.WithCtrl, Command.StartOfPage); + KeyBindings.Add (Key.CursorDown.WithCtrl, Command.EndOfPage); LayoutComplete += HexView_LayoutComplete; } @@ -478,7 +478,7 @@ public class HexView : View } // Ignore control characters and other special keys - if (keyEvent.KeyCode < KeyCode.Space || keyEvent.KeyCode > KeyCode.CharMask) + if (keyEvent < Key.Space || keyEvent.KeyCode > KeyCode.CharMask) { return false; } diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 82cd9644f..5f04cfee3 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -1,4 +1,6 @@ -namespace Terminal.Gui; +using System.Reflection.Metadata.Ecma335; + +namespace Terminal.Gui; /// /// The Label displays a string at a given position and supports multiple lines separated by @@ -17,38 +19,44 @@ public class Label : View AutoSize = true; // Things this view knows how to do - AddCommand ( - Command.Default, - () => - { - // BUGBUG: This is a hack, but it does work. - bool can = CanFocus; - CanFocus = true; - SetFocus (); - SuperView.FocusNext (); - CanFocus = can; - - return true; - } - ); - AddCommand (Command.Accept, () => AcceptKey ()); + AddCommand (Command.HotKey, FocusNext); // Default key bindings for this view - KeyBindings.Add (KeyCode.Space, Command.Accept); + KeyBindings.Add (Key.Space, Command.Accept); + + TitleChanged += Label_TitleChanged; } - /// - /// The event fired when the user clicks the primary mouse button within the Bounds of this or - /// if the user presses the action key while this view is focused. (TODO: IsDefault) - /// - /// - /// Client code can hook up to this event, it is raised when the button is activated either with the mouse or the - /// keyboard. - /// - public event EventHandler Clicked; + private void Label_TitleChanged (object sender, StateEventArgs e) + { + base.Text = e.NewValue; + TextFormatter.HotKeySpecifier = HotKeySpecifier; + } - /// Virtual method to invoke the event. - public virtual void OnClicked () { Clicked?.Invoke (this, EventArgs.Empty); } + /// + public override string Text + { + get => base.Title; + set => base.Text = base.Title = value; + } + + /// + public override Rune HotKeySpecifier + { + get => base.HotKeySpecifier; + set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value; + } + + private new bool? FocusNext () + { + var me = SuperView?.Subviews.IndexOf (this) ?? -1; + if (me != -1 && me < SuperView?.Subviews.Count - 1) + { + SuperView?.Subviews [me + 1].SetFocus (); + } + + return true; + } /// public override bool OnEnter (View view) @@ -77,6 +85,11 @@ public class Label : View if (mouseEvent.Flags == MouseFlags.Button1Clicked) { + if (!CanFocus) + { + FocusNext (); + } + if (!HasFocus && SuperView is { }) { if (!SuperView.HasFocus) @@ -88,23 +101,11 @@ public class Label : View SetNeedsDisplay (); } - OnClicked (); + OnAccept (); return true; } return false; } - - private bool AcceptKey () - { - if (!HasFocus) - { - SetFocus (); - } - - OnClicked (); - - return true; - } } diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index a85f8ec6c..b70e78fd8 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -113,26 +113,27 @@ public class ListView : View AddCommand (Command.PageDown, () => MovePageDown ()); AddCommand (Command.TopHome, () => MoveHome ()); AddCommand (Command.BottomEnd, () => MoveEnd ()); + AddCommand (Command.Accept, () => OnOpenSelectedItem ()); AddCommand (Command.OpenSelectedItem, () => OnOpenSelectedItem ()); - AddCommand (Command.ToggleChecked, () => MarkUnmarkRow ()); + AddCommand (Command.Select, () => MarkUnmarkRow ()); // Default keybindings for all ListViews - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.P | KeyCode.CtrlMask, Command.LineUp); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.P.WithCtrl, Command.LineUp); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.N | KeyCode.CtrlMask, Command.LineDown); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.N.WithCtrl, Command.LineDown); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); + KeyBindings.Add (Key.PageUp, Command.PageUp); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.V | KeyCode.CtrlMask, Command.PageDown); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.V.WithCtrl, Command.PageDown); - KeyBindings.Add (KeyCode.Home, Command.TopHome); + KeyBindings.Add (Key.Home, Command.TopHome); - KeyBindings.Add (KeyCode.End, Command.BottomEnd); + KeyBindings.Add (Key.End, Command.BottomEnd); - KeyBindings.Add (KeyCode.Enter, Command.OpenSelectedItem); + KeyBindings.Add (Key.Enter, Command.OpenSelectedItem); } /// Gets or sets whether this allows items to be marked. @@ -150,11 +151,11 @@ public class ListView : View if (_allowsMarking) { - KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + KeyBindings.Add (Key.Space, Command.Select); } else { - KeyBindings.Remove (KeyCode.Space); + KeyBindings.Remove (Key.Space); } SetNeedsDisplay (); @@ -691,9 +692,10 @@ public class ListView : View return base.OnEnter (view); } + // TODO: This should be cancelable /// Invokes the event if it is defined. - /// - public virtual bool OnOpenSelectedItem () + /// if the event was fired. + public bool OnOpenSelectedItem () { if (_source.Count <= _selected || _selected < 0 || OpenSelectedItem is null) { @@ -702,8 +704,12 @@ public class ListView : View object value = _source.ToList () [_selected]; - OpenSelectedItem?.Invoke (this, new ListViewItemEventArgs (_selected, value)); + if (OnAccept () == true) + { + return false; + } + OpenSelectedItem?.Invoke (this, new ListViewItemEventArgs (_selected, value)); return true; } diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs index 60a3134e2..bc65d4ffd 100644 --- a/Terminal.Gui/Views/Menu/Menu.cs +++ b/Terminal.Gui/Views/Menu/Menu.cs @@ -464,16 +464,16 @@ internal sealed class Menu : View ); AddCommand (Command.Select, () => _host?.SelectItem (_menuItemToSelect)); AddCommand (Command.ToggleExpandCollapse, () => SelectOrRun ()); - AddCommand (Command.Default, () => _host?.SelectItem (_menuItemToSelect)); + AddCommand (Command.HotKey, () => _host?.SelectItem (_menuItemToSelect)); // Default key bindings for this view - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.Esc, Command.Cancel); - KeyBindings.Add (KeyCode.Enter, Command.Accept); - KeyBindings.Add (KeyCode.F9, KeyBindingScope.HotKey, Command.ToggleExpandCollapse); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.Esc, Command.Cancel); + KeyBindings.Add (Key.Enter, Command.Accept); + KeyBindings.Add (Key.F9, KeyBindingScope.HotKey, Command.ToggleExpandCollapse); KeyBindings.Add ( KeyCode.CtrlMask | KeyCode.Space, @@ -610,7 +610,7 @@ internal sealed class Menu : View { _menuBarItemToActivate = -1; _menuItemToSelect = c; - keyEvent.Scope = KeyBindingScope.HotKey; + //keyEvent.Scope = KeyBindingScope.HotKey; return base.OnInvokingKeyBindings (keyEvent); } @@ -619,7 +619,7 @@ internal sealed class Menu : View if (FindShortcutInChildMenu (key, subMenu)) { - keyEvent.Scope = KeyBindingScope.HotKey; + //keyEvent.Scope = KeyBindingScope.HotKey; return base.OnInvokingKeyBindings (keyEvent); } diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index ace5e588e..38fb5c961 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -313,12 +313,12 @@ public class MenuBar : View AddCommand (Command.Select, () => Run (_menuItemToSelect?.Action)); // Default key bindings for this view - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.Esc, Command.Cancel); - KeyBindings.Add (KeyCode.CursorDown, Command.Accept); - KeyBindings.Add (KeyCode.Enter, Command.Accept); - KeyBindings.Add ((KeyCode)Key, KeyBindingScope.HotKey, Command.ToggleExpandCollapse); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.Esc, Command.Cancel); + KeyBindings.Add (Key.CursorDown, Command.Accept); + KeyBindings.Add (Key.Enter, Command.Accept); + KeyBindings.Add (Key, KeyBindingScope.HotKey, Command.ToggleExpandCollapse); KeyBindings.Add ( KeyCode.CtrlMask | KeyCode.Space, @@ -588,7 +588,7 @@ public class MenuBar : View _selected = 0; SetNeedsDisplay (); - _previousFocused = SuperView is null ? Application.Current.Focused : SuperView.Focused; + _previousFocused = SuperView is null ? Application.Current?.Focused : SuperView.Focused; OpenMenu (_selected); if (!SelectEnabledItem ( @@ -654,46 +654,6 @@ public class MenuBar : View SetNeedsDisplay (); } - internal void AltKeyUpHandler (Key e) - { - if (e.KeyCode == KeyCode.AltMask) - { - e.Handled = true; - - // User pressed Alt - if (!IsMenuOpen && _openMenu is null && !_openedByAltKey) - { - // There's no open menu, the first menu item should be highlighted. - // The right way to do this is to SetFocus(MenuBar), but for some reason - // that faults. - - GetMouseGrabViewInstance (this)?.CleanUp (); - - IsMenuOpen = true; - _openedByAltKey = true; - _selected = 0; - CanFocus = true; - - _lastFocused = SuperView == null - ? Application.Current.MostFocused - : SuperView.MostFocused; - SetFocus (); - SetNeedsDisplay (); - Application.GrabMouse (this); - } - else if (!_openedByHotKey) - { - // There's an open menu. Close it. - CleanUp (); - } - else - { - _openedByAltKey = false; - _openedByHotKey = false; - } - } - } - internal void CleanUp () { _isCleaning = true; @@ -1554,15 +1514,13 @@ public class MenuBar : View } /// - public override bool? OnInvokingKeyBindings (Key keyEvent) + public override bool? OnInvokingKeyBindings (Key key) { // This is a bit of a hack. We want to handle the key bindings for menu bar but // InvokeKeyBindings doesn't pass any context so we can't tell which item it is for. // So before we call the base class we set SelectedItem appropriately. // TODO: Figure out if there's a way to have KeyBindings pass context instead. Maybe a KeyBindingContext property? - KeyCode key = keyEvent.KeyCode; - if (KeyBindings.TryGet (key, out _)) { _menuBarItemToActivate = -1; @@ -1572,12 +1530,12 @@ public class MenuBar : View for (var i = 0; i < Menus.Length; i++) { // Recurse through the menu to find one with the shortcut. - if (FindShortcutInChildMenu (key, Menus [i], out _menuItemToSelect)) + if (FindShortcutInChildMenu (key.KeyCode, Menus [i], out _menuItemToSelect)) { _menuBarItemToActivate = i; - keyEvent.Scope = KeyBindingScope.HotKey; + //keyEvent.Scope = KeyBindingScope.HotKey; - return base.OnInvokingKeyBindings (keyEvent); + return base.OnInvokingKeyBindings (key); } // Now see if any of the menu bar items have a hot key that matches @@ -1603,12 +1561,11 @@ public class MenuBar : View // No submenu item matched (or the menu is closed) // Check if one of the menu bar item has a hot key that matches - int hotKeyValue = Menus [i]?.HotKey.Value ?? default (int); - var hotKey = (KeyCode)hotKeyValue; + var hotKey = new Key ((char)Menus [i]?.HotKey.Value); - if (hotKey != KeyCode.Null) + if (hotKey != Key.Empty) { - bool matches = key == hotKey || key == (hotKey | KeyCode.AltMask); + bool matches = key == hotKey || key == hotKey.WithAlt || key == hotKey.NoShift.WithAlt; if (IsMenuOpen) { @@ -1619,7 +1576,7 @@ public class MenuBar : View if (matches) { _menuBarItemToActivate = i; - keyEvent.Scope = KeyBindingScope.HotKey; + //keyEvent.Scope = KeyBindingScope.HotKey; break; } @@ -1627,7 +1584,7 @@ public class MenuBar : View } } - return base.OnInvokingKeyBindings (keyEvent); + return base.OnInvokingKeyBindings (key); } // TODO: Update to use Key instead of KeyCode diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index 06eb44ca2..b5c342408 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -451,7 +451,7 @@ public static class MessageBox int buttonId = n; Button b = buttonList [n]; - b.Clicked += (s, e) => + b.Accept += (s, e) => { Clicked = buttonId; Application.RequestStop (); diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 782b66871..2b6926b97 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -16,7 +16,6 @@ public class RadioGroup : View /// public RadioGroup () { - HotKeySpecifier = new Rune ('_'); CanFocus = true; // Things this view knows how to do @@ -65,17 +64,16 @@ public class RadioGroup : View () => { SelectItem (); - - return true; + return !OnAccept (); } ); // Default keybindings for this view - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.Home, Command.TopHome); - KeyBindings.Add (KeyCode.End, Command.BottomEnd); - KeyBindings.Add (KeyCode.Space, Command.Accept); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.Home, Command.TopHome); + KeyBindings.Add (Key.End, Command.BottomEnd); + KeyBindings.Add (Key.Space, Command.Accept); LayoutStarted += RadioGroup_LayoutStarted; } @@ -124,7 +122,7 @@ public class RadioGroup : View { if (TextFormatter.FindHotKey (label, HotKeySpecifier, out _, out Key hotKey)) { - AddKeyBindingsForHotKey (hotKey, KeyCode.Null); + AddKeyBindingsForHotKey (hotKey, Key.Empty); } } @@ -135,7 +133,7 @@ public class RadioGroup : View { if (TextFormatter.FindHotKey (label, HotKeySpecifier, out _, out Key hotKey)) { - AddKeyBindingsForHotKey (KeyCode.Null, hotKey); + AddKeyBindingsForHotKey (Key.Empty, hotKey); } } @@ -228,7 +226,7 @@ public class RadioGroup : View Driver.AddStr ($"{(i == _selected ? Glyphs.Selected : Glyphs.UnSelected)} "); TextFormatter.FindHotKey (rl, HotKeySpecifier, out int hotPos, out Key hotKey); - if (hotPos != -1 && hotKey != KeyCode.Null) + if (hotPos != -1 && hotKey != Key.Empty) { Rune [] rlRunes = rl.ToRunes (); @@ -316,8 +314,6 @@ public class RadioGroup : View && key.NoAlt.NoCtrl.NoShift == hotKey) { SelectedItem = i; - keyEvent.Scope = KeyBindingScope.HotKey; - break; } } @@ -343,6 +339,7 @@ public class RadioGroup : View return args.Cancel; } + // TODO: This should be cancelable /// Called whenever the current selected item changes. Invokes the event. /// /// @@ -377,6 +374,7 @@ public class RadioGroup : View /// Allow to invoke the after their creation. public void Refresh () { OnSelectedItemChanged (_selected, -1); } + // TODO: This should use StateEventArgs and should be cancelable. /// Invoked when the selected radio label has changed. public event EventHandler SelectedItemChanged; diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index d1be39a8a..78ad0833e 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -93,23 +93,23 @@ public class ScrollView : View AddCommand (Command.RightEnd, () => ScrollRight (_contentSize.Width)); // Default keybindings for this view - KeyBindings.Add (KeyCode.CursorUp, Command.ScrollUp); - KeyBindings.Add (KeyCode.CursorDown, Command.ScrollDown); - KeyBindings.Add (KeyCode.CursorLeft, Command.ScrollLeft); - KeyBindings.Add (KeyCode.CursorRight, Command.ScrollRight); + KeyBindings.Add (Key.CursorUp, Command.ScrollUp); + KeyBindings.Add (Key.CursorDown, Command.ScrollDown); + KeyBindings.Add (Key.CursorLeft, Command.ScrollLeft); + KeyBindings.Add (Key.CursorRight, Command.ScrollRight); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); - KeyBindings.Add ((KeyCode)'v' | KeyCode.AltMask, Command.PageUp); + KeyBindings.Add (Key.PageUp, Command.PageUp); + KeyBindings.Add (Key.V.WithAlt, Command.PageUp); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.V | KeyCode.CtrlMask, Command.PageDown); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.V.WithCtrl, Command.PageDown); - KeyBindings.Add (KeyCode.PageUp | KeyCode.CtrlMask, Command.PageLeft); - KeyBindings.Add (KeyCode.PageDown | KeyCode.CtrlMask, Command.PageRight); - KeyBindings.Add (KeyCode.Home, Command.TopHome); - KeyBindings.Add (KeyCode.End, Command.BottomEnd); - KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask, Command.LeftHome); - KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask, Command.RightEnd); + KeyBindings.Add (Key.PageUp.WithCtrl, Command.PageLeft); + KeyBindings.Add (Key.PageDown.WithCtrl, Command.PageRight); + KeyBindings.Add (Key.Home, Command.TopHome); + KeyBindings.Add (Key.End, Command.BottomEnd); + KeyBindings.Add (Key.Home.WithCtrl, Command.LeftHome); + KeyBindings.Add (Key.End.WithCtrl, Command.RightEnd); Initialized += (s, e) => { diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 69006bda2..f6c3cbfc2 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -1667,33 +1667,33 @@ public class Slider : View { if (_config._sliderOrientation == Orientation.Horizontal) { - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Remove (KeyCode.CursorDown); - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Remove (KeyCode.CursorUp); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Remove (Key.CursorDown); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Remove (Key.CursorUp); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.CtrlMask, Command.RightExtend); - KeyBindings.Remove (KeyCode.CursorDown | KeyCode.CtrlMask); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.CtrlMask, Command.LeftExtend); - KeyBindings.Remove (KeyCode.CursorUp | KeyCode.CtrlMask); + KeyBindings.Add (Key.CursorRight.WithCtrl, Command.RightExtend); + KeyBindings.Remove (Key.CursorDown.WithCtrl); + KeyBindings.Add (Key.CursorLeft.WithCtrl, Command.LeftExtend); + KeyBindings.Remove (Key.CursorUp.WithCtrl); } else { - KeyBindings.Remove (KeyCode.CursorRight); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Remove (KeyCode.CursorLeft); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); + KeyBindings.Remove (Key.CursorRight); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Remove (Key.CursorLeft); + KeyBindings.Add (Key.CursorUp, Command.LineUp); - KeyBindings.Remove (KeyCode.CursorRight | KeyCode.CtrlMask); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.CtrlMask, Command.RightExtend); - KeyBindings.Remove (KeyCode.CursorLeft | KeyCode.CtrlMask); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.CtrlMask, Command.LeftExtend); + KeyBindings.Remove (Key.CursorRight.WithCtrl); + KeyBindings.Add (Key.CursorDown.WithCtrl, Command.RightExtend); + KeyBindings.Remove (Key.CursorLeft.WithCtrl); + KeyBindings.Add (Key.CursorUp.WithCtrl, Command.LeftExtend); } - KeyBindings.Add (KeyCode.Home, Command.LeftHome); - KeyBindings.Add (KeyCode.End, Command.RightEnd); - KeyBindings.Add (KeyCode.Enter, Command.Accept); - KeyBindings.Add (KeyCode.Space, Command.Accept); + KeyBindings.Add (Key.Home, Command.LeftHome); + KeyBindings.Add (Key.End, Command.RightEnd); + KeyBindings.Add (Key.Enter, Command.Accept); + KeyBindings.Add (Key.Space, Command.Accept); } private Dictionary> GetSetOptionDictionary () { return _setOptions.ToDictionary (e => e, e => _options [e]); } diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 0b0d0a186..364dae3a9 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -105,14 +105,14 @@ public class StatusBar : View { foreach (StatusItem item in _items) { - KeyBindings.Remove ((KeyCode)item.Shortcut); + KeyBindings.Remove (item.Shortcut); } _items = value; foreach (StatusItem item in _items) { - KeyBindings.Add ((KeyCode)item.Shortcut, KeyBindingScope.HotKey, Command.Accept); + KeyBindings.Add (item.Shortcut, KeyBindingScope.HotKey, Command.Accept); } } } @@ -229,7 +229,7 @@ public class StatusBar : View // This is a bit of a hack. We want to handle the key bindings for status bar but // InvokeKeyBindings doesn't pass any context so we can't tell which item it is for. // So before we call the base class we set SelectedItem appropriately. - KeyCode key = keyEvent.KeyCode; + Key key = new (keyEvent); if (KeyBindings.TryGet (key, out _)) { @@ -239,7 +239,7 @@ public class StatusBar : View if (item.Shortcut == key) { _itemToInvoke = item; - keyEvent.Scope = KeyBindingScope.HotKey; + //keyEvent.Scope = KeyBindingScope.HotKey; break; } diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index b2a4285c2..4a3f3da86 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -124,14 +124,14 @@ public class TabView : View ); // Default keybindings for this view - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.Home, Command.LeftHome); - KeyBindings.Add (KeyCode.End, Command.RightEnd); - KeyBindings.Add (KeyCode.CursorDown, Command.NextView); - KeyBindings.Add (KeyCode.CursorUp, Command.PreviousView); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.Home, Command.LeftHome); + KeyBindings.Add (Key.End, Command.RightEnd); + KeyBindings.Add (Key.CursorDown, Command.NextView); + KeyBindings.Add (Key.CursorUp, Command.PreviousView); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.PageUp, Command.PageUp); } /// diff --git a/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs b/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs index bacc953f4..b755aa64f 100644 --- a/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs +++ b/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs @@ -26,7 +26,7 @@ public abstract class CheckBoxTableSourceWrapperBase : ITableSource Wrapping = toWrap; this.tableView = tableView; - tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + tableView.KeyBindings.Add (Key.Space, Command.Select); tableView.MouseClick += TableView_MouseClick; tableView.CellToggled += TableView_CellToggled; diff --git a/Terminal.Gui/Views/TableView/TableSelection.cs b/Terminal.Gui/Views/TableView/TableSelection.cs index 78a1798bb..be5e73e12 100644 --- a/Terminal.Gui/Views/TableView/TableSelection.cs +++ b/Terminal.Gui/Views/TableView/TableSelection.cs @@ -13,7 +13,7 @@ public class TableSelection } /// - /// True if the selection was made through and therefore should persist even + /// True if the selection was made through and therefore should persist even /// through keyboard navigation. /// public bool IsToggled { get; set; } diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 06f4bc27e..c5ac1bdb3 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -273,7 +273,7 @@ public class TableView : View ); AddCommand ( - Command.ToggleChecked, + Command.Select, // was Command.ToggleChecked () => { ToggleCurrentCellSelection (); @@ -283,30 +283,31 @@ public class TableView : View ); // Default keybindings for this view - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.Home, Command.LeftHome); - KeyBindings.Add (KeyCode.End, Command.RightEnd); - KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask, Command.TopHome); - KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask, Command.BottomEnd); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.PageUp, Command.PageUp); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.Home, Command.LeftHome); + KeyBindings.Add (Key.End, Command.RightEnd); + KeyBindings.Add (Key.Home.WithCtrl, Command.TopHome); + KeyBindings.Add (Key.End.WithCtrl, Command.BottomEnd); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.ShiftMask, Command.LeftExtend); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.ShiftMask, Command.RightExtend); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.ShiftMask, Command.LineUpExtend); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.ShiftMask, Command.LineDownExtend); - KeyBindings.Add (KeyCode.PageUp | KeyCode.ShiftMask, Command.PageUpExtend); - KeyBindings.Add (KeyCode.PageDown | KeyCode.ShiftMask, Command.PageDownExtend); - KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask, Command.LeftHomeExtend); - KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask, Command.RightEndExtend); - KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.TopHomeExtend); - KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.BottomEndExtend); + KeyBindings.Add (Key.CursorLeft.WithShift, Command.LeftExtend); + KeyBindings.Add (Key.CursorRight.WithShift, Command.RightExtend); + KeyBindings.Add (Key.CursorUp.WithShift, Command.LineUpExtend); + KeyBindings.Add (Key.CursorDown.WithShift, Command.LineDownExtend); + KeyBindings.Add (Key.PageUp.WithShift, Command.PageUpExtend); + KeyBindings.Add (Key.PageDown.WithShift, Command.PageDownExtend); + KeyBindings.Add (Key.Home.WithShift, Command.LeftHomeExtend); + KeyBindings.Add (Key.End.WithShift, Command.RightEndExtend); + KeyBindings.Add (Key.Home.WithCtrl.WithShift, Command.TopHomeExtend); + KeyBindings.Add (Key.End.WithCtrl.WithShift, Command.BottomEndExtend); - KeyBindings.Add (KeyCode.A | KeyCode.CtrlMask, Command.SelectAll); + KeyBindings.Add (Key.A.WithCtrl, Command.SelectAll); KeyBindings.Add (CellActivationKey, Command.Accept); + KeyBindings.Add (Key.Space, Command.Select); } // TODO: Update to use Key instead of KeyCode @@ -432,7 +433,7 @@ public class TableView : View } /// - /// The symbol to add after each cell value and header value to visually seperate values (if not using vertical + /// The symbol to add after each cell value and header value to visually separate values (if not using vertical /// gridlines) /// public char SeparatorSymbol { get; set; } = ' '; @@ -460,12 +461,12 @@ public class TableView : View } /// - /// This event is raised when a cell is activated e.g. by double clicking or pressing + /// This event is raised when a cell is activated e.g. by double-clicking or pressing /// /// public event EventHandler CellActivated; - /// This event is raised when a cell is toggled (see + /// This event is raised when a cell is toggled (see public event EventHandler CellToggled; /// @@ -1487,7 +1488,7 @@ public class TableView : View /// Origin point for the selection in Y /// End point for the selection in X /// End point for the selection in Y - /// True if selection is result of + /// True if selection is result of /// private TableSelection CreateTableSelection (int pt1X, int pt1Y, int pt2X, int pt2Y, bool toggle = false) { diff --git a/Terminal.Gui/Views/TextChangedEventArgs.cs b/Terminal.Gui/Views/TextChangedEventArgs.cs deleted file mode 100644 index 97cbd256a..000000000 --- a/Terminal.Gui/Views/TextChangedEventArgs.cs +++ /dev/null @@ -1,19 +0,0 @@ -// -// TextField.cs: single-line text editor with Emacs keybindings -// -// Authors: -// Miguel de Icaza (miguel@gnome.org) -// - -namespace Terminal.Gui; - -/// Event args for the event -public class TextChangedEventArgs : EventArgs -{ - /// Creates a new instance of the class - /// - public TextChangedEventArgs (string oldValue) { OldValue = oldValue; } - - /// The old value before the text changed - public string OldValue { get; } -} diff --git a/Terminal.Gui/Views/TextChangingEventArgs.cs b/Terminal.Gui/Views/TextChangingEventArgs.cs deleted file mode 100644 index 63fc5d5ab..000000000 --- a/Terminal.Gui/Views/TextChangingEventArgs.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -// TextField.cs: single-line text editor with Emacs keybindings -// -// Authors: -// Miguel de Icaza (miguel@gnome.org) -// - -namespace Terminal.Gui; - -/// An which allows passing a cancelable new text value event. -public class TextChangingEventArgs : EventArgs -{ - /// Initializes a new instance of - /// The new to be replaced. - public TextChangingEventArgs (string newText) { NewText = newText; } - - /// Flag which allows to cancel the new text value. - public bool Cancel { get; set; } - - /// The new text to be replaced. - public string NewText { get; set; } -} diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 66501b680..7d0e4aeec 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -1,3 +1,4 @@ +using System.Data; using System.Globalization; using Terminal.Gui.Resources; @@ -340,82 +341,91 @@ public class TextField : View } ); + // OnAccept returns true if the event is canceled. + // By Default pressing ENTER should be ignored (Invoke(Command.Accept) should return false). + AddCommand (Command.Accept, () => OnAccept() != true); + // Default keybindings for this view // We follow this as closely as possible: https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts - KeyBindings.Add (KeyCode.Delete, Command.DeleteCharRight); - KeyBindings.Add (KeyCode.D | KeyCode.CtrlMask, Command.DeleteCharRight); + KeyBindings.Add (Key.Delete, Command.DeleteCharRight); + KeyBindings.Add (Key.D.WithCtrl, Command.DeleteCharRight); - KeyBindings.Add (KeyCode.Backspace, Command.DeleteCharLeft); + KeyBindings.Add (Key.Backspace, Command.DeleteCharLeft); - KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask, Command.LeftHomeExtend); - KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.LeftHomeExtend); - KeyBindings.Add (KeyCode.A | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.LeftHomeExtend); + KeyBindings.Add (Key.Home.WithShift, Command.LeftHomeExtend); + KeyBindings.Add (Key.Home.WithShift.WithCtrl, Command.LeftHomeExtend); + KeyBindings.Add (Key.A.WithShift.WithCtrl, Command.LeftHomeExtend); - KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask, Command.RightEndExtend); - KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.RightEndExtend); - KeyBindings.Add (KeyCode.E | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.RightEndExtend); + KeyBindings.Add (Key.End.WithShift, Command.RightEndExtend); + KeyBindings.Add (Key.End.WithShift.WithCtrl, Command.RightEndExtend); + KeyBindings.Add (Key.E.WithShift.WithCtrl, Command.RightEndExtend); - KeyBindings.Add (KeyCode.Home, Command.LeftHome); - KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask, Command.LeftHome); - KeyBindings.Add (KeyCode.A | KeyCode.CtrlMask, Command.LeftHome); + KeyBindings.Add (Key.Home, Command.LeftHome); + KeyBindings.Add (Key.Home.WithCtrl, Command.LeftHome); + KeyBindings.Add (Key.A.WithCtrl, Command.LeftHome); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.ShiftMask, Command.LeftExtend); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.ShiftMask, Command.LeftExtend); + KeyBindings.Add (Key.CursorLeft.WithShift, Command.LeftExtend); + KeyBindings.Add (Key.CursorUp.WithShift, Command.LeftExtend); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.ShiftMask, Command.RightExtend); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.ShiftMask, Command.RightExtend); + KeyBindings.Add (Key.CursorRight.WithShift, Command.RightExtend); + KeyBindings.Add (Key.CursorDown.WithShift, Command.RightExtend); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.WordLeftExtend); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.WordLeftExtend); - KeyBindings.Add (('B' + KeyCode.ShiftMask) | KeyCode.AltMask, Command.WordLeftExtend); + KeyBindings.Add (Key.CursorLeft.WithShift.WithCtrl, Command.WordLeftExtend); + KeyBindings.Add (Key.CursorUp.WithShift.WithCtrl, Command.WordLeftExtend); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.WordRightExtend); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.ShiftMask | KeyCode.CtrlMask, Command.WordRightExtend); - KeyBindings.Add (('F' + KeyCode.ShiftMask) | KeyCode.AltMask, Command.WordRightExtend); + KeyBindings.Add (Key.CursorRight.WithShift.WithCtrl, Command.WordRightExtend); + KeyBindings.Add (Key.CursorDown.WithShift.WithCtrl, Command.WordRightExtend); - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.B | KeyCode.CtrlMask, Command.Left); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.B.WithCtrl, Command.Left); - KeyBindings.Add (KeyCode.End, Command.RightEnd); - KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask, Command.RightEnd); - KeyBindings.Add (KeyCode.E | KeyCode.CtrlMask, Command.RightEnd); + KeyBindings.Add (Key.End, Command.RightEnd); + KeyBindings.Add (Key.End.WithCtrl, Command.RightEnd); + KeyBindings.Add (Key.E.WithCtrl, Command.RightEnd); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.F | KeyCode.CtrlMask, Command.Right); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.F.WithCtrl, Command.Right); - KeyBindings.Add (KeyCode.K | KeyCode.CtrlMask, Command.CutToEndLine); - KeyBindings.Add (KeyCode.K | KeyCode.AltMask, Command.CutToStartLine); + KeyBindings.Add (Key.K.WithCtrl, Command.CutToEndLine); + KeyBindings.Add (Key.K.WithCtrl.WithShift, Command.CutToStartLine); - KeyBindings.Add (KeyCode.Z | KeyCode.CtrlMask, Command.Undo); - KeyBindings.Add (KeyCode.Backspace | KeyCode.AltMask, Command.Undo); + KeyBindings.Add (Key.Z.WithCtrl, Command.Undo); - KeyBindings.Add (KeyCode.Y | KeyCode.CtrlMask, Command.Redo); + KeyBindings.Add (Key.Y.WithCtrl, Command.Redo); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.CtrlMask, Command.WordLeft); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.CtrlMask, Command.WordLeft); - KeyBindings.Add ('B' + KeyCode.AltMask, Command.WordLeft); + KeyBindings.Add (Key.CursorLeft.WithCtrl, Command.WordLeft); + KeyBindings.Add (Key.CursorUp.WithCtrl, Command.WordLeft); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.CtrlMask, Command.WordRight); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.CtrlMask, Command.WordRight); - KeyBindings.Add ('F' + KeyCode.AltMask, Command.WordRight); + KeyBindings.Add (Key.CursorRight.WithCtrl, Command.WordRight); + KeyBindings.Add (Key.CursorDown.WithCtrl, Command.WordRight); - KeyBindings.Add (KeyCode.Delete | KeyCode.CtrlMask, Command.KillWordForwards); - KeyBindings.Add (KeyCode.Backspace | KeyCode.CtrlMask, Command.KillWordBackwards); - KeyBindings.Add (KeyCode.Insert, Command.ToggleOverwrite); - KeyBindings.Add (KeyCode.C | KeyCode.CtrlMask, Command.Copy); - KeyBindings.Add (KeyCode.X | KeyCode.CtrlMask, Command.Cut); - KeyBindings.Add (KeyCode.V | KeyCode.CtrlMask, Command.Paste); - KeyBindings.Add (KeyCode.T | KeyCode.CtrlMask, Command.SelectAll); +#if UNIX_KEY_BINDINGS + KeyBindings.Add (Key.F.WithShift.WithAlt, Command.WordRightExtend); + KeyBindings.Add (Key.K.WithAlt, Command.CutToStartLine); + KeyBindings.Add (Key.B.WithShift.WithAlt, Command.WordLeftExtend); + KeyBindings.Add (Key.B.WithAlt, Command.WordLeft); + KeyBindings.Add (Key.F.WithAlt, Command.WordRight); + KeyBindings.Add (Key.Backspace.WithAlt, Command.Undo); +#endif - KeyBindings.Add (KeyCode.R | KeyCode.CtrlMask, Command.DeleteAll); - KeyBindings.Add (KeyCode.D | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.DeleteAll); + KeyBindings.Add (Key.Delete.WithCtrl, Command.KillWordForwards); + KeyBindings.Add (Key.Backspace.WithCtrl, Command.KillWordBackwards); + KeyBindings.Add (Key.InsertChar, Command.ToggleOverwrite); + KeyBindings.Add (Key.C.WithCtrl, Command.Copy); + KeyBindings.Add (Key.X.WithCtrl, Command.Cut); + KeyBindings.Add (Key.V.WithCtrl, Command.Paste); + KeyBindings.Add (Key.T.WithCtrl, Command.SelectAll); + + KeyBindings.Add (Key.R.WithCtrl, Command.DeleteAll); + KeyBindings.Add (Key.D.WithCtrl.WithShift, Command.DeleteAll); _currentCulture = Thread.CurrentThread.CurrentUICulture; ContextMenu = new ContextMenu { Host = this, MenuItems = BuildContextMenuBarItem () }; ContextMenu.KeyChanged += ContextMenu_KeyChanged; - KeyBindings.Add (ContextMenu.Key.KeyCode, KeyBindingScope.HotKey, Command.ShowContextMenu); + KeyBindings.Add (ContextMenu.Key, KeyBindingScope.HotKey, Command.ShowContextMenu); + KeyBindings.Add (Key.Enter, Command.Accept); } /// @@ -551,7 +561,7 @@ public class TextField : View return; } - TextChangingEventArgs newText = OnTextChanging (value.Replace ("\t", "").Split ("\n") [0]); + StateEventArgs newText = OnTextChanging (value.Replace ("\t", "").Split ("\n") [0]); if (newText.Cancel) { @@ -564,7 +574,7 @@ public class TextField : View } ClearAllSelection (); - _text = newText.NewText.EnumerateRunes ().ToList (); + _text = newText.NewValue.EnumerateRunes ().ToList (); if (!Secret && !_historyText.IsFromHistory) { @@ -580,7 +590,7 @@ public class TextField : View ); } - TextChanged?.Invoke (this, new TextChangedEventArgs (oldText)); + OnTextChanged (oldText, StringExtensions.ToString (_text)); ProcessAutocomplete (); @@ -1132,10 +1142,10 @@ public class TextField : View /// Virtual method that invoke the event if it's defined. /// The new text to be replaced. - /// Returns the - public virtual TextChangingEventArgs OnTextChanging (string newText) + /// Returns the + public virtual StateEventArgs OnTextChanging (string newText) { - var ev = new TextChangingEventArgs (newText); + StateEventArgs ev = new (string.Empty, newText); TextChanging?.Invoke (this, ev); return ev; @@ -1258,17 +1268,17 @@ public class TextField : View SetNeedsDisplay (); } - /// - /// Changed event, raised when the text has changed. - /// - /// This event is raised when the changes. The passed is a - /// containing the old value. - /// - /// - public event EventHandler TextChanged; + ///// + ///// Changed event, raised when the text has changed. + ///// + ///// This event is raised when the changes. The passed is a + ///// containing the old value. + ///// + ///// + //public event EventHandler> TextChanged; /// Changing event, raised before the changes and can be canceled or changing the new text. - public event EventHandler TextChanging; + public event EventHandler> TextChanging; /// Undoes the latest changes. public void Undo () diff --git a/Terminal.Gui/Views/TextValidateField.cs b/Terminal.Gui/Views/TextValidateField.cs index 551e9002a..a4efd6a83 100644 --- a/Terminal.Gui/Views/TextValidateField.cs +++ b/Terminal.Gui/Views/TextValidateField.cs @@ -64,8 +64,8 @@ namespace Terminal.Gui /// Method that invoke the event if it's defined. /// The previous text before replaced. - /// Returns the - void OnTextChanged (TextChangedEventArgs oldValue); + /// Returns the + void OnTextChanged (StringEventArgs oldValue); /// /// Changed event, raised when the text has changed. @@ -74,7 +74,7 @@ namespace Terminal.Gui /// containing the old value. /// /// - event EventHandler TextChanged; + event EventHandler TextChanged; } ////////////////////////////////////////////////////////////////////////////// @@ -125,7 +125,7 @@ namespace Terminal.Gui } /// - public event EventHandler TextChanged; + public event EventHandler TextChanged; /// public string Text @@ -206,7 +206,7 @@ namespace Terminal.Gui if (result) { - OnTextChanged (new TextChangedEventArgs (oldValue)); + OnTextChanged (new StringEventArgs { NewValue = oldValue }); } return result; @@ -220,14 +220,14 @@ namespace Terminal.Gui if (result) { - OnTextChanged (new TextChangedEventArgs (oldValue)); + OnTextChanged (new StringEventArgs { NewValue = oldValue }); } return result; } /// - public void OnTextChanged (TextChangedEventArgs oldValue) { TextChanged?.Invoke (this, oldValue); } + public void OnTextChanged (StringEventArgs oldValue) { TextChanged?.Invoke (this, oldValue); } } #endregion @@ -260,7 +260,7 @@ namespace Terminal.Gui public bool ValidateOnInput { get; set; } = true; /// - public event EventHandler TextChanged; + public event EventHandler TextChanged; /// public string Text @@ -333,7 +333,7 @@ namespace Terminal.Gui { string oldValue = Text; _text.RemoveAt (pos); - OnTextChanged (new TextChangedEventArgs (oldValue)); + OnTextChanged (new StringEventArgs { NewValue = Text, OldValue = oldValue }); } return true; @@ -349,7 +349,7 @@ namespace Terminal.Gui { string oldValue = Text; _text.Insert (pos, (Rune)ch); - OnTextChanged (new TextChangedEventArgs (oldValue)); + OnTextChanged (new StringEventArgs { NewValue = Text, OldValue = oldValue }); return true; } @@ -358,7 +358,7 @@ namespace Terminal.Gui } /// - public void OnTextChanged (TextChangedEventArgs oldValue) { TextChanged?.Invoke (this, oldValue); } + public void OnTextChanged (StringEventArgs oldValue) { TextChanged?.Invoke (this, oldValue); } /// Compiles the regex pattern for validation./> private void CompileMask () { _regex = new Regex (StringExtensions.ToString (_pattern), RegexOptions.Compiled); } @@ -462,15 +462,15 @@ namespace Terminal.Gui ); // Default keybindings for this view - KeyBindings.Add (KeyCode.Home, Command.LeftHome); - KeyBindings.Add (KeyCode.End, Command.RightEnd); + KeyBindings.Add (Key.Home, Command.LeftHome); + KeyBindings.Add (Key.End, Command.RightEnd); - KeyBindings.Add (KeyCode.Delete, Command.DeleteCharRight); - KeyBindings.Add (KeyCode.Delete, Command.DeleteCharRight); + KeyBindings.Add (Key.Delete, Command.DeleteCharRight); + KeyBindings.Add (Key.Delete, Command.DeleteCharRight); - KeyBindings.Add (KeyCode.Backspace, Command.DeleteCharLeft); - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); + KeyBindings.Add (Key.Backspace, Command.DeleteCharLeft); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorRight, Command.Right); } /// This property returns true if the input is valid. diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index ca9717110..d3e339b2a 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2409,113 +2409,103 @@ public class TextView : View ); // Default keybindings for this view - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.V | KeyCode.CtrlMask, Command.PageDown); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.V.WithCtrl, Command.PageDown); - KeyBindings.Add (KeyCode.PageDown | KeyCode.ShiftMask, Command.PageDownExtend); + KeyBindings.Add (Key.PageDown.WithShift, Command.PageDownExtend); - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); - KeyBindings.Add ('V' + KeyCode.AltMask, Command.PageUp); + KeyBindings.Add (Key.PageUp, Command.PageUp); + KeyBindings.Add (Key.V.WithAlt, Command.PageUp); - KeyBindings.Add (KeyCode.PageUp | KeyCode.ShiftMask, Command.PageUpExtend); + KeyBindings.Add (Key.PageUp.WithShift, Command.PageUpExtend); - KeyBindings.Add (KeyCode.N | KeyCode.CtrlMask, Command.LineDown); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); + KeyBindings.Add (Key.N.WithCtrl, Command.LineDown); + KeyBindings.Add (Key.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.ShiftMask, Command.LineDownExtend); + KeyBindings.Add (Key.CursorDown.WithShift, Command.LineDownExtend); - KeyBindings.Add (KeyCode.P | KeyCode.CtrlMask, Command.LineUp); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); + KeyBindings.Add (Key.P.WithCtrl, Command.LineUp); + KeyBindings.Add (Key.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.ShiftMask, Command.LineUpExtend); + KeyBindings.Add (Key.CursorUp.WithShift, Command.LineUpExtend); - KeyBindings.Add (KeyCode.F | KeyCode.CtrlMask, Command.Right); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); + KeyBindings.Add (Key.F.WithCtrl, Command.Right); + KeyBindings.Add (Key.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.ShiftMask, Command.RightExtend); + KeyBindings.Add (Key.CursorRight.WithShift, Command.RightExtend); - KeyBindings.Add (KeyCode.B | KeyCode.CtrlMask, Command.Left); - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); + KeyBindings.Add (Key.B.WithCtrl, Command.Left); + KeyBindings.Add (Key.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.ShiftMask, Command.LeftExtend); + KeyBindings.Add (Key.CursorLeft.WithShift, Command.LeftExtend); - KeyBindings.Add (KeyCode.Backspace, Command.DeleteCharLeft); + KeyBindings.Add (Key.Backspace, Command.DeleteCharLeft); - KeyBindings.Add (KeyCode.Home, Command.StartOfLine); - KeyBindings.Add (KeyCode.A | KeyCode.CtrlMask, Command.StartOfLine); + KeyBindings.Add (Key.Home, Command.StartOfLine); + KeyBindings.Add (Key.A.WithCtrl, Command.StartOfLine); - KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask, Command.StartOfLineExtend); + KeyBindings.Add (Key.Home.WithShift, Command.StartOfLineExtend); - KeyBindings.Add (KeyCode.Delete, Command.DeleteCharRight); - KeyBindings.Add (KeyCode.D | KeyCode.CtrlMask, Command.DeleteCharRight); + KeyBindings.Add (Key.Delete, Command.DeleteCharRight); + KeyBindings.Add (Key.D.WithCtrl, Command.DeleteCharRight); - KeyBindings.Add (KeyCode.End, Command.EndOfLine); - KeyBindings.Add (KeyCode.E | KeyCode.CtrlMask, Command.EndOfLine); + KeyBindings.Add (Key.End, Command.EndOfLine); + KeyBindings.Add (Key.E.WithCtrl, Command.EndOfLine); - KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask, Command.EndOfLineExtend); + KeyBindings.Add (Key.End.WithShift, Command.EndOfLineExtend); - KeyBindings.Add (KeyCode.K | KeyCode.CtrlMask, Command.CutToEndLine); // kill-to-end + KeyBindings.Add (Key.K.WithCtrl, Command.CutToEndLine); // kill-to-end - KeyBindings.Add ( - KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask, - Command.CutToEndLine - ); // kill-to-end + KeyBindings.Add (Key.Delete.WithCtrl.WithShift, Command.CutToEndLine); // kill-to-end - KeyBindings.Add (KeyCode.K | KeyCode.AltMask, Command.CutToStartLine); // kill-to-start + KeyBindings.Add (Key.K.WithAlt, Command.CutToStartLine); // kill-to-start - KeyBindings.Add ( - KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask, - Command.CutToStartLine - ); // kill-to-start + KeyBindings.Add (Key.Backspace.WithCtrl.WithShift, Command.CutToStartLine); // kill-to-start - KeyBindings.Add (KeyCode.Y | KeyCode.CtrlMask, Command.Paste); // Control-y, yank - KeyBindings.Add (KeyCode.Space | KeyCode.CtrlMask, Command.ToggleExtend); + KeyBindings.Add (Key.Y.WithCtrl, Command.Paste); // Control-y, yank + KeyBindings.Add (Key.Space.WithCtrl, Command.ToggleExtend); - KeyBindings.Add ('C' + KeyCode.AltMask, Command.Copy); - KeyBindings.Add (KeyCode.C | KeyCode.CtrlMask, Command.Copy); + KeyBindings.Add (Key.C.WithAlt, Command.Copy); + KeyBindings.Add (Key.C.WithCtrl, Command.Copy); - KeyBindings.Add ('W' + KeyCode.AltMask, Command.Cut); - KeyBindings.Add (KeyCode.W | KeyCode.CtrlMask, Command.Cut); - KeyBindings.Add (KeyCode.X | KeyCode.CtrlMask, Command.Cut); + KeyBindings.Add (Key.W.WithAlt, Command.Cut); + KeyBindings.Add (Key.W.WithCtrl, Command.Cut); + KeyBindings.Add (Key.X.WithCtrl, Command.Cut); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.CtrlMask, Command.WordLeft); - KeyBindings.Add ('B' + KeyCode.AltMask, Command.WordLeft); + KeyBindings.Add (Key.CursorLeft.WithCtrl, Command.WordLeft); + KeyBindings.Add (Key.B.WithAlt, Command.WordLeft); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.WordLeftExtend); + KeyBindings.Add (Key.CursorLeft.WithCtrl.WithShift, Command.WordLeftExtend); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.CtrlMask, Command.WordRight); - KeyBindings.Add ('F' + KeyCode.AltMask, Command.WordRight); + KeyBindings.Add (Key.CursorRight.WithCtrl, Command.WordRight); + KeyBindings.Add (Key.F.WithAlt, Command.WordRight); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.WordRightExtend); - KeyBindings.Add (KeyCode.Delete | KeyCode.CtrlMask, Command.KillWordForwards); // kill-word-forwards - - KeyBindings.Add ( - KeyCode.Backspace | KeyCode.CtrlMask, - Command.KillWordBackwards - ); // kill-word-backwards + KeyBindings.Add (Key.CursorRight.WithCtrl.WithShift, Command.WordRightExtend); + KeyBindings.Add (Key.Delete.WithCtrl, Command.KillWordForwards); // kill-word-forwards + KeyBindings.Add (Key.Backspace.WithCtrl, Command.KillWordBackwards); // kill-word-backwards // BUGBUG: If AllowsReturn is false, Key.Enter should not be bound (so that Toplevel can cause Command.Accept). - KeyBindings.Add (KeyCode.Enter, Command.NewLine); - KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask, Command.BottomEnd); - KeyBindings.Add (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.BottomEndExtend); - KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask, Command.TopHome); - KeyBindings.Add (KeyCode.Home | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.TopHomeExtend); - KeyBindings.Add (KeyCode.T | KeyCode.CtrlMask, Command.SelectAll); - KeyBindings.Add (KeyCode.Insert, Command.ToggleOverwrite); - KeyBindings.Add (KeyCode.Tab, Command.Tab); - KeyBindings.Add (KeyCode.Tab | KeyCode.ShiftMask, Command.BackTab); + KeyBindings.Add (Key.Enter, Command.NewLine); + KeyBindings.Add (Key.End.WithCtrl, Command.BottomEnd); + KeyBindings.Add (Key.End.WithCtrl.WithShift, Command.BottomEndExtend); + KeyBindings.Add (Key.Home.WithCtrl, Command.TopHome); + KeyBindings.Add (Key.Home.WithCtrl.WithShift, Command.TopHomeExtend); + KeyBindings.Add (Key.T.WithCtrl, Command.SelectAll); + KeyBindings.Add (Key.InsertChar, Command.ToggleOverwrite); + KeyBindings.Add (Key.Tab, Command.Tab); + KeyBindings.Add (Key.Tab.WithShift, Command.BackTab); - KeyBindings.Add (KeyCode.Tab | KeyCode.CtrlMask, Command.NextView); - KeyBindings.Add ((KeyCode)Application.AlternateForwardKey, Command.NextView); + KeyBindings.Add (Key.Tab.WithCtrl, Command.NextView); + KeyBindings.Add (Application.AlternateForwardKey, Command.NextView); - KeyBindings.Add (KeyCode.Tab | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.PreviousView); - KeyBindings.Add ((KeyCode)Application.AlternateBackwardKey, Command.PreviousView); + KeyBindings.Add (Key.Tab.WithCtrl.WithShift, Command.PreviousView); + KeyBindings.Add (Application.AlternateBackwardKey, Command.PreviousView); - KeyBindings.Add (KeyCode.Z | KeyCode.CtrlMask, Command.Undo); - KeyBindings.Add (KeyCode.R | KeyCode.CtrlMask, Command.Redo); + KeyBindings.Add (Key.Z.WithCtrl, Command.Undo); + KeyBindings.Add (Key.R.WithCtrl, Command.Redo); - KeyBindings.Add (KeyCode.G | KeyCode.CtrlMask, Command.DeleteAll); - KeyBindings.Add (KeyCode.D | KeyCode.CtrlMask | KeyCode.ShiftMask, Command.DeleteAll); + KeyBindings.Add (Key.G.WithCtrl, Command.DeleteAll); + KeyBindings.Add (Key.D.WithCtrl.WithShift, Command.DeleteAll); _currentCulture = Thread.CurrentThread.CurrentUICulture; @@ -2863,7 +2853,7 @@ public class TextView : View /// Sets or gets the text in the . /// - /// The event is fired whenever this property is set. Note, however, that Text is not + /// The event is fired whenever this property is set. Note, however, that Text is not /// set by as the user types. /// public override string Text @@ -2879,6 +2869,7 @@ public class TextView : View } set { + var old = Text; ResetPosition (); _model.LoadString (value); @@ -2888,7 +2879,7 @@ public class TextView : View _model = _wrapManager.WrapModel (_frameWidth, out _, out _, out _, out _); } - TextChanged?.Invoke (this, EventArgs.Empty); + OnTextChanged (old,Text); SetNeedsDisplay (); _historyText.Clear (Text); @@ -2961,7 +2952,7 @@ public class TextView : View /// Raised when the contents of the are changed. /// - /// Unlike the event, this event is raised whenever the user types or otherwise changes + /// Unlike the event, this event is raised whenever the user types or otherwise changes /// the contents of the . /// public event EventHandler? ContentsChanged; @@ -3723,15 +3714,14 @@ public class TextView : View } /// - public override bool OnKeyUp (Key a) + public override bool OnKeyUp (Key key) { - switch (a.KeyCode) + if (key == Key.Space.WithCtrl) { - case KeyCode.Space | KeyCode.CtrlMask: - return true; + return true; } - return base.OnKeyUp (a); + return base.OnKeyUp (key); } /// @@ -3993,12 +3983,12 @@ public class TextView : View SetNeedsDisplay (); } - /// Raised when the property of the changes. - /// - /// The property of only changes when it is explicitly set, not as the - /// user types. To be notified as the user changes the contents of the TextView see . - /// - public event EventHandler? TextChanged; + ///// Raised when the property of the changes. + ///// + ///// The property of only changes when it is explicitly set, not as the + ///// user types. To be notified as the user changes the contents of the TextView see . + ///// + //public event EventHandler? TextChanged; /// Undoes the latest changes. public void Undo () @@ -4377,7 +4367,7 @@ public class TextView : View DoNeededAction (); } - private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.Replace ((KeyCode)e.OldKey, (KeyCode)e.NewKey); } + private void ContextMenu_KeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.Replace (e.OldKey, e.NewKey); } private bool DeleteTextBackwards () { @@ -6465,8 +6455,8 @@ public class TextView : View _selectionStartRow = CurrentRow; } - private void Top_AlternateBackwardKeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.Replace ((KeyCode)e.OldKey, (KeyCode)e.NewKey); } - private void Top_AlternateForwardKeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.Replace ((KeyCode)e.OldKey, (KeyCode)e.NewKey); } + private void Top_AlternateBackwardKeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.Replace (e.OldKey, e.NewKey); } + private void Top_AlternateForwardKeyChanged (object sender, KeyChangedEventArgs e) { KeyBindings.Replace (e.OldKey, e.NewKey); } // Tries to snap the cursor to the tracking column private void TrackColumn () diff --git a/Terminal.Gui/Views/Tile.cs b/Terminal.Gui/Views/Tile.cs index a24c6e442..df7cefbb7 100644 --- a/Terminal.Gui/Views/Tile.cs +++ b/Terminal.Gui/Views/Tile.cs @@ -1,4 +1,6 @@ -namespace Terminal.Gui; +using System.ComponentModel; + +namespace Terminal.Gui; /// /// A single presented in a . To create new instances use @@ -59,7 +61,7 @@ public class Tile /// The new to be replaced. public virtual void OnTitleChanged (string oldTitle, string newTitle) { - var args = new TitleEventArgs (oldTitle, newTitle); + var args = new StringEventArgs (oldTitle, newTitle); TitleChanged?.Invoke (this, args); } @@ -72,18 +74,18 @@ public class Tile /// true if an event handler cancelled the Title change. public virtual bool OnTitleChanging (string oldTitle, string newTitle) { - var args = new TitleEventArgs (oldTitle, newTitle); + var args = new StringEventArgs (oldTitle, newTitle); TitleChanging?.Invoke (this, args); return args.Cancel; } /// Event fired after the has been changed. - public event EventHandler TitleChanged; + public event EventHandler TitleChanged; /// - /// Event fired when the is changing. Set to true - /// to cancel the Title change. + /// Event fired when the is changing. + /// can be set to true to cancel the change. /// - public event EventHandler TitleChanging; + public event EventHandler TitleChanging; } diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index eaa801c06..223b1273b 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -880,10 +880,10 @@ public class TileView : View AddCommand (Command.LineDown, () => { return MoveSplitter (0, 1); }); - KeyBindings.Add (KeyCode.CursorRight, Command.Right); - KeyBindings.Add (KeyCode.CursorLeft, Command.Left); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); + KeyBindings.Add (Key.CursorRight, Command.Right); + KeyBindings.Add (Key.CursorLeft, Command.Left); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.CursorDown, Command.LineDown); } public int Idx { get; } diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 3d016153f..2779c2f83 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -59,11 +59,10 @@ public class TimeField : TextField AddCommand (Command.Right, () => MoveRight ()); // Default keybindings for this view - KeyBindings.Add (KeyCode.Delete, Command.DeleteCharRight); + KeyBindings.Add (Key.Delete, Command.DeleteCharRight); KeyBindings.Add (Key.D.WithCtrl, Command.DeleteCharRight); KeyBindings.Add (Key.Backspace, Command.DeleteCharLeft); - KeyBindings.Add (Key.D.WithAlt, Command.DeleteCharLeft); KeyBindings.Add (Key.Home, Command.LeftHome); KeyBindings.Add (Key.A.WithCtrl, Command.LeftHome); @@ -76,6 +75,10 @@ public class TimeField : TextField KeyBindings.Add (Key.CursorRight, Command.Right); KeyBindings.Add (Key.F.WithCtrl, Command.Right); + +#if UNIX_KEY_BINDINGS + KeyBindings.Add (Key.D.WithAlt, Command.DeleteCharLeft); +#endif } /// @@ -427,15 +430,15 @@ public class TimeField : TextField return true; } - private void TextField_TextChanging (object sender, TextChangingEventArgs e) + private void TextField_TextChanging (object sender, StateEventArgs e) { try { var spaces = 0; - for (var i = 0; i < e.NewText.Length; i++) + for (var i = 0; i < e.NewValue.Length; i++) { - if (e.NewText [i] == ' ') + if (e.NewValue [i] == ' ') { spaces++; } @@ -446,17 +449,17 @@ public class TimeField : TextField } spaces += FieldLength; - string trimedText = e.NewText [..spaces]; + string trimedText = e.NewValue [..spaces]; spaces -= FieldLength; trimedText = trimedText.Replace (new string (' ', spaces), " "); - if (trimedText != e.NewText) + if (trimedText != e.NewValue) { - e.NewText = trimedText; + e.NewValue = trimedText; } if (!TimeSpan.TryParseExact ( - e.NewText.Trim (), + e.NewValue.Trim (), Format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, diff --git a/Terminal.Gui/Views/ToplevelOverlapped.cs b/Terminal.Gui/Views/ToplevelOverlapped.cs index f3c5a832b..864882b9c 100644 --- a/Terminal.Gui/Views/ToplevelOverlapped.cs +++ b/Terminal.Gui/Views/ToplevelOverlapped.cs @@ -65,7 +65,7 @@ public static partial class Application View top = FindTopFromView (Top?.MostFocused); - if (top is { } && Top.Subviews.Count > 1 && Top.Subviews [Top.Subviews.Count - 1] != top) + if (top is Toplevel && Top.Subviews.Count > 1 && Top.Subviews [Top.Subviews.Count - 1] != top) { Top.BringSubviewToFront (top); } diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index 4fd0e41fd..f833b8c88 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -7,7 +7,7 @@ using System.Collections.ObjectModel; namespace Terminal.Gui; /// -/// Interface for all non generic members of . +/// Interface for all non-generic members of . /// See TreeView Deep Dive for more information. /// public interface ITreeView @@ -272,38 +272,31 @@ public class TreeView : View, ITreeView where T : class } ); - AddCommand ( - Command.Accept, - () => - { - ActivateSelectedObjectIfAny (); - - return true; - } - ); + AddCommand (Command.Select, ActivateSelectedObjectIfAny); + AddCommand (Command.Accept, ActivateSelectedObjectIfAny); // Default keybindings for this view - KeyBindings.Add (KeyCode.PageUp, Command.PageUp); - KeyBindings.Add (KeyCode.PageDown, Command.PageDown); - KeyBindings.Add (KeyCode.PageUp | KeyCode.ShiftMask, Command.PageUpExtend); - KeyBindings.Add (KeyCode.PageDown | KeyCode.ShiftMask, Command.PageDownExtend); - KeyBindings.Add (KeyCode.CursorRight, Command.Expand); - KeyBindings.Add (KeyCode.CursorRight | KeyCode.CtrlMask, Command.ExpandAll); - KeyBindings.Add (KeyCode.CursorLeft, Command.Collapse); - KeyBindings.Add (KeyCode.CursorLeft | KeyCode.CtrlMask, Command.CollapseAll); + KeyBindings.Add (Key.PageUp, Command.PageUp); + KeyBindings.Add (Key.PageDown, Command.PageDown); + KeyBindings.Add (Key.PageUp.WithShift, Command.PageUpExtend); + KeyBindings.Add (Key.PageDown.WithShift, Command.PageDownExtend); + KeyBindings.Add (Key.CursorRight, Command.Expand); + KeyBindings.Add (Key.CursorRight.WithCtrl, Command.ExpandAll); + KeyBindings.Add (Key.CursorLeft, Command.Collapse); + KeyBindings.Add (Key.CursorLeft.WithCtrl, Command.CollapseAll); - KeyBindings.Add (KeyCode.CursorUp, Command.LineUp); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.ShiftMask, Command.LineUpExtend); - KeyBindings.Add (KeyCode.CursorUp | KeyCode.CtrlMask, Command.LineUpToFirstBranch); + KeyBindings.Add (Key.CursorUp, Command.LineUp); + KeyBindings.Add (Key.CursorUp.WithShift, Command.LineUpExtend); + KeyBindings.Add (Key.CursorUp.WithCtrl, Command.LineUpToFirstBranch); - KeyBindings.Add (KeyCode.CursorDown, Command.LineDown); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.ShiftMask, Command.LineDownExtend); - KeyBindings.Add (KeyCode.CursorDown | KeyCode.CtrlMask, Command.LineDownToLastBranch); + KeyBindings.Add (Key.CursorDown, Command.LineDown); + KeyBindings.Add (Key.CursorDown.WithShift, Command.LineDownExtend); + KeyBindings.Add (Key.CursorDown.WithCtrl, Command.LineDownToLastBranch); - KeyBindings.Add (KeyCode.Home, Command.TopHome); - KeyBindings.Add (KeyCode.End, Command.BottomEnd); - KeyBindings.Add (KeyCode.A | KeyCode.CtrlMask, Command.SelectAll); - KeyBindings.Add (ObjectActivationKey, Command.Accept); + KeyBindings.Add (Key.Home, Command.TopHome); + KeyBindings.Add (Key.End, Command.BottomEnd); + KeyBindings.Add (Key.A.WithCtrl, Command.SelectAll); + KeyBindings.Add (ObjectActivationKey, Command.Select); } /// @@ -459,15 +452,25 @@ public class TreeView : View, ITreeView where T : class /// Triggers the event with the . /// This method also ensures that the selected object is visible. /// - public void ActivateSelectedObjectIfAny () + /// if was fired. + public bool? ActivateSelectedObjectIfAny () { + if (OnAccept () == true) + { + return false; + } + T o = SelectedObject; if (o is { }) { - OnObjectActivated (new ObjectActivatedEventArgs (this, o)); + // TODO: Should this be cancelable? + ObjectActivatedEventArgs e = new (this, o); + OnObjectActivated (e); PositionCursor (); + return true; } + return false; } /// Adds a new root level object unless it is already a root of the tree. diff --git a/Terminal.Gui/Views/Wizard/Wizard.cs b/Terminal.Gui/Views/Wizard/Wizard.cs index ba5bb8937..a21744607 100644 --- a/Terminal.Gui/Views/Wizard/Wizard.cs +++ b/Terminal.Gui/Views/Wizard/Wizard.cs @@ -100,8 +100,8 @@ public class Wizard : Dialog NextFinishButton.IsDefault = true; AddButton (NextFinishButton); - BackButton.Clicked += BackBtn_Clicked; - NextFinishButton.Clicked += NextfinishBtn_Clicked; + BackButton.Accept += BackBtn_Clicked; + NextFinishButton.Accept += NextfinishBtn_Clicked; Loaded += Wizard_Loaded; Closing += Wizard_Closing; @@ -110,7 +110,7 @@ public class Wizard : Dialog if (Modal) { KeyBindings.Clear (Command.QuitToplevel); - KeyBindings.Add (KeyCode.Esc, Command.QuitToplevel); + KeyBindings.Add (Key.Esc, Command.QuitToplevel); } SetNeedsLayout (); @@ -408,17 +408,15 @@ public class Wizard : Dialog /// to instead fire the event when Wizard is being used as a /// non-modal (see . /// - /// + /// /// - public override bool OnProcessKeyDown (Key a) + public override bool OnProcessKeyDown (Key key) { //// BUGBUG: Why is this not handled by a key binding??? if (!Modal) { - switch (a.KeyCode) + if (key == Key.Esc) { - // BUGBUG: This should be handled by Dialog - case KeyCode.Esc: var args = new WizardButtonEventArgs (); Cancelled?.Invoke (this, args); @@ -582,11 +580,11 @@ public class Wizard : Dialog // gets the first step if CurrentStep == null } - private void Wizard_TitleChanged (object sender, TitleEventArgs e) + private void Wizard_TitleChanged (object sender, StateEventArgs e) { if (string.IsNullOrEmpty (_wizardTitle)) { - _wizardTitle = e.NewTitle; + _wizardTitle = e.NewValue; } } } diff --git a/UICatalog/KeyBindingsDialog.cs b/UICatalog/KeyBindingsDialog.cs index 8a5947cf6..ab6c3e534 100644 --- a/UICatalog/KeyBindingsDialog.cs +++ b/UICatalog/KeyBindingsDialog.cs @@ -43,11 +43,11 @@ internal class KeyBindingsDialog : Dialog var btnChange = new Button { X = Pos.Percent (50), Y = 1, Text = "Ch_ange" }; Add (btnChange); - btnChange.Clicked += RemapKey; + btnChange.Accept += RemapKey; var close = new Button { Text = "Ok" }; - close.Clicked += (s, e) => + close.Accept += (s, e) => { Application.RequestStop (); ViewTracker.Instance.StartUsingNewKeyMap (CurrentBindings); @@ -55,7 +55,7 @@ internal class KeyBindingsDialog : Dialog AddButton (close); var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => Application.RequestStop (); + cancel.Accept += (s, e) => Application.RequestStop (); AddButton (cancel); // Register event handler as the last thing in constructor to prevent early calls diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index c7bb08845..555558557 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -143,7 +143,7 @@ public class ASCIICustomButtonTest : Scenario SetNeedsDisplay (); } - OnClicked (); + OnAccept (); return true; } @@ -224,7 +224,7 @@ public class ASCIICustomButtonTest : Scenario Height = BUTTON_HEIGHT }; button.CustomInitialize (); - button.Clicked += Button_Clicked; + button.Accept += Button_Clicked; button.PointerEnter += Button_PointerEnter; button.MouseClick += Button_MouseClick; button.KeyDown += Button_KeyPress; @@ -243,7 +243,7 @@ public class ASCIICustomButtonTest : Scenario Height = BUTTON_HEIGHT }; closeButton.CustomInitialize (); - closeButton.Clicked += Button_Clicked; + closeButton.Accept += Button_Clicked; closeButton.PointerEnter += Button_PointerEnter; closeButton.MouseClick += Button_MouseClick; closeButton.KeyDown += Button_KeyPress; diff --git a/UICatalog/Scenarios/Adornments.cs b/UICatalog/Scenarios/Adornments.cs index 78e2c1efc..0b9e5c885 100644 --- a/UICatalog/Scenarios/Adornments.cs +++ b/UICatalog/Scenarios/Adornments.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Terminal.Gui; @@ -17,7 +18,7 @@ public class Adornments : Scenario ConfigurationManager.Apply (); Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme]; - var view = new Window { Title = "The Window" }; + var view = new Window { Title = "The _Window" }; var tf1 = new TextField { Width = 10, Text = "TextField" }; var color = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd (11) }; color.BorderStyle = LineStyle.RoundedDotted; @@ -35,7 +36,7 @@ public class Adornments : Scenario var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" }; - button.Clicked += (s, e) => + button.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", $"Am I a {view.GetType ().Name}?", "Yes", "No"); var label = new TextView @@ -97,7 +98,7 @@ public class Adornments : Scenario { private readonly ColorPicker _backgroundColorPicker = new () { - Title = "BG", + Title = "_BG", BoxWidth = 1, BoxHeight = 1, BorderStyle = LineStyle.Single, @@ -106,7 +107,7 @@ public class Adornments : Scenario private readonly ColorPicker _foregroundColorPicker = new () { - Title = "FG", + Title = "_FG", BoxWidth = 1, BoxHeight = 1, BorderStyle = LineStyle.Single, @@ -187,37 +188,41 @@ public class Adornments : Scenario var editWidth = 3; _topEdit = new TextField { X = Pos.Center (), Y = 0, Width = editWidth }; - _topEdit.TextChanging += Edit_TextChanging; + + _topEdit.Accept += Edit_Accept; Add (_topEdit); _leftEdit = new TextField { X = Pos.Left (_topEdit) - editWidth, Y = Pos.Bottom (_topEdit), Width = editWidth }; - _leftEdit.TextChanging += Edit_TextChanging; + + _leftEdit.Accept += Edit_Accept; Add (_leftEdit); _rightEdit = new TextField { X = Pos.Right (_topEdit), Y = Pos.Bottom (_topEdit), Width = editWidth }; - _rightEdit.TextChanging += Edit_TextChanging; + + _rightEdit.Accept += Edit_Accept; Add (_rightEdit); _bottomEdit = new TextField { X = Pos.Center (), Y = Pos.Bottom (_leftEdit), Width = editWidth }; - _bottomEdit.TextChanging += Edit_TextChanging; + + _bottomEdit.Accept += Edit_Accept; Add (_bottomEdit); var copyTop = new Button { X = Pos.Center () + 1, Y = Pos.Bottom (_bottomEdit), Text = "Cop_y Top" }; - copyTop.Clicked += (s, e) => - { - Thickness = new Thickness (Thickness.Top); + copyTop.Accept += (s, e) => + { + Thickness = new Thickness (Thickness.Top); - if (string.IsNullOrEmpty (_topEdit.Text)) - { - _topEdit.Text = "0"; - } + if (string.IsNullOrEmpty (_topEdit.Text)) + { + _topEdit.Text = "0"; + } - _bottomEdit.Text = _leftEdit.Text = _rightEdit.Text = _topEdit.Text; - }; + _bottomEdit.Text = _leftEdit.Text = _rightEdit.Text = _topEdit.Text; + }; Add (copyTop); // Foreground ColorPicker. @@ -258,67 +263,17 @@ public class Adornments : Scenario LayoutSubviews (); Height = GetAdornmentsThickness ().Vertical + 4 + 4; Width = GetAdornmentsThickness ().Horizontal + _foregroundColorPicker.Frame.Width * 2 - 3; + + } - private void Edit_TextChanging (object sender, TextChangingEventArgs e) + private void Edit_Accept (object sender, CancelEventArgs e) { - try - { - if (string.IsNullOrEmpty (e.NewText)) - { - e.Cancel = true; - ((TextField)sender).Text = "0"; - - return; - } - - switch (sender.ToString ()) - { - case var s when s == _topEdit.ToString (): - Thickness = new Thickness ( - Thickness.Left, - int.Parse (e.NewText), - Thickness.Right, - Thickness.Bottom - ); - - break; - case var s when s == _leftEdit.ToString (): - Thickness = new Thickness ( - int.Parse (e.NewText), - Thickness.Top, - Thickness.Right, - Thickness.Bottom - ); - - break; - case var s when s == _rightEdit.ToString (): - Thickness = new Thickness ( - Thickness.Left, - Thickness.Top, - int.Parse (e.NewText), - Thickness.Bottom - ); - - break; - case var s when s == _bottomEdit.ToString (): - Thickness = new Thickness ( - Thickness.Left, - Thickness.Top, - Thickness.Right, - int.Parse (e.NewText) - ); - - break; - } - } - catch - { - if (!string.IsNullOrEmpty (e.NewText)) - { - e.Cancel = true; - } - } + e.Cancel = true; + Thickness = new Thickness(int.Parse(_leftEdit.Text), + int.Parse(_topEdit.Text), + int.Parse (_rightEdit.Text), + int.Parse (_bottomEdit.Text)); } } @@ -343,7 +298,7 @@ public class Adornments : Scenario { X = 0, Y = 0, - Title = "Margin", + Title = "_Margin", Thickness = _viewToEdit.Margin.Thickness, Color = new Attribute (_viewToEdit.Margin.ColorScheme.Normal), SuperViewRendersLineCanvas = true @@ -356,7 +311,7 @@ public class Adornments : Scenario { X = Pos.Left (_marginEditor), Y = Pos.Bottom (_marginEditor), - Title = "Border", + Title = "B_order", Thickness = _viewToEdit.Border.Thickness, Color = new Attribute (_viewToEdit.Border.ColorScheme.Normal), SuperViewRendersLineCanvas = true @@ -373,7 +328,7 @@ public class Adornments : Scenario Y = Pos.Top (_borderEditor), SelectedItem = (int)_viewToEdit.Border.LineStyle, BorderStyle = LineStyle.Double, - Title = "Border Style", + Title = "Border St_yle", SuperViewRendersLineCanvas = true, RadioLabels = borderStyleEnum.Select ( e => e.ToString () @@ -435,7 +390,7 @@ public class Adornments : Scenario { X = Pos.Left (_borderEditor), Y = Pos.Bottom (rbBorderStyle), - Title = "Padding", + Title = "_Padding", Thickness = _viewToEdit.Padding.Thickness, Color = new Attribute (_viewToEdit.Padding.ColorScheme.Normal), SuperViewRendersLineCanvas = true diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 1715cbdec..03738a90b 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -291,7 +291,7 @@ public class AllViewsTester : Scenario _curView = CreateClass (_viewClasses.First ().Value); } - // TODO: Add Command.Default handler (pop a message box?) + // TODO: Add Command.HotKey handler (pop a message box?) private View CreateClass (Type type) { // If we are to create a generic Type diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index c70fb8547..9445c226f 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -263,7 +263,7 @@ public class BackgroundWorkerCollection : Scenario _start = new Button { Text = "Start", IsDefault = true, ClearOnVisibleFalse = false }; - _start.Clicked += (s, e) => + _start.Accept += (s, e) => { Staging = new Staging (DateTime.Now); RequestStop (); @@ -271,7 +271,7 @@ public class BackgroundWorkerCollection : Scenario Add (_start); _close = new Button { Text = "Close" }; - _close.Clicked += OnReportClosed; + _close.Accept += OnReportClosed; Add (_close); KeyDown += (s, e) => diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 237d9570a..121e123bb 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -22,12 +22,12 @@ public class Buttons : Scenario // This is the default button (IsDefault = true); if user presses ENTER in the TextField // the scenario will quit var defaultButton = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (1), IsDefault = true, Text = "_Quit" }; - defaultButton.Clicked += (s, e) => Application.RequestStop (); + defaultButton.Accept += (s, e) => Application.RequestStop (); Win.Add (defaultButton); var swapButton = new Button { X = 50, Text = "S_wap Default (Absolute Layout)" }; - swapButton.Clicked += (s, e) => + swapButton.Accept += (s, e) => { defaultButton.IsDefault = !defaultButton.IsDefault; swapButton.IsDefault = !swapButton.IsDefault; @@ -36,7 +36,7 @@ public class Buttons : Scenario static void DoMessage (Button button, string txt) { - button.Clicked += (s, e) => + button.Accept += (s, e) => { string btnText = button.Text; MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); @@ -87,11 +87,11 @@ public class Buttons : Scenario Win.Add ( button = new Button { X = 2, Y = Pos.Bottom (button) + 1, Text = "a Newline\nin the button" } ); - button.Clicked += (s, e) => MessageBox.Query ("Message", "Question?", "Yes", "No"); + button.Accept += (s, e) => MessageBox.Query ("Message", "Question?", "Yes", "No"); var textChanger = new Button { X = 2, Y = Pos.Bottom (button) + 1, Text = "Te_xt Changer" }; Win.Add (textChanger); - textChanger.Clicked += (s, e) => textChanger.Text += "!"; + textChanger.Accept += (s, e) => textChanger.Text += "!"; Win.Add ( button = new Button @@ -109,7 +109,7 @@ public class Buttons : Scenario Win.Add (removeButton); // This in interesting test case because `moveBtn` and below are laid out relative to this one! - removeButton.Clicked += (s, e) => + removeButton.Accept += (s, e) => { // Now this throw a InvalidOperationException on the TopologicalSort method as is expected. //Win.Remove (removeButton); @@ -139,7 +139,7 @@ public class Buttons : Scenario Text = "Move This \u263b Button v_ia Pos" }; - moveBtn.Clicked += (s, e) => + moveBtn.Accept += (s, e) => { moveBtn.X = moveBtn.Frame.X + 5; @@ -160,7 +160,7 @@ public class Buttons : Scenario Text = "Size This \u263a Button _via Pos" }; - sizeBtn.Clicked += (s, e) => + sizeBtn.Accept += (s, e) => { sizeBtn.Width = sizeBtn.Frame.Width + 5; @@ -181,7 +181,7 @@ public class Buttons : Scenario // Demonstrates how changing the View.Frame property can move Views var moveBtnA = new Button { ColorScheme = Colors.ColorSchemes ["Error"], Text = "Move This Button via Frame" }; - moveBtnA.Clicked += (s, e) => + moveBtnA.Accept += (s, e) => { moveBtnA.Frame = new Rect ( moveBtnA.Frame.X + 5, @@ -198,7 +198,7 @@ public class Buttons : Scenario Y = 2, ColorScheme = Colors.ColorSchemes ["Error"], Text = " ~  s  gui.cs   master ↑_10 = Сохранить" }; - sizeBtnA.Clicked += (s, e) => + sizeBtnA.Accept += (s, e) => { sizeBtnA.Frame = new Rect ( sizeBtnA.Frame.X, @@ -268,7 +268,7 @@ public class Buttons : Scenario ColorScheme = Colors.ColorSchemes ["TopLevel"], Text = mhkb }; - moveHotKeyBtn.Clicked += (s, e) => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; + moveHotKeyBtn.Accept += (s, e) => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; Win.Add (moveHotKeyBtn); var muhkb = " ~  s  gui.cs   master ↑10 = Сохранить"; @@ -283,7 +283,7 @@ public class Buttons : Scenario ColorScheme = Colors.ColorSchemes ["TopLevel"], Text = muhkb }; - moveUnicodeHotKeyBtn.Clicked += (s, e) => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; + moveUnicodeHotKeyBtn.Accept += (s, e) => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; Win.Add (moveUnicodeHotKeyBtn); radioGroup.SelectedItemChanged += (s, args) => diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index b0f955e26..56f3f713c 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -3,6 +3,7 @@ //#define BASE_DRAW_CONTENT using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Linq; using System.Net.Http; @@ -64,8 +65,18 @@ public class CharacterMap : Scenario }; Application.Top.Add (_errorLabel); +#if TEXT_CHANGED_TO_JUMP jumpEdit.TextChanged += JumpEdit_TextChanged; +#else + jumpEdit.Accept += JumpEditOnAccept; + void JumpEditOnAccept (object sender, CancelEventArgs e) + { + JumpEdit_TextChanged (sender, new StateEventArgs (jumpEdit.Text, jumpEdit.Text)); + // Cancel the event to prevent ENTER from being handled elsewhere + e.Cancel = true; + } +#endif _categoryList = new TableView { X = Pos.Right (_charMap), Y = Pos.Bottom (jumpLabel), Height = Dim.Fill () }; _categoryList.FullRowSelect = true; @@ -212,7 +223,7 @@ public class CharacterMap : Scenario return item; } - private void JumpEdit_TextChanged (object sender, TextChangedEventArgs e) + private void JumpEdit_TextChanged (object sender, StateEventArgs e) { var jumpEdit = sender as TextField; @@ -941,18 +952,18 @@ internal class CharMap : ScrollView var dlg = new Dialog { Title = title, Buttons = [copyGlyph, copyCP, cancel] }; - copyGlyph.Clicked += (s, a) => + copyGlyph.Accept += (s, a) => { CopyGlyph (); dlg.RequestStop (); }; - copyCP.Clicked += (s, a) => + copyCP.Accept += (s, a) => { CopyCodePoint (); dlg.RequestStop (); }; - cancel.Clicked += (s, a) => dlg.RequestStop (); + cancel.Accept += (s, a) => dlg.RequestStop (); var rune = (Rune)SelectedCodePoint; var label = new Label { Text = "IsAscii: ", X = 0, Y = 0 }; diff --git a/UICatalog/Scenarios/ChineseUI.cs b/UICatalog/Scenarios/ChineseUI.cs index 124b8cb2d..c59f85c14 100644 --- a/UICatalog/Scenarios/ChineseUI.cs +++ b/UICatalog/Scenarios/ChineseUI.cs @@ -33,7 +33,7 @@ public class ChineseUI : Scenario var btn = new Button { X = 1, Y = 1, Text = "你" }; // v1: A - btn.Clicked += (s, e) => + btn.Accept += (s, e) => { int result = MessageBox.Query ( "Confirm", diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 4f0c88155..e13eceeb6 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -67,7 +67,7 @@ public class Clipping : Scenario }; var testButton = new Button { X = 2, Y = 2, Text = "click me" }; - testButton.Clicked += (s, e) => { MessageBox.Query (10, 5, "Test", "test message", "Ok"); }; + testButton.Accept += (s, e) => { MessageBox.Query (10, 5, "Test", "test message", "Ok"); }; embedded3.Add (testButton); embedded2.Add (embedded3); diff --git a/UICatalog/Scenarios/ComboBoxIteration.cs b/UICatalog/Scenarios/ComboBoxIteration.cs index 9b22b4f21..b7c387ae4 100644 --- a/UICatalog/Scenarios/ComboBoxIteration.cs +++ b/UICatalog/Scenarios/ComboBoxIteration.cs @@ -58,7 +58,7 @@ public class ComboBoxIteration : Scenario var btnTwo = new Button { X = Pos.Right (comboBox) + 1, Text = "Two" }; - btnTwo.Clicked += (s, e) => + btnTwo.Accept += (s, e) => { items = new List { "one", "two" }; comboBox.SetSource (items); @@ -69,7 +69,7 @@ public class ComboBoxIteration : Scenario var btnThree = new Button { X = Pos.Right (comboBox) + 1, Y = Pos.Top (comboBox), Text = "Three" }; - btnThree.Clicked += (s, e) => + btnThree.Accept += (s, e) => { items = new List { "one", "two", "three" }; comboBox.SetSource (items); diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index 859e7c8fc..f15fc7726 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -318,7 +318,7 @@ public class ComputedLayout : Scenario var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd () - 1 }; anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); - anchorButton.Clicked += (s, e) => + anchorButton.Accept += (s, e) => { // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer @@ -364,7 +364,7 @@ public class ComputedLayout : Scenario Text = "Left", Y = Pos.AnchorEnd () - 1 // Pos.Combine }; - leftButton.Clicked += (s, e) => + leftButton.Accept += (s, e) => { // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer @@ -380,7 +380,7 @@ public class ComputedLayout : Scenario Text = "Center", X = Pos.Center (), Y = Pos.AnchorEnd (1) // Pos.AnchorEnd(1) }; - centerButton.Clicked += (s, e) => + centerButton.Accept += (s, e) => { // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer @@ -393,7 +393,7 @@ public class ComputedLayout : Scenario // show positioning vertically using another window and Pos.Bottom var rightButton = new Button { Text = "Right", Y = Pos.Y (centerButton) }; - rightButton.Clicked += (s, e) => + rightButton.Accept += (s, e) => { // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index bc743f39c..400e133f5 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -21,7 +21,7 @@ public class ContextMenus : Scenario { var text = "Context Menu"; var width = 20; - KeyCode winContextMenuKey = KeyCode.Space | KeyCode.CtrlMask; + KeyCode winContextMenuKey = (KeyCode)Key.Space.WithCtrl; var label = new Label { diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 36a7cf121..6adb9d20a 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -299,13 +299,13 @@ public class CsvEditor : Scenario var ok = new Button { Text = "Ok", IsDefault = true }; - ok.Clicked += (s, e) => + ok.Accept += (s, e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => { Application.RequestStop (); }; + cancel.Accept += (s, e) => { Application.RequestStop (); }; var d = new Dialog { Title = title, Buttons = [ok, cancel] }; var lbl = new Label { X = 0, Y = 1, Text = label }; @@ -556,7 +556,7 @@ public class CsvEditor : Scenario } } - private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs e) + private void SelectedCellLabel_TextChanged (object sender, StateEventArgs e) { // if user is in the text control and editing the selected cell if (!_selectedCellLabel.HasFocus) diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index de1d6811e..91db58805 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -14,12 +14,27 @@ public class Dialogs : Scenario { var frame = new FrameView { X = Pos.Center (), Y = 1, Width = Dim.Percent (75), Title = "Dialog Options" }; - var label = new Label { X = 0, Y = 0, TextAlignment = TextAlignment.Right, Text = "Width:" }; + var numButtonsLabel = new Label + { + X = 0, + TextAlignment = TextAlignment.Right, + Text = "_Number of Buttons:" + }; + + var label = new Label { + X = 0, + Y = 0, + AutoSize = false, + Width = Dim.Width (numButtonsLabel), + Height = 1, + TextAlignment = TextAlignment.Right, + Text = "_Width:" + }; frame.Add (label); var widthEdit = new TextField { - X = Pos.Right (label) + 1, + X = Pos.Right (numButtonsLabel) + 1, Y = Pos.Top (label), Width = 5, Height = 1, @@ -32,16 +47,16 @@ public class Dialogs : Scenario AutoSize = false, X = 0, Y = Pos.Bottom (label), - Width = Dim.Width (label), + Width = Dim.Width (numButtonsLabel), Height = 1, TextAlignment = TextAlignment.Right, - Text = "Height:" + Text = "_Height:" }; frame.Add (label); var heightEdit = new TextField { - X = Pos.Right (label) + 1, + X = Pos.Right (numButtonsLabel) + 1, Y = Pos.Top (label), Width = 5, Height = 1, @@ -67,10 +82,10 @@ public class Dialogs : Scenario AutoSize = false, X = 0, Y = Pos.Bottom (label), - Width = Dim.Width (label), + Width = Dim.Width (numButtonsLabel), Height = 1, TextAlignment = TextAlignment.Right, - Text = "Title:" + Text = "_Title:" }; frame.Add (label); @@ -84,22 +99,13 @@ public class Dialogs : Scenario }; frame.Add (titleEdit); - label = new Label - { - AutoSize = false, - X = 0, - Y = Pos.Bottom (label), - Width = Dim.Width (label), - Height = 1, - TextAlignment = TextAlignment.Right, - Text = "Num Buttons:" - }; - frame.Add (label); + numButtonsLabel.Y = Pos.Bottom (label); + frame.Add (numButtonsLabel); var numButtonsEdit = new TextField { - X = Pos.Right (label) + 1, - Y = Pos.Top (label), + X = Pos.Right (numButtonsLabel) + 1, + Y = Pos.Top (numButtonsLabel), Width = 5, Height = 1, Text = "3" @@ -108,21 +114,25 @@ public class Dialogs : Scenario var glyphsNotWords = new CheckBox { - X = Pos.Left (numButtonsEdit), - Y = Pos.Bottom (label), + X = Pos.Right (numButtonsLabel) + 1, + Y = Pos.Bottom (numButtonsLabel), TextAlignment = TextAlignment.Right, - Text = - $"Add {char.ConvertFromUtf32 (CODE_POINT)} to button text to stress wide char support", + Text = $"_Add {char.ConvertFromUtf32 (CODE_POINT)} to button text to stress wide char support", Checked = false }; frame.Add (glyphsNotWords); label = new Label { - X = 0, Y = Pos.Bottom (glyphsNotWords), TextAlignment = TextAlignment.Right, Text = "Button Style:" + AutoSize = false, + X = 0, + Y = Pos.Bottom (glyphsNotWords), + Width = Dim.Width (numButtonsLabel), + Height = 1, + TextAlignment = TextAlignment.Right, + Text = "Button St_yle:" }; frame.Add (label); - var styleRadioGroup = new RadioGroup { X = Pos.Right (label) + 1, @@ -170,7 +180,7 @@ public class Dialogs : Scenario X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, Text = "_Show Dialog" }; - showDialogButton.Clicked += (s, e) => + showDialogButton.Accept += (s, e) => { Dialog dlg = CreateDemoDialog ( widthEdit, @@ -233,7 +243,7 @@ public class Dialogs : Scenario button = new Button { Text = NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; } - button.Clicked += (s, e) => + button.Accept += (s, e) => { clicked = buttonId; Application.RequestStop (); @@ -264,9 +274,9 @@ public class Dialogs : Scenario dialog.Width = width; } - var add = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Add a button" }; + var add = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "_Add a button" }; - add.Clicked += (s, e) => + add.Accept += (s, e) => { int buttonId = buttons.Count; Button button; @@ -284,7 +294,7 @@ public class Dialogs : Scenario button = new Button { Text = NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; } - button.Clicked += (s, e) => + button.Accept += (s, e) => { clicked = buttonId; Application.RequestStop (); @@ -303,10 +313,10 @@ public class Dialogs : Scenario { X = Pos.Center (), Y = Pos.Center () + 1, - Text = $"Add a {char.ConvertFromUtf32 (CODE_POINT)} to each button" + Text = $"A_dd a {char.ConvertFromUtf32 (CODE_POINT)} to each button" }; - addChar.Clicked += (s, e) => + addChar.Accept += (s, e) => { foreach (Button button in buttons) { diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 05061c577..84a453532 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/UICatalog/Scenarios/DynamicMenuBar.cs @@ -237,7 +237,7 @@ public class DynamicMenuBar : Scenario { X = Pos.X (_lblShortcut), Y = Pos.Bottom (TextShortcut) + 1, Text = "Clear Shortcut" }; - _btnShortcut.Clicked += (s, e) => { TextShortcut.Text = ""; }; + _btnShortcut.Accept += (s, e) => { TextShortcut.Text = ""; }; Add (_btnShortcut); CkbIsTopLevel.Toggled += (s, e) => @@ -419,7 +419,7 @@ public class DynamicMenuBar : Scenario var _btnOk = new Button { IsDefault = true, Text = "Ok" }; - _btnOk.Clicked += (s, e) => + _btnOk.Accept += (s, e) => { if (string.IsNullOrEmpty (TextTitle.Text)) { @@ -433,7 +433,7 @@ public class DynamicMenuBar : Scenario }; var _btnCancel = new Button { Text = "Cancel" }; - _btnCancel.Clicked += (s, e) => + _btnCancel.Accept += (s, e) => { TextTitle.Text = string.Empty; Application.RequestStop (); @@ -684,7 +684,7 @@ public class DynamicMenuBar : Scenario }; Add (_frmMenuDetails); - _btnMenuBarUp.Clicked += (s, e) => + _btnMenuBarUp.Accept += (s, e) => { int i = _currentSelectedMenuBar; @@ -706,7 +706,7 @@ public class DynamicMenuBar : Scenario } }; - _btnMenuBarDown.Clicked += (s, e) => + _btnMenuBarDown.Accept += (s, e) => { int i = _currentSelectedMenuBar; @@ -728,7 +728,7 @@ public class DynamicMenuBar : Scenario } }; - _btnUp.Clicked += (s, e) => + _btnUp.Accept += (s, e) => { int i = _lstMenus.SelectedItem; MenuItem menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null; @@ -750,7 +750,7 @@ public class DynamicMenuBar : Scenario } }; - _btnDown.Clicked += (s, e) => + _btnDown.Accept += (s, e) => { int i = _lstMenus.SelectedItem; MenuItem menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null; @@ -772,7 +772,7 @@ public class DynamicMenuBar : Scenario } }; - _btnPreviowsParent.Clicked += (s, e) => + _btnPreviowsParent.Accept += (s, e) => { if (_currentMenuBarItem != null && _currentMenuBarItem.Parent != null) { @@ -805,12 +805,12 @@ public class DynamicMenuBar : Scenario Add (_btnOk); var _btnCancel = new Button { X = Pos.Right (_btnOk) + 3, Y = Pos.Top (_btnOk), Text = "Cancel" }; - _btnCancel.Clicked += (s, e) => { SetFrameDetails (_currentEditMenuBarItem); }; + _btnCancel.Accept += (s, e) => { SetFrameDetails (_currentEditMenuBarItem); }; Add (_btnCancel); _lstMenus.SelectedItemChanged += (s, e) => { SetFrameDetails (); }; - _btnOk.Clicked += (s, e) => + _btnOk.Accept += (s, e) => { if (string.IsNullOrEmpty (_frmMenuDetails.TextTitle.Text) && _currentEditMenuBarItem != null) { @@ -836,7 +836,7 @@ public class DynamicMenuBar : Scenario } }; - _btnAdd.Clicked += (s, e) => + _btnAdd.Accept += (s, e) => { if (MenuBar == null) { @@ -897,7 +897,7 @@ public class DynamicMenuBar : Scenario } }; - _btnRemove.Clicked += (s, e) => + _btnRemove.Accept += (s, e) => { MenuItem menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem @@ -989,7 +989,7 @@ public class DynamicMenuBar : Scenario SetFrameDetails (menuBarItem); }; - _btnNext.Clicked += (s, e) => + _btnNext.Accept += (s, e) => { if (_menuBar != null && _currentSelectedMenuBar + 1 < _menuBar.Menus.Length) { @@ -999,7 +999,7 @@ public class DynamicMenuBar : Scenario SelectCurrentMenuBarItem (); }; - _btnPrevious.Clicked += (s, e) => + _btnPrevious.Accept += (s, e) => { if (_currentSelectedMenuBar - 1 > -1) { @@ -1018,7 +1018,7 @@ public class DynamicMenuBar : Scenario } }; - _btnAddMenuBar.Clicked += (s, e) => + _btnAddMenuBar.Accept += (s, e) => { var frameDetails = new DynamicMenuBarDetails (null); DynamicMenuItem item = frameDetails.EnterMenuItem (); @@ -1050,7 +1050,7 @@ public class DynamicMenuBar : Scenario _menuBar.SetNeedsDisplay (); }; - _btnRemoveMenuBar.Clicked += (s, e) => + _btnRemoveMenuBar.Accept += (s, e) => { if (_menuBar == null || _menuBar.Menus.Length == 0) { diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index 370d1e2a0..a37c94d67 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/UICatalog/Scenarios/DynamicStatusBar.cs @@ -203,7 +203,7 @@ public class DynamicStatusBar : Scenario { X = Pos.X (_lblShortcut), Y = Pos.Bottom (TextShortcut) + 1, Text = "Clear Shortcut" }; - _btnShortcut.Clicked += (s, e) => { TextShortcut.Text = ""; }; + _btnShortcut.Accept += (s, e) => { TextShortcut.Text = ""; }; Add (_btnShortcut); } @@ -255,7 +255,7 @@ public class DynamicStatusBar : Scenario var _btnOk = new Button { IsDefault = true, Text = "OK" }; - _btnOk.Clicked += (s, e) => + _btnOk.Accept += (s, e) => { if (string.IsNullOrEmpty (TextTitle.Text)) { @@ -277,7 +277,7 @@ public class DynamicStatusBar : Scenario }; var _btnCancel = new Button { Text = "Cancel" }; - _btnCancel.Clicked += (s, e) => + _btnCancel.Accept += (s, e) => { TextTitle.Text = string.Empty; Application.RequestStop (); @@ -406,7 +406,7 @@ public class DynamicStatusBar : Scenario }; Add (_frmStatusBarDetails); - _btnUp.Clicked += (s, e) => + _btnUp.Accept += (s, e) => { int i = _lstItems.SelectedItem; StatusItem statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null; @@ -429,7 +429,7 @@ public class DynamicStatusBar : Scenario } }; - _btnDown.Clicked += (s, e) => + _btnDown.Accept += (s, e) => { int i = _lstItems.SelectedItem; StatusItem statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null; @@ -459,12 +459,12 @@ public class DynamicStatusBar : Scenario Add (_btnOk); var _btnCancel = new Button { X = Pos.Right (_btnOk) + 3, Y = Pos.Top (_btnOk), Text = "Cancel" }; - _btnCancel.Clicked += (s, e) => { SetFrameDetails (_currentEditStatusItem); }; + _btnCancel.Accept += (s, e) => { SetFrameDetails (_currentEditStatusItem); }; Add (_btnCancel); _lstItems.SelectedItemChanged += (s, e) => { SetFrameDetails (); }; - _btnOk.Clicked += (s, e) => + _btnOk.Accept += (s, e) => { if (string.IsNullOrEmpty (_frmStatusBarDetails.TextTitle.Text) && _currentEditStatusItem != null) { @@ -487,7 +487,7 @@ public class DynamicStatusBar : Scenario } }; - _btnAdd.Clicked += (s, e) => + _btnAdd.Accept += (s, e) => { if (StatusBar == null) { @@ -517,7 +517,7 @@ public class DynamicStatusBar : Scenario SetFrameDetails (); }; - _btnRemove.Clicked += (s, e) => + _btnRemove.Accept += (s, e) => { StatusItem statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem @@ -546,7 +546,7 @@ public class DynamicStatusBar : Scenario SetFrameDetails (statusItem); }; - _btnAddStatusBar.Clicked += (s, e) => + _btnAddStatusBar.Accept += (s, e) => { if (_statusBar != null) { @@ -557,7 +557,7 @@ public class DynamicStatusBar : Scenario Add (_statusBar); }; - _btnRemoveStatusBar.Clicked += (s, e) => + _btnRemoveStatusBar.Accept += (s, e) => { if (_statusBar == null) { diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 91251a13e..01cbb7c87 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -907,7 +907,7 @@ public class Editor : Scenario AutoSize = false, Text = "Find _Next" }; - btnFindNext.Clicked += (s, e) => FindNext (); + btnFindNext.Accept += (s, e) => FindNext (); d.Add (btnFindNext); var btnFindPrevious = new Button @@ -920,7 +920,7 @@ public class Editor : Scenario AutoSize = false, Text = "Find _Previous" }; - btnFindPrevious.Clicked += (s, e) => FindPrevious (); + btnFindPrevious.Accept += (s, e) => FindPrevious (); d.Add (btnFindPrevious); txtToFind.TextChanged += (s, e) => @@ -940,7 +940,7 @@ public class Editor : Scenario AutoSize = false, Text = "Cancel" }; - btnCancel.Clicked += (s, e) => { DisposeWinDialog (); }; + btnCancel.Accept += (s, e) => { DisposeWinDialog (); }; d.Add (btnCancel); var ckbMatchCase = new CheckBox @@ -1157,7 +1157,7 @@ public class Editor : Scenario AutoSize = false, Text = "Replace _Next" }; - btnFindNext.Clicked += (s, e) => ReplaceNext (); + btnFindNext.Accept += (s, e) => ReplaceNext (); d.Add (btnFindNext); label = new Label { X = Pos.Left (label), Y = Pos.Top (label) + 1, Text = "Replace:" }; @@ -1182,7 +1182,7 @@ public class Editor : Scenario AutoSize = false, Text = "Replace _Previous" }; - btnFindPrevious.Clicked += (s, e) => ReplacePrevious (); + btnFindPrevious.Accept += (s, e) => ReplacePrevious (); d.Add (btnFindPrevious); var btnReplaceAll = new Button @@ -1195,7 +1195,7 @@ public class Editor : Scenario AutoSize = false, Text = "Replace _All" }; - btnReplaceAll.Clicked += (s, e) => ReplaceAll (); + btnReplaceAll.Accept += (s, e) => ReplaceAll (); d.Add (btnReplaceAll); txtToFind.TextChanged += (s, e) => @@ -1216,7 +1216,7 @@ public class Editor : Scenario AutoSize = false, Text = "Cancel" }; - btnCancel.Clicked += (s, e) => { DisposeWinDialog (); }; + btnCancel.Accept += (s, e) => { DisposeWinDialog (); }; d.Add (btnCancel); var ckbMatchCase = new CheckBox diff --git a/UICatalog/Scenarios/FileDialogExamples.cs b/UICatalog/Scenarios/FileDialogExamples.cs index 57151bc60..3a5f26963 100644 --- a/UICatalog/Scenarios/FileDialogExamples.cs +++ b/UICatalog/Scenarios/FileDialogExamples.cs @@ -232,7 +232,7 @@ public class FileDialogExamples : Scenario private void SetupHandler (Button btn) { - btn.Clicked += (s, e) => + btn.Accept += (s, e) => { try { diff --git a/UICatalog/Scenarios/HotKeys.cs b/UICatalog/Scenarios/HotKeys.cs new file mode 100644 index 000000000..1b4a24869 --- /dev/null +++ b/UICatalog/Scenarios/HotKeys.cs @@ -0,0 +1,138 @@ +using Terminal.Gui; + +namespace UICatalog.Scenarios; + +[ScenarioMetadata ("HotKeys", "Demonstrates how HotKeys work.")] +[ScenarioCategory ("Controls")] +[ScenarioCategory("Mouse and Keyboard")] +public class HotKeys : Scenario +{ + public override void Init () + { + Application.Init (); + ConfigurationManager.Themes.Theme = Theme; + ConfigurationManager.Apply (); + Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme]; + Application.Top.BorderStyle = LineStyle.RoundedDotted; + Application.Top.Title = $"{Application.QuitKey} to _Quit - Scenario: {GetName ()}"; + } + + public override void Run () + { + var textViewLabel = new Label { Text = "_TextView:", X = 0, Y = 0 }; + Application.Top.Add (textViewLabel); + + var textField = new TextField (){ X = Pos.Right (textViewLabel) + 1, Y = 0, Width = 10 }; + Application.Top.Add (textField); + + var viewLabel = new Label { Text = "_View:", X = 0, Y = Pos.Bottom (textField) + 1 }; + Application.Top.Add (viewLabel); + + var view = new View () { + Title = "View (_focusable)", + Text = "Text renders _Underscore", + CanFocus = true, + X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (view); + + viewLabel = new Label { Text = "Vi_ew:", X = 0, Y = Pos.Bottom (view) + 1 }; + Application.Top.Add (viewLabel); + + view = new View () + { + Title = "View (n_ot focusable)", + Text = "Text renders _Underscore", + X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (view); + + var labelWithFrameLabel = new Label { Text = "_Label with Frame:", X = 0, Y = Pos.Bottom (view) + 1 }; + Application.Top.Add (labelWithFrameLabel); + + var labelWithFrameFocusable = new Label () + { + AutoSize = false, + Title = "Label _with Frame (focusable)", + CanFocus = true, + X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (labelWithFrameFocusable); + + labelWithFrameLabel = new Label { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 }; + Application.Top.Add (labelWithFrameLabel); + + var labelWithFrame = new Label () + { + AutoSize = false, + Title = "Label with Frame (_not focusable)", + X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (labelWithFrame); + + + var buttonWithFrameLabel = new Label { Text = "_Button with Frame:", X = 0, Y = Pos.Bottom (labelWithFrame) + 1 }; + Application.Top.Add (buttonWithFrameLabel); + + var buttonWithFrameFocusable = new Button () + { + AutoSize = false, + Title = "B_utton with Frame (focusable)", + CanFocus = true, + X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (buttonWithFrameFocusable); + + buttonWithFrameLabel = new Label { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 }; + Application.Top.Add (buttonWithFrameLabel); + + var buttonWithFrame = new Button () + { + AutoSize = false, + Title = "Button with Frame (not focusab_le)", + X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3, + CanFocus = false, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (buttonWithFrame); + + + + var checkboxWithFrameLabel = new Label { Text = "_Checkbox with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrame) + 1 }; + Application.Top.Add (checkboxWithFrameLabel); + + var checkboxWithFrameFocusable = new CheckBox + { + AutoSize = false, + Title = "C_heckbox with Frame (focusable)", + CanFocus = true, + X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (checkboxWithFrameFocusable); + + checkboxWithFrameLabel = new Label { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 }; + Application.Top.Add (checkboxWithFrameLabel); + + var checkboxWithFrame = new CheckBox + { + AutoSize = false, + Title = "Checkbox with Frame (not focusable)", + X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3, + CanFocus = false, + BorderStyle = LineStyle.Dashed, + }; + Application.Top.Add (checkboxWithFrame); + + + var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (1), Text = "_Press me!" }; + Application.Top.Add (button); + + Application.Run (Application.Top); + } +} diff --git a/UICatalog/Scenarios/Images.cs b/UICatalog/Scenarios/Images.cs index 18c4fac20..e7cf26793 100644 --- a/UICatalog/Scenarios/Images.cs +++ b/UICatalog/Scenarios/Images.cs @@ -54,7 +54,7 @@ public class Images : Scenario }; Win.Add (imageView); - btnOpenImage.Clicked += (_, _) => + btnOpenImage.Accept += (_, _) => { var ofd = new OpenDialog { Title = "Open Image", AllowsMultipleSelection = false }; Application.Run (ofd); diff --git a/UICatalog/Scenarios/InteractiveTree.cs b/UICatalog/Scenarios/InteractiveTree.cs index 17831c2bf..4818e4836 100644 --- a/UICatalog/Scenarios/InteractiveTree.cs +++ b/UICatalog/Scenarios/InteractiveTree.cs @@ -86,13 +86,13 @@ public class InteractiveTree : Scenario var ok = new Button { Text = "Ok", IsDefault = true }; - ok.Clicked += (s, e) => + ok.Accept += (s, e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => Application.RequestStop (); + cancel.Accept += (s, e) => Application.RequestStop (); var d = new Dialog { Title = title, Buttons = [ok, cancel] }; var lbl = new Label { X = 0, Y = 1, Text = label }; diff --git a/UICatalog/Scenarios/InvertColors.cs b/UICatalog/Scenarios/InvertColors.cs index 6d22dcc35..be8297cc6 100644 --- a/UICatalog/Scenarios/InvertColors.cs +++ b/UICatalog/Scenarios/InvertColors.cs @@ -31,7 +31,7 @@ public class InvertColors : Scenario var button = new Button { X = Pos.Center (), Y = foreColors.Length + 1, Text = "Invert color!" }; - button.Clicked += (s, e) => + button.Accept += (s, e) => { foreach (Label label in labels) { diff --git a/UICatalog/Scenarios/LabelsAsButtons.cs b/UICatalog/Scenarios/LabelsAsButtons.cs deleted file mode 100644 index e372f32d4..000000000 --- a/UICatalog/Scenarios/LabelsAsButtons.cs +++ /dev/null @@ -1,386 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using Terminal.Gui; - -namespace UICatalog.Scenarios; - -[ScenarioMetadata ("Labels As Buttons", "Illustrates that Button is really just a Label++")] -[ScenarioCategory ("Controls")] -[ScenarioCategory ("Proof of Concept")] -public class LabelsAsLabels : Scenario -{ - public override void Setup () - { - // Add a label & text field so we can demo IsDefault - var editLabel = new Label { X = 0, Y = 0, Text = "TextField (to demo IsDefault):" }; - Win.Add (editLabel); - - // Add a TextField using Absolute layout. - var edit = new TextField { X = 31, Width = 15 }; - Win.Add (edit); - - // This is the default Label (IsDefault = true); if user presses ENTER in the TextField - // the scenario will quit - var defaultLabel = new Label - { - X = Pos.Center (), - Y = Pos.Bottom (Win) - 3, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "_Quit" - }; - defaultLabel.Clicked += (s, e) => Application.RequestStop (); - Win.Add (defaultLabel); - - var swapLabel = new Label - { - X = 50, HotKeySpecifier = (Rune)'_', CanFocus = true, Text = "S_wap Default (Absolute Layout)" - }; - - swapLabel.Clicked += (s, e) => - { - //defaultLabel.IsDefault = !defaultLabel.IsDefault; - //swapLabel.IsDefault = !swapLabel.IsDefault; - }; - Win.Add (swapLabel); - - static void DoMessage (Label Label, string txt) - { - Label.Clicked += (s, e) => - { - string btnText = Label.Text; - MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No"); - }; - } - - var colorLabelsLabel = new Label { X = 0, Y = Pos.Bottom (editLabel) + 1, Text = "Color Labels:" }; - Win.Add (colorLabelsLabel); - - //With this method there is no need to call Application.TopReady += () => Application.TopRedraw (Top.Bounds); - Pos x = Pos.Right (colorLabelsLabel) + 2; - - foreach (KeyValuePair colorScheme in Colors.ColorSchemes) - { - var colorLabel = new Label - { - ColorScheme = colorScheme.Value, - X = x, - Y = Pos.Y (colorLabelsLabel), - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = $"{colorScheme.Key}" - }; - DoMessage (colorLabel, colorLabel.Text); - Win.Add (colorLabel); - x += colorLabel.Text.Length + 2; - } - - Application.Top.Ready += (s, e) => Application.Top.Draw (); - - Label Label; - - Win.Add ( - Label = new Label - { - X = 2, - Y = Pos.Bottom (colorLabelsLabel) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = - "A super long _Label that will probably expose a bug in clipping or wrapping of text. Will it?" - } - ); - DoMessage (Label, Label.Text); - - // Note the 'N' in 'Newline' will be the hotkey - Win.Add ( - Label = new Label - { - X = 2, - Y = Pos.Bottom (Label) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - TextAlignment = TextAlignment.Centered, - VerticalTextAlignment = VerticalTextAlignment.Middle, - Text = "a Newline\nin the Label" - } - ); - Label.Clicked += (s, e) => MessageBox.Query ("Message", "Question?", "Yes", "No"); - - var textChanger = new Label - { - X = 2, - Y = Pos.Bottom (Label) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Te_xt Changer" - }; - Win.Add (textChanger); - textChanger.Clicked += (s, e) => textChanger.Text += "!"; - - Win.Add ( - Label = new Label - { - X = Pos.Right (textChanger) + 2, - Y = Pos.Y (textChanger), - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Lets see if this will move as \"Text Changer\" grows" - } - ); - - var removeLabel = new Label - { - X = 2, - Y = Pos.Bottom (Label) + 1, - ColorScheme = Colors.ColorSchemes ["Error"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Remove this Label" - }; - Win.Add (removeLabel); - - // This in interesting test case because `moveBtn` and below are laid out relative to this one! - removeLabel.Clicked += (s, e) => - { - // Now this throw a InvalidOperationException on the TopologicalSort method as is expected. - //Win.Remove (removeLabel); - - removeLabel.Visible = false; - Win.SetNeedsDisplay (); - }; - - var computedFrame = new FrameView - { - X = 0, - Y = Pos.Bottom (removeLabel) + 1, - Width = Dim.Percent (50), - Height = 5, - Title = "Computed Layout" - }; - Win.Add (computedFrame); - - // Demonstrates how changing the View.Frame property can move Views - var moveBtn = new Label - { - X = 0, - Y = Pos.Center () - 1, - AutoSize = false, - Width = 30, - ColorScheme = Colors.ColorSchemes ["Error"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Move This \u263b Label _via Pos" - }; - - moveBtn.Clicked += (s, e) => - { - moveBtn.X = moveBtn.Frame.X + 5; - - // This is already fixed with the call to SetNeedDisplay() in the Pos Dim. - //computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly - }; - computedFrame.Add (moveBtn); - - // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtn = new Label - { - X = 0, - Y = Pos.Center () + 1, - AutoSize = false, - Width = 30, - ColorScheme = Colors.ColorSchemes ["Error"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Size This \u263a Label _via Pos" - }; - - sizeBtn.Clicked += (s, e) => - { - sizeBtn.Width = sizeBtn.Frame.Width + 5; - - //computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly - }; - computedFrame.Add (sizeBtn); - - var absoluteFrame = new FrameView - { - X = Pos.Right (computedFrame), - Y = Pos.Bottom (removeLabel) + 1, - Width = Dim.Fill (), - Height = 5, - Title = "Absolute Layout" - }; - Win.Add (absoluteFrame); - - // Demonstrates how changing the View.Frame property can move Views - var moveBtnA = new Label - { - ColorScheme = Colors.ColorSchemes ["Error"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Move This Label via Frame" - }; - - moveBtnA.Clicked += (s, e) => - { - moveBtnA.Frame = new Rect ( - moveBtnA.Frame.X + 5, - moveBtnA.Frame.Y, - moveBtnA.Frame.Width, - moveBtnA.Frame.Height - ); - }; - absoluteFrame.Add (moveBtnA); - - // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtnA = new Label - { - Y = 2, - ColorScheme = Colors.ColorSchemes ["Error"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - AutoSize = false, - Text = " ~  s  gui.cs   master ↑10 = Со_хранить" - }; - - sizeBtnA.Clicked += (s, e) => - { - sizeBtnA.Frame = new Rect ( - sizeBtnA.Frame.X, - sizeBtnA.Frame.Y, - sizeBtnA.Frame.Width + 5, - sizeBtnA.Frame.Height - ); - }; - absoluteFrame.Add (sizeBtnA); - - var label = new Label - { - X = 2, - Y = Pos.Bottom (computedFrame) + 1, - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = "Text Alignment (changes the four Labels above): " - }; - Win.Add (label); - - var radioGroup = new RadioGroup - { - X = 4, - Y = Pos.Bottom (label) + 1, - SelectedItem = 2, - RadioLabels = new [] { "Left", "Right", "Centered", "Justified" } - }; - Win.Add (radioGroup); - - // Demo changing hotkey - string MoveHotkey (string txt) - { - // Remove the '_' - List runes = txt.ToRuneList (); - - int i = runes.IndexOf ((Rune)'_'); - var start = ""; - - if (i > -1) - { - start = StringExtensions.ToString (runes.GetRange (0, i)); - } - - txt = start + StringExtensions.ToString (runes.GetRange (i + 1, runes.Count - (i + 1))); - - runes = txt.ToRuneList (); - - // Move over one or go to start - i++; - - if (i >= runes.Count) - { - i = 0; - } - - // Slip in the '_' - start = StringExtensions.ToString (runes.GetRange (0, i)); - - return start + '_' + StringExtensions.ToString (runes.GetRange (i, runes.Count - i)); - } - - var mhkb = "Click to Change th_is Label's Hotkey"; - - var moveHotKeyBtn = new Label - { - X = 2, - Y = Pos.Bottom (radioGroup) + 1, - AutoSize = false, - Width = Dim.Width (computedFrame) - 2, - ColorScheme = Colors.ColorSchemes ["TopLevel"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = mhkb - }; - moveHotKeyBtn.Clicked += (s, e) => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; - Win.Add (moveHotKeyBtn); - - var muhkb = " ~  s  gui.cs   master ↑10 = Сохранить"; - - var moveUnicodeHotKeyBtn = new Label - { - X = Pos.Left (absoluteFrame) + 1, - Y = Pos.Bottom (radioGroup) + 1, - AutoSize = false, - Width = Dim.Width (absoluteFrame) - 2, - ColorScheme = Colors.ColorSchemes ["TopLevel"], - HotKeySpecifier = (Rune)'_', - CanFocus = true, - Text = muhkb - }; - moveUnicodeHotKeyBtn.Clicked += (s, e) => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; - Win.Add (moveUnicodeHotKeyBtn); - - radioGroup.SelectedItemChanged += (s, args) => - { - switch (args.SelectedItem) - { - case 0: - moveBtn.TextAlignment = TextAlignment.Left; - sizeBtn.TextAlignment = TextAlignment.Left; - moveBtnA.TextAlignment = TextAlignment.Left; - sizeBtnA.TextAlignment = TextAlignment.Left; - moveHotKeyBtn.TextAlignment = TextAlignment.Left; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Left; - - break; - case 1: - moveBtn.TextAlignment = TextAlignment.Right; - sizeBtn.TextAlignment = TextAlignment.Right; - moveBtnA.TextAlignment = TextAlignment.Right; - sizeBtnA.TextAlignment = TextAlignment.Right; - moveHotKeyBtn.TextAlignment = TextAlignment.Right; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Right; - - break; - case 2: - moveBtn.TextAlignment = TextAlignment.Centered; - sizeBtn.TextAlignment = TextAlignment.Centered; - moveBtnA.TextAlignment = TextAlignment.Centered; - sizeBtnA.TextAlignment = TextAlignment.Centered; - moveHotKeyBtn.TextAlignment = TextAlignment.Centered; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Centered; - - break; - case 3: - moveBtn.TextAlignment = TextAlignment.Justified; - sizeBtn.TextAlignment = TextAlignment.Justified; - moveBtnA.TextAlignment = TextAlignment.Justified; - sizeBtnA.TextAlignment = TextAlignment.Justified; - moveHotKeyBtn.TextAlignment = TextAlignment.Justified; - moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Justified; - - break; - } - }; - - Application.Top.Ready += (s, e) => radioGroup.Refresh (); - } -} diff --git a/UICatalog/Scenarios/LineDrawing.cs b/UICatalog/Scenarios/LineDrawing.cs index 7f9f2b2ca..756b49688 100644 --- a/UICatalog/Scenarios/LineDrawing.cs +++ b/UICatalog/Scenarios/LineDrawing.cs @@ -208,7 +208,7 @@ public class LineDrawing : Scenario _addLayerBtn = new Button { Text = "New Layer", X = Pos.Center (), Y = Pos.Bottom (_stylePicker) }; - _addLayerBtn.Clicked += (s, a) => AddLayer?.Invoke (); + _addLayerBtn.Accept += (s, a) => AddLayer?.Invoke (); Add (_colorPicker, _stylePicker, _addLayerBtn); } diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index 060d038c2..03959fd46 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -267,7 +267,7 @@ public class ListColumns : Scenario // if user clicks the mouse in TableView _listColView.MouseClick += (s, e) => { _listColView.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out int? clickedCol); }; - _listColView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + _listColView.KeyBindings.Add (Key.Space, Command.Accept); } private void CloseExample () { _listColView.Table = null; } @@ -279,13 +279,13 @@ public class ListColumns : Scenario var accepted = false; var ok = new Button { Text = "Ok", IsDefault = true }; - ok.Clicked += (s, e) => + ok.Accept += (s, e) => { accepted = true; Application.RequestStop (); }; var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => { Application.RequestStop (); }; + cancel.Accept += (s, e) => { Application.RequestStop (); }; var d = new Dialog { Title = prompt, Buttons = [ok, cancel] }; var tf = new TextField { Text = getter (_listColView).ToString (), X = 0, Y = 1, Width = Dim.Fill () }; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index bd0151ce4..4dd7d00ad 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using System.Text; +using JetBrains.Annotations; using Terminal.Gui; namespace UICatalog.Scenarios; @@ -102,9 +103,9 @@ public class ListViewWithSelection : Scenario Win.Add (keepCheckBox); } - private void _customRenderCB_Toggled (object sender, ToggleEventArgs e) + private void _customRenderCB_Toggled (object sender, StateEventArgs stateEventArgs) { - if (e.OldValue == true) + if (stateEventArgs.OldValue == true) { _listView.SetSource (_scenarios); } @@ -116,16 +117,16 @@ public class ListViewWithSelection : Scenario Win.SetNeedsDisplay (); } - private void AllowMarkingCB_Toggled (object sender, ToggleEventArgs e) + private void AllowMarkingCB_Toggled (object sender, [NotNull] StateEventArgs stateEventArgs) { - _listView.AllowsMarking = (bool)!e.OldValue; + _listView.AllowsMarking = (bool)!stateEventArgs.OldValue; _allowMultipleCB.Visible = _listView.AllowsMarking; Win.SetNeedsDisplay (); } - private void AllowMultipleCB_Toggled (object sender, ToggleEventArgs e) + private void AllowMultipleCB_Toggled (object sender, [NotNull] StateEventArgs stateEventArgs) { - _listView.AllowsMultipleSelection = (bool)!e.OldValue; + _listView.AllowsMultipleSelection = (bool)!stateEventArgs.OldValue; Win.SetNeedsDisplay (); } diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index 4c84006ef..149d5152b 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -145,13 +145,13 @@ public class ListsAndCombos : Scenario }; var btnMoveUp = new Button { X = 1, Y = Pos.Bottom (lbListView), Text = "Move _Up" }; - btnMoveUp.Clicked += (s, e) => { listview.MoveUp (); }; + btnMoveUp.Accept += (s, e) => { listview.MoveUp (); }; var btnMoveDown = new Button { X = Pos.Right (btnMoveUp) + 1, Y = Pos.Bottom (lbListView), Text = "Move _Down" }; - btnMoveDown.Clicked += (s, e) => { listview.MoveDown (); }; + btnMoveDown.Accept += (s, e) => { listview.MoveDown (); }; Win.Add (btnMoveUp, btnMoveDown); } diff --git a/UICatalog/Scenarios/Localization.cs b/UICatalog/Scenarios/Localization.cs index 818981c12..444f9adfb 100644 --- a/UICatalog/Scenarios/Localization.cs +++ b/UICatalog/Scenarios/Localization.cs @@ -150,14 +150,14 @@ public class Localization : Scenario { X = Pos.Right (_allowAnyCheckBox) + 1, Y = Pos.Bottom (textAndFileDialogLabel) + 1, Text = "Open" }; - openDialogButton.Clicked += (sender, e) => ShowFileDialog (false); + openDialogButton.Accept += (sender, e) => ShowFileDialog (false); Win.Add (openDialogButton); var saveDialogButton = new Button { X = Pos.Right (openDialogButton) + 1, Y = Pos.Bottom (textAndFileDialogLabel) + 1, Text = "Save" }; - saveDialogButton.Clicked += (sender, e) => ShowFileDialog (true); + saveDialogButton.Accept += (sender, e) => ShowFileDialog (true); Win.Add (saveDialogButton); var wizardLabel = new Label @@ -171,7 +171,7 @@ public class Localization : Scenario Win.Add (wizardLabel); var wizardButton = new Button { X = 2, Y = Pos.Bottom (wizardLabel) + 1, Text = "Open _wizard" }; - wizardButton.Clicked += (sender, e) => ShowWizard (); + wizardButton.Accept += (sender, e) => ShowWizard (); Win.Add (wizardButton); Win.Unloaded += (sender, e) => Quit (); diff --git a/UICatalog/Scenarios/MenuBarScenario.cs b/UICatalog/Scenarios/MenuBarScenario.cs index 2fba7575b..b767cda61 100644 --- a/UICatalog/Scenarios/MenuBarScenario.cs +++ b/UICatalog/Scenarios/MenuBarScenario.cs @@ -279,15 +279,15 @@ public class MenuBarScenario : Scenario menuBar.LayoutComplete += (s, e) => { _focusedView.Text = Application.Top.MostFocused?.ToString () ?? "None"; }; var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefault = true }; - openBtn.Clicked += (s, e) => { menuBar.OpenMenu (); }; + openBtn.Accept += (s, e) => { menuBar.OpenMenu (); }; Application.Top.Add (openBtn); var hideBtn = new Button { X = Pos.Center (), Y = Pos.Bottom (openBtn), Text = "Toggle Menu._Visible" }; - hideBtn.Clicked += (s, e) => { menuBar.Visible = !menuBar.Visible; }; + hideBtn.Accept += (s, e) => { menuBar.Visible = !menuBar.Visible; }; Application.Top.Add (hideBtn); var enableBtn = new Button { X = Pos.Center (), Y = Pos.Bottom (hideBtn), Text = "_Toggle Menu.Enable" }; - enableBtn.Clicked += (s, e) => { menuBar.Enabled = !menuBar.Enabled; }; + enableBtn.Accept += (s, e) => { menuBar.Enabled = !menuBar.Enabled; }; Application.Top.Add (enableBtn); Application.Top.Add (menuBar); diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index 9a7afb2b4..e00228aed 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -215,7 +215,7 @@ public class MessageBoxes : Scenario X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, Text = "_Show MessageBox" }; - showMessageBoxButton.Clicked += (s, e) => + showMessageBoxButton.Accept += (s, e) => { try { diff --git a/UICatalog/Scenarios/MultiColouredTable.cs b/UICatalog/Scenarios/MultiColouredTable.cs index ddad7e2b1..be152973f 100644 --- a/UICatalog/Scenarios/MultiColouredTable.cs +++ b/UICatalog/Scenarios/MultiColouredTable.cs @@ -100,13 +100,13 @@ public class MultiColouredTable : Scenario var ok = new Button { Text = "Ok", IsDefault = true }; - ok.Clicked += (s, e) => + ok.Accept += (s, e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => { Application.RequestStop (); }; + cancel.Accept += (s, e) => { Application.RequestStop (); }; var d = new Dialog { Title = title, Buttons = [ok, cancel] }; var lbl = new Label { X = 0, Y = 1, Text = label }; diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index d1ec6ea4f..2af53b037 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -139,7 +139,7 @@ public class Progress : Scenario var startBoth = new Button { X = Pos.Center (), Y = Pos.Bottom (mainLoopTimeoutDemo) + 1, Text = "Start Both" }; - startBoth.Clicked += (s, e) => + startBoth.Accept += (s, e) => { systemTimerDemo.Start (); mainLoopTimeoutDemo.Start (); @@ -186,15 +186,15 @@ public class Progress : Scenario Add (LeftFrame); var startButton = new Button { X = Pos.Right (LeftFrame) + 1, Y = 0, Text = "Start Timer" }; - startButton.Clicked += (s, e) => Start (); + startButton.Accept += (s, e) => Start (); var pulseButton = new Button { X = Pos.Right (startButton) + 2, Y = Pos.Y (startButton), Text = "Pulse" }; - pulseButton.Clicked += (s, e) => Pulse (); + pulseButton.Accept += (s, e) => Pulse (); var stopbutton = new Button { X = Pos.Right (pulseButton) + 2, Y = Pos.Top (pulseButton), Text = "Stop Timer" }; - stopbutton.Clicked += (s, e) => Stop (); + stopbutton.Accept += (s, e) => Stop (); Add (startButton); Add (pulseButton); diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index f148dab85..8133bd892 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -91,7 +91,7 @@ public class ProgressBarStyles : Scenario }; editor.Add (fgColorPickerBtn); - fgColorPickerBtn.Clicked += (s, e) => + fgColorPickerBtn.Accept += (s, e) => { ColorName newColor = ChooseColor ( fgColorPickerBtn.Text, @@ -116,7 +116,7 @@ public class ProgressBarStyles : Scenario }; editor.Add (bgColorPickerBtn); - bgColorPickerBtn.Clicked += (s, e) => + bgColorPickerBtn.Accept += (s, e) => { ColorName newColor = ChooseColor ( fgColorPickerBtn.Text, @@ -177,7 +177,7 @@ public class ProgressBarStyles : Scenario }; editor.Add (continuousPB); - button.Clicked += (s, e) => + button.Accept += (s, e) => { if (_fractionTimer == null) { diff --git a/UICatalog/Scenarios/RunTExample.cs b/UICatalog/Scenarios/RunTExample.cs index 93e6e9d9a..7f0629455 100644 --- a/UICatalog/Scenarios/RunTExample.cs +++ b/UICatalog/Scenarios/RunTExample.cs @@ -60,7 +60,7 @@ public class RunTExample : Scenario }; // When login button is clicked display a message popup - btnLogin.Clicked += (s, e) => + btnLogin.Accept += (s, e) => { if (_usernameText.Text == "admin" && passwordText.Text == "password") { diff --git a/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs b/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs index 573aac6f5..65d7b1416 100644 --- a/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs +++ b/UICatalog/Scenarios/RuneWidthGreaterThanOne.cs @@ -103,7 +103,7 @@ public class RuneWidthGreaterThanOne : Scenario _label.Text = "Enter your name 你:"; _text.Text = "gui.cs 你:"; _button.Text = "Say Hello 你"; - _button.Clicked += MixedMessage; + _button.Accept += MixedMessage; _labelR.X = Pos.AnchorEnd (21); _labelR.Y = 18; _labelR.Text = "This is a test text 你"; @@ -123,7 +123,7 @@ public class RuneWidthGreaterThanOne : Scenario _label.Text = "Enter your name:"; _text.Text = "gui.cs"; _button.Text = "Say Hello"; - _button.Clicked += NarrowMessage; + _button.Accept += NarrowMessage; _labelR.X = Pos.AnchorEnd (19); _labelR.Y = 18; _labelR.Text = "This is a test text"; @@ -140,15 +140,15 @@ public class RuneWidthGreaterThanOne : Scenario switch (_lastRunesUsed) { case "Narrow": - _button.Clicked -= NarrowMessage; + _button.Accept -= NarrowMessage; break; case "Mixed": - _button.Clicked -= MixedMessage; + _button.Accept -= MixedMessage; break; case "Wide": - _button.Clicked -= WideMessage; + _button.Accept -= WideMessage; break; } @@ -162,7 +162,7 @@ public class RuneWidthGreaterThanOne : Scenario _label.Text = "あなたの名前を入力してください:"; _text.Text = "ティラミス"; _button.Text = "こんにちはと言う"; - _button.Clicked += WideMessage; + _button.Accept += WideMessage; _labelR.X = Pos.AnchorEnd (29); _labelR.Y = 18; _labelR.Text = "あなたの名前を入力してください"; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index d38cbeb33..4a164cbe4 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -84,7 +84,7 @@ public class Scrolling : Scenario Application.Top.Loaded += Top_Loaded; var pressMeButton = new Button { X = 3, Y = 3, Text = "Press me!" }; - pressMeButton.Clicked += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); + pressMeButton.Accept += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); scrollView.Add (pressMeButton); var aLongButton = new Button @@ -95,7 +95,7 @@ public class Scrolling : Scenario Width = Dim.Fill (3), Text = "A very long button. Should be wide enough to demo clipping!" }; - aLongButton.Clicked += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); + aLongButton.Accept += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No"); scrollView.Add (aLongButton); scrollView.Add ( @@ -137,7 +137,7 @@ public class Scrolling : Scenario // TODO: Use Pos.Width instead of (Right-Left) when implemented (#502) anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); - anchorButton.Clicked += (s, e) => + anchorButton.Accept += (s, e) => { // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer diff --git a/UICatalog/Scenarios/SendKeys.cs b/UICatalog/Scenarios/SendKeys.cs index 9830d22e7..e38079a43 100644 --- a/UICatalog/Scenarios/SendKeys.cs +++ b/UICatalog/Scenarios/SendKeys.cs @@ -98,7 +98,7 @@ public class SendKeys : Scenario txtInput.SetFocus (); } - button.Clicked += (s, e) => ProcessInput (); + button.Accept += (s, e) => ProcessInput (); Win.KeyDown += (s, e) => { diff --git a/UICatalog/Scenarios/SingleBackgroundWorker.cs b/UICatalog/Scenarios/SingleBackgroundWorker.cs index 9386e053d..7b2e02c8b 100644 --- a/UICatalog/Scenarios/SingleBackgroundWorker.cs +++ b/UICatalog/Scenarios/SingleBackgroundWorker.cs @@ -101,7 +101,7 @@ public class SingleBackgroundWorker : Scenario var cancel = new Button { Text = "Cancel Worker" }; - cancel.Clicked += (s, e) => + cancel.Accept += (s, e) => { if (_worker == null) { diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index ee7d63141..56614a71b 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -767,7 +767,7 @@ public class TableEditor : Scenario } }; - _tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + _tableView.KeyBindings.Add (Key.Space, Command.Accept); } protected override void Dispose (bool disposing) @@ -869,13 +869,13 @@ public class TableEditor : Scenario var ok = new Button { Text = "Ok", IsDefault = true }; - ok.Clicked += (s, e) => + ok.Accept += (s, e) => { okPressed = true; Application.RequestStop (); }; var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => { Application.RequestStop (); }; + cancel.Accept += (s, e) => { Application.RequestStop (); }; var d = new Dialog { Title = title, Buttons = [ok, cancel] }; var lbl = new Label { X = 0, Y = 1, Text = _tableView.Table.ColumnNames [e.Col] }; @@ -1066,13 +1066,13 @@ public class TableEditor : Scenario var accepted = false; var ok = new Button { Text = "Ok", IsDefault = true }; - ok.Clicked += (s, e) => + ok.Accept += (s, e) => { accepted = true; Application.RequestStop (); }; var cancel = new Button { Text = "Cancel" }; - cancel.Clicked += (s, e) => { Application.RequestStop (); }; + cancel.Accept += (s, e) => { Application.RequestStop (); }; var d = new Dialog { Title = prompt, Buttons = [ok, cancel] }; ColumnStyle style = _tableView.Style.GetOrCreateColumnStyle (col.Value); diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs index 05b08c763..bbc570642 100644 --- a/UICatalog/Scenarios/Text.cs +++ b/UICatalog/Scenarios/Text.cs @@ -21,9 +21,11 @@ public class Text : Scenario public override void Setup () { // TextField is a simple, single-line text input control + var label = new Label { Text = "_TextField:" }; + Win.Add (label); var textField = new TextField { - X = 1, + X = Pos.Right (label) + 1, Y = 0, Width = Dim.Percent (50) - 1, @@ -34,17 +36,14 @@ public class Text : Scenario var singleWordGenerator = new SingleWordSuggestionGenerator (); textField.Autocomplete.SuggestionGenerator = singleWordGenerator; - textField.TextChanging += TextField_TextChanging; - - void TextField_TextChanging (object sender, TextChangingEventArgs e) + void TextField_TextChanging (object sender, StateEventArgs e) { - singleWordGenerator.AllSuggestions = Regex.Matches (e.NewText, "\\w+") + singleWordGenerator.AllSuggestions = Regex.Matches (e.NewValue, "\\w+") .Select (s => s.Value) .Distinct () .ToList (); } - Win.Add (textField); var labelMirroringTextField = new Label @@ -53,16 +52,18 @@ public class Text : Scenario Y = Pos.Top (textField), AutoSize = false, Width = Dim.Fill (1) - 1, + Height = 1, Text = textField.Text }; Win.Add (labelMirroringTextField); - textField.TextChanged += (s, prev) => { labelMirroringTextField.Text = textField.Text; }; // TextView is a rich (as in functionality, not formatting) text editing control + label = new Label { Text = "T_extView:", Y = Pos.Bottom (label) + 1 }; + Win.Add (label); var textView = new TextView { - X = 1, Y = Pos.Bottom (textField) + 1, Width = Dim.Percent (50) - 1, Height = Dim.Percent (30) + X = Pos.Right (label) + 1, Y = Pos.Bottom (textField) + 1, Width = Dim.Percent (50) - 1, Height = Dim.Percent (30) }; textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹Aℝ𝔽!"; textView.DrawContent += TextView_DrawContent; @@ -101,7 +102,7 @@ public class Text : Scenario // single-line mode. var chxMultiline = new CheckBox { - X = Pos.Left (textView), Y = Pos.Bottom (textView), Checked = textView.Multiline, Text = "Multiline" + X = Pos.Left (textView), Y = Pos.Bottom (textView), Checked = textView.Multiline, Text = "_Multiline" }; Win.Add (chxMultiline); @@ -110,7 +111,7 @@ public class Text : Scenario X = Pos.Right (chxMultiline) + 2, Y = Pos.Top (chxMultiline), Checked = textView.WordWrap, - Text = "Word Wrap" + Text = "_Word Wrap" }; chxWordWrap.Toggled += (s, e) => textView.WordWrap = (bool)e.NewValue; Win.Add (chxWordWrap); @@ -123,7 +124,7 @@ public class Text : Scenario X = Pos.Right (chxWordWrap) + 2, Y = Pos.Top (chxWordWrap), Checked = textView.AllowsTab, - Text = "Capture Tabs" + Text = "_Capture Tabs" }; chxMultiline.Toggled += (s, e) => @@ -161,10 +162,17 @@ public class Text : Scenario }; Win.Add (chxCaptureTabs); + // Hex editor + label = new Label { Text = "_HexView:", Y = Pos.Bottom (chxMultiline) + 1 }; + Win.Add (label); + var hexEditor = new HexView ( new MemoryStream (Encoding.UTF8.GetBytes ("HexEditor Unicode that shouldn't 𝔹Aℝ𝔽!")) - ) { X = 1, Y = Pos.Bottom (chxMultiline) + 1, Width = Dim.Percent (50) - 1, Height = Dim.Percent (30) }; + ) + { + X = Pos.Right (label) + 1, Y = Pos.Bottom (chxMultiline) + 1, Width = Dim.Percent (50) - 1, Height = Dim.Percent (30) + }; Win.Add (hexEditor); var labelMirroringHexEditor = new Label @@ -186,7 +194,11 @@ public class Text : Scenario }; Win.Add (labelMirroringHexEditor); - var dateField = new DateField (DateTime.Now) { X = 1, Y = Pos.Bottom (hexEditor) + 1, Width = 20 }; + // DateField + label = new Label { Text = "_DateField:", Y = Pos.Bottom (hexEditor) + 1 }; + Win.Add (label); + + var dateField = new DateField (DateTime.Now) { X = Pos.Right (label) + 1, Y = Pos.Bottom (hexEditor) + 1, Width = 20 }; Win.Add (dateField); var labelMirroringDateField = new Label @@ -202,10 +214,14 @@ public class Text : Scenario dateField.TextChanged += (s, prev) => { labelMirroringDateField.Text = dateField.Text; }; + // TimeField + label = new Label { Text = "T_imeField:", Y = Pos.Top (dateField), X = Pos.Right (labelMirroringDateField) + 5 }; + Win.Add (label); + _timeField = new TimeField { - X = Pos.Right (labelMirroringDateField) + 5, - Y = Pos.Bottom (hexEditor) + 1, + X = Pos.Right (label) + 1, + Y = Pos.Top (dateField), Width = 20, IsShortFormat = false, Time = DateTime.Now.TimeOfDay @@ -230,7 +246,7 @@ public class Text : Scenario { X = Pos.Left (dateField), Y = Pos.Bottom (dateField) + 1, - Text = "NetMaskedTextProvider [ 999 000 LLL >LLL |AAA aaa ]" + Text = "_NetMaskedTextProvider [ 999 000 LLL >LLL |AAA aaa ]:" }; Win.Add (netProviderLabel); @@ -260,7 +276,7 @@ public class Text : Scenario { X = Pos.Left (netProviderLabel), Y = Pos.Bottom (netProviderLabel) + 1, - Text = "TextRegexProvider [ ^([0-9]?[0-9]?[0-9]|1000)$ ]" + Text = "Text_RegexProvider [ ^([0-9]?[0-9]?[0-9]|1000)$ ]:" }; Win.Add (regexProvider); @@ -291,12 +307,12 @@ public class Text : Scenario var labelAppendAutocomplete = new Label { - Y = Pos.Y (regexProviderField) + 2, X = 1, Text = "Append Autocomplete:" + Y = Pos.Y (regexProviderField) + 2, X = 1, Text = "_Append Autocomplete:" }; var appendAutocompleteTextField = new TextField { - X = Pos.Right (labelAppendAutocomplete), Y = Pos.Top (labelAppendAutocomplete), Width = Dim.Fill () + X = Pos.Right (labelAppendAutocomplete) + 1, Y = Pos.Top (labelAppendAutocomplete), Width = Dim.Fill () }; appendAutocompleteTextField.Autocomplete = new AppendAutocomplete (appendAutocompleteTextField); diff --git a/UICatalog/Scenarios/TextAlignments.cs b/UICatalog/Scenarios/TextAlignments.cs index 3801c4721..ff7c5867c 100644 --- a/UICatalog/Scenarios/TextAlignments.cs +++ b/UICatalog/Scenarios/TextAlignments.cs @@ -74,12 +74,12 @@ public class TextAlignments : Scenario Win.Add (edit); var unicodeSample = new Button { X = Pos.Right (edit) + 1, Y = 0, Text = "Unicode Sample" }; - unicodeSample.Clicked += (s, e) => { edit.Text = unicodeSampleText; }; + unicodeSample.Accept += (s, e) => { edit.Text = unicodeSampleText; }; Win.Add (unicodeSample); var update = new Button { X = Pos.Right (edit) + 1, Y = Pos.Bottom (edit) - 1, Text = "_Update" }; - update.Clicked += (s, e) => + update.Accept += (s, e) => { foreach (TextAlignment alignment in alignments) { diff --git a/UICatalog/Scenarios/Threading.cs b/UICatalog/Scenarios/Threading.cs index 312dbb5b5..a6d162dfc 100644 --- a/UICatalog/Scenarios/Threading.cs +++ b/UICatalog/Scenarios/Threading.cs @@ -54,7 +54,7 @@ public class Threading : Scenario }; _btnActionCancel = new Button { X = 1, Y = 1, Text = "Cancelable Load Items" }; - _btnActionCancel.Clicked += (s, e) => Application.Invoke (CallLoadItemsAsync); + _btnActionCancel.Accept += (s, e) => Application.Invoke (CallLoadItemsAsync); Win.Add (new Label { X = Pos.X (_btnActionCancel), Y = Pos.Y (_btnActionCancel) + 4, Text = "Data Items:" }); @@ -82,24 +82,24 @@ public class Threading : Scenario var text = new TextField { X = 1, Y = 3, Width = 100, Text = "Type anything after press the button" }; var btnAction = new Button { X = 80, Y = 10, Text = "Load Data Action" }; - btnAction.Clicked += (s, e) => _action.Invoke (); + btnAction.Accept += (s, e) => _action.Invoke (); var btnLambda = new Button { X = 80, Y = 12, Text = "Load Data Lambda" }; - btnLambda.Clicked += (s, e) => _lambda.Invoke (); + btnLambda.Accept += (s, e) => _lambda.Invoke (); var btnHandler = new Button { X = 80, Y = 14, Text = "Load Data Handler" }; - btnHandler.Clicked += (s, e) => _handler.Invoke (null, EventArgs.Empty); + btnHandler.Accept += (s, e) => _handler.Invoke (null, EventArgs.Empty); var btnSync = new Button { X = 80, Y = 16, Text = "Load Data Synchronous" }; - btnSync.Clicked += (s, e) => _sync.Invoke (); + btnSync.Accept += (s, e) => _sync.Invoke (); var btnMethod = new Button { X = 80, Y = 18, Text = "Load Data Method" }; - btnMethod.Clicked += async (s, e) => await MethodAsync (); + btnMethod.Accept += async (s, e) => await MethodAsync (); var btnClearData = new Button { X = 80, Y = 20, Text = "Clear Data" }; - btnClearData.Clicked += (s, e) => + btnClearData.Accept += (s, e) => { _itemsList.Source = null; LogJob ("Cleaning Data"); }; var btnQuit = new Button { X = 80, Y = 22, Text = "Quit" }; - btnQuit.Clicked += (s, e) => Application.RequestStop (); + btnQuit.Accept += (s, e) => Application.RequestStop (); Win.Add ( _itemsList, diff --git a/UICatalog/Scenarios/TimeAndDate.cs b/UICatalog/Scenarios/TimeAndDate.cs index 8fc4da5fb..6b8bf601e 100644 --- a/UICatalog/Scenarios/TimeAndDate.cs +++ b/UICatalog/Scenarios/TimeAndDate.cs @@ -124,7 +124,7 @@ public class TimeAndDate : Scenario X = Pos.Center (), Y = Pos.Bottom (Win) - 5, Text = "Swap Long/Short & Read/Read Only" }; - swapButton.Clicked += (s, e) => + swapButton.Accept += (s, e) => { longTime.ReadOnly = !longTime.ReadOnly; shortTime.ReadOnly = !shortTime.ReadOnly; diff --git a/UICatalog/Scenarios/VkeyPacketSimulator.cs b/UICatalog/Scenarios/VkeyPacketSimulator.cs index c207f1492..37ffced39 100644 --- a/UICatalog/Scenarios/VkeyPacketSimulator.cs +++ b/UICatalog/Scenarios/VkeyPacketSimulator.cs @@ -242,7 +242,7 @@ public class VkeyPacketSimulator : Scenario } }; - btnInput.Clicked += (s, e) => + btnInput.Accept += (s, e) => { if (!tvInput.HasFocus && _keyboardStrokes.Count == 0) { @@ -250,7 +250,7 @@ public class VkeyPacketSimulator : Scenario } }; - btnOutput.Clicked += (s, e) => + btnOutput.Accept += (s, e) => { if (!tvOutput.HasFocus && _keyboardStrokes.Count == 0) { diff --git a/UICatalog/Scenarios/WindowsAndFrameViews.cs b/UICatalog/Scenarios/WindowsAndFrameViews.cs index e5db7ecca..2fd42d7ab 100644 --- a/UICatalog/Scenarios/WindowsAndFrameViews.cs +++ b/UICatalog/Scenarios/WindowsAndFrameViews.cs @@ -49,7 +49,7 @@ public class WindowsAndFrameViews : Scenario ColorScheme = Colors.ColorSchemes ["Error"], Text = $"Padding of container is {padding}" }; - paddingButton.Clicked += (s, e) => About (); + paddingButton.Accept += (s, e) => About (); Win.Add (paddingButton); Win.Add ( @@ -94,7 +94,7 @@ public class WindowsAndFrameViews : Scenario X = Pos.Center (), Y = 0, ColorScheme = Colors.ColorSchemes ["Error"], Text = "Press me! (Y = 0)" }; - pressMeButton.Clicked += (s, e) => + pressMeButton.Accept += (s, e) => MessageBox.ErrorQuery (win.Title, "Neat?", "Yes", "No"); win.Add (pressMeButton); diff --git a/UICatalog/Scenarios/WizardAsView.cs b/UICatalog/Scenarios/WizardAsView.cs index 729111fec..e828416d4 100644 --- a/UICatalog/Scenarios/WizardAsView.cs +++ b/UICatalog/Scenarios/WizardAsView.cs @@ -113,7 +113,7 @@ public class WizardAsView : Scenario Text = "Press Me to Rename Step", X = Pos.Right (buttonLbl), Y = Pos.Top (buttonLbl) }; - button.Clicked += (s, e) => + button.Accept += (s, e) => { secondStep.Title = "2nd Step"; diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index d7a03a828..167d0f87b 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -103,7 +103,7 @@ public class Wizards : Scenario X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, Text = "Show Wizard" }; - showWizardButton.Clicked += (s, e) => + showWizardButton.Accept += (s, e) => { try { @@ -173,7 +173,7 @@ public class Wizards : Scenario Text = "Press Me to Rename Step", X = Pos.Right (buttonLbl), Y = Pos.Top (buttonLbl) }; - button.Clicked += (s, e) => + button.Accept += (s, e) => { secondStep.Title = "2nd Step"; @@ -269,7 +269,7 @@ public class Wizards : Scenario Text = "Press me to show/hide help", X = Pos.Center (), Y = Pos.AnchorEnd (1) }; - hideHelpBtn.Clicked += (s, e) => + hideHelpBtn.Accept += (s, e) => { if (fourthStep.HelpText.Length > 0) { diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 3abdcf754..b2e8691a2 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -495,7 +495,7 @@ internal class UICatalogApp Height = Dim.Fill (1), AllowsMarking = false, CanFocus = true, - Title = "Categories", + Title = "_Categories", BorderStyle = LineStyle.Single, SuperViewRendersLineCanvas = true, Source = new ListWrapper (_categories) @@ -515,7 +515,7 @@ internal class UICatalogApp //AllowsMarking = false, CanFocus = true, - Title = "Scenarios", + Title = "_Scenarios", BorderStyle = LineStyle.Single, SuperViewRendersLineCanvas = true }; diff --git a/UICatalog/UICatalog.csproj b/UICatalog/UICatalog.csproj index 082140a75..03b0823e4 100644 --- a/UICatalog/UICatalog.csproj +++ b/UICatalog/UICatalog.csproj @@ -30,7 +30,7 @@ - + diff --git a/UnitTests/Application/KeyboardTests.cs b/UnitTests/Application/KeyboardTests.cs index 513ab3c96..c0ea94343 100644 --- a/UnitTests/Application/KeyboardTests.cs +++ b/UnitTests/Application/KeyboardTests.cs @@ -38,62 +38,62 @@ public class KeyboardTests Assert.True (v1.HasFocus); // Using default keys. - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (v2.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (v3.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (v4.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (v1.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithShift.WithCtrl); Assert.True (v4.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithShift.WithCtrl); Assert.True (v3.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithShift.WithCtrl); Assert.True (v2.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithShift.WithCtrl); Assert.True (v1.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageDown)); + top.NewKeyDownEvent (Key.PageDown.WithCtrl); Assert.True (v2.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageDown)); + top.NewKeyDownEvent (Key.PageDown.WithCtrl); Assert.True (v3.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageDown)); + top.NewKeyDownEvent (Key.PageDown.WithCtrl); Assert.True (v4.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageDown)); + top.NewKeyDownEvent (Key.PageDown.WithCtrl); Assert.True (v1.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageUp)); + top.NewKeyDownEvent (Key.PageUp.WithCtrl); Assert.True (v4.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageUp)); + top.NewKeyDownEvent (Key.PageUp.WithCtrl); Assert.True (v3.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageUp)); + top.NewKeyDownEvent (Key.PageUp.WithCtrl); Assert.True (v2.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.PageUp)); + top.NewKeyDownEvent (Key.PageUp.WithCtrl); Assert.True (v1.HasFocus); // Using another's alternate keys. - Application.AlternateForwardKey = KeyCode.F7; - Application.AlternateBackwardKey = KeyCode.F6; + Application.AlternateForwardKey = Key.F7; + Application.AlternateBackwardKey = Key.F6; - top.NewKeyDownEvent (new Key (KeyCode.F7)); + top.NewKeyDownEvent (Key.F7); Assert.True (v2.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F7)); + top.NewKeyDownEvent (Key.F7); Assert.True (v3.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F7)); + top.NewKeyDownEvent (Key.F7); Assert.True (v4.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F7)); + top.NewKeyDownEvent (Key.F7); Assert.True (v1.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F6)); + top.NewKeyDownEvent (Key.F6); Assert.True (v4.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F6)); + top.NewKeyDownEvent (Key.F6); Assert.True (v3.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F6)); + top.NewKeyDownEvent (Key.F6); Assert.True (v2.HasFocus); - top.NewKeyDownEvent (new Key (KeyCode.F6)); + top.NewKeyDownEvent (Key.F6); Assert.True (v1.HasFocus); Application.RequestStop (); @@ -102,9 +102,9 @@ public class KeyboardTests Application.Run (top); // Replacing the defaults keys to avoid errors on others unit tests that are using it. - Application.AlternateForwardKey = KeyCode.PageDown | KeyCode.CtrlMask; - Application.AlternateBackwardKey = KeyCode.PageUp | KeyCode.CtrlMask; - Application.QuitKey = KeyCode.Q | KeyCode.CtrlMask; + Application.AlternateForwardKey = Key.PageDown.WithCtrl; + Application.AlternateBackwardKey = Key.PageUp.WithCtrl; + Application.QuitKey = Key.Q.WithCtrl; Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey.KeyCode); Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey.KeyCode); @@ -158,14 +158,14 @@ public class KeyboardTests Assert.True (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (win2.CanFocus); Assert.False (win.HasFocus); Assert.True (win2.CanFocus); Assert.True (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.False (win.CanFocus); Assert.False (win.HasFocus); Assert.True (win2.CanFocus); @@ -219,14 +219,14 @@ public class KeyboardTests Assert.False (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (win.CanFocus); Assert.False (win.HasFocus); Assert.True (win2.CanFocus); Assert.True (win2.HasFocus); Assert.Equal ("win2", ((Window)top.Subviews [top.Subviews.Count - 1]).Title); - top.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); Assert.True (win.CanFocus); Assert.True (win.HasFocus); Assert.True (win2.CanFocus); @@ -342,31 +342,31 @@ public class KeyboardTests Application.Top.Add (view); Application.Begin (Application.Top); - Application.OnKeyDown (new Key (KeyCode.A)); + Application.OnKeyDown (Key.A); Assert.True (invoked); Assert.True (view.ApplicationCommand); invoked = false; view.ApplicationCommand = false; view.KeyBindings.Remove (KeyCode.A); - Application.OnKeyDown (new Key (KeyCode.A)); // old + Application.OnKeyDown (Key.A); // old Assert.False (invoked); Assert.False (view.ApplicationCommand); - view.KeyBindings.Add (KeyCode.A | KeyCode.CtrlMask, KeyBindingScope.Application, Command.Save); - Application.OnKeyDown (new Key (KeyCode.A)); // old + view.KeyBindings.Add (Key.A.WithCtrl, KeyBindingScope.Application, Command.Save); + Application.OnKeyDown (Key.A); // old Assert.False (invoked); Assert.False (view.ApplicationCommand); - Application.OnKeyDown (new Key (KeyCode.A | KeyCode.CtrlMask)); // new + Application.OnKeyDown (Key.A.WithCtrl); // new Assert.True (invoked); Assert.True (view.ApplicationCommand); invoked = false; - Application.OnKeyDown (new Key (KeyCode.H)); + Application.OnKeyDown (Key.H); Assert.True (invoked); invoked = false; Assert.False (view.HasFocus); - Application.OnKeyDown (new Key (KeyCode.F)); + Application.OnKeyDown (Key.F); Assert.False (invoked); Assert.True (view.ApplicationCommand); @@ -385,7 +385,7 @@ public class KeyboardTests Application.Top.Add (view); Application.Begin (Application.Top); - Application.OnKeyDown (new Key (KeyCode.A | KeyCode.CtrlMask)); + Application.OnKeyDown (Key.A.WithCtrl); Assert.False (invoked); Assert.False (view.ApplicationCommand); Assert.False (view.HotKeyCommand); @@ -393,7 +393,7 @@ public class KeyboardTests invoked = false; Assert.False (view.HasFocus); - Application.OnKeyDown (new Key (KeyCode.Z)); + Application.OnKeyDown (Key.Z); Assert.False (invoked); Assert.False (view.ApplicationCommand); Assert.False (view.HotKeyCommand); @@ -421,21 +421,21 @@ public class KeyboardTests Assert.True (isQuiting); isQuiting = false; - Application.OnKeyDown (new Key (KeyCode.Q | KeyCode.CtrlMask)); + Application.OnKeyDown (Key.Q.WithCtrl); Assert.True (isQuiting); isQuiting = false; - Application.QuitKey = KeyCode.C | KeyCode.CtrlMask; + Application.QuitKey = Key.C.WithCtrl; Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true); Assert.False (isQuiting); - Application.OnKeyDown (new Key (KeyCode.Q | KeyCode.CtrlMask)); + Application.OnKeyDown (Key.Q.WithCtrl); Assert.False (isQuiting); Application.OnKeyDown (Application.QuitKey); Assert.True (isQuiting); // Reset the QuitKey to avoid throws errors on another tests - Application.QuitKey = KeyCode.Q | KeyCode.CtrlMask; + Application.QuitKey = Key.Q.WithCtrl; } // test Application key Bindings @@ -444,12 +444,12 @@ public class KeyboardTests public ScopedKeyBindingView () { AddCommand (Command.Save, () => ApplicationCommand = true); - AddCommand (Command.Default, () => HotKeyCommand = true); + AddCommand (Command.HotKey, () => HotKeyCommand = true); AddCommand (Command.Left, () => FocusedCommand = true); - KeyBindings.Add (KeyCode.A, KeyBindingScope.Application, Command.Save); + KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Save); HotKey = KeyCode.H; - KeyBindings.Add (KeyCode.F, KeyBindingScope.Focused, Command.Left); + KeyBindings.Add (Key.F, KeyBindingScope.Focused, Command.Left); } public bool ApplicationCommand { get; set; } diff --git a/UnitTests/Application/MainLoopTests.cs b/UnitTests/Application/MainLoopTests.cs index 7cf27e92d..043927478 100644 --- a/UnitTests/Application/MainLoopTests.cs +++ b/UnitTests/Application/MainLoopTests.cs @@ -670,7 +670,7 @@ public class MainLoopTests var btnLaunch = new Button { Text = "Open Window" }; - btnLaunch.Clicked += (s, e) => action (); + btnLaunch.Accept += (s, e) => action (); Application.Top.Add (btnLaunch); @@ -684,7 +684,7 @@ public class MainLoopTests { Assert.Null (btn); Assert.Equal (zero, total); - Assert.True (btnLaunch.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (btnLaunch.NewKeyDownEvent (Key.Space)); if (btn == null) { @@ -701,7 +701,7 @@ public class MainLoopTests { Assert.Equal (clickMe, btn.Text); Assert.Equal (zero, total); - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (btn.NewKeyDownEvent (Key.Space)); Assert.Equal (cancel, btn.Text); Assert.Equal (one, total); } @@ -902,11 +902,11 @@ public class MainLoopTests btn = new Button { Text = "Click Me" }; - btn.Clicked += RunAsyncTest; + btn.Accept += RunAsyncTest; var totalbtn = new Button { X = Pos.Right (btn), Text = "total" }; - totalbtn.Clicked += (s, e) => { MessageBox.Query ("Count", $"Count is {total}", "Ok"); }; + totalbtn.Accept += (s, e) => { MessageBox.Query ("Count", $"Count is {total}", "Ok"); }; startWindow.Add (btn); startWindow.Add (totalbtn); diff --git a/UnitTests/Configuration/ConfigurationMangerTests.cs b/UnitTests/Configuration/ConfigurationMangerTests.cs index 56f0b543c..94f17eb7e 100644 --- a/UnitTests/Configuration/ConfigurationMangerTests.cs +++ b/UnitTests/Configuration/ConfigurationMangerTests.cs @@ -30,9 +30,9 @@ public class ConfigurationManagerTests } // act - Settings ["Application.QuitKey"].PropertyValue = new Key (KeyCode.Q); - Settings ["Application.AlternateForwardKey"].PropertyValue = new Key (KeyCode.F); - Settings ["Application.AlternateBackwardKey"].PropertyValue = new Key (KeyCode.B); + Settings ["Application.QuitKey"].PropertyValue = Key.Q; + Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F; + Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B; Settings ["Application.IsMouseDisabled"].PropertyValue = true; Apply (); @@ -143,9 +143,9 @@ public class ConfigurationManagerTests { Reset (); - Settings ["Application.QuitKey"].PropertyValue = new Key (KeyCode.Q); - Settings ["Application.AlternateForwardKey"].PropertyValue = new Key (KeyCode.F); - Settings ["Application.AlternateBackwardKey"].PropertyValue = new Key (KeyCode.B); + Settings ["Application.QuitKey"].PropertyValue = Key.Q; + Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F; + Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B; Settings ["Application.IsMouseDisabled"].PropertyValue = true; Updated += ConfigurationManager_Updated; @@ -221,9 +221,9 @@ public class ConfigurationManagerTests // arrange Reset (); - Settings ["Application.QuitKey"].PropertyValue = new Key (KeyCode.Q); - Settings ["Application.AlternateForwardKey"].PropertyValue = new Key (KeyCode.F); - Settings ["Application.AlternateBackwardKey"].PropertyValue = new Key (KeyCode.B); + Settings ["Application.QuitKey"].PropertyValue = Key.Q; + Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F; + Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B; Settings ["Application.IsMouseDisabled"].PropertyValue = true; Settings.Apply (); @@ -245,9 +245,9 @@ public class ConfigurationManagerTests Assert.False (Application.IsMouseDisabled); // arrange - Settings ["Application.QuitKey"].PropertyValue = new Key (KeyCode.Q); - Settings ["Application.AlternateForwardKey"].PropertyValue = new Key (KeyCode.F); - Settings ["Application.AlternateBackwardKey"].PropertyValue = new Key (KeyCode.B); + Settings ["Application.QuitKey"].PropertyValue = Key.Q; + Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F; + Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B; Settings ["Application.IsMouseDisabled"].PropertyValue = true; Settings.Apply (); diff --git a/UnitTests/Configuration/JsonConverterTests.cs b/UnitTests/Configuration/JsonConverterTests.cs index d4af116ec..bb9733080 100644 --- a/UnitTests/Configuration/JsonConverterTests.cs +++ b/UnitTests/Configuration/JsonConverterTests.cs @@ -299,8 +299,6 @@ public class KeyJsonConverterTests [InlineData (KeyCode.A | KeyCode.ShiftMask, "\"A\"")] [InlineData (KeyCode.A | KeyCode.CtrlMask, "\"Ctrl+A\"")] [InlineData (KeyCode.A | KeyCode.AltMask | KeyCode.CtrlMask, "\"Ctrl+Alt+A\"")] - [InlineData ((KeyCode)'a' | KeyCode.AltMask | KeyCode.CtrlMask, "\"Ctrl+Alt+A\"")] - [InlineData ((KeyCode)'a' | KeyCode.ShiftMask, "\"A\"")] [InlineData (KeyCode.Delete | KeyCode.AltMask | KeyCode.CtrlMask, "\"Ctrl+Alt+Delete\"")] [InlineData (KeyCode.D4, "\"4\"")] [InlineData (KeyCode.Esc, "\"Esc\"")] @@ -323,8 +321,6 @@ public class KeyJsonConverterTests [InlineData (KeyCode.A | KeyCode.ShiftMask, "A")] [InlineData (KeyCode.A | KeyCode.CtrlMask, "Ctrl+A")] [InlineData (KeyCode.A | KeyCode.AltMask | KeyCode.CtrlMask, "Ctrl+Alt+A")] - [InlineData ((KeyCode)'a' | KeyCode.AltMask | KeyCode.CtrlMask, "Ctrl+Alt+A")] - [InlineData ((KeyCode)'a' | KeyCode.ShiftMask, "A")] [InlineData (KeyCode.Delete | KeyCode.AltMask | KeyCode.CtrlMask, "Ctrl+Alt+Delete")] [InlineData (KeyCode.D4, "4")] [InlineData (KeyCode.Esc, "Esc")] diff --git a/UnitTests/Configuration/SettingsScopeTests.cs b/UnitTests/Configuration/SettingsScopeTests.cs index 9d3aaec64..04ce56862 100644 --- a/UnitTests/Configuration/SettingsScopeTests.cs +++ b/UnitTests/Configuration/SettingsScopeTests.cs @@ -23,9 +23,9 @@ public class SettingsScopeTests Assert.False ((bool)Settings ["Application.IsMouseDisabled"].PropertyValue); // act - Settings ["Application.QuitKey"].PropertyValue = new Key (KeyCode.Q); - Settings ["Application.AlternateForwardKey"].PropertyValue = new Key (KeyCode.F); - Settings ["Application.AlternateBackwardKey"].PropertyValue = new Key (KeyCode.B); + Settings ["Application.QuitKey"].PropertyValue = Key.Q; + Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F; + Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B; Settings ["Application.IsMouseDisabled"].PropertyValue = true; Settings.Apply (); @@ -41,14 +41,14 @@ public class SettingsScopeTests [AutoInitShutdown] public void CopyUpdatedPropertiesFrom_ShouldCopyChangedPropertiesOnly () { - Settings ["Application.QuitKey"].PropertyValue = new Key (KeyCode.End); + Settings ["Application.QuitKey"].PropertyValue = Key.End; ; var updatedSettings = new SettingsScope (); ///Don't set Quitkey - updatedSettings ["Application.AlternateForwardKey"].PropertyValue = new Key (KeyCode.F); - updatedSettings ["Application.AlternateBackwardKey"].PropertyValue = new Key (KeyCode.B); + updatedSettings ["Application.AlternateForwardKey"].PropertyValue = Key.F; + updatedSettings ["Application.AlternateBackwardKey"].PropertyValue = Key.B; updatedSettings ["Application.IsMouseDisabled"].PropertyValue = true; Settings.Update (updatedSettings); diff --git a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs index 51b914f95..1ac22ef4b 100644 --- a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs +++ b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using System.Text; +using Xunit.Abstractions; // Alias Console to MockConsole so we don't accidentally use Console using Console = Terminal.Gui.FakeConsole; @@ -42,7 +43,7 @@ public class ConsoleDriverTests foreach (char r in text.Reverse ()) { ConsoleKey ck = char.IsLetter (r) ? (ConsoleKey)char.ToUpper (r) : (ConsoleKey)r; - var cki = new ConsoleKeyInfo (r, ck, false, false, false); + var cki = new ConsoleKeyInfo (r, ck, char.IsUpper(r), false, false); mKeys.Push (cki); } @@ -55,8 +56,8 @@ public class ConsoleDriverTests view.KeyDown += (s, e) => { - Assert.Equal (text [idx], (char)e.KeyCode); - rText += (char)e.KeyCode; + Assert.Equal (new Rune(text [idx]), e.AsRune); + rText += e.AsRune; Assert.Equal (rText, text.Substring (0, idx + 1)); e.Handled = true; idx++; diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index 893cbc7de..205552451 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -982,18 +982,18 @@ public class DialogTests Button btn3 = null; string expected = null; - btn1.Clicked += (s, e) => + btn1.Accept += (s, e) => { btn2 = new Button { Text = "Show Sub" }; btn3 = new Button { Text = "Close" }; - btn3.Clicked += (s, e) => RequestStop (); + btn3.Accept += (s, e) => RequestStop (); - btn2.Clicked += (s, e) => + btn2.Accept += (s, e) => { // Don't test MessageBox in Dialog unit tests! var subBtn = new Button { Text = "Ok", IsDefault = true }; var subDlg = new Dialog { Text = "ya", Width = 20, Height = 5, Buttons = [subBtn] }; - subBtn.Clicked += (s, e) => RequestStop (subDlg); + subBtn.Accept += (s, e) => RequestStop (subDlg); Run (subDlg); }; var dlg = new Dialog { Buttons = [btn2, btn3] }; @@ -1020,7 +1020,7 @@ public class DialogTests if (iterations == 0) { - Assert.True (btn1.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (btn1.NewKeyDownEvent (Key.Space)); } else if (iterations == 1) { @@ -1043,7 +1043,7 @@ public class DialogTests └───────────────────────┘"; TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (btn2.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (btn2.NewKeyDownEvent (Key.Space)); } else if (iterations == 2) { @@ -1070,13 +1070,13 @@ public class DialogTests _output ); - Assert.True (Current.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (Current.NewKeyDownEvent (Key.Enter)); } else if (iterations == 3) { TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (btn3.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (btn3.NewKeyDownEvent (Key.Space)); } else if (iterations == 4) { diff --git a/UnitTests/Dialogs/WizardTests.cs b/UnitTests/Dialogs/WizardTests.cs index 58f456ad1..ede643c73 100644 --- a/UnitTests/Dialogs/WizardTests.cs +++ b/UnitTests/Dialogs/WizardTests.cs @@ -38,7 +38,7 @@ public class WizardTests var firstIteration = true; Application.RunIteration (ref runstate, ref firstIteration); - wizard.NextFinishButton.OnClicked (); + wizard.NextFinishButton.OnAccept (); Application.RunIteration (ref runstate, ref firstIteration); Application.End (runstate); Assert.True (finishedFired); @@ -64,13 +64,13 @@ public class WizardTests Application.RunIteration (ref runstate, ref firstIteration); Assert.Equal (step1.Title, wizard.CurrentStep.Title); - wizard.NextFinishButton.OnClicked (); + wizard.NextFinishButton.OnAccept (); Assert.False (finishedFired); Assert.False (closedFired); Assert.Equal (step2.Title, wizard.CurrentStep.Title); Assert.Equal (wizard.GetLastStep ().Title, wizard.CurrentStep.Title); - wizard.NextFinishButton.OnClicked (); + wizard.NextFinishButton.OnAccept (); Application.End (runstate); Assert.True (finishedFired); Assert.True (closedFired); @@ -99,7 +99,7 @@ public class WizardTests Assert.Equal (step2.Title, wizard.CurrentStep.Title); Assert.Equal (wizard.GetLastStep ().Title, wizard.CurrentStep.Title); - wizard.NextFinishButton.OnClicked (); + wizard.NextFinishButton.OnAccept (); Application.End (runstate); Assert.True (finishedFired); Assert.True (closedFired); @@ -606,7 +606,7 @@ public class WizardTests Assert.Equal (string.Empty, r.Title); var expected = string.Empty; - r.TitleChanged += (s, args) => { Assert.Equal (r.Title, args.NewTitle); }; + r.TitleChanged += (s, args) => { Assert.Equal (r.Title, args.NewValue); }; expected = "title"; r.Title = expected; @@ -630,7 +630,7 @@ public class WizardTests r.TitleChanging += (s, args) => { - Assert.Equal (expectedDuring, args.NewTitle); + Assert.Equal (expectedDuring, args.NewValue); args.Cancel = cancel; }; diff --git a/UnitTests/FileServices/FileDialogTests.cs b/UnitTests/FileServices/FileDialogTests.cs index a4d4321cb..db3d07e66 100644 --- a/UnitTests/FileServices/FileDialogTests.cs +++ b/UnitTests/FileServices/FileDialogTests.cs @@ -48,9 +48,9 @@ public class FileDialogTests ); // continue typing the rest of the path - Send ("bob"); + Send ("BOB"); Send ('.', ConsoleKey.OemPeriod); - Send ("csv"); + Send ("CSV"); Assert.True (dlg.Canceled); @@ -73,7 +73,7 @@ public class FileDialogTests dlg.Path = openIn + Path.DirectorySeparatorChar; - Send ("x"); + Send ("X"); // nothing selected yet Assert.True (dlg.Canceled); @@ -103,9 +103,9 @@ public class FileDialogTests #if BROKE_IN_2927 Send ('f', ConsoleKey.F, false, true, false); #else - Application.OnKeyDown (new Key (KeyCode.Tab)); - Application.OnKeyDown (new Key (KeyCode.Tab)); - Application.OnKeyDown (new Key (KeyCode.Tab)); + Application.OnKeyDown (Key.Tab); + Application.OnKeyDown (Key.Tab); + Application.OnKeyDown (Key.Tab); #endif Assert.IsType (dlg.MostFocused); @@ -359,7 +359,7 @@ public class FileDialogTests // so to add to current path user must press End or right Send ('>', ConsoleKey.RightArrow); - Send ("subfolder"); + Send ("SUBFOLDER"); // Dialog has not yet been confirmed with a choice Assert.True (dlg.Canceled); diff --git a/UnitTests/Input/KeyBindingTests.cs b/UnitTests/Input/KeyBindingTests.cs index e9ac956bd..f7c248c92 100644 --- a/UnitTests/Input/KeyBindingTests.cs +++ b/UnitTests/Input/KeyBindingTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using UICatalog.Scenarios; +using Xunit.Abstractions; namespace Terminal.Gui.InputTests; @@ -36,13 +37,13 @@ public class KeyBindingTests public void Add_Single_Adds () { var keyBindings = new KeyBindings (); - keyBindings.Add (Key.A, Command.Default); + keyBindings.Add (Key.A, Command.HotKey); Command [] resultCommands = keyBindings.GetCommands (Key.A); - Assert.Contains (Command.Default, resultCommands); + Assert.Contains (Command.HotKey, resultCommands); - keyBindings.Add (Key.B, Command.Default); + keyBindings.Add (Key.B, Command.HotKey); resultCommands = keyBindings.GetCommands (Key.B); - Assert.Contains (Command.Default, resultCommands); + Assert.Contains (Command.HotKey, resultCommands); } // Clear @@ -50,8 +51,7 @@ public class KeyBindingTests public void Clear_Clears () { var keyBindings = new KeyBindings (); - keyBindings.Add (Key.A, Command.Default); - keyBindings.Add (Key.B, Command.Default); + keyBindings.Add (Key.B, Command.HotKey); keyBindings.Clear (); Command [] resultCommands = keyBindings.GetCommands (Key.A); Assert.Empty (resultCommands); @@ -79,9 +79,9 @@ public class KeyBindingTests public void GetCommands_WithCommands_ReturnsCommands () { var keyBindings = new KeyBindings (); - keyBindings.Add (Key.A, Command.Default); + keyBindings.Add (Key.A, Command.HotKey); Command [] resultCommands = keyBindings.GetCommands (Key.A); - Assert.Contains (Command.Default, resultCommands); + Assert.Contains (Command.HotKey, resultCommands); } [Fact] @@ -155,8 +155,8 @@ public class KeyBindingTests public void GetKeyFromCommands_WithCommands_ReturnsKey () { var keyBindings = new KeyBindings (); - keyBindings.Add (Key.A, Command.Default); - Key resultKey = keyBindings.GetKeyFromCommands (Command.Default); + keyBindings.Add (Key.A, Command.HotKey); + Key resultKey = keyBindings.GetKeyFromCommands (Command.HotKey); Assert.Equal (Key.A, resultKey); } @@ -164,26 +164,26 @@ public class KeyBindingTests public void Replace_Key () { var keyBindings = new KeyBindings (); - keyBindings.Add (Key.A, Command.Default); - keyBindings.Add (Key.B, Command.Default); - keyBindings.Add (Key.C, Command.Default); - keyBindings.Add (Key.D, Command.Default); + keyBindings.Add (Key.A, Command.HotKey); + keyBindings.Add (Key.B, Command.HotKey); + keyBindings.Add (Key.C, Command.HotKey); + keyBindings.Add (Key.D, Command.HotKey); keyBindings.Replace (Key.A, Key.E); Assert.Empty (keyBindings.GetCommands (Key.A)); - Assert.Contains (Command.Default, keyBindings.GetCommands (Key.E)); + Assert.Contains (Command.HotKey, keyBindings.GetCommands (Key.E)); keyBindings.Replace (Key.B, Key.E); Assert.Empty (keyBindings.GetCommands (Key.B)); - Assert.Contains (Command.Default, keyBindings.GetCommands (Key.E)); + Assert.Contains (Command.HotKey, keyBindings.GetCommands (Key.E)); keyBindings.Replace (Key.C, Key.E); Assert.Empty (keyBindings.GetCommands (Key.C)); - Assert.Contains (Command.Default, keyBindings.GetCommands (Key.E)); + Assert.Contains (Command.HotKey, keyBindings.GetCommands (Key.E)); keyBindings.Replace (Key.D, Key.E); Assert.Empty (keyBindings.GetCommands (Key.D)); - Assert.Contains (Command.Default, keyBindings.GetCommands (Key.E)); + Assert.Contains (Command.HotKey, keyBindings.GetCommands (Key.E)); } // Add with scope does the right things @@ -196,16 +196,17 @@ public class KeyBindingTests var keyBindings = new KeyBindings (); Command [] commands = { Command.Right, Command.Left }; + var key = new Key (Key.A); keyBindings.Add (Key.A, scope, commands); - KeyBinding binding = keyBindings.Get (Key.A); + KeyBinding binding = keyBindings.Get (key); Assert.Contains (Command.Right, binding.Commands); Assert.Contains (Command.Left, binding.Commands); - binding = keyBindings.Get (Key.A, scope); + binding = keyBindings.Get (key, scope); Assert.Contains (Command.Right, binding.Commands); Assert.Contains (Command.Left, binding.Commands); - Command [] resultCommands = keyBindings.GetCommands (Key.A); + Command [] resultCommands = keyBindings.GetCommands (key); Assert.Contains (Command.Right, resultCommands); Assert.Contains (Command.Left, resultCommands); } @@ -219,20 +220,49 @@ public class KeyBindingTests var keyBindings = new KeyBindings (); Command [] commands = { Command.Right, Command.Left }; - keyBindings.Add (Key.A, scope, commands); - KeyBinding binding = keyBindings.Get (Key.A); + var key = new Key (Key.A); + keyBindings.Add (key, scope, commands); + KeyBinding binding = keyBindings.Get (key); Assert.Contains (Command.Right, binding.Commands); Assert.Contains (Command.Left, binding.Commands); - binding = keyBindings.Get (Key.A, scope); + binding = keyBindings.Get (key, scope); Assert.Contains (Command.Right, binding.Commands); Assert.Contains (Command.Left, binding.Commands); // negative test - binding = keyBindings.Get (Key.A, (KeyBindingScope)(-1)); + binding = keyBindings.Get (key, (KeyBindingScope)0); Assert.Null (binding); - Command [] resultCommands = keyBindings.GetCommands (Key.A); + Command [] resultCommands = keyBindings.GetCommands (key); + Assert.Contains (Command.Right, resultCommands); + Assert.Contains (Command.Left, resultCommands); + } + + [Theory] + [InlineData (KeyBindingScope.Focused)] + [InlineData (KeyBindingScope.HotKey)] + [InlineData (KeyBindingScope.Application)] + public void Scope_TryGet_Filters (KeyBindingScope scope) + { + var keyBindings = new KeyBindings (); + Command [] commands = { Command.Right, Command.Left }; + + var key = new Key (Key.A); + keyBindings.Add (key, scope, commands); + bool success = keyBindings.TryGet (key, out KeyBinding binding); + Assert.Contains (Command.Right, binding.Commands); + Assert.Contains (Command.Left, binding.Commands); + + success = keyBindings.TryGet (key, scope, out binding); + Assert.Contains (Command.Right, binding.Commands); + Assert.Contains (Command.Left, binding.Commands); + + // negative test + success = keyBindings.TryGet (key, (KeyBindingScope)0, out binding); + Assert.False (success); + + Command [] resultCommands = keyBindings.GetCommands (key); Assert.Contains (Command.Right, resultCommands); Assert.Contains (Command.Left, resultCommands); } @@ -250,9 +280,9 @@ public class KeyBindingTests public void TryGet_WithCommands_ReturnsTrue () { var keyBindings = new KeyBindings (); - keyBindings.Add (Key.A, Command.Default); + keyBindings.Add (Key.A, Command.HotKey); bool result = keyBindings.TryGet (Key.A, out KeyBinding bindings); Assert.True (result); - Assert.Contains (Command.Default, bindings.Commands); + Assert.Contains (Command.HotKey, bindings.Commands); } } diff --git a/UnitTests/Input/KeyTests.cs b/UnitTests/Input/KeyTests.cs index b3785086c..15d123fb2 100644 --- a/UnitTests/Input/KeyTests.cs +++ b/UnitTests/Input/KeyTests.cs @@ -12,61 +12,47 @@ public class KeyTests public static TheoryData ValidStrings => new () { - { "a", new Key (KeyCode.A) }, - { "Ctrl+A", new Key (KeyCode.A | KeyCode.CtrlMask) }, - { "Alt+A", new Key (KeyCode.A | KeyCode.AltMask) }, - { "Shift+A", new Key (KeyCode.A | KeyCode.ShiftMask) }, - { "A", new Key (KeyCode.A | KeyCode.ShiftMask) }, + { "a", Key.A }, + { "Ctrl+A", Key.A.WithCtrl }, + { "Alt+A", Key.A.WithAlt }, + { "Shift+A", Key.A.WithShift }, + { "A", Key.A.WithShift }, { "â", new Key ((KeyCode)'â') }, { "Shift+â", new Key ((KeyCode)'â' | KeyCode.ShiftMask) }, { "Shift+Â", new Key ((KeyCode)'Â' | KeyCode.ShiftMask) }, - { "Ctrl+Shift+CursorUp", new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.CursorUp) }, - { - "Ctrl+Alt+Shift+CursorUp", - new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.AltMask | KeyCode.CursorUp) - }, - { - "ctrl+alt+shift+cursorup", - new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.AltMask | KeyCode.CursorUp) - }, - { - "CTRL+ALT+SHIFT+CURSORUP", - new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.AltMask | KeyCode.CursorUp) - }, - { - "Ctrl+Alt+Shift+Delete", - new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.AltMask | KeyCode.Delete) - }, - { - "Ctrl+Alt+Shift+Enter", new Key (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.AltMask | KeyCode.Enter) - }, - { "Tab", new Key (KeyCode.Tab) }, - { "Shift+Tab", new Key (KeyCode.Tab | KeyCode.ShiftMask) }, - { "Ctrl+Tab", new Key (KeyCode.Tab | KeyCode.CtrlMask) }, - { "Alt+Tab", new Key (KeyCode.Tab | KeyCode.AltMask) }, - { "Ctrl+Shift+Tab", new Key (KeyCode.Tab | KeyCode.ShiftMask | KeyCode.CtrlMask) }, - { "Ctrl+Alt+Tab", new Key (KeyCode.Tab | KeyCode.AltMask | KeyCode.CtrlMask) }, - { "", new Key (KeyCode.Null) }, - { " ", new Key (KeyCode.Space) }, - { "Space", new Key (KeyCode.Space) }, - { "Shift+Space", new Key (KeyCode.Space | KeyCode.ShiftMask) }, - { "Ctrl+Space", new Key (KeyCode.Space | KeyCode.CtrlMask) }, - { "Alt+Space", new Key (KeyCode.Space | KeyCode.AltMask) }, - { "Shift+ ", new Key (KeyCode.Space | KeyCode.ShiftMask) }, - { "Ctrl+ ", new Key (KeyCode.Space | KeyCode.CtrlMask) }, - { "Alt+ ", new Key (KeyCode.Space | KeyCode.AltMask) }, - { "F1", new Key (KeyCode.F1) }, - { "0", new Key (KeyCode.D0) }, - { "9", new Key (KeyCode.D9) }, - { "D0", new Key (KeyCode.D0) }, - { "65", new Key (KeyCode.A | KeyCode.ShiftMask) }, - { "97", new Key (KeyCode.A) }, - { "Shift", new Key (KeyCode.ShiftMask) }, - { "Ctrl", new Key (KeyCode.CtrlMask) }, - { "Ctrl-A", new Key (KeyCode.A | KeyCode.CtrlMask) }, - { "Alt-A", new Key (KeyCode.A | KeyCode.AltMask) }, - { "A-Ctrl", new Key (KeyCode.A | KeyCode.CtrlMask) }, - { "Alt-A-Ctrl", new Key (KeyCode.A | KeyCode.CtrlMask | KeyCode.AltMask) } + { "Ctrl+Shift+CursorUp", Key.CursorUp.WithShift.WithCtrl }, + { "Ctrl+Alt+Shift+CursorUp", Key.CursorUp.WithShift.WithCtrl.WithAlt }, + { "ctrl+alt+shift+cursorup", Key.CursorUp.WithShift.WithCtrl.WithAlt }, + { "CTRL+ALT+SHIFT+CURSORUP", Key.CursorUp.WithShift.WithCtrl.WithAlt }, + { "Ctrl+Alt+Shift+Delete", Key.Delete.WithCtrl.WithAlt.WithShift }, + { "Ctrl+Alt+Shift+Enter", Key.Enter.WithCtrl.WithAlt.WithShift }, + { "Tab", Key.Tab }, + { "Shift+Tab", Key.Tab.WithShift }, + { "Ctrl+Tab", Key.Tab.WithCtrl }, + { "Alt+Tab", Key.Tab.WithAlt }, + { "Ctrl+Shift+Tab", Key.Tab.WithShift.WithCtrl }, + { "Ctrl+Alt+Tab", Key.Tab.WithAlt.WithCtrl }, + { "", Key.Empty }, + { " ", Key.Space }, + { "Space", Key.Space }, + { "Shift+Space", Key.Space.WithShift }, + { "Ctrl+Space", Key.Space.WithCtrl }, + { "Alt+Space", Key.Space.WithAlt }, + { "Shift+ ", Key.Space.WithShift }, + { "Ctrl+ ", Key.Space.WithCtrl }, + { "Alt+ ", Key.Space.WithAlt }, + { "F1", Key.F1 }, + { "0", Key.D0 }, + { "9", Key.D9 }, + { "D0", Key.D0 }, + { "65", Key.A.WithShift }, + { "97", Key.A }, + { "Shift", KeyCode.ShiftMask }, + { "Ctrl", KeyCode.CtrlMask }, + { "Ctrl-A", Key.A.WithCtrl }, + { "Alt-A", Key.A.WithAlt }, + { "A-Ctrl", Key.A.WithCtrl }, + { "Alt-A-Ctrl", Key.A.WithCtrl.WithAlt } }; [Theory] @@ -80,8 +66,7 @@ public class KeyTests [InlineData ((KeyCode)'ó' | KeyCode.ShiftMask, 'ó')] [InlineData ((KeyCode)'Ó', 'Ó')] [InlineData ((KeyCode)'ç' | KeyCode.ShiftMask | KeyCode.AltMask | KeyCode.CtrlMask, '\0')] - [InlineData ((KeyCode)'a', 97)] // 97 or Key.Space | Key.A - [InlineData ((KeyCode)'A', 97)] // 65 or equivalent to Key.A, but A-Z are mapped to lower case by drivers + [InlineData (KeyCode.A, 97)] // 65 or equivalent to Key.A, but A-Z are mapped to lower case by drivers //[InlineData (Key.A, 97)] // 65 equivalent to (Key)'A', but A-Z are mapped to lower case by drivers [InlineData (KeyCode.ShiftMask | KeyCode.A, 65)] [InlineData (KeyCode.CtrlMask | KeyCode.A, '\0')] @@ -90,8 +75,7 @@ public class KeyTests [InlineData (KeyCode.ShiftMask | KeyCode.AltMask | KeyCode.A, '\0')] [InlineData (KeyCode.AltMask | KeyCode.CtrlMask | KeyCode.A, '\0')] [InlineData (KeyCode.ShiftMask | KeyCode.CtrlMask | KeyCode.AltMask | KeyCode.A, '\0')] - [InlineData ((KeyCode)'z', 'z')] - [InlineData ((KeyCode)'Z', 'z')] + [InlineData (KeyCode.Z, 'z')] [InlineData (KeyCode.ShiftMask | KeyCode.Z, 'Z')] [InlineData ((KeyCode)'1', '1')] [InlineData (KeyCode.ShiftMask | KeyCode.D1, '1')] @@ -156,9 +140,9 @@ public class KeyTests [Theory] [InlineData (KeyCode.Enter, KeyCode.Enter)] [InlineData (KeyCode.Esc, KeyCode.Esc)] - [InlineData (KeyCode.A, (KeyCode)'a')] + [InlineData (KeyCode.A, KeyCode.A)] [InlineData (KeyCode.A | KeyCode.ShiftMask, KeyCode.A | KeyCode.ShiftMask)] - [InlineData (KeyCode.Z, (KeyCode)'z')] + [InlineData (KeyCode.Z, KeyCode.Z)] [InlineData (KeyCode.Space, KeyCode.Space)] public void Cast_KeyCode_To_Key (KeyCode cdk, KeyCode expected) { @@ -265,8 +249,6 @@ public class KeyTests } [Theory] - [InlineData ((KeyCode)'a', true)] - [InlineData ((KeyCode)'a' | KeyCode.ShiftMask, true)] [InlineData (KeyCode.A, true)] [InlineData (KeyCode.A | KeyCode.ShiftMask, true)] [InlineData (KeyCode.F, true)] @@ -319,14 +301,14 @@ public class KeyTests Assert.Equal (KeyCode.Delete | KeyCode.AltMask, CAD.NoCtrl); - Key a = new Key (KeyCode.A).WithCtrl.WithAlt.WithShift; + Key a = Key.A.WithCtrl.WithAlt.WithShift; Assert.Equal (KeyCode.A, a.NoCtrl.NoShift.NoAlt); Assert.Equal (KeyCode.A, a.NoAlt.NoShift.NoCtrl); Assert.Equal (KeyCode.A, a.NoAlt.NoShift.NoCtrl.NoCtrl.NoAlt.NoShift); Assert.Equal (Key.Delete, Key.Delete.WithCtrl.NoCtrl); - Assert.Equal ((KeyCode)Key.Delete | KeyCode.CtrlMask, Key.Delete.NoCtrl.WithCtrl); + Assert.Equal ((KeyCode)Key.Delete.WithCtrl, Key.Delete.NoCtrl.WithCtrl); } [Fact] @@ -461,7 +443,7 @@ public class KeyTests [Fact] public void ToString_ShouldReturnReadableString () { - var eventArgs = new Key (KeyCode.CtrlMask | KeyCode.A); + var eventArgs = Key.A.WithCtrl; Assert.Equal ("Ctrl+A", eventArgs.ToString ()); } @@ -540,10 +522,38 @@ public class KeyTests [Fact] public void WithShift_ShouldReturnCorrectValue () { - var a = new Key (KeyCode.A); + var a = Key.A; Assert.Equal (KeyCode.A | KeyCode.ShiftMask, a.WithShift); Key CAD = Key.Delete.WithCtrl.WithAlt; Assert.Equal (KeyCode.Delete | KeyCode.CtrlMask | KeyCode.AltMask, CAD); } + + // Test Equals + [Fact] + public void Equals_ShouldReturnTrue_WhenEqual () + { + var a = Key.A; + var b = Key.A; + Assert.True (a.Equals (b)); + } + + [Fact] + public void Equals_Handled_Changed_ShouldReturnTrue_WhenEqual () + { + var a = Key.A; + a.Handled = true; + var b = Key.A; + b.Handled = true; + Assert.True (a.Equals (b)); + } + + [Fact] + public void Equals_Handled_Changed_ShouldReturnFalse_WhenNotEqual () + { + var a = Key.A; + a.Handled = true; + var b = Key.A; + Assert.False (a.Equals (b)); + } } diff --git a/UnitTests/Text/AutocompleteTests.cs b/UnitTests/Text/AutocompleteTests.cs index b19cd8708..f44f48ca9 100644 --- a/UnitTests/Text/AutocompleteTests.cs +++ b/UnitTests/Text/AutocompleteTests.cs @@ -26,7 +26,7 @@ public class AutocompleteTests for (var i = 0; i < 7; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); if (i < 4 || i > 5) @@ -64,7 +64,7 @@ This a long line and against TextView. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.G))); + Assert.True (tv.NewKeyDownEvent (Key.G)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -74,7 +74,7 @@ This ag long line and against TextView. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -84,7 +84,7 @@ This ag long line and against TextView. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -94,7 +94,7 @@ This ag long line and against TextView. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -105,7 +105,7 @@ This ag long line and against TextView.", for (var i = 0; i < 3; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -116,7 +116,7 @@ This ag long line and against TextView. ); } - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -127,7 +127,7 @@ This a long line and against TextView. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.N))); + Assert.True (tv.NewKeyDownEvent (Key.N)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -137,7 +137,7 @@ This an long line and against TextView. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -172,7 +172,7 @@ This an long line and against TextView.", Assert.Equal ("feature", g.AllSuggestions [^1]); Assert.Equal (0, tv.Autocomplete.SelectedIdx); Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.F | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithShift)); top.Draw (); Assert.Equal ("F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -181,7 +181,7 @@ This an long line and against TextView.", Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (0, tv.Autocomplete.SelectedIdx); Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (tv.NewKeyDownEvent (Key.CursorDown)); top.Draw (); Assert.Equal ("F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -190,7 +190,7 @@ This an long line and against TextView.", Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (1, tv.Autocomplete.SelectedIdx); Assert.Equal ("feature", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (tv.NewKeyDownEvent (Key.CursorDown)); top.Draw (); Assert.Equal ("F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -199,7 +199,7 @@ This an long line and against TextView.", Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (0, tv.Autocomplete.SelectedIdx); Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (tv.NewKeyDownEvent (Key.CursorUp)); top.Draw (); Assert.Equal ("F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -208,7 +208,7 @@ This an long line and against TextView.", Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement); Assert.Equal (1, tv.Autocomplete.SelectedIdx); Assert.Equal ("feature", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (tv.NewKeyDownEvent (Key.CursorUp)); top.Draw (); Assert.Equal ("F Fortunately super feature.", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 2159193d0..2a15d53cb 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -21,13 +21,13 @@ TRACE;DEBUG_IDISPOSABLE - - + + - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/UnitTests/View/Adornment/BorderTests.cs b/UnitTests/View/Adornment/BorderTests.cs index f9917f160..606d5d02e 100644 --- a/UnitTests/View/Adornment/BorderTests.cs +++ b/UnitTests/View/Adornment/BorderTests.cs @@ -17,7 +17,8 @@ public class BorderTests view.ColorScheme = new ColorScheme { - Normal = new Attribute (Color.Red, Color.Green), Focus = new Attribute (Color.Green, Color.Red) + Normal = new Attribute (Color.Red, Color.Green), + Focus = new Attribute (Color.Green, Color.Red) }; Assert.NotEqual (view.ColorScheme.Normal.Foreground, view.ColorScheme.Focus.Foreground); Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ()); diff --git a/UnitTests/View/HotKeyTests.cs b/UnitTests/View/HotKeyTests.cs index 1c6c5769e..f1b3109f9 100644 --- a/UnitTests/View/HotKeyTests.cs +++ b/UnitTests/View/HotKeyTests.cs @@ -28,9 +28,9 @@ public class HotKeyTests // As passed Command [] commands = view.KeyBindings.GetCommands (key); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (key | KeyCode.AltMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); KeyCode baseKey = key & ~KeyCode.ShiftMask; @@ -38,13 +38,13 @@ public class HotKeyTests if (baseKey is >= KeyCode.A and <= KeyCode.Z) { commands = view.KeyBindings.GetCommands (key | KeyCode.ShiftMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (key & ~KeyCode.ShiftMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (key | KeyCode.AltMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands ((key & ~KeyCode.ShiftMask) | KeyCode.AltMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); } else { @@ -83,10 +83,10 @@ public class HotKeyTests [InlineData (KeyCode.ShiftMask | KeyCode.CtrlMask, false)] public void KeyPress_Runs_Default_HotKey_Command (KeyCode mask, bool expected) { - var view = new View { HotKeySpecifier = (Rune)'^', Text = "^Test" }; + var view = new View { HotKeySpecifier = (Rune)'^', Title = "^Test" }; view.CanFocus = true; Assert.False (view.HasFocus); - view.NewKeyDownEvent (new Key (KeyCode.T | mask)); + view.NewKeyDownEvent (KeyCode.T | mask); Assert.Equal (expected, view.HasFocus); } @@ -94,20 +94,20 @@ public class HotKeyTests public void ProcessKeyDown_Ignores_KeyBindings_Out_Of_Scope_SuperView () { var view = new View (); - view.KeyBindings.Add (KeyCode.A, Command.Default); + view.KeyBindings.Add (Key.A, Command.HotKey); view.InvokingKeyBindings += (s, e) => { Assert.Fail (); }; var superView = new View (); superView.Add (view); - var ke = new Key (KeyCode.A); + var ke = Key.A; superView.NewKeyDownEvent (ke); } [Fact] public void ProcessKeyDown_Invokes_HotKey_Command_With_SuperView () { - var view = new View { HotKeySpecifier = (Rune)'^', Text = "^Test" }; + var view = new View { HotKeySpecifier = (Rune)'^', Title = "^Test" }; var superView = new View (); superView.Add (view); @@ -115,7 +115,7 @@ public class HotKeyTests view.CanFocus = true; Assert.False (view.HasFocus); - var ke = new Key (KeyCode.T); + var ke = Key.T; superView.NewKeyDownEvent (ke); Assert.True (view.HasFocus); } @@ -130,16 +130,16 @@ public class HotKeyTests // Verify key bindings were set Command [] commands = view.KeyBindings.GetCommands (KeyCode.A); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.AltMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask | KeyCode.AltMask); - Assert.Contains (Command.Accept, commands); + Assert.Contains (Command.HotKey, commands); // Now set again view.HotKey = KeyCode.B; @@ -147,21 +147,20 @@ public class HotKeyTests Assert.Equal (KeyCode.B, view.HotKey); commands = view.KeyBindings.GetCommands (KeyCode.A); - Assert.DoesNotContain (Command.Accept, commands); + Assert.DoesNotContain (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask); - Assert.DoesNotContain (Command.Accept, commands); + Assert.DoesNotContain (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.AltMask); - Assert.DoesNotContain (Command.Accept, commands); + Assert.DoesNotContain (Command.HotKey, commands); commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask | KeyCode.AltMask); - Assert.DoesNotContain (Command.Accept, commands); + Assert.DoesNotContain (Command.HotKey, commands); } [Theory] [InlineData (KeyCode.A)] - [InlineData ((KeyCode)'a')] [InlineData (KeyCode.A | KeyCode.ShiftMask)] [InlineData (KeyCode.D1)] [InlineData (KeyCode.D1 | KeyCode.ShiftMask)] @@ -195,34 +194,34 @@ public class HotKeyTests // Verify key bindings were set // As passed - Command [] commands = view.KeyBindings.GetCommands (key); - Assert.Contains (Command.Accept, commands); + Command [] commands = view.KeyBindings.GetCommands (view.HotKey); + Assert.Contains (Command.HotKey, commands); - Key baseKey = ((Key)key).NoShift; + Key baseKey = view.HotKey.NoShift; // If A...Z, with and without shift if (baseKey.IsKeyCodeAtoZ) { - commands = view.KeyBindings.GetCommands (((Key)key).WithShift); - Assert.Contains (Command.Accept, commands); - commands = view.KeyBindings.GetCommands (((Key)key).NoShift); - Assert.Contains (Command.Accept, commands); - commands = view.KeyBindings.GetCommands (((Key)key).WithAlt); - Assert.Contains (Command.Accept, commands); - commands = view.KeyBindings.GetCommands (((Key)key).NoShift.WithAlt); - Assert.Contains (Command.Accept, commands); + commands = view.KeyBindings.GetCommands (view.HotKey.WithShift); + Assert.Contains (Command.HotKey, commands); + commands = view.KeyBindings.GetCommands (view.HotKey.NoShift); + Assert.Contains (Command.HotKey, commands); + commands = view.KeyBindings.GetCommands (view.HotKey.WithAlt); + Assert.Contains (Command.HotKey, commands); + commands = view.KeyBindings.GetCommands (view.HotKey.NoShift.WithAlt); + Assert.Contains (Command.HotKey, commands); } else { // Non A..Z keys should not have shift bindings - if (((Key)key).IsShift) + if (view.HotKey.IsShift) { - commands = view.KeyBindings.GetCommands (((Key)key).NoShift); + commands = view.KeyBindings.GetCommands (view.HotKey.NoShift); Assert.Empty (commands); } else { - commands = view.KeyBindings.GetCommands (((Key)key).WithShift); + commands = view.KeyBindings.GetCommands (view.HotKey.WithShift); Assert.Empty (commands); } } @@ -234,8 +233,8 @@ public class HotKeyTests var view = new View (); // A..Z must be naked (Alt is assumed) - view.HotKey = KeyCode.A | KeyCode.AltMask; - Assert.Throws (() => view.HotKey = KeyCode.A | KeyCode.CtrlMask); + view.HotKey = Key.A.WithAlt; + Assert.Throws (() => view.HotKey = Key.A.WithCtrl); Assert.Throws ( () => @@ -244,8 +243,8 @@ public class HotKeyTests ); // All others must not have Ctrl (Alt is assumed) - view.HotKey = KeyCode.D1 | KeyCode.AltMask; - Assert.Throws (() => view.HotKey = KeyCode.D1 | KeyCode.CtrlMask); + view.HotKey = Key.D1.WithAlt; + Assert.Throws (() => view.HotKey = Key.D1.WithCtrl); Assert.Throws ( () => @@ -254,7 +253,7 @@ public class HotKeyTests ); // Shift is ok (e.g. this is '!') - view.HotKey = KeyCode.D1 | KeyCode.ShiftMask; + view.HotKey = Key.D1.WithShift; } [Theory] @@ -286,26 +285,26 @@ public class HotKeyTests // BUGBUG: '!' should be supported. Line 968 of TextFormatter filters on char.IsLetterOrDigit //[InlineData ("Test^!", (Key)'!')] - public void Text_Change_Sets_HotKey (string text, KeyCode expectedHotKey) + public void Title_Change_Sets_HotKey (string title, KeyCode expectedHotKey) { - var view = new View { HotKeySpecifier = new Rune ('^'), Text = "^Hello" }; + var view = new View { HotKeySpecifier = new Rune ('^'), Title = "^Hello" }; Assert.Equal (KeyCode.H, view.HotKey); - view.Text = text; + view.Title = title; Assert.Equal (expectedHotKey, view.HotKey); } [Theory] [InlineData ("^Test")] - public void Text_Empty_Sets_HotKey_To_Null (string text) + public void Title_Empty_Sets_HotKey_To_Null (string title) { - var view = new View { HotKeySpecifier = (Rune)'^', Text = text }; + var view = new View { HotKeySpecifier = (Rune)'^', Title = title }; - Assert.Equal (text, view.Text); + Assert.Equal (title, view.Title); Assert.Equal (KeyCode.T, view.HotKey); - view.Text = string.Empty; - Assert.Equal ("", view.Text); + view.Title = string.Empty; + Assert.Equal ("", view.Title); Assert.Equal (KeyCode.Null, view.HotKey); } } diff --git a/UnitTests/View/KeyboardEventTests.cs b/UnitTests/View/KeyboardEventTests.cs index 1edf11868..59faae09e 100644 --- a/UnitTests/View/KeyboardEventTests.cs +++ b/UnitTests/View/KeyboardEventTests.cs @@ -188,7 +188,7 @@ public class KeyboardEventTests Assert.Equal (KeyCode.N, e.KeyCode); }; - view.NewKeyDownEvent (new Key (KeyCode.N)); + view.NewKeyDownEvent (Key.N); Assert.True (keyPressInvoked); Assert.True (invokingKeyBindingsInvoked); Assert.True (processKeyPressInvoked); @@ -197,7 +197,7 @@ public class KeyboardEventTests invokingKeyBindingsInvoked = false; processKeyPressInvoked = false; setHandledTo = true; - view.NewKeyDownEvent (new Key (KeyCode.N)); + view.NewKeyDownEvent (Key.N); Assert.True (keyPressInvoked); Assert.True (invokingKeyBindingsInvoked); Assert.False (processKeyPressInvoked); @@ -241,7 +241,7 @@ public class KeyboardEventTests keyPressed = true; }; - view.NewKeyDownEvent (new Key (KeyCode.A)); + view.NewKeyDownEvent (Key.A); Assert.True (keyDown); Assert.True (invokingKeyBindings); Assert.False (keyPressed); @@ -289,7 +289,7 @@ public class KeyboardEventTests keyPressed = true; }; - view.NewKeyDownEvent (new Key (KeyCode.A)); + view.NewKeyDownEvent (Key.A); Assert.True (keyDown); Assert.False (invokingKeyBindings); Assert.False (keyPressed); @@ -328,14 +328,14 @@ public class KeyboardEventTests Assert.Equal (KeyCode.N, e.KeyCode); }; - view.NewKeyDownEvent (new Key (KeyCode.N)); + view.NewKeyDownEvent (Key.N); Assert.True (invokingKeyBindingsInvoked); Assert.True (processKeyPressInvoked); invokingKeyBindingsInvoked = false; processKeyPressInvoked = false; setHandledTo = true; - view.NewKeyDownEvent (new Key (KeyCode.N)); + view.NewKeyDownEvent (Key.N); Assert.False (invokingKeyBindingsInvoked); Assert.False (processKeyPressInvoked); } @@ -378,7 +378,7 @@ public class KeyboardEventTests keyPressed = true; }; - view.NewKeyDownEvent (new Key (KeyCode.A)); + view.NewKeyDownEvent (Key.A); Assert.True (keyDown); Assert.True (invokingKeyBindings); Assert.True (keyPressed); @@ -406,7 +406,7 @@ public class KeyboardEventTests keyUp = true; }; - view.NewKeyUpEvent (new Key (KeyCode.A)); + view.NewKeyUpEvent (Key.A); Assert.True (keyUp); Assert.False (view.OnKeyUpContinued); @@ -424,7 +424,7 @@ public class KeyboardEventTests var view = new KeyBindingsTestView (); view.CommandReturns = toReturn; - bool? result = view.OnInvokingKeyBindings (new Key (KeyCode.A)); + bool? result = view.OnInvokingKeyBindings (Key.A); Assert.Equal (expected, result); } @@ -434,8 +434,8 @@ public class KeyboardEventTests public KeyBindingsTestView () { CanFocus = true; - AddCommand (Command.Default, () => CommandReturns); - KeyBindings.Add (KeyCode.A, Command.Default); + AddCommand (Command.HotKey, () => CommandReturns); + KeyBindings.Add (Key.A, Command.HotKey); } public bool? CommandReturns { get; set; } diff --git a/UnitTests/View/Layout/DimTests.cs b/UnitTests/View/Layout/DimTests.cs index e713e9472..45b0bfb40 100644 --- a/UnitTests/View/Layout/DimTests.cs +++ b/UnitTests/View/Layout/DimTests.cs @@ -55,7 +55,7 @@ public class DimTests { while (count < 20) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); } Application.RequestStop (); @@ -142,7 +142,7 @@ public class DimTests { while (count > 0) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); } Application.RequestStop (); diff --git a/UnitTests/View/Layout/PosTests.cs b/UnitTests/View/Layout/PosTests.cs index 7cc47f7c3..915de0d49 100644 --- a/UnitTests/View/Layout/PosTests.cs +++ b/UnitTests/View/Layout/PosTests.cs @@ -494,7 +494,7 @@ public class PosTests { while (count < 20) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); } Application.RequestStop (); @@ -562,7 +562,7 @@ public class PosTests { while (count > 0) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); } Application.RequestStop (); diff --git a/UnitTests/View/NavigationTests.cs b/UnitTests/View/NavigationTests.cs index cf51df9bd..51cea39d0 100644 --- a/UnitTests/View/NavigationTests.cs +++ b/UnitTests/View/NavigationTests.cs @@ -323,13 +323,13 @@ public class NavigationTests Assert.True (view2.CanFocus); Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab)); Assert.True (view1.CanFocus); Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus Assert.True (view2.CanFocus); Assert.True (view2.HasFocus); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab)); Assert.True (view1.CanFocus); Assert.True (view1.HasFocus); Assert.True (view2.CanFocus); @@ -362,13 +362,13 @@ public class NavigationTests Assert.True (view2.CanFocus); Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.True (view1.CanFocus); Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus Assert.True (view2.CanFocus); Assert.True (view2.HasFocus); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.True (view1.CanFocus); Assert.True (view1.HasFocus); Assert.True (view2.CanFocus); @@ -412,14 +412,14 @@ public class NavigationTests Assert.True (view2.CanFocus); Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl)); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.True (view1.CanFocus); Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus Assert.True (view2.CanFocus); Assert.True (view2.HasFocus); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.True (view1.CanFocus); Assert.True (view1.HasFocus); Assert.True (view2.CanFocus); @@ -440,10 +440,10 @@ public class NavigationTests { var wasClicked = false; var view = new Button { Text = "Click Me" }; - view.Clicked += (s, e) => wasClicked = !wasClicked; + view.Accept += (s, e) => wasClicked = !wasClicked; Application.Top.Add (view); - view.NewKeyDownEvent (new Key (KeyCode.Space)); + view.NewKeyDownEvent (Key.Space); Assert.True (wasClicked); view.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked }); Assert.False (wasClicked); @@ -452,7 +452,7 @@ public class NavigationTests Assert.True (view.HasFocus); view.Enabled = false; - view.NewKeyDownEvent (new Key (KeyCode.Space)); + view.NewKeyDownEvent (Key.Space); Assert.False (wasClicked); view.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked }); Assert.False (wasClicked); @@ -470,7 +470,7 @@ public class NavigationTests var wasClicked = false; var button = new Button { Text = "Click Me" }; button.IsDefault = true; - button.Clicked += (s, e) => wasClicked = !wasClicked; + button.Accept += (s, e) => wasClicked = !wasClicked; var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (button); Application.Top.Add (win); @@ -481,7 +481,7 @@ public class NavigationTests { iterations++; - win.NewKeyDownEvent (new Key (KeyCode.Enter)); + win.NewKeyDownEvent (Key.Enter); Assert.True (wasClicked); button.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked }); Assert.False (wasClicked); @@ -493,7 +493,7 @@ public class NavigationTests Assert.True (win.HasFocus); win.Enabled = false; - button.NewKeyDownEvent (new Key (KeyCode.Enter)); + button.NewKeyDownEvent (Key.Enter); Assert.False (wasClicked); button.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked }); Assert.False (wasClicked); @@ -538,16 +538,16 @@ public class NavigationTests frm.Add (frmSubview); top.Add (frm); - top.NewKeyDownEvent (new Key (KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab); Assert.Equal ("WindowSubview", top.MostFocused.Text); - top.NewKeyDownEvent (new Key (KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab); Assert.Equal ("FrameSubview", top.MostFocused.Text); - top.NewKeyDownEvent (new Key (KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab); Assert.Equal ("WindowSubview", top.MostFocused.Text); - top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + top.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal ("FrameSubview", top.MostFocused.Text); - top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + top.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal ("WindowSubview", top.MostFocused.Text); top.Dispose (); } @@ -599,7 +599,7 @@ public class NavigationTests Assert.False (removed); Assert.Null (view3); - Assert.True (top1.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (top1.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.True (top1.HasFocus); Assert.False (view1.HasFocus); Assert.True (view2.HasFocus); @@ -607,7 +607,7 @@ public class NavigationTests Assert.NotNull (view3); Exception exception = - Record.Exception (() => top1.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Record.Exception (() => top1.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.Null (exception); Assert.True (removed); Assert.Null (view3); diff --git a/UnitTests/View/SubviewTests.cs b/UnitTests/View/SubviewTests.cs new file mode 100644 index 000000000..af96206b8 --- /dev/null +++ b/UnitTests/View/SubviewTests.cs @@ -0,0 +1,333 @@ +using System.Text; +using Xunit.Abstractions; + +namespace Terminal.Gui.ViewTests; + +public class SubviewTests +{ + private readonly ITestOutputHelper _output; + public SubviewTests (ITestOutputHelper output) { _output = output; } + + [Fact] + [TestRespondersDisposed] + public void Added_Removed () + { + var v = new View { Frame = new Rect (0, 0, 10, 24) }; + var t = new View (); + + v.Added += (s, e) => + { + Assert.Same (v.SuperView, e.Parent); + Assert.Same (t, e.Parent); + Assert.Same (v, e.Child); + }; + + v.Removed += (s, e) => + { + Assert.Same (t, e.Parent); + Assert.Same (v, e.Child); + Assert.True (v.SuperView == null); + }; + + t.Add (v); + Assert.True (t.Subviews.Count == 1); + + t.Remove (v); + Assert.True (t.Subviews.Count == 0); + + t.Dispose (); + v.Dispose (); + } + + [Fact] + [AutoInitShutdown] + public void GetTopSuperView_Test () + { + var v1 = new View (); + var fv1 = new FrameView (); + fv1.Add (v1); + var tf1 = new TextField (); + var w1 = new Window (); + w1.Add (fv1, tf1); + var top1 = new Toplevel (); + top1.Add (w1); + + var v2 = new View (); + var fv2 = new FrameView (); + fv2.Add (v2); + var tf2 = new TextField (); + var w2 = new Window (); + w2.Add (fv2, tf2); + var top2 = new Toplevel (); + top2.Add (w2); + + Assert.Equal (top1, v1.GetTopSuperView ()); + Assert.Equal (top2, v2.GetTopSuperView ()); + + v1.Dispose (); + fv1.Dispose (); + tf1.Dispose (); + w1.Dispose (); + top1.Dispose (); + v2.Dispose (); + fv2.Dispose (); + tf2.Dispose (); + w2.Dispose (); + top2.Dispose (); + } + + [Fact] + [TestRespondersDisposed] + public void Initialized_Event_Comparing_With_Added_Event () + { + Application.Init (new FakeDriver ()); + + var top = new Toplevel { Id = "0" }; // Frame: 0, 0, 80, 25; Bounds: 0, 0, 80, 25 + + var winAddedToTop = new Window + { + Id = "t", Width = Dim.Fill (), Height = Dim.Fill () + }; // Frame: 0, 0, 80, 25; Bounds: 0, 0, 78, 23 + + var v1AddedToWin = new View + { + Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () + }; // Frame: 1, 1, 78, 23 (because Windows has a border) + + var v2AddedToWin = new View + { + Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () + }; // Frame: 1, 1, 78, 23 (because Windows has a border) + + var svAddedTov1 = new View + { + Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () + }; // Frame: 1, 1, 78, 23 (same as it's superview v1AddedToWin) + + int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; + + winAddedToTop.Added += (s, e) => + { + Assert.Equal (e.Parent.Frame.Width, winAddedToTop.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, winAddedToTop.Frame.Height); + }; + + v1AddedToWin.Added += (s, e) => + { + Assert.Equal (e.Parent.Frame.Width, v1AddedToWin.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, v1AddedToWin.Frame.Height); + }; + + v2AddedToWin.Added += (s, e) => + { + Assert.Equal (e.Parent.Frame.Width, v2AddedToWin.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, v2AddedToWin.Frame.Height); + }; + + svAddedTov1.Added += (s, e) => + { + Assert.Equal (e.Parent.Frame.Width, svAddedTov1.Frame.Width); + Assert.Equal (e.Parent.Frame.Height, svAddedTov1.Frame.Height); + }; + + top.Initialized += (s, e) => + { + tc++; + Assert.Equal (1, tc); + Assert.Equal (1, wc); + Assert.Equal (1, v1c); + Assert.Equal (1, v2c); + Assert.Equal (1, sv1c); + + Assert.True (top.CanFocus); + Assert.True (winAddedToTop.CanFocus); + Assert.False (v1AddedToWin.CanFocus); + Assert.False (v2AddedToWin.CanFocus); + Assert.False (svAddedTov1.CanFocus); + + Application.Refresh (); + }; + + winAddedToTop.Initialized += (s, e) => + { + wc++; + Assert.Equal (top.Bounds.Width, winAddedToTop.Frame.Width); + Assert.Equal (top.Bounds.Height, winAddedToTop.Frame.Height); + }; + + v1AddedToWin.Initialized += (s, e) => + { + v1c++; + + // Top.Frame: 0, 0, 80, 25; Top.Bounds: 0, 0, 80, 25 + // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. + // in no way should the v1AddedToWin.Frame be the same as the Top.Frame/Bounds + // as it is a subview of winAddedToTop, which has a border! + //Assert.Equal (top.Bounds.Width, v1AddedToWin.Frame.Width); + //Assert.Equal (top.Bounds.Height, v1AddedToWin.Frame.Height); + }; + + v2AddedToWin.Initialized += (s, e) => + { + v2c++; + + // Top.Frame: 0, 0, 80, 25; Top.Bounds: 0, 0, 80, 25 + // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. + // in no way should the v2AddedToWin.Frame be the same as the Top.Frame/Bounds + // as it is a subview of winAddedToTop, which has a border! + //Assert.Equal (top.Bounds.Width, v2AddedToWin.Frame.Width); + //Assert.Equal (top.Bounds.Height, v2AddedToWin.Frame.Height); + }; + + svAddedTov1.Initialized += (s, e) => + { + sv1c++; + + // Top.Frame: 0, 0, 80, 25; Top.Bounds: 0, 0, 80, 25 + // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. + // in no way should the svAddedTov1.Frame be the same as the Top.Frame/Bounds + // because sv1AddedTov1 is a subview of v1AddedToWin, which is a subview of + // winAddedToTop, which has a border! + //Assert.Equal (top.Bounds.Width, svAddedTov1.Frame.Width); + //Assert.Equal (top.Bounds.Height, svAddedTov1.Frame.Height); + Assert.False (svAddedTov1.CanFocus); + Assert.Throws (() => svAddedTov1.CanFocus = true); + Assert.False (svAddedTov1.CanFocus); + }; + + v1AddedToWin.Add (svAddedTov1); + winAddedToTop.Add (v1AddedToWin, v2AddedToWin); + top.Add (winAddedToTop); + + Application.Iteration += (s, a) => + { + Application.Refresh (); + top.Running = false; + }; + + Application.Run (top); + Application.Shutdown (); + + Assert.Equal (1, tc); + Assert.Equal (1, wc); + Assert.Equal (1, v1c); + Assert.Equal (1, v2c); + Assert.Equal (1, sv1c); + + Assert.True (top.CanFocus); + Assert.True (winAddedToTop.CanFocus); + Assert.False (v1AddedToWin.CanFocus); + Assert.False (v2AddedToWin.CanFocus); + Assert.False (svAddedTov1.CanFocus); + + v1AddedToWin.CanFocus = true; + Assert.False (svAddedTov1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1. + } + + [Fact] + [TestRespondersDisposed] + public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically () + { + Application.Init (new FakeDriver ()); + + var t = new Toplevel { Id = "0" }; + + var w = new Window { Id = "t", Width = Dim.Fill (), Height = Dim.Fill () }; + var v1 = new View { Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () }; + var v2 = new View { Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () }; + + int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; + + t.Initialized += (s, e) => + { + tc++; + Assert.Equal (1, tc); + Assert.Equal (1, wc); + Assert.Equal (1, v1c); + Assert.Equal (1, v2c); + Assert.Equal (0, sv1c); // Added after t in the Application.Iteration. + + Assert.True (t.CanFocus); + Assert.True (w.CanFocus); + Assert.False (v1.CanFocus); + Assert.False (v2.CanFocus); + + Application.Refresh (); + }; + + w.Initialized += (s, e) => + { + wc++; + Assert.Equal (t.Bounds.Width, w.Frame.Width); + Assert.Equal (t.Bounds.Height, w.Frame.Height); + }; + + v1.Initialized += (s, e) => + { + v1c++; + + //Assert.Equal (t.Bounds.Width, v1.Frame.Width); + //Assert.Equal (t.Bounds.Height, v1.Frame.Height); + }; + + v2.Initialized += (s, e) => + { + v2c++; + + //Assert.Equal (t.Bounds.Width, v2.Frame.Width); + //Assert.Equal (t.Bounds.Height, v2.Frame.Height); + }; + w.Add (v1, v2); + t.Add (w); + + Application.Iteration += (s, a) => + { + var sv1 = new View { Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () }; + + sv1.Initialized += (s, e) => + { + sv1c++; + Assert.NotEqual (t.Frame.Width, sv1.Frame.Width); + Assert.NotEqual (t.Frame.Height, sv1.Frame.Height); + Assert.False (sv1.CanFocus); + Assert.Throws (() => sv1.CanFocus = true); + Assert.False (sv1.CanFocus); + }; + + v1.Add (sv1); + + Application.Refresh (); + t.Running = false; + }; + + Application.Run (t); + Application.Shutdown (); + + Assert.Equal (1, tc); + Assert.Equal (1, wc); + Assert.Equal (1, v1c); + Assert.Equal (1, v2c); + Assert.Equal (1, sv1c); + + Assert.True (t.CanFocus); + Assert.True (w.CanFocus); + Assert.False (v1.CanFocus); + Assert.False (v2.CanFocus); + } + + [Fact] + [TestRespondersDisposed] + public void IsAdded_Added_Removed () + { + var top = new Toplevel (); + var view = new View (); + Assert.False (view.IsAdded); + top.Add (view); + Assert.True (view.IsAdded); + top.Remove (view); + Assert.False (view.IsAdded); + + top.Dispose (); + view.Dispose (); + } +} diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs index 6c5b9b85c..7ae2866a0 100644 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ b/UnitTests/View/Text/AutoSizeTrueTests.cs @@ -610,11 +610,11 @@ public class AutoSizeTrueTests { while (count < 21) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); if (count == 20) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); break; } @@ -714,11 +714,11 @@ public class AutoSizeTrueTests { while (count > -1) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); if (count == 0) { - field.NewKeyDownEvent (new Key (KeyCode.Enter)); + field.NewKeyDownEvent (Key.Enter); break; } @@ -2114,7 +2114,7 @@ Y var horizontalView = new View { - Id = "horizontalView", AutoSize = true, HotKeySpecifier = (Rune)'_', Text = text + Id = "horizontalView", AutoSize = true, Text = text }; var verticalView = new View @@ -2122,7 +2122,6 @@ Y Id = "verticalView", Y = 3, AutoSize = true, - HotKeySpecifier = (Rune)'_', Text = text, TextDirection = TextDirection.TopBottom_LeftRight }; @@ -2136,27 +2135,17 @@ Y Assert.True (verticalView.AutoSize); Assert.Equal (new Size (text.GetColumns (), 1), horizontalView.TextFormatter.Size); Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size); - Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame); - Assert.Equal ("Absolute(0)", horizontalView.X.ToString ()); - Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ()); - - // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always grow or keep initial value, - - Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ()); - Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ()); - Assert.Equal (new Rect (0, 3, 9, 8), verticalView.Frame); - Assert.Equal ("Absolute(0)", verticalView.X.ToString ()); - Assert.Equal ("Absolute(3)", verticalView.Y.ToString ()); - Assert.Equal ("Absolute(9)", verticalView.Width.ToString ()); - Assert.Equal ("Absolute(8)", verticalView.Height.ToString ()); + Assert.Equal (new Rect (0, 0, 10, 1), horizontalView.Frame); + Assert.Equal (new Rect (0, 3, 10, 9), verticalView.Frame); var expected = @" ┌────────────────────┐ -│Finish 終 │ +│Fi_nish 終 │ │ │ │ │ │F │ │i │ +│_ │ │n │ │i │ │s │ @@ -2171,12 +2160,10 @@ Y │ │ │ │ │ │ -│ │ └────────────────────┘ "; Rect pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 22, 22), pos); verticalView.Text = "最初_の行二行目"; Application.Top.Draw (); @@ -2184,19 +2171,16 @@ Y Assert.True (verticalView.AutoSize); // height was initialized with 8 and can only grow or keep initial value - Assert.Equal (new Rect (0, 3, 9, 8), verticalView.Frame); - Assert.Equal ("Absolute(0)", verticalView.X.ToString ()); - Assert.Equal ("Absolute(3)", verticalView.Y.ToString ()); - Assert.Equal ("Absolute(9)", verticalView.Width.ToString ()); - Assert.Equal ("Absolute(8)", verticalView.Height.ToString ()); + Assert.Equal (new Rect (0, 3, 10, 9), verticalView.Frame); expected = @" ┌────────────────────┐ -│Finish 終 │ +│Fi_nish 終 │ │ │ │ │ │最 │ │初 │ +│_ │ │の │ │行 │ │二 │ @@ -2211,12 +2195,10 @@ Y │ │ │ │ │ │ -│ │ └────────────────────┘ "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 22, 22), pos); Application.End (rs); } @@ -2684,15 +2666,18 @@ Y var text = "Say Hello 你"; // Frame: 0, 0, 12, 1 - var horizontalView = new View { AutoSize = true, HotKeySpecifier = (Rune)'_' }; + var horizontalView = new View { AutoSize = true }; + horizontalView.TextFormatter.HotKeySpecifier = (Rune)'_'; horizontalView.Text = text; // Frame: 0, 0, 1, 12 var verticalView = new View { - AutoSize = true, HotKeySpecifier = (Rune)'_', TextDirection = TextDirection.TopBottom_LeftRight + AutoSize = true, TextDirection = TextDirection.TopBottom_LeftRight }; verticalView.Text = text; + verticalView.TextFormatter.HotKeySpecifier = (Rune)'_'; + Application.Top.Add (horizontalView, verticalView); Application.Begin (Application.Top); @@ -2807,69 +2792,6 @@ Y Application.End (rs); } - [Fact] - [AutoInitShutdown] - public void Test_Label_Full_Border () - { - var label = new Label { Text = "Test", /*Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; - Application.Top.Add (label); - Application.Begin (Application.Top); - - Assert.Equal (new Rect (0, 0, 6, 3), label.Frame); - Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds); - - TestHelpers.AssertDriverContentsWithFrameAre ( - @" -┌────┐ -│Test│ -└────┘", - _output - ); - } - - [Fact] - [AutoInitShutdown] - public void Test_Label_With_Top_Margin_Without_Top_Border () - { - var label = new Label { Text = "Test", /*Width = 6, Height = 3,*/ BorderStyle = LineStyle.Single }; - label.Margin.Thickness = new Thickness (0, 1, 0, 0); - label.Border.Thickness = new Thickness (1, 0, 1, 1); - Application.Top.Add (label); - Application.Begin (Application.Top); - - Assert.Equal (new Rect (0, 0, 6, 3), label.Frame); - Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds); - Application.Begin (Application.Top); - - TestHelpers.AssertDriverContentsWithFrameAre ( - @" -│Test│ -└────┘", - _output - ); - } - - [Fact] - [AutoInitShutdown] - public void Test_Label_Without_Top_Border () - { - var label = new Label { Text = "Test", /* Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; - label.Border.Thickness = new Thickness (1, 0, 1, 1); - Application.Top.Add (label); - Application.Begin (Application.Top); - - Assert.Equal (new Rect (0, 0, 6, 2), label.Frame); - Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds); - Application.Begin (Application.Top); - - TestHelpers.AssertDriverContentsWithFrameAre ( - @" -│Test│ -└────┘", - _output - ); - } - [Fact] [AutoInitShutdown] public void TrySetHeight_ForceValidatePosDim () diff --git a/UnitTests/View/Text/TextTests.cs b/UnitTests/View/Text/TextTests.cs index d32d417f5..0a46e9179 100644 --- a/UnitTests/View/Text/TextTests.cs +++ b/UnitTests/View/Text/TextTests.cs @@ -65,6 +65,15 @@ public class TextTests Assert.Equal ("Hello World", view.TextFormatter.Text); } + // Setting Text does NOT set the HotKey + [Fact] + public void Text_Does_Not_Set_HotKey () + { + var view = new View { HotKeySpecifier = (Rune)'_', Text = "_Hello World" }; + + Assert.NotEqual (Key.H, view.HotKey); + } + // Test that TextFormatter is init only [Fact] public void TextFormatterIsInitOnly () @@ -72,11 +81,10 @@ public class TextTests var view = new View (); // Use reflection to ensure the TextFormatter property is `init` only - Assert.True ( - typeof (View).GetMethod ("set_TextFormatter") - .ReturnParameter.GetRequiredCustomModifiers () - .Contains (typeof (IsExternalInit)) - ); + Assert.Contains ( + typeof (IsExternalInit), + typeof (View).GetMethod ("set_TextFormatter") + .ReturnParameter.GetRequiredCustomModifiers ()); } // Test that the Text property is set correctly. @@ -88,15 +96,6 @@ public class TextTests Assert.Equal ("Hello World", view.Text); } - // Setting Text sets the HotKey - [Fact] - public void TextSetsHotKey () - { - var view = new View { HotKeySpecifier = (Rune)'_', Text = "_Hello World" }; - - Assert.Equal (Key.H, view.HotKey); - } - // Test view.UpdateTextFormatterText overridden in a subclass updates TextFormatter.Text [Fact] public void UpdateTextFormatterText_Overridden () diff --git a/UnitTests/View/TitleTests.cs b/UnitTests/View/TitleTests.cs index 5bb9158b6..1262d1cab 100644 --- a/UnitTests/View/TitleTests.cs +++ b/UnitTests/View/TitleTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using System.Text; +using Xunit.Abstractions; //using GraphViewTests = Terminal.Gui.Views.GraphViewTests; @@ -22,8 +23,8 @@ public class TitleTests r.TitleChanged += (s, args) => { - Assert.Equal (expectedOld, args.OldTitle); - Assert.Equal (r.Title, args.NewTitle); + Assert.Equal (expectedOld, args.OldValue); + Assert.Equal (r.Title, args.NewValue); }; expected = "title"; @@ -46,8 +47,8 @@ public class TitleTests r.TitleChanging += (s, args) => { - Assert.Equal (expectedOld, args.OldTitle); - Assert.Equal (expectedDuring, args.NewTitle); + Assert.Equal (expectedOld, args.OldValue); + Assert.Equal (expectedDuring, args.NewValue); args.Cancel = cancel; }; @@ -66,4 +67,13 @@ public class TitleTests Assert.Equal (expectedAfter, r.Title); r.Dispose (); } + + // Setting Text does NOT set the HotKey + [Fact] + public void Title_Does_Set_HotKey () + { + var view = new View { HotKeySpecifier = (Rune)'_', Title = "_Hello World" }; + + Assert.Equal (Key.H, view.HotKey); + } } diff --git a/UnitTests/View/ViewKeyBindingTests.cs b/UnitTests/View/ViewKeyBindingTests.cs index 348217491..4fe5b69b4 100644 --- a/UnitTests/View/ViewKeyBindingTests.cs +++ b/UnitTests/View/ViewKeyBindingTests.cs @@ -18,16 +18,16 @@ public class ViewKeyBindingTests Application.Top.Add (view); Application.Begin (Application.Top); - Application.OnKeyDown (new Key (KeyCode.A)); + Application.OnKeyDown (Key.A); Assert.True (invoked); invoked = false; - Application.OnKeyDown (new Key (KeyCode.H)); + Application.OnKeyDown (Key.H); Assert.True (invoked); invoked = false; Assert.False (view.HasFocus); - Application.OnKeyDown (new Key (KeyCode.F)); + Application.OnKeyDown (Key.F); Assert.False (invoked); Assert.False (view.FocusedCommand); @@ -35,7 +35,7 @@ public class ViewKeyBindingTests view.CanFocus = true; view.SetFocus (); Assert.True (view.HasFocus); - Application.OnKeyDown (new Key (KeyCode.F)); + Application.OnKeyDown (Key.F); Assert.True (invoked); Assert.True (view.ApplicationCommand); @@ -54,7 +54,7 @@ public class ViewKeyBindingTests Application.Top.Add (view); Application.Begin (Application.Top); - Application.OnKeyDown (new Key (KeyCode.Z)); + Application.OnKeyDown (Key.Z); Assert.False (invoked); Assert.False (view.ApplicationCommand); Assert.False (view.HotKeyCommand); @@ -62,7 +62,7 @@ public class ViewKeyBindingTests invoked = false; Assert.False (view.HasFocus); - Application.OnKeyDown (new Key (KeyCode.F)); + Application.OnKeyDown (Key.F); Assert.False (invoked); Assert.False (view.ApplicationCommand); Assert.False (view.HotKeyCommand); @@ -81,18 +81,18 @@ public class ViewKeyBindingTests Application.Begin (Application.Top); invoked = false; - Application.OnKeyDown (new Key (KeyCode.H)); + Application.OnKeyDown (Key.H); Assert.True (invoked); Assert.True (view.HotKeyCommand); view.HotKey = KeyCode.Z; invoked = false; view.HotKeyCommand = false; - Application.OnKeyDown (new Key (KeyCode.H)); // old hot key + Application.OnKeyDown (Key.H); // old hot key Assert.False (invoked); Assert.False (view.HotKeyCommand); - Application.OnKeyDown (new Key (KeyCode.Z)); // new hot key + Application.OnKeyDown (Key.Z); // new hot key Assert.True (invoked); Assert.True (view.HotKeyCommand); } @@ -108,12 +108,12 @@ public class ViewKeyBindingTests Application.Top.Add (view); Application.Begin (Application.Top); - Application.OnKeyDown (new Key (KeyCode.Z)); + Application.OnKeyDown (Key.Z); Assert.False (invoked); Assert.False (view.HotKeyCommand); invoked = false; - Application.OnKeyDown (new Key (KeyCode.F)); + Application.OnKeyDown (Key.F); Assert.False (view.HotKeyCommand); } @@ -124,12 +124,12 @@ public class ViewKeyBindingTests public ScopedKeyBindingView () { AddCommand (Command.Save, () => ApplicationCommand = true); - AddCommand (Command.Default, () => HotKeyCommand = true); + AddCommand (Command.HotKey, () => HotKeyCommand = true); AddCommand (Command.Left, () => FocusedCommand = true); - KeyBindings.Add (KeyCode.A, KeyBindingScope.Application, Command.Save); + KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Save); HotKey = KeyCode.H; - KeyBindings.Add (KeyCode.F, KeyBindingScope.Focused, Command.Left); + KeyBindings.Add (Key.F, KeyBindingScope.Focused, Command.Left); } public bool ApplicationCommand { get; set; } diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index 5b336366a..ea8ccb86e 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -1,8 +1,7 @@ -using System.Text; +using System.ComponentModel; +using System.Text; using Xunit.Abstractions; -// Alias Console to MockConsole so we don't accidentally use Console - namespace Terminal.Gui.ViewTests; public class ViewTests @@ -10,37 +9,6 @@ public class ViewTests private readonly ITestOutputHelper _output; public ViewTests (ITestOutputHelper output) { _output = output; } - [Fact] - [TestRespondersDisposed] - public void Added_Removed () - { - var v = new View { Frame = new Rect (0, 0, 10, 24) }; - var t = new View (); - - v.Added += (s, e) => - { - Assert.Same (v.SuperView, e.Parent); - Assert.Same (t, e.Parent); - Assert.Same (v, e.Child); - }; - - v.Removed += (s, e) => - { - Assert.Same (t, e.Parent); - Assert.Same (v, e.Child); - Assert.True (v.SuperView == null); - }; - - t.Add (v); - Assert.True (t.Subviews.Count == 1); - - t.Remove (v); - Assert.True (t.Subviews.Count == 0); - - t.Dispose (); - v.Dispose (); - } - [Fact] [AutoInitShutdown] public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () @@ -539,43 +507,6 @@ At 0,0 view.Dispose (); } - [Fact] - [AutoInitShutdown] - public void GetTopSuperView_Test () - { - var v1 = new View (); - var fv1 = new FrameView (); - fv1.Add (v1); - var tf1 = new TextField (); - var w1 = new Window (); - w1.Add (fv1, tf1); - var top1 = new Toplevel (); - top1.Add (w1); - - var v2 = new View (); - var fv2 = new FrameView (); - fv2.Add (v2); - var tf2 = new TextField (); - var w2 = new Window (); - w2.Add (fv2, tf2); - var top2 = new Toplevel (); - top2.Add (w2); - - Assert.Equal (top1, v1.GetTopSuperView ()); - Assert.Equal (top2, v2.GetTopSuperView ()); - - v1.Dispose (); - fv1.Dispose (); - tf1.Dispose (); - w1.Dispose (); - top1.Dispose (); - v2.Dispose (); - fv2.Dispose (); - tf2.Dispose (); - w2.Dispose (); - top2.Dispose (); - } - [Fact] [AutoInitShutdown] public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame () @@ -766,245 +697,6 @@ At 0,0 Application.End (runState); } - [Fact] - [TestRespondersDisposed] - public void Initialized_Event_Comparing_With_Added_Event () - { - Application.Init (new FakeDriver ()); - - var top = new Toplevel { Id = "0" }; // Frame: 0, 0, 80, 25; Bounds: 0, 0, 80, 25 - - var winAddedToTop = new Window - { - Id = "t", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 0, 0, 80, 25; Bounds: 0, 0, 78, 23 - - var v1AddedToWin = new View - { - Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 1, 1, 78, 23 (because Windows has a border) - - var v2AddedToWin = new View - { - Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 1, 1, 78, 23 (because Windows has a border) - - var svAddedTov1 = new View - { - Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () - }; // Frame: 1, 1, 78, 23 (same as it's superview v1AddedToWin) - - int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; - - winAddedToTop.Added += (s, e) => - { - Assert.Equal (e.Parent.Frame.Width, winAddedToTop.Frame.Width); - Assert.Equal (e.Parent.Frame.Height, winAddedToTop.Frame.Height); - }; - - v1AddedToWin.Added += (s, e) => - { - Assert.Equal (e.Parent.Frame.Width, v1AddedToWin.Frame.Width); - Assert.Equal (e.Parent.Frame.Height, v1AddedToWin.Frame.Height); - }; - - v2AddedToWin.Added += (s, e) => - { - Assert.Equal (e.Parent.Frame.Width, v2AddedToWin.Frame.Width); - Assert.Equal (e.Parent.Frame.Height, v2AddedToWin.Frame.Height); - }; - - svAddedTov1.Added += (s, e) => - { - Assert.Equal (e.Parent.Frame.Width, svAddedTov1.Frame.Width); - Assert.Equal (e.Parent.Frame.Height, svAddedTov1.Frame.Height); - }; - - top.Initialized += (s, e) => - { - tc++; - Assert.Equal (1, tc); - Assert.Equal (1, wc); - Assert.Equal (1, v1c); - Assert.Equal (1, v2c); - Assert.Equal (1, sv1c); - - Assert.True (top.CanFocus); - Assert.True (winAddedToTop.CanFocus); - Assert.False (v1AddedToWin.CanFocus); - Assert.False (v2AddedToWin.CanFocus); - Assert.False (svAddedTov1.CanFocus); - - Application.Refresh (); - }; - - winAddedToTop.Initialized += (s, e) => - { - wc++; - Assert.Equal (top.Bounds.Width, winAddedToTop.Frame.Width); - Assert.Equal (top.Bounds.Height, winAddedToTop.Frame.Height); - }; - - v1AddedToWin.Initialized += (s, e) => - { - v1c++; - - // Top.Frame: 0, 0, 80, 25; Top.Bounds: 0, 0, 80, 25 - // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. - // in no way should the v1AddedToWin.Frame be the same as the Top.Frame/Bounds - // as it is a subview of winAddedToTop, which has a border! - //Assert.Equal (top.Bounds.Width, v1AddedToWin.Frame.Width); - //Assert.Equal (top.Bounds.Height, v1AddedToWin.Frame.Height); - }; - - v2AddedToWin.Initialized += (s, e) => - { - v2c++; - - // Top.Frame: 0, 0, 80, 25; Top.Bounds: 0, 0, 80, 25 - // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. - // in no way should the v2AddedToWin.Frame be the same as the Top.Frame/Bounds - // as it is a subview of winAddedToTop, which has a border! - //Assert.Equal (top.Bounds.Width, v2AddedToWin.Frame.Width); - //Assert.Equal (top.Bounds.Height, v2AddedToWin.Frame.Height); - }; - - svAddedTov1.Initialized += (s, e) => - { - sv1c++; - - // Top.Frame: 0, 0, 80, 25; Top.Bounds: 0, 0, 80, 25 - // BUGBUG: This is wrong, it should be 78, 23. This test has always been broken. - // in no way should the svAddedTov1.Frame be the same as the Top.Frame/Bounds - // because sv1AddedTov1 is a subview of v1AddedToWin, which is a subview of - // winAddedToTop, which has a border! - //Assert.Equal (top.Bounds.Width, svAddedTov1.Frame.Width); - //Assert.Equal (top.Bounds.Height, svAddedTov1.Frame.Height); - Assert.False (svAddedTov1.CanFocus); - Assert.Throws (() => svAddedTov1.CanFocus = true); - Assert.False (svAddedTov1.CanFocus); - }; - - v1AddedToWin.Add (svAddedTov1); - winAddedToTop.Add (v1AddedToWin, v2AddedToWin); - top.Add (winAddedToTop); - - Application.Iteration += (s, a) => - { - Application.Refresh (); - top.Running = false; - }; - - Application.Run (top); - Application.Shutdown (); - - Assert.Equal (1, tc); - Assert.Equal (1, wc); - Assert.Equal (1, v1c); - Assert.Equal (1, v2c); - Assert.Equal (1, sv1c); - - Assert.True (top.CanFocus); - Assert.True (winAddedToTop.CanFocus); - Assert.False (v1AddedToWin.CanFocus); - Assert.False (v2AddedToWin.CanFocus); - Assert.False (svAddedTov1.CanFocus); - - v1AddedToWin.CanFocus = true; - Assert.False (svAddedTov1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1. - } - - [Fact] - [TestRespondersDisposed] - public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically () - { - Application.Init (new FakeDriver ()); - - var t = new Toplevel { Id = "0" }; - - var w = new Window { Id = "t", Width = Dim.Fill (), Height = Dim.Fill () }; - var v1 = new View { Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () }; - var v2 = new View { Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () }; - - int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; - - t.Initialized += (s, e) => - { - tc++; - Assert.Equal (1, tc); - Assert.Equal (1, wc); - Assert.Equal (1, v1c); - Assert.Equal (1, v2c); - Assert.Equal (0, sv1c); // Added after t in the Application.Iteration. - - Assert.True (t.CanFocus); - Assert.True (w.CanFocus); - Assert.False (v1.CanFocus); - Assert.False (v2.CanFocus); - - Application.Refresh (); - }; - - w.Initialized += (s, e) => - { - wc++; - Assert.Equal (t.Bounds.Width, w.Frame.Width); - Assert.Equal (t.Bounds.Height, w.Frame.Height); - }; - - v1.Initialized += (s, e) => - { - v1c++; - - //Assert.Equal (t.Bounds.Width, v1.Frame.Width); - //Assert.Equal (t.Bounds.Height, v1.Frame.Height); - }; - - v2.Initialized += (s, e) => - { - v2c++; - - //Assert.Equal (t.Bounds.Width, v2.Frame.Width); - //Assert.Equal (t.Bounds.Height, v2.Frame.Height); - }; - w.Add (v1, v2); - t.Add (w); - - Application.Iteration += (s, a) => - { - var sv1 = new View { Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () }; - - sv1.Initialized += (s, e) => - { - sv1c++; - Assert.NotEqual (t.Frame.Width, sv1.Frame.Width); - Assert.NotEqual (t.Frame.Height, sv1.Frame.Height); - Assert.False (sv1.CanFocus); - Assert.Throws (() => sv1.CanFocus = true); - Assert.False (sv1.CanFocus); - }; - - v1.Add (sv1); - - Application.Refresh (); - t.Running = false; - }; - - Application.Run (t); - Application.Shutdown (); - - Assert.Equal (1, tc); - Assert.Equal (1, wc); - Assert.Equal (1, v1c); - Assert.Equal (1, v2c); - Assert.Equal (1, sv1c); - - Assert.True (t.CanFocus); - Assert.True (w.CanFocus); - Assert.False (v1.CanFocus); - Assert.False (v2.CanFocus); - } - [Fact] public void Internal_Tests () { @@ -1013,67 +705,18 @@ At 0,0 } [Fact] - [TestRespondersDisposed] - public void IsAdded_Added_Removed () + [SetupFakeDriver] + public void SetText_RendersCorrectly () { - var top = new Toplevel (); - var view = new View (); - Assert.False (view.IsAdded); - top.Add (view); - Assert.True (view.IsAdded); - top.Remove (view); - Assert.False (view.IsAdded); + View view; + var text = "test"; - top.Dispose (); - view.Dispose (); - } + view = new Label { Text = text }; + view.BeginInit (); + view.EndInit (); + view.Draw (); - [Theory] - [TestRespondersDisposed] - [InlineData (1)] - [InlineData (2)] - [InlineData (3)] - public void LabelChangeText_RendersCorrectly_Constructors (int choice) - { - var driver = new FakeDriver (); - Application.Init (driver); - - try - { - // Create a label with a short text - Label lbl; - var text = "test"; - - if (choice == 1) - { - // An object initializer should call the default constructor. - lbl = new Label { Text = text }; - } - else if (choice == 2) - { - // Calling the default constructor followed by the object initializer. - lbl = new Label { Text = text }; - } - else - { - // Calling the Text constructor. - lbl = new Label { Text = text }; - } - - Application.Top.Add (lbl); - Application.Begin (Application.Top); - - // should have the initial text - Assert.Equal ((Rune)'t', driver.Contents [0, 0].Rune); - Assert.Equal ((Rune)'e', driver.Contents [0, 1].Rune); - Assert.Equal ((Rune)'s', driver.Contents [0, 2].Rune); - Assert.Equal ((Rune)'t', driver.Contents [0, 3].Rune); - Assert.Equal ((Rune)' ', driver.Contents [0, 4].Rune); - } - finally - { - Application.Shutdown (); - } + TestHelpers.AssertDriverContentsWithFrameAre ( text, _output); } [Fact] @@ -1166,11 +809,11 @@ At 0,0 // BUGBUG: IsInitialized must be true to process calculation r.BeginInit (); r.EndInit (); - #if DEBUG +#if DEBUG Assert.Equal ("View(Vertical View)(0,0,1,13)", r.ToString ()); - #else +#else Assert.Equal ("View()(0,0,1,13)", r.ToString ()); - #endif +#endif Assert.False (r.CanFocus); Assert.False (r.HasFocus); Assert.Equal (new Rect (0, 0, 1, 13), r.Bounds); @@ -1178,11 +821,11 @@ At 0,0 Assert.Null (r.Focused); Assert.Null (r.ColorScheme); Assert.False (r.IsCurrentTop); - #if DEBUG +#if DEBUG Assert.Equal ("Vertical View", r.Id); - #else +#else Assert.Equal (string.Empty, r.Id); - #endif +#endif Assert.Empty (r.Subviews); Assert.False (r.WantContinuousButtonPressed); Assert.False (r.WantMousePositionReports); @@ -1513,4 +1156,65 @@ At 0,0 return true; } } + + // OnAccept/Accept tests + [Fact] + public void OnAccept_Fires_Accept () + { + var view = new View (); + var accepted = false; + + view.Accept += ViewOnAccept; + + view.OnAccept (); + Assert.True (accepted); + + return; + void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Cancel_Event_OnAccept_Returns_True () + { + var view = new View (); + var acceptInvoked = false; + + view.Accept += ViewOnAccept; + + var ret = view.OnAccept (); + Assert.True (ret); + Assert.True (acceptInvoked); + + return; + void ViewOnAccept (object sender, CancelEventArgs e) { + acceptInvoked = true; + e.Cancel = true; + } + } + + [Fact] + public void Accept_Command_Invokes_Accept_Event () + { + var view = new View (); + var accepted = false; + + view.Accept += ViewOnAccept; + + view.InvokeCommand (Command.Accept); + Assert.True (accepted); + + return; + void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new View (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } } diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index 4fe6133b2..9305c9f08 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -115,21 +115,21 @@ public class AllViewsTests if (vType is TextView) { - top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); } else if (vType is DatePicker) { for (var i = 0; i < 4; i++) { - top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)); + top.NewKeyDownEvent (Key.Tab.WithCtrl); } } else { - top.NewKeyDownEvent (new Key (KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab); } - top.NewKeyDownEvent (new Key (KeyCode.Tab)); + top.NewKeyDownEvent (Key.Tab); Assert.Equal (2, vTypeEnter); Assert.Equal (1, vTypeLeave); diff --git a/UnitTests/Views/AppendAutocompleteTests.cs b/UnitTests/Views/AppendAutocompleteTests.cs index 8667ba04e..f8818795b 100644 --- a/UnitTests/Views/AppendAutocompleteTests.cs +++ b/UnitTests/Views/AppendAutocompleteTests.cs @@ -151,10 +151,10 @@ public class AppendAutocompleteTests tf.Draw (); tf.PositionCursor (); TestHelpers.AssertDriverContentsAre ("", output); - tf.NewKeyDownEvent (new Key ((KeyCode)'m')); - tf.NewKeyDownEvent (new Key ((KeyCode)'y')); - tf.NewKeyDownEvent (new Key (KeyCode.Space)); - tf.NewKeyDownEvent (new Key ((KeyCode)'f')); + tf.NewKeyDownEvent (Key.M); + tf.NewKeyDownEvent (Key.Y); + tf.NewKeyDownEvent (Key.Space); + tf.NewKeyDownEvent (Key.F); Assert.Equal ("my f", tf.Text); // Even though there is no match on case we should still get the suggestion diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 672196fbf..3e15664b1 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using System.ComponentModel; +using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -7,6 +8,33 @@ public class ButtonTests private readonly ITestOutputHelper _output; public ButtonTests (ITestOutputHelper output) { _output = output; } + // Test that Title and Text are the same + [Fact] + public void Text_Mirrors_Title () + { + var view = new Button (); + view.Title = "Hello"; + Assert.Equal ("Hello", view.Title); + Assert.Equal ($"Hello", view.TitleTextFormatter.Text); + + Assert.Equal ("Hello", view.Text); + Assert.Equal ($"{CM.Glyphs.LeftBracket} Hello {CM.Glyphs.RightBracket}", view.TextFormatter.Text); + } + + [Fact] + public void Title_Mirrors_Text () + { + var view = new Button (); + view.Text = "Hello"; + Assert.Equal ("Hello", view.Text); + Assert.Equal ($"{CM.Glyphs.LeftBracket} Hello {CM.Glyphs.RightBracket}", view.TextFormatter.Text); + + Assert.Equal ("Hello", view.Title); + Assert.Equal ($"Hello", view.TitleTextFormatter.Text); + } + + // BUGBUG: This test is NOT a unit test and needs to be broken apart into + // more specific tests (e.g. it tests Checkbox as well as Button) [Fact] [AutoInitShutdown] public void AutoSize_False_With_Fixed_Width () @@ -102,8 +130,8 @@ public class ButtonTests Assert.Equal (new Rect (30, 1, 20, 1), btnFindNext.Frame); Assert.Equal (new Rect (30, 2, 20, 1), btnFindPrevious.Frame); Assert.Equal (new Rect (30, 4, 20, 1), btnCancel.Frame); - Assert.Equal (new Rect (0, 3, 12, 1), ckbMatchCase.Frame); - Assert.Equal (new Rect (0, 4, 18, 1), ckbMatchWholeWord.Frame); +// Assert.Equal (new Rect (0, 3, 12, 1), ckbMatchCase.Frame); +// Assert.Equal (new Rect (0, 4, 18, 1), ckbMatchWholeWord.Frame); var btn1 = $"{ @@ -503,21 +531,21 @@ public class ButtonTests { var clicked = false; var btn = new Button { Text = "_Test" }; - btn.Clicked += (s, e) => clicked = true; + btn.Accept += (s, e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); Assert.Equal (KeyCode.T, btn.HotKey); - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T))); + Assert.True (btn.NewKeyDownEvent (Key.T)); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.AltMask))); + Assert.True (btn.NewKeyDownEvent (Key.T.WithAlt)); Assert.True (clicked); clicked = false; btn.HotKey = KeyCode.E; - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.AltMask))); + Assert.True (btn.NewKeyDownEvent (Key.E.WithAlt)); Assert.True (clicked); } @@ -532,10 +560,10 @@ public class ButtonTests var pressed = 0; var btn = new Button { Text = "Press Me" }; - btn.Clicked += (s, e) => pressed++; + btn.Accept += (s, e) => pressed++; // The Button class supports the Default and Accept command - Assert.Contains (Command.Default, btn.GetSupportedCommands ()); + Assert.Contains (Command.HotKey, btn.GetSupportedCommands ()); Assert.Contains (Command.Accept, btn.GetSupportedCommands ()); Application.Top.Add (btn); @@ -548,29 +576,31 @@ public class ButtonTests Assert.Equal (1, pressed); // remove the default keybinding (Space) - btn.KeyBindings.Clear (Command.Default, Command.Accept); + btn.KeyBindings.Clear (Command.HotKey); + btn.KeyBindings.Clear (Command.Accept); // After clearing the default keystroke the Space button no longer does anything for the Button Application.OnKeyDown (new Key ((KeyCode)' ')); Assert.Equal (1, pressed); // Set a new binding of b for the click (Accept) event - btn.KeyBindings.Add (KeyCode.B, Command.Default, Command.Accept); + btn.KeyBindings.Add (Key.B, Command.HotKey); + btn.KeyBindings.Add (Key.B, Command.Accept); // now pressing B should call the button click event - Application.OnKeyDown (new Key (KeyCode.B)); + Application.OnKeyDown (Key.B); Assert.Equal (2, pressed); // now pressing Shift-B should NOT call the button click event - Application.OnKeyDown (new Key (KeyCode.ShiftMask | KeyCode.B)); + Application.OnKeyDown (Key.B.WithShift); Assert.Equal (2, pressed); // now pressing Alt-B should NOT call the button click event - Application.OnKeyDown (new Key (KeyCode.AltMask | KeyCode.B)); + Application.OnKeyDown (Key.B.WithAlt); Assert.Equal (2, pressed); // now pressing Shift-Alt-B should NOT call the button click event - Application.OnKeyDown (new Key (KeyCode.ShiftMask | KeyCode.AltMask | KeyCode.B)); + Application.OnKeyDown (Key.B.WithAlt.WithShift); Assert.Equal (2, pressed); } @@ -580,17 +610,17 @@ public class ButtonTests { var clicked = false; var btn = new Button { Text = "_Test" }; - btn.Clicked += (s, e) => clicked = true; + btn.Accept += (s, e) => clicked = true; Application.Top.Add (btn); Application.Begin (Application.Top); // Hot key. Both alone and with alt Assert.Equal (KeyCode.T, btn.HotKey); - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T))); + Assert.True (btn.NewKeyDownEvent (Key.T)); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.AltMask))); + Assert.True (btn.NewKeyDownEvent (Key.T.WithAlt)); Assert.True (clicked); clicked = false; @@ -604,28 +634,28 @@ public class ButtonTests // IsDefault = false // Space and Enter should work Assert.False (btn.IsDefault); - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (btn.NewKeyDownEvent (Key.Enter)); Assert.True (clicked); clicked = false; // IsDefault = true // Space and Enter should work btn.IsDefault = true; - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (btn.NewKeyDownEvent (Key.Enter)); Assert.True (clicked); clicked = false; // Toplevel does not handle Enter, so it should get passed on to button - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (Application.Top.NewKeyDownEvent (Key.Enter)); Assert.True (clicked); clicked = false; // Direct - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (btn.NewKeyDownEvent (Key.Enter)); Assert.True (clicked); clicked = false; - Assert.True (btn.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (btn.NewKeyDownEvent (Key.Space)); Assert.True (clicked); clicked = false; @@ -640,6 +670,40 @@ public class ButtonTests clicked = false; } + [Fact] + public void HotKey_Command_Accepts () + { + var button = new Button (); + var accepted = false; + + button.Accept += ButtonOnAccept; + button.InvokeCommand (Command.HotKey); + + Assert.True (accepted); + + return; + void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Cancel_Event_OnAccept_Returns_True () + { + var button = new Button (); + var acceptInvoked = false; + + button.Accept += ButtonAccept; + + var ret = button.OnAccept (); + Assert.True (ret); + Assert.True (acceptInvoked); + + return; + void ButtonAccept (object sender, CancelEventArgs e) + { + acceptInvoked = true; + e.Cancel = true; + } + } [Fact] public void Setting_Empty_Text_Sets_HoKey_To_KeyNull () { diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index e2ad70e44..00b97cb46 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using System.ComponentModel; +using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -7,6 +8,32 @@ public class CheckBoxTests private readonly ITestOutputHelper _output; public CheckBoxTests (ITestOutputHelper output) { _output = output; } + + // Test that Title and Text are the same + [Fact] + public void Text_Mirrors_Title () + { + var view = new CheckBox (); + view.Title = "Hello"; + Assert.Equal ("Hello", view.Title); + Assert.Equal ($"Hello", view.TitleTextFormatter.Text); + + Assert.Equal ("Hello", view.Text); + Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text); + } + + [Fact] + public void Title_Mirrors_Text () + { + var view = new CheckBox (); + view.Text = "Hello"; + Assert.Equal ("Hello", view.Text); + Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text); + + Assert.Equal ("Hello", view.Title); + Assert.Equal ($"Hello", view.TitleTextFormatter.Text); + } + [Fact] [AutoInitShutdown] public void AllowNullChecked_Get_Set () @@ -17,26 +44,24 @@ public class CheckBoxTests Application.Begin (top); Assert.False (checkBox.Checked); - Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (checkBox.NewKeyDownEvent (Key.Space)); Assert.True (checkBox.Checked); Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); Assert.False (checkBox.Checked); checkBox.AllowNullChecked = true; - Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (checkBox.NewKeyDownEvent (Key.Space)); Assert.Null (checkBox.Checked); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @$" -{ - CM.Glyphs.NullChecked -} Check this out 你", +{CM.Glyphs.NullChecked} Check this out 你", _output ); Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); Assert.True (checkBox.Checked); - Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (checkBox.NewKeyDownEvent (Key.Space)); Assert.False (checkBox.Checked); Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked })); Assert.Null (checkBox.Checked); @@ -65,9 +90,7 @@ public class CheckBoxTests var expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check this out 你│ +│ {CM.Glyphs.UnChecked} Check this out 你│ │ │ └────────────────────────────┘ "; @@ -82,9 +105,7 @@ public class CheckBoxTests expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check this out 你 changed│ +│ {CM.Glyphs.UnChecked} Check this out 你 changed│ │ │ └────────────────────────────┘ "; @@ -112,9 +133,7 @@ public class CheckBoxTests var expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check this out 你│ +│ {CM.Glyphs.UnChecked} Check this out 你│ │ │ └────────────────────────────┘ "; @@ -129,9 +148,7 @@ public class CheckBoxTests expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check this out 你 changed│ +│ {CM.Glyphs.UnChecked} Check this out 你 changed│ │ │ └────────────────────────────┘ "; @@ -257,59 +274,69 @@ public class CheckBoxTests } [Fact] - [AutoInitShutdown] public void KeyBindings_Command () { var toggled = false; var ckb = new CheckBox (); ckb.Toggled += (s, e) => toggled = true; - Application.Top.Add (ckb); - Application.Begin (Application.Top); Assert.False (ckb.Checked); Assert.False (toggled); - Assert.Equal (KeyCode.Null, ckb.HotKey); + Assert.Equal (Key.Empty, ckb.HotKey); ckb.Text = "_Test"; - Assert.Equal (KeyCode.T, ckb.HotKey); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.T))); + Assert.Equal (Key.T, ckb.HotKey); + Assert.True (ckb.NewKeyDownEvent (Key.T)); Assert.True (ckb.Checked); Assert.True (toggled); ckb.Text = "T_est"; toggled = false; - Assert.Equal (KeyCode.E, ckb.HotKey); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.AltMask))); + Assert.Equal (Key.E, ckb.HotKey); + Assert.True (ckb.NewKeyDownEvent (Key.E.WithAlt)); Assert.True (toggled); Assert.False (ckb.Checked); toggled = false; - Assert.Equal (KeyCode.E, ckb.HotKey); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.E))); + Assert.Equal (Key.E, ckb.HotKey); + Assert.True (ckb.NewKeyDownEvent (Key.E)); Assert.True (toggled); Assert.True (ckb.Checked); toggled = false; - Assert.True (Application.Top.NewKeyDownEvent (new Key ((KeyCode)' '))); + Assert.True (ckb.NewKeyDownEvent (Key.Space)); Assert.True (toggled); Assert.False (ckb.Checked); toggled = false; - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (ckb.NewKeyDownEvent (Key.Space)); Assert.True (toggled); Assert.True (ckb.Checked); - Assert.True (ckb.AutoSize); - Application.Refresh (); + toggled = false; + Assert.False (ckb.NewKeyDownEvent (Key.Enter)); + Assert.False (toggled); + Assert.True (ckb.Checked); + } - var expected = @$" -{ - CM.Glyphs.Checked -} Test -"; + [Fact] + public void Accept_Cancel_Event_OnAccept_Returns_True () + { + var ckb = new CheckBox (); + var acceptInvoked = false; - Rect pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 6, 1), pos); + ckb.Accept += ViewOnAccept; + + var ret = ckb.OnAccept (); + Assert.True (ret); + Assert.True (acceptInvoked); + + return; + void ViewOnAccept (object sender, CancelEventArgs e) + { + acceptInvoked = true; + e.Cancel = true; + } } [Fact] @@ -340,9 +367,7 @@ public class CheckBoxTests var expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check this out 你 │ +│ {CM.Glyphs.UnChecked} Check this out 你 │ │ │ └────────────────────────────┘ "; @@ -356,9 +381,7 @@ public class CheckBoxTests expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.Checked -} Check this out 你 │ +│ {CM.Glyphs.Checked} Check this out 你 │ │ │ └────────────────────────────┘ "; @@ -407,12 +430,8 @@ public class CheckBoxTests var expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check first out 你 │ -│ { - CM.Glyphs.UnChecked -} Check second out 你 │ +│ {CM.Glyphs.UnChecked} Check first out 你 │ +│ {CM.Glyphs.UnChecked} Check second out 你 │ │ │ └────────────────────────────┘ "; @@ -431,12 +450,8 @@ public class CheckBoxTests expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.Checked -} Check first out 你 │ -│ { - CM.Glyphs.Checked -} Check second out 你 │ +│ {CM.Glyphs.Checked} Check first out 你 │ +│ {CM.Glyphs.Checked} Check second out 你 │ │ │ └────────────────────────────┘ "; @@ -471,9 +486,7 @@ public class CheckBoxTests var expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.UnChecked -} Check this out 你 │ +│ {CM.Glyphs.UnChecked} Check this out 你 │ │ │ └────────────────────────────┘ "; @@ -487,9 +500,7 @@ public class CheckBoxTests expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ { - CM.Glyphs.Checked -} Check this out 你 │ +│ {CM.Glyphs.Checked} Check this out 你 │ │ │ └────────────────────────────┘ "; @@ -526,9 +537,7 @@ public class CheckBoxTests var expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ Check this out 你 { - CM.Glyphs.UnChecked -} │ +│ Check this out 你 {CM.Glyphs.UnChecked} │ │ │ └────────────────────────────┘ "; @@ -542,9 +551,7 @@ public class CheckBoxTests expected = @$" ┌┤Test Demo 你├──────────────┐ │ │ -│ Check this out 你 { - CM.Glyphs.Checked -} │ +│ Check this out 你 {CM.Glyphs.Checked} │ │ │ └────────────────────────────┘ "; @@ -552,4 +559,45 @@ public class CheckBoxTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 30, 5), pos); } + + [Fact] + public void HotKey_Command_Fires_Accept () + { + var cb = new CheckBox (); + var accepted = false; + + cb.Accept += ButtonOnAccept; + cb.InvokeCommand (Command.HotKey); + + Assert.True (accepted); + + return; + void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Theory] + [InlineData (true)] + [InlineData (false)] + [InlineData (null)] + public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState) + { + var ckb = new CheckBox () { AllowNullChecked = true }; + var checkedInvoked = false; + + ckb.Toggled += CheckBoxToggled; + + ckb.Checked = initialState; + Assert.Equal(initialState, ckb.Checked); + var ret = ckb.OnToggled (); + Assert.True (ret); + Assert.True (checkedInvoked); + Assert.Equal (initialState, ckb.Checked); + + return; + void CheckBoxToggled (object sender, CancelEventArgs e) + { + checkedInvoked = true; + e.Cancel = true; + } + } } diff --git a/UnitTests/Views/ColorPickerTests.cs b/UnitTests/Views/ColorPickerTests.cs index 7a7a281c4..b849669b4 100644 --- a/UnitTests/Views/ColorPickerTests.cs +++ b/UnitTests/Views/ColorPickerTests.cs @@ -23,22 +23,22 @@ public class ColorPickerTests var colorPicker = new ColorPicker (); Assert.Equal (ColorName.Black, colorPicker.SelectedColor); - Assert.True (colorPicker.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (colorPicker.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (ColorName.Blue, colorPicker.SelectedColor); - Assert.True (colorPicker.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (colorPicker.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (ColorName.BrightBlue, colorPicker.SelectedColor); - Assert.True (colorPicker.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (colorPicker.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (ColorName.DarkGray, colorPicker.SelectedColor); - Assert.True (colorPicker.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (colorPicker.NewKeyDownEvent (Key.CursorUp)); Assert.Equal (ColorName.Black, colorPicker.SelectedColor); - Assert.True (colorPicker.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (colorPicker.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (ColorName.Black, colorPicker.SelectedColor); - Assert.True (colorPicker.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (colorPicker.NewKeyDownEvent (Key.CursorUp)); Assert.Equal (ColorName.Black, colorPicker.SelectedColor); } diff --git a/UnitTests/Views/ComboBoxTests.cs b/UnitTests/Views/ComboBoxTests.cs index 43e440001..1e76512fc 100644 --- a/UnitTests/Views/ComboBoxTests.cs +++ b/UnitTests/Views/ComboBoxTests.cs @@ -112,13 +112,13 @@ public class ComboBoxTests Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.NotNull (cb.Source); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Null (cb.Source); Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -152,30 +152,30 @@ public class ComboBoxTests Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (cb.NewKeyDownEvent (Key.Esc)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -208,8 +208,8 @@ public class ComboBoxTests Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -244,30 +244,30 @@ public class ComboBoxTests Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (cb.NewKeyDownEvent (Key.Esc)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -418,7 +418,7 @@ public class ComboBoxTests Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.True ( cb.Subviews [1] @@ -442,7 +442,7 @@ public class ComboBoxTests Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.True ( cb.Subviews [1] @@ -466,7 +466,7 @@ public class ComboBoxTests Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.True ( cb.Subviews [1] @@ -549,7 +549,7 @@ Three ", attributes ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -566,7 +566,7 @@ Three ", attributes ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -583,13 +583,13 @@ Three ", attributes ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); Assert.Equal ("Three", selected); Assert.False (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("Three", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -606,7 +606,7 @@ Three ", attributes ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorUp)); Assert.Equal ("Three", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -623,7 +623,7 @@ Three ", attributes ); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorUp)); Assert.Equal ("Three", selected); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -640,7 +640,7 @@ Three ", attributes ); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("Three", selected); Assert.False (cb.IsShow); Assert.Equal (2, cb.SelectedItem); @@ -673,7 +673,7 @@ Three ", Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.True ( cb.MouseEvent ( @@ -695,7 +695,7 @@ Three ", Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorUp)); Assert.True ( cb.MouseEvent ( @@ -734,30 +734,30 @@ Three ", Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.Enter)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Assert.Equal ("Two", selected); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (cb.NewKeyDownEvent (Key.Esc)); Assert.Equal ("Two", selected); Assert.False (cb.IsShow); Assert.Equal (1, cb.SelectedItem); @@ -790,8 +790,8 @@ Three ", Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.Equal ("", selected); Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -811,28 +811,28 @@ Three ", Assert.Equal (string.Empty, cb.Text); var opened = false; cb.OpenSelectedItem += (s, _) => opened = true; - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.NewKeyDownEvent (Key.Enter)); Assert.False (opened); cb.Text = "Tw"; - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.NewKeyDownEvent (Key.Enter)); Assert.True (opened); Assert.Equal ("Tw", cb.Text); Assert.False (cb.IsShow); cb.SetSource (null); - Assert.False (cb.NewKeyDownEvent (new Key (KeyCode.Enter))); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); // with no source also expand empty + Assert.False (cb.NewKeyDownEvent (Key.Enter)); + Assert.True (cb.NewKeyDownEvent (Key.F4)); // with no source also expand empty Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); cb.SetSource (source); cb.Text = ""; - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); // collapse + Assert.True (cb.NewKeyDownEvent (Key.F4)); // collapse Assert.False (cb.IsShow); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); // expand + Assert.True (cb.NewKeyDownEvent (Key.F4)); // expand Assert.True (cb.IsShow); cb.Collapse (); Assert.False (cb.IsShow); Assert.True (cb.HasFocus); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorDown))); // losing focus + Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); // losing focus Assert.False (cb.IsShow); Assert.False (cb.HasFocus); Application.Top.FocusFirst (); // Gets focus again @@ -842,27 +842,27 @@ Three ", Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (cb.NewKeyDownEvent (Key.CursorUp)); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (cb.NewKeyDownEvent (Key.CursorUp)); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (cb.NewKeyDownEvent (Key.CursorUp)); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); @@ -876,7 +876,7 @@ One _output ); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.PageDown))); + Assert.True (cb.NewKeyDownEvent (Key.PageDown)); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); @@ -890,7 +890,7 @@ Two _output ); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.PageDown))); + Assert.True (cb.NewKeyDownEvent (Key.PageDown)); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); @@ -903,43 +903,43 @@ Three ", _output ); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.PageUp))); + Assert.True (cb.NewKeyDownEvent (Key.PageUp)); Assert.True (cb.IsShow); Assert.Equal (1, cb.SelectedItem); Assert.Equal ("Two", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.PageUp))); + Assert.True (cb.NewKeyDownEvent (Key.PageUp)); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.False (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (cb.NewKeyDownEvent (Key.End)); Assert.False (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (cb.NewKeyDownEvent (Key.Home)); Assert.False (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (cb.NewKeyDownEvent (Key.End)); Assert.True (cb.IsShow); Assert.Equal (2, cb.SelectedItem); Assert.Equal ("Three", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (cb.NewKeyDownEvent (Key.Home)); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (cb.NewKeyDownEvent (Key.Esc)); Assert.False (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.CursorDown))); // losing focus + Assert.True (cb.NewKeyDownEvent (Key.CursorDown)); // losing focus Assert.False (cb.HasFocus); Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -949,7 +949,7 @@ Three Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("One", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.U | KeyCode.CtrlMask))); + Assert.True (cb.NewKeyDownEvent (Key.U.WithCtrl)); Assert.True (cb.HasFocus); Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -974,7 +974,7 @@ Three source.Add ("One"); Assert.Equal (1, cb.Source.Count); Assert.Equal (-1, cb.SelectedItem); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.F4))); + Assert.True (cb.NewKeyDownEvent (Key.F4)); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); Assert.Equal ("One", cb.Text); @@ -985,12 +985,12 @@ Three Assert.True (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("T", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (cb.NewKeyDownEvent (Key.Enter)); Assert.False (cb.IsShow); Assert.Equal (2, cb.Source.Count); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("T", cb.Text); - Assert.True (cb.NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (cb.NewKeyDownEvent (Key.Esc)); Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); // retains last accept selected item Assert.Equal ("", cb.Text); // clear text diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index 8f4f23a98..85c3bb128 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -511,37 +511,7 @@ public class ContextMenuTests top.RequestStop (); Assert.False (ContextMenu.IsShow); } - - [Fact] - [AutoInitShutdown] - public void Key_Changing () - { - var lbl = new Label { Text = "Original" }; - - var cm = new ContextMenu (); - - lbl.KeyDown += (s, e) => - { - if (e == cm.Key) - { - lbl.Text = "Replaced"; - e.Handled = true; - } - }; - - Toplevel top = Application.Top; - top.Add (lbl); - Application.Begin (top); - - Assert.True (lbl.NewKeyDownEvent (cm.Key)); - Assert.Equal ("Replaced", lbl.Text); - - lbl.Text = "Original"; - cm.Key = KeyCode.Space | KeyCode.CtrlMask; - Assert.True (lbl.NewKeyDownEvent (cm.Key)); - Assert.Equal ("Replaced", lbl.Text); - } - + [Fact] [AutoInitShutdown] public void Key_Open_And_Close_The_ContextMenu () @@ -550,9 +520,9 @@ public class ContextMenuTests Application.Top.Add (tf); Application.Begin (Application.Top); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.F10 | KeyCode.ShiftMask))); + Assert.True (Application.OnKeyDown (ContextMenu.DefaultKey)); Assert.True (tf.ContextMenu.MenuBar.IsMenuOpen); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.F10 | KeyCode.ShiftMask))); + Assert.True (Application.OnKeyDown (ContextMenu.DefaultKey)); Assert.Null (tf.ContextMenu.MenuBar); } @@ -560,14 +530,14 @@ public class ContextMenuTests [AutoInitShutdown] public void KeyChanged_Event () { - var oldKey = KeyCode.Null; + var oldKey = Key.Empty; var cm = new ContextMenu (); - cm.KeyChanged += (s, e) => oldKey = (KeyCode)e.OldKey; + cm.KeyChanged += (s, e) => oldKey = e.OldKey; - cm.Key = KeyCode.Space | KeyCode.CtrlMask; - Assert.Equal (KeyCode.Space | KeyCode.CtrlMask, cm.Key); - Assert.Equal (KeyCode.F10 | KeyCode.ShiftMask, oldKey); + cm.Key = Key.Space.WithCtrl; + Assert.Equal (Key.Space.WithCtrl, cm.Key); + Assert.Equal (ContextMenu.DefaultKey, oldKey); } [Fact] diff --git a/UnitTests/Views/DateFieldTests.cs b/UnitTests/Views/DateFieldTests.cs index b1051d093..d131a0795 100644 --- a/UnitTests/Views/DateFieldTests.cs +++ b/UnitTests/Views/DateFieldTests.cs @@ -37,16 +37,16 @@ public class DateFieldTests var df2 = new DateField (DateTime.Parse ("12/31/2023")); // Select all text - Assert.True (df2.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.ShiftMask))); + Assert.True (df2.NewKeyDownEvent (Key.End.WithShift)); Assert.Equal (1, df2.SelectedStart); Assert.Equal (10, df2.SelectedLength); Assert.Equal (11, df2.CursorPosition); // Copy from df2 - Assert.True (df2.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (df2.NewKeyDownEvent (Key.C.WithCtrl)); // Paste into df1 - Assert.True (df1.NewKeyDownEvent (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (df1.NewKeyDownEvent (Key.V.WithCtrl)); Assert.Equal (" 12/31/2023", df1.Text); Assert.Equal (11, df1.CursorPosition); } @@ -70,22 +70,22 @@ public class DateFieldTests var df = new DateField (); // Start selection - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask))); + Assert.True (df.NewKeyDownEvent (Key.CursorLeft.WithShift)); Assert.Equal (1, df.SelectedStart); Assert.Equal (1, df.SelectedLength); Assert.Equal (0, df.CursorPosition); // Without selection - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (df.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (-1, df.SelectedStart); Assert.Equal (0, df.SelectedLength); Assert.Equal (1, df.CursorPosition); df.CursorPosition = 10; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (df.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal (10, df.SelectedStart); Assert.Equal (1, df.SelectedLength); Assert.Equal (11, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (df.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (-1, df.SelectedStart); Assert.Equal (0, df.SelectedLength); Assert.Equal (10, df.CursorPosition); @@ -106,43 +106,45 @@ public class DateFieldTests public void KeyBindings_Command () { var df = new DateField (DateTime.Parse ("12/12/1971")) { ReadOnly = true }; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (df.NewKeyDownEvent (Key.Delete)); Assert.Equal (" 12/12/1971", df.Text); df.ReadOnly = false; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.CtrlMask))); + Assert.True (df.NewKeyDownEvent (Key.D.WithCtrl)); Assert.Equal (" 02/12/1971", df.Text); df.CursorPosition = 4; df.ReadOnly = true; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (df.NewKeyDownEvent (Key.Delete)); Assert.Equal (" 02/12/1971", df.Text); df.ReadOnly = false; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (df.NewKeyDownEvent (Key.Backspace)); Assert.Equal (" 02/02/1971", df.Text); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (df.NewKeyDownEvent (Key.Home)); Assert.Equal (1, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (df.NewKeyDownEvent (Key.End)); Assert.Equal (10, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.CtrlMask))); + Assert.True (df.NewKeyDownEvent (Key.A.WithCtrl)); Assert.Equal (1, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.CtrlMask))); + Assert.True (df.NewKeyDownEvent (Key.E.WithCtrl)); Assert.Equal (10, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (df.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (9, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (df.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (10, df.CursorPosition); // Non-numerics are ignored - Assert.False (df.NewKeyDownEvent (new Key (KeyCode.A))); + Assert.False (df.NewKeyDownEvent (Key.A)); df.ReadOnly = true; df.CursorPosition = 1; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (df.NewKeyDownEvent (Key.D1)); Assert.Equal (" 02/02/1971", df.Text); df.ReadOnly = false; - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (df.NewKeyDownEvent (Key.D1)); Assert.Equal (" 12/02/1971", df.Text); Assert.Equal (2, df.CursorPosition); - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (df.NewKeyDownEvent (Key.D.WithAlt)); Assert.Equal (" 10/02/1971", df.Text); +#endif } [Fact] @@ -156,13 +158,13 @@ public class DateFieldTests }; // Now select the separator / - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (df.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal (2, df.SelectedStart); Assert.Equal (1, df.SelectedLength); Assert.Equal (3, df.CursorPosition); // Type 3 over the separator - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.D3))); + Assert.True (df.NewKeyDownEvent (Key.D3)); // The format was normalized and replaced again with / Assert.Equal (" 12/12/1971", df.Text); @@ -282,7 +284,7 @@ public class DateFieldTests }; // Type 3 over the separator - Assert.True (df.NewKeyDownEvent (new Key (KeyCode.D3))); + Assert.True (df.NewKeyDownEvent (Key.D3)); // If InvariantCulture was used this will fail but not with PT culture Assert.Equal (" 13/12/1971", df.Text); diff --git a/UnitTests/Views/DatePickerTests.cs b/UnitTests/Views/DatePickerTests.cs index 85839d053..4c8008ffa 100644 --- a/UnitTests/Views/DatePickerTests.cs +++ b/UnitTests/Views/DatePickerTests.cs @@ -58,11 +58,11 @@ public class DatePickerTests datePicker.FocusNext (); // Change month to December - Assert.True (datePicker.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (datePicker.NewKeyDownEvent (Key.Enter)); Assert.Equal (12, datePicker.Date.Month); // Date should not change as next month button is disabled - Assert.False (datePicker.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.False (datePicker.NewKeyDownEvent (Key.Enter)); Assert.Equal (12, datePicker.Date.Month); } @@ -82,11 +82,11 @@ public class DatePickerTests datePicker.FocusNext (); // Change month to January - Assert.True (datePicker.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (datePicker.NewKeyDownEvent (Key.Enter)); Assert.Equal (1, datePicker.Date.Month); // Date should not change as previous month button is disabled - Assert.False (datePicker.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.False (datePicker.NewKeyDownEvent (Key.Enter)); Assert.Equal (1, datePicker.Date.Month); } } diff --git a/UnitTests/Views/HexViewTests.cs b/UnitTests/Views/HexViewTests.cs index 300d15547..eff9013e5 100644 --- a/UnitTests/Views/HexViewTests.cs +++ b/UnitTests/Views/HexViewTests.cs @@ -14,23 +14,23 @@ public class HexViewTests Assert.Empty (hv.Edits); hv.AllowEdits = false; - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Home))); - Assert.False (hv.NewKeyDownEvent (new Key (KeyCode.A))); + Assert.True (hv.NewKeyDownEvent (Key.Home)); + Assert.False (hv.NewKeyDownEvent (Key.A)); Assert.Empty (hv.Edits); Assert.Equal (126, hv.Source.Length); hv.AllowEdits = true; - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D4))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (hv.NewKeyDownEvent (Key.D4)); + Assert.True (hv.NewKeyDownEvent (Key.D1)); Assert.Single (hv.Edits); Assert.Equal (65, hv.Edits.ToList () [0].Value); Assert.Equal ('A', (char)hv.Edits.ToList () [0].Value); Assert.Equal (126, hv.Source.Length); // Appends byte - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D4))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (hv.NewKeyDownEvent (Key.End)); + Assert.True (hv.NewKeyDownEvent (Key.D4)); + Assert.True (hv.NewKeyDownEvent (Key.D2)); Assert.Equal (2, hv.Edits.Count); Assert.Equal (66, hv.Edits.ToList () [1].Value); Assert.Equal ('B', (char)hv.Edits.ToList () [1].Value); @@ -62,8 +62,8 @@ public class HexViewTests hv.Source.Read (readBuffer); Assert.Equal ("Fest", Encoding.Default.GetString (readBuffer)); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D5))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D4))); + Assert.True (hv.NewKeyDownEvent (Key.D5)); + Assert.True (hv.NewKeyDownEvent (Key.D4)); readBuffer [hv.Edits.ToList () [0].Key] = hv.Edits.ToList () [0].Value; Assert.Equal ("Test", Encoding.Default.GetString (readBuffer)); @@ -103,18 +103,18 @@ public class HexViewTests Assert.Equal (new Point (1, 1), hv.CursorPosition); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Enter))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.Enter)); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight.WithCtrl)); Assert.Equal (hv.CursorPosition.X, hv.BytesPerLine); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (hv.NewKeyDownEvent (Key.Home)); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (new Point (2, 1), hv.CursorPosition); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (hv.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (new Point (2, 2), hv.CursorPosition); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); int col = hv.CursorPosition.X; int line = hv.CursorPosition.Y; int offset = (line - 1) * (hv.BytesPerLine - col); @@ -131,18 +131,18 @@ public class HexViewTests Assert.Equal (new Point (1, 1), hv.CursorPosition); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Enter))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.Enter)); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight.WithCtrl)); Assert.Equal (hv.CursorPosition.X, hv.BytesPerLine); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (hv.NewKeyDownEvent (Key.Home)); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (new Point (2, 1), hv.CursorPosition); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (hv.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (new Point (2, 2), hv.CursorPosition); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); int col = hv.CursorPosition.X; int line = hv.CursorPosition.Y; int offset = (line - 1) * (hv.BytesPerLine - col); @@ -157,8 +157,8 @@ public class HexViewTests // Needed because HexView relies on LayoutComplete to calc sizes hv.LayoutSubviews (); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D4))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (hv.NewKeyDownEvent (Key.D4)); + Assert.True (hv.NewKeyDownEvent (Key.D1)); Assert.Single (hv.Edits); Assert.Equal (65, hv.Edits.ToList () [0].Value); Assert.Equal ('A', (char)hv.Edits.ToList () [0].Value); @@ -178,11 +178,11 @@ public class HexViewTests Assert.Equal (0, hv.DisplayStart); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.PageDown))); + Assert.True (hv.NewKeyDownEvent (Key.PageDown)); Assert.Equal (4 * hv.Frame.Height, hv.DisplayStart); Assert.Equal (hv.Source.Length, hv.Source.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); // already on last page and so the DisplayStart is the same as before Assert.Equal (4 * hv.Frame.Height, hv.DisplayStart); @@ -200,8 +200,8 @@ public class HexViewTests KeyValuePair keyValuePair = default; hv.Edited += (s, e) => keyValuePair = new KeyValuePair (e.Position, e.NewValue); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D4))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.D6))); + Assert.True (hv.NewKeyDownEvent (Key.D4)); + Assert.True (hv.NewKeyDownEvent (Key.D6)); Assert.Equal (0, (int)keyValuePair.Key); Assert.Equal (70, keyValuePair.Value); @@ -228,48 +228,48 @@ public class HexViewTests Assert.Equal (4, hv.BytesPerLine); // right side only needed to press one time - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (hv.NewKeyDownEvent (Key.Enter)); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (2, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (hv.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (hv.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (5, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (hv.NewKeyDownEvent (Key.CursorUp)); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.V.WithCtrl)); Assert.Equal (41, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key ('v' + KeyCode.AltMask))); + Assert.True (hv.NewKeyDownEvent (new Key (Key.V.WithAlt))); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.PageDown))); + Assert.True (hv.NewKeyDownEvent (Key.PageDown)); Assert.Equal (41, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.PageUp))); + Assert.True (hv.NewKeyDownEvent (Key.PageUp)); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (64, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (hv.NewKeyDownEvent (Key.Home)); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight.WithCtrl)); Assert.Equal (4, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.CursorLeft.WithCtrl)); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.CursorDown.WithCtrl)); Assert.Equal (37, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.CtrlMask))); + Assert.True (hv.NewKeyDownEvent (Key.CursorUp.WithCtrl)); Assert.Equal (1, hv.Position); } @@ -285,23 +285,23 @@ public class HexViewTests Assert.Equal (1, hv.Position); // left side needed to press twice - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (63, hv.Source.Position); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (63, hv.Source.Position); Assert.Equal (2, hv.Position); // right side only needed to press one time - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (hv.NewKeyDownEvent (Key.Enter)); Assert.Equal (63, hv.Source.Position); Assert.Equal (2, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (hv.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (63, hv.Source.Position); Assert.Equal (1, hv.Position); // last position is equal to the source length - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (63, hv.Source.Position); Assert.Equal (64, hv.Position); Assert.Equal (hv.Position - 1, hv.Source.Length); @@ -319,23 +319,23 @@ public class HexViewTests Assert.Equal (1, hv.Position); // left side needed to press twice - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (126, hv.Source.Position); Assert.Equal (1, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (126, hv.Source.Position); Assert.Equal (2, hv.Position); // right side only needed to press one time - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (hv.NewKeyDownEvent (Key.Enter)); Assert.Equal (126, hv.Source.Position); Assert.Equal (2, hv.Position); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (hv.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (126, hv.Source.Position); Assert.Equal (1, hv.Position); // last position is equal to the source length - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (126, hv.Source.Position); Assert.Equal (127, hv.Position); Assert.Equal (hv.Position - 1, hv.Source.Length); @@ -351,9 +351,9 @@ public class HexViewTests Application.Top.Add (hv); Application.Begin (Application.Top); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); // left side must press twice - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); // left side must press twice + Assert.True (hv.NewKeyDownEvent (Key.CursorRight)); + Assert.True (hv.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (12, hexViewEventArgs.BytesPerLine); Assert.Equal (new Point (2, 2), hexViewEventArgs.CursorPosition); @@ -368,7 +368,7 @@ public class HexViewTests Application.Top.Add (hv); Application.Begin (Application.Top); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (62, hv.DisplayStart); Assert.Equal (64, hv.Position); @@ -383,7 +383,7 @@ public class HexViewTests Assert.Equal (0, hv.DisplayStart); Assert.Equal (0, hv.Position - 1); - Assert.True (hv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (hv.NewKeyDownEvent (Key.End)); Assert.Equal (0, hv.DisplayStart); Assert.Equal (64, hv.Position); diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index d05e312e3..4f61ef8cd 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using System.ComponentModel; +using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -7,6 +8,64 @@ public class LabelTests private readonly ITestOutputHelper _output; public LabelTests (ITestOutputHelper output) { _output = output; } + // Test that Title and Text are the same + [Fact] + public void Text_Mirrors_Title () + { + var label = new Label (); + label.Title = "Hello"; + Assert.Equal ("Hello", label.Title); + Assert.Equal ("Hello", label.TitleTextFormatter.Text); + + Assert.Equal ("Hello", label.Text); + Assert.Equal ("Hello", label.TextFormatter.Text); + } + + [Fact] + public void Title_Mirrors_Text () + { + var label = new Label (); + label.Text = "Hello"; + Assert.Equal ("Hello", label.Text); + Assert.Equal ("Hello", label.TextFormatter.Text); + + Assert.Equal ("Hello", label.Title); + Assert.Equal ("Hello", label.TitleTextFormatter.Text); + } + + [Fact] + public void HotKey_Command_SetsFocus_OnNextSubview () + { + var superView = new View () { CanFocus = true }; + var label = new Label (); + var nextSubview = new View () { CanFocus = true }; + superView.Add (label, nextSubview); + superView.BeginInit (); + superView.EndInit (); + + Assert.False (label.HasFocus); + Assert.False (nextSubview.HasFocus); + + label.InvokeCommand (Command.HotKey); + Assert.False (label.HasFocus); + Assert.True (nextSubview.HasFocus); + } + + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var label = new Label (); + var accepted = false; + + label.Accept += LabelOnAccept; + label.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + [Fact] [AutoInitShutdown] public void AutoSize_Stays_True_AnchorEnd () @@ -421,4 +480,69 @@ e Rect pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 30, 5), pos); } + + + [Fact] + [AutoInitShutdown] + public void Full_Border () + { + var label = new Label { Text = "Test", /*Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; + Application.Top.Add (label); + Application.Begin (Application.Top); + + Assert.Equal (new Rect (0, 0, 6, 3), label.Frame); + Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌┤Te├┐ +│Test│ +└────┘", + _output + ); + } + + [Fact] + [AutoInitShutdown] + public void With_Top_Margin_Without_Top_Border () + { + var label = new Label { Text = "Test", /*Width = 6, Height = 3,*/ BorderStyle = LineStyle.Single }; + label.Margin.Thickness = new Thickness (0, 1, 0, 0); + label.Border.Thickness = new Thickness (1, 0, 1, 1); + Application.Top.Add (label); + Application.Begin (Application.Top); + + Assert.Equal (new Rect (0, 0, 6, 3), label.Frame); + Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds); + Application.Begin (Application.Top); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +│Test│ +└────┘", + _output + ); + } + + [Fact] + [AutoInitShutdown] + public void Without_Top_Border () + { + var label = new Label { Text = "Test", /* Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; + label.Border.Thickness = new Thickness (1, 0, 1, 1); + Application.Top.Add (label); + Application.Begin (Application.Top); + + Assert.Equal (new Rect (0, 0, 6, 2), label.Frame); + Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds); + Application.Begin (Application.Top); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +│Test│ +└────┘", + _output + ); + } + } diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index 89b310d2e..63dd37f1b 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.ComponentModel; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -367,29 +368,121 @@ Item 6", lv.BeginInit (); lv.EndInit (); Assert.Equal (-1, lv.SelectedItem); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (lv.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (0, lv.SelectedItem); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (lv.NewKeyDownEvent (Key.CursorUp)); Assert.Equal (0, lv.SelectedItem); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.PageDown))); + Assert.True (lv.NewKeyDownEvent (Key.PageDown)); Assert.Equal (2, lv.SelectedItem); Assert.Equal (2, lv.TopItem); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.PageUp))); + Assert.True (lv.NewKeyDownEvent (Key.PageUp)); Assert.Equal (0, lv.SelectedItem); Assert.Equal (0, lv.TopItem); Assert.False (lv.Source.IsMarked (lv.SelectedItem)); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (lv.NewKeyDownEvent (Key.Space)); Assert.True (lv.Source.IsMarked (lv.SelectedItem)); var opened = false; lv.OpenSelectedItem += (s, _) => opened = true; - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (lv.NewKeyDownEvent (Key.Enter)); Assert.True (opened); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (lv.NewKeyDownEvent (Key.End)); Assert.Equal (2, lv.SelectedItem); - Assert.True (lv.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (lv.NewKeyDownEvent (Key.Home)); Assert.Equal (0, lv.SelectedItem); } + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new ListView (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } + + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var listView = new ListView (); + var accepted = false; + + listView.Accept += OnAccept; + listView.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + void OnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + + [Fact] + public void Accept_Command_Accepts_and_Opens_Selected_Item () + { + List source = ["One", "Two", "Three"]; + var listView = new ListView {Source = new ListWrapper (source) }; + listView.SelectedItem = 0; + + var accepted = false; + var opened = false; + string selectedValue = string.Empty; + + listView.Accept += Accept; + listView.OpenSelectedItem += OpenSelectedItem; + + listView.InvokeCommand (Command.Accept); + + Assert.True (accepted); + Assert.True (opened); + Assert.Equal (source [0], selectedValue); + + return; + + void OpenSelectedItem (object sender, ListViewItemEventArgs e) + { + opened = true; + selectedValue = e.Value.ToString (); + } + void Accept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Cancel_Event_Prevents_OpenSelectedItem () + { + List source = ["One", "Two", "Three"]; + var listView = new ListView { Source = new ListWrapper (source) }; + listView.SelectedItem = 0; + + var accepted = false; + var opened = false; + string selectedValue = string.Empty; + + listView.Accept += Accept; + listView.OpenSelectedItem += OpenSelectedItem; + + listView.InvokeCommand (Command.Accept); + + Assert.True (accepted); + Assert.False (opened); + Assert.Equal (string.Empty, selectedValue); + + return; + + void OpenSelectedItem (object sender, ListViewItemEventArgs e) + { + opened = true; + selectedValue = e.Value.ToString (); + } + + void Accept (object sender, CancelEventArgs e) + { + accepted = true; + e.Cancel = true; + } + } + /// /// Tests that when none of the Commands in a chained keybinding are possible the /// returns the appropriate result @@ -405,9 +498,9 @@ Item 6", Assert.Equal (-1, lv.SelectedItem); // bind shift down to move down twice in control - lv.KeyBindings.Add (KeyCode.CursorDown | KeyCode.ShiftMask, Command.LineDown, Command.LineDown); + lv.KeyBindings.Add (Key.CursorDown.WithShift, Command.LineDown, Command.LineDown); - var ev = new Key (KeyCode.CursorDown | KeyCode.ShiftMask); + var ev = Key.CursorDown.WithShift; Assert.True (lv.NewKeyDownEvent (ev), "The first time we move down 2 it should be possible"); @@ -437,9 +530,9 @@ Item 6", Assert.False (lv.Source.IsMarked (1)); Assert.False (lv.Source.IsMarked (2)); - lv.KeyBindings.Add (KeyCode.Space | KeyCode.ShiftMask, Command.ToggleChecked, Command.LineDown); + lv.KeyBindings.Add (Key.Space.WithShift, Command.Select, Command.LineDown); - var ev = new Key (KeyCode.Space | KeyCode.ShiftMask); + var ev = Key.Space.WithShift; // view should indicate that it has accepted and consumed the event Assert.True (lv.NewKeyDownEvent (ev)); @@ -568,7 +661,7 @@ Item 6", public void SettingEmptyKeybindingThrows () { var lv = new ListView { Source = new ListWrapper (new List { "One", "Two", "Three" }) }; - Assert.Throws (() => lv.KeyBindings.Add (KeyCode.Space)); + Assert.Throws (() => lv.KeyBindings.Add (Key.Space)); } private class NewListDataSource : IListDataSource diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index cfc0e312f..1f453ef92 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -32,7 +32,7 @@ public class MenuBarTests Assert.False (mi.Checked); Assert.True (menu.NewKeyDownEvent (menu.Key)); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.Enter)); Application.MainLoop.RunIteration (); Assert.True (mi.Checked); @@ -52,7 +52,7 @@ public class MenuBarTests mi.AllowNullChecked = true; Assert.True (menu.NewKeyDownEvent (menu.Key)); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.Enter)); Application.MainLoop.RunIteration (); Assert.Null (mi.Checked); @@ -82,7 +82,7 @@ public class MenuBarTests Application.MainLoop.RunIteration (); Assert.True (mi.Checked); Assert.True (menu.NewKeyDownEvent (menu.Key)); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.Enter)); Application.MainLoop.RunIteration (); Assert.False (mi.Checked); @@ -152,8 +152,8 @@ public class MenuBarTests Assert.True (CanExecuteNew ()); Assert.False (CanExecuteClose ()); - Assert.True (top.NewKeyDownEvent (new Key (KeyCode.F | KeyCode.AltMask))); - Assert.True (top.NewKeyDownEvent (new Key (KeyCode.N | KeyCode.AltMask))); + Assert.True (top.NewKeyDownEvent (Key.F.WithAlt)); + Assert.True (top.NewKeyDownEvent (Key.N.WithAlt)); Application.MainLoop.RunIteration (); Assert.NotNull (win); Assert.False (CanExecuteNew ()); @@ -1104,21 +1104,21 @@ wo Assert.False (newAction); Assert.False (copyAction); - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.AltMask | KeyCode.F))); + Assert.True (menu.NewKeyDownEvent (Key.F.WithAlt)); Assert.True (menu.IsMenuOpen); Application.Top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), _output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.N))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.N)); Application.MainLoop.RunIteration (); Assert.True (newAction); - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.AltMask | KeyCode.E))); + Assert.True (menu.NewKeyDownEvent (Key.E.WithAlt)); Assert.True (menu.IsMenuOpen); Application.Top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), _output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.C))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.C)); Application.MainLoop.RunIteration (); Assert.True (copyAction); } @@ -1142,13 +1142,13 @@ wo Assert.True (Application.Top.NewKeyDownEvent (menu.Key)); Assert.False (menu.IsMenuOpen); - menu.Key = KeyCode.F10 | KeyCode.ShiftMask; - Assert.False (Application.Top.NewKeyDownEvent (new Key (KeyCode.F9))); + menu.Key = Key.F10.WithShift; + Assert.False (Application.Top.NewKeyDownEvent (Key.F9)); Assert.False (menu.IsMenuOpen); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.F10 | KeyCode.ShiftMask))); + Assert.True (Application.Top.NewKeyDownEvent (Key.F10.WithShift)); Assert.True (menu.IsMenuOpen); - Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.F10 | KeyCode.ShiftMask))); + Assert.True (Application.Top.NewKeyDownEvent (Key.F10.WithShift)); Assert.False (menu.IsMenuOpen); } @@ -1230,26 +1230,11 @@ wo [InlineData ("_Edit", "F_ind", "", KeyCode.AltMask | KeyCode.E, KeyCode.F)] [InlineData ("_Edit", "F_ind", "", KeyCode.AltMask | KeyCode.E, KeyCode.AltMask | KeyCode.F)] [InlineData ("Closed", "None", "Replace", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.R)] - [InlineData ( - "Closed", - "None", - "", - KeyCode.AltMask | KeyCode.E, - KeyCode.F, - KeyCode.C - )] // BUGBUG: Action should be "Copy" + [InlineData ("Closed", "None", "", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.C)] [InlineData ("_Edit", "_1st", "", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.D3)] [InlineData ("Closed", "None", "1", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.D3, KeyCode.D1)] [InlineData ("Closed", "None", "1", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.D3, KeyCode.Enter)] - [InlineData ( - "Closed", - "None", - "", - KeyCode.AltMask | KeyCode.E, - KeyCode.F, - KeyCode.D3, - KeyCode.D4 - )] // BUGBUG: Should be back on _3rd Level + [InlineData ("Closed", "None", "", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.D3, KeyCode.D4)] [InlineData ("Closed", "None", "5", KeyCode.AltMask | KeyCode.E, KeyCode.F, KeyCode.D4, KeyCode.D5)] [InlineData ("_About", "_About", "", KeyCode.AltMask | KeyCode.A)] public void KeyBindings_Navigation_Commands ( @@ -1546,7 +1531,7 @@ wo _output ); - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu.NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1562,7 +1547,7 @@ wo _output ); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1578,7 +1563,7 @@ wo _output ); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1656,7 +1641,7 @@ wo _output ); - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu.NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1672,7 +1657,7 @@ wo _output ); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1688,7 +1673,7 @@ wo _output ); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1767,7 +1752,7 @@ wo _output ); - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu.NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1783,7 +1768,7 @@ wo _output ); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); win.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1799,7 +1784,7 @@ wo _output ); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); win.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1839,7 +1824,7 @@ wo _output ); - Assert.True (top.NewKeyDownEvent (new Key (KeyCode.F9))); + Assert.True (top.NewKeyDownEvent (Key.F9)); top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1855,7 +1840,7 @@ wo _output ); - Assert.True (top.Subviews [0].NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (top.Subviews [0].NewKeyDownEvent (Key.CursorRight)); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1872,7 +1857,7 @@ wo ); Assert.True ( - ((MenuBar)top.Subviews [0])._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight)) + ((MenuBar)top.Subviews [0])._openMenu.NewKeyDownEvent (Key.CursorRight) ); top.Draw (); @@ -1890,7 +1875,7 @@ wo ); Assert.True ( - ((MenuBar)top.Subviews [0])._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight)) + ((MenuBar)top.Subviews [0])._openMenu.NewKeyDownEvent (Key.CursorRight) ); top.Draw (); @@ -1963,7 +1948,7 @@ wo TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), _output); // Open second - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); Application.Top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), _output); @@ -2008,7 +1993,7 @@ wo TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), _output); // Open second - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); Application.Top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), _output); @@ -2120,8 +2105,8 @@ wo ) ); // changed to true because Alt activates menu bar #endif - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); - Assert.True (menu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu.NewKeyDownEvent (Key.CursorRight)); + Assert.True (menu.NewKeyDownEvent (Key.CursorRight)); } [Fact] @@ -2137,7 +2122,7 @@ wo }; Application.Top.Add (menu); - Exception exception = Record.Exception (() => menu.NewKeyDownEvent (new Key (KeyCode.Space))); + Exception exception = Record.Exception (() => menu.NewKeyDownEvent (Key.Space)); Assert.Null (exception); } @@ -2238,12 +2223,12 @@ wo Assert.Equal ("_New", miCurrent.Parent.Title); Assert.Equal ("_New doc", miCurrent.Title); - Assert.True (mCurrent.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (mCurrent.NewKeyDownEvent (Key.CursorDown)); Assert.True (menu.IsMenuOpen); Assert.Equal ("_File", miCurrent.Parent.Title); Assert.Equal ("_Save", miCurrent.Title); - Assert.True (mCurrent.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (mCurrent.NewKeyDownEvent (Key.CursorUp)); Assert.True (menu.IsMenuOpen); Assert.Equal ("_File", miCurrent.Parent.Title); Assert.Equal ("_New", miCurrent.Title); @@ -2492,7 +2477,7 @@ Edit TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), _output); // Right - Edit has no sub menu; this tests that no sub menu shows - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); Assert.False (tf.HasFocus); Assert.Equal (1, menu._selected); @@ -2502,20 +2487,20 @@ Edit TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), _output); // Right - Format - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); Assert.True (menu.IsMenuOpen); Assert.False (tf.HasFocus); Application.Top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (2), _output); // Left - Edit - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorLeft)); Assert.True (menu.IsMenuOpen); Assert.False (tf.HasFocus); Application.Top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), _output); - Assert.True (menu._openMenu.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorLeft)); Assert.True (menu.IsMenuOpen); Assert.False (tf.HasFocus); Application.Top.Draw (); @@ -2753,14 +2738,7 @@ Edit ] }; - Exception exception = Record.Exception ( - () => - Assert.True ( - menu.NewKeyDownEvent ( - new Key (KeyCode.AltMask | KeyCode.Q) - ) - ) - ); + Exception exception = Record.Exception (() => Assert.True (menu.NewKeyDownEvent (Key.Q.WithAlt))); Assert.Null (exception); } @@ -2784,7 +2762,7 @@ Edit () => { saveAction = true; }, null, null, - KeyCode.S | KeyCode.CtrlMask + (KeyCode)Key.S.WithCtrl ) } ) @@ -2794,7 +2772,7 @@ Edit Application.Top.Add (menu); Application.Begin (Application.Top); - Application.OnKeyDown (new Key (KeyCode.S | KeyCode.CtrlMask)); + Application.OnKeyDown (Key.S.WithCtrl); Application.MainLoop.RunIteration (); Assert.True (saveAction); @@ -2871,7 +2849,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Application.Top.Draw (); expected = @" @@ -2886,7 +2864,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (Application.Top.Subviews [2].NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (Application.Top.Subviews [2].NewKeyDownEvent (Key.CursorLeft)); Application.Top.Draw (); expected = @" @@ -2900,7 +2878,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Esc)); Application.Top.Draw (); expected = @" @@ -3093,7 +3071,7 @@ Edit _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorDown)); Application.Top.Draw (); expected = @" @@ -3172,8 +3150,8 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 0, 10, 6), pos); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Enter)); Application.Top.Draw (); expected = @" @@ -3189,7 +3167,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 0, 15, 7), pos); - Assert.True (Application.Top.Subviews [2].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (Application.Top.Subviews [2].NewKeyDownEvent (Key.Enter)); Application.Top.Draw (); expected = @" @@ -3204,7 +3182,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 0, 10, 6), pos); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Esc))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Esc)); Application.Top.Draw (); expected = @" @@ -3394,8 +3372,8 @@ Edit _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.CursorDown))); - Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.CursorDown)); + Assert.True (Application.Top.Subviews [1].NewKeyDownEvent (Key.Enter)); Application.Top.Draw (); expected = @" diff --git a/UnitTests/Views/RadioGroupTests.cs b/UnitTests/Views/RadioGroupTests.cs index 3660b7fc7..88ddd62bb 100644 --- a/UnitTests/Views/RadioGroupTests.cs +++ b/UnitTests/Views/RadioGroupTests.cs @@ -1,4 +1,5 @@ -using Xunit.Abstractions; +using System.ComponentModel; +using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -54,7 +55,7 @@ public class RadioGroupTests { var rg = new RadioGroup { RadioLabels = new [] { "Test" }, SelectedItem = -1 }; Assert.Equal (-1, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (rg.NewKeyDownEvent (Key.Space)); Assert.Equal (0, rg.SelectedItem); } @@ -62,14 +63,14 @@ public class RadioGroupTests public void KeyBindings_Are_Added_Correctly () { var rg = new RadioGroup { RadioLabels = new [] { "_Left", "_Right" } }; - Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L)); - Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.R)); + Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.L)); + Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.R)); - Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.ShiftMask)); - Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask)); + Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.L.WithShift)); + Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.L.WithAlt)); - Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.R | KeyCode.ShiftMask)); - Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.R | KeyCode.AltMask)); + Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.R.WithShift)); + Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.R.WithAlt)); } [Fact] @@ -77,16 +78,16 @@ public class RadioGroupTests { var rg = new RadioGroup { RadioLabels = new [] { "Test", "New Test" } }; - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.CursorUp))); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.CursorDown))); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.Home))); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.End))); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.Space))); + Assert.True (rg.NewKeyDownEvent (Key.CursorUp)); + Assert.True (rg.NewKeyDownEvent (Key.CursorDown)); + Assert.True (rg.NewKeyDownEvent (Key.Home)); + Assert.True (rg.NewKeyDownEvent (Key.End)); + Assert.True (rg.NewKeyDownEvent (Key.Space)); Assert.Equal (1, rg.SelectedItem); } [Fact] - public void KeyBindings_HotKeys () + public void HotKeys_Select_RadioLabels () { var rg = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } }; Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L)); @@ -94,45 +95,75 @@ public class RadioGroupTests Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask)); // BUGBUG: These tests only test that RG works on it's own, not if it's a subview - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.T))); + Assert.True (rg.NewKeyDownEvent (Key.T)); Assert.Equal (2, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.L))); + Assert.True (rg.NewKeyDownEvent (Key.L)); Assert.Equal (0, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.J))); + Assert.True (rg.NewKeyDownEvent (Key.J)); Assert.Equal (3, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.R))); + Assert.True (rg.NewKeyDownEvent (Key.R)); Assert.Equal (1, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.AltMask))); + Assert.True (rg.NewKeyDownEvent (Key.T.WithAlt)); Assert.Equal (2, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.L | KeyCode.AltMask))); + Assert.True (rg.NewKeyDownEvent (Key.L.WithAlt)); Assert.Equal (0, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.J | KeyCode.AltMask))); + Assert.True (rg.NewKeyDownEvent (Key.J.WithAlt)); Assert.Equal (3, rg.SelectedItem); - Assert.True (rg.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.AltMask))); + Assert.True (rg.NewKeyDownEvent (Key.R.WithAlt)); Assert.Equal (1, rg.SelectedItem); var superView = new View (); superView.Add (rg); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.T))); + Assert.True (superView.NewKeyDownEvent (Key.T)); Assert.Equal (2, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.L))); + Assert.True (superView.NewKeyDownEvent (Key.L)); Assert.Equal (0, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.J))); + Assert.True (superView.NewKeyDownEvent (Key.J)); Assert.Equal (3, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.R))); + Assert.True (superView.NewKeyDownEvent (Key.R)); Assert.Equal (1, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.AltMask))); + Assert.True (superView.NewKeyDownEvent (Key.T.WithAlt)); Assert.Equal (2, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.L | KeyCode.AltMask))); + Assert.True (superView.NewKeyDownEvent (Key.L.WithAlt)); Assert.Equal (0, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.J | KeyCode.AltMask))); + Assert.True (superView.NewKeyDownEvent (Key.J.WithAlt)); Assert.Equal (3, rg.SelectedItem); - Assert.True (superView.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.AltMask))); + Assert.True (superView.NewKeyDownEvent (Key.R.WithAlt)); Assert.Equal (1, rg.SelectedItem); } + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var group = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } }; + var accepted = false; + + group.Accept += OnAccept; + group.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + void OnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Command_Fires_Accept () + { + var group = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } }; + var accepted = false; + + group.Accept += OnAccept; + group.InvokeCommand (Command.Accept); + + Assert.True (accepted); + + return; + void OnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + [Fact] [AutoInitShutdown] public void Orientation_Width_Height_Vertical_Horizontal_Space () diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 701591174..166a0c67f 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1115,7 +1115,7 @@ This is a test var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { AutoSize = false, Width = 14, Height = 5, Text = text }; var btn = new Button { X = 14, Text = "Click Me!" }; - btn.Clicked += (s, e) => clicked = true; + btn.Accept += (s, e) => clicked = true; Application.Top.Add (label, btn); var sbv = new ScrollBarView (label, true, false) { Size = 5 }; diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 4b4dd60ff..236c9f545 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -569,7 +569,7 @@ public class ScrollViewTests Rect pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -593,7 +593,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -617,7 +617,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -641,7 +641,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -665,7 +665,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -689,7 +689,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -713,7 +713,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (scrollView.OnKeyDown (Key.CursorRight)); Application.Top.Draw (); expected = @" @@ -736,7 +736,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CtrlMask | KeyCode.End))); + Assert.True (scrollView.OnKeyDown (Key.End.WithCtrl)); Application.Top.Draw (); expected = @" @@ -759,8 +759,8 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CtrlMask | KeyCode.Home))); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (scrollView.OnKeyDown (Key.Home.WithCtrl)); + Assert.True (scrollView.OnKeyDown (Key.CursorDown)); Application.Top.Draw (); expected = @" @@ -783,7 +783,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (scrollView.OnKeyDown (Key.CursorDown)); Application.Top.Draw (); expected = @" @@ -806,7 +806,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (scrollView.OnKeyDown (Key.CursorDown)); Application.Top.Draw (); expected = @" @@ -829,7 +829,7 @@ public class ScrollViewTests pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (1, 1, 21, 14), pos); - Assert.True (scrollView.OnKeyDown (new Key (KeyCode.End))); + Assert.True (scrollView.OnKeyDown (Key.End)); Application.Top.Draw (); expected = @" @@ -926,114 +926,114 @@ public class ScrollViewTests Assert.True (sv.KeepContentAlwaysInViewport); Assert.True (sv.AutoHideScrollBars); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorUp))); + Assert.False (sv.OnKeyDown (Key.CursorUp)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (sv.OnKeyDown (Key.CursorDown)); Assert.Equal (new Point (0, -1), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorUp))); + Assert.True (sv.OnKeyDown (Key.CursorUp)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageUp))); + Assert.False (sv.OnKeyDown (Key.PageUp)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown))); + Assert.True (sv.OnKeyDown (Key.PageDown)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageDown))); + Assert.False (sv.OnKeyDown (Key.PageDown)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.False (sv.OnKeyDown (Key.CursorDown)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key ((KeyCode)'v' | KeyCode.AltMask))); + Assert.True (sv.OnKeyDown (Key.V.WithAlt)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.V.WithCtrl)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorLeft))); + Assert.False (sv.OnKeyDown (Key.CursorLeft)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (sv.OnKeyDown (Key.CursorRight)); Assert.Equal (new Point (-1, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorLeft))); + Assert.True (sv.OnKeyDown (Key.CursorLeft)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageUp | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.PageUp.WithCtrl)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.False (sv.OnKeyDown (Key.CursorRight)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.True (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-20, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.False (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-20, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.End))); + Assert.True (sv.OnKeyDown (Key.End)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.End))); + Assert.False (sv.OnKeyDown (Key.End)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.Home.WithCtrl)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.Home.WithCtrl)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.End.WithCtrl)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.End.WithCtrl)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.True (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-20, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.Home.WithCtrl)); Assert.Equal (new Point (0, 0), sv.ContentOffset); sv.KeepContentAlwaysInViewport = false; Assert.False (sv.KeepContentAlwaysInViewport); Assert.True (sv.AutoHideScrollBars); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorUp))); + Assert.False (sv.OnKeyDown (Key.CursorUp)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (sv.OnKeyDown (Key.CursorDown)); Assert.Equal (new Point (0, -1), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorUp))); + Assert.True (sv.OnKeyDown (Key.CursorUp)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageUp))); + Assert.False (sv.OnKeyDown (Key.PageUp)); Assert.Equal (new Point (0, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown))); + Assert.True (sv.OnKeyDown (Key.PageDown)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown))); + Assert.True (sv.OnKeyDown (Key.PageDown)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageDown))); + Assert.False (sv.OnKeyDown (Key.PageDown)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.False (sv.OnKeyDown (Key.CursorDown)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key ((KeyCode)'v' | KeyCode.AltMask))); + Assert.True (sv.OnKeyDown (Key.V.WithAlt)); Assert.Equal (new Point (0, -9), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.V.WithCtrl)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorLeft))); + Assert.False (sv.OnKeyDown (Key.CursorLeft)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (sv.OnKeyDown (Key.CursorRight)); Assert.Equal (new Point (-1, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorLeft))); + Assert.True (sv.OnKeyDown (Key.CursorLeft)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageUp | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.PageUp.WithCtrl)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); Assert.Equal (new Point (-20, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageDown | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.PageDown.WithCtrl)); Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.False (sv.OnKeyDown (Key.CursorRight)); Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageUp | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.PageUp.WithCtrl)); Assert.Equal (new Point (-19, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.True (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-19, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.False (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-19, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.End))); + Assert.True (sv.OnKeyDown (Key.End)); Assert.Equal (new Point (-19, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.End))); + Assert.False (sv.OnKeyDown (Key.End)); Assert.Equal (new Point (-19, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.Home.WithCtrl)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.Home.WithCtrl)); Assert.Equal (new Point (0, -19), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (sv.OnKeyDown (Key.End.WithCtrl)); Assert.Equal (new Point (-39, -19), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.False (sv.OnKeyDown (Key.End.WithCtrl)); Assert.Equal (new Point (-39, -19), sv.ContentOffset); } diff --git a/UnitTests/Views/StatusBarTests.cs b/UnitTests/Views/StatusBarTests.cs index 3c3cd88b3..d72c78148 100644 --- a/UnitTests/Views/StatusBarTests.cs +++ b/UnitTests/Views/StatusBarTests.cs @@ -79,7 +79,7 @@ public class StatusBarTests Assert.True (CanExecuteNew ()); Assert.False (CanExecuteClose ()); - Assert.True (top.NewKeyDownEvent (new Key (KeyCode.N | KeyCode.CtrlMask))); + Assert.True (top.NewKeyDownEvent (Key.N.WithCtrl)); Application.MainLoop.RunIteration (); Assert.NotNull (win); Assert.False (CanExecuteNew ()); @@ -157,7 +157,7 @@ CTRL-O Open { if (iteration == 0) { Assert.Equal ("", msg); - sb.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Q)); + sb.NewKeyDownEvent (Key.Q.WithCtrl); } else if (iteration == 1) { diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 8327bb649..f0db280cb 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -618,14 +618,14 @@ public class TableViewTests Assert.Equal (0, tableView.RowOffset); - tableView.NewKeyDownEvent (new Key (KeyCode.PageDown)); + tableView.NewKeyDownEvent (Key.PageDown); // window height is 5 rows 2 are header so page down should give 3 new rows Assert.Equal (3, tableView.SelectedRow); Assert.Equal (1, tableView.RowOffset); // header is no longer visible so page down should give 5 new rows - tableView.NewKeyDownEvent (new Key (KeyCode.PageDown)); + tableView.NewKeyDownEvent (Key.PageDown); Assert.Equal (8, tableView.SelectedRow); Assert.Equal (4, tableView.RowOffset); @@ -1008,7 +1008,7 @@ public class TableViewTests Application.Begin (Application.Top); // pressing enter should activate the first cell (selected cell) - tv.NewKeyDownEvent (new Key (KeyCode.Enter)); + tv.NewKeyDownEvent (Key.Enter); Assert.Equal ("R0C0", activatedValue); // reset the test @@ -1016,12 +1016,12 @@ public class TableViewTests // clear keybindings and ensure that Enter does not trigger the event anymore tv.KeyBindings.Clear (); - tv.NewKeyDownEvent (new Key (KeyCode.Enter)); + tv.NewKeyDownEvent (Key.Enter); Assert.Null (activatedValue); // New method for changing the activation key - tv.KeyBindings.Add (KeyCode.Z, Command.Accept); - tv.NewKeyDownEvent (new Key (KeyCode.Z)); + tv.KeyBindings.Add (Key.Z, Command.Accept); + tv.NewKeyDownEvent (Key.Z); Assert.Equal ("R0C0", activatedValue); // reset the test @@ -1030,7 +1030,7 @@ public class TableViewTests // Old method for changing the activation key tv.CellActivationKey = KeyCode.Z; - tv.NewKeyDownEvent (new Key (KeyCode.Z)); + tv.NewKeyDownEvent (Key.Z); Assert.Equal ("R0C0", activatedValue); } @@ -1489,14 +1489,14 @@ public class TableViewTests tv.MultiSelect = true; tv.SelectedColumn = 0; tv.SelectedRow = 0; - tv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask)); - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorRight.WithShift); + tv.NewKeyDownEvent (Key.CursorDown.WithShift); Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect); // this next moves should be ignored because we already selected the whole table - tv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask)); - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorRight.WithShift); + tv.NewKeyDownEvent (Key.CursorDown.WithShift); Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect); Assert.Equal (1, tv.SelectedColumn); @@ -1515,12 +1515,12 @@ public class TableViewTests tv.MultiSelect = true; tv.SelectedColumn = 1; tv.SelectedRow = 1; - tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorLeft.WithShift); Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect); // this next shift left should be ignored because we are already at the bounds - tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorLeft.WithShift); Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect); @@ -1540,12 +1540,12 @@ public class TableViewTests tv.MultiSelect = true; tv.SelectedColumn = 0; tv.SelectedRow = 1; - tv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorRight.WithShift); Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect); // this next shift right should be ignored because we are already at the right bounds - tv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorRight.WithShift); Assert.Equal (new Rect (0, 1, 2, 1), tv.MultiSelectedRegions.Single ().Rect); @@ -1566,14 +1566,14 @@ public class TableViewTests tv.MultiSelect = true; tv.SelectedColumn = 1; tv.SelectedRow = 1; - tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask)); - tv.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorLeft.WithShift); + tv.NewKeyDownEvent (Key.CursorUp.WithShift); Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect); // this next moves should be ignored because we already selected the whole table - tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask)); - tv.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorLeft.WithShift); + tv.NewKeyDownEvent (Key.CursorUp.WithShift); Assert.Equal (new Rect (0, 0, 2, 2), tv.MultiSelectedRegions.Single ().Rect); Assert.Equal (0, tv.SelectedColumn); @@ -2167,7 +2167,7 @@ public class TableViewTests // if middle column is invisible tableView.Style.GetOrCreateColumnStyle (1).Visible = false; - tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.CursorRight | KeyCode.ShiftMask }); + tableView.NewKeyDownEvent (Key.CursorRight.WithShift); // Selection should extend from A to C but skip B Assert.Equal (2, tableView.GetAllSelectedCells ().Count ()); @@ -2508,9 +2508,7 @@ A B C tableView.SelectedRow = 1; tableView.SelectedColumn = 1; - tableView.NewKeyDownEvent ( - new Key { KeyCode = KeyCode.Home | KeyCode.CtrlMask } - ); + tableView.NewKeyDownEvent (Key.Home.WithCtrl); if (withFullRowSelect) { @@ -2606,7 +2604,7 @@ A B C Assert.Empty (pets.Where (p => p.IsPicked)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); Assert.True (pets.First ().IsPicked); @@ -2623,8 +2621,8 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorDown); + tv.NewKeyDownEvent (Key.Space); Assert.True (pets.ElementAt (0).IsPicked); Assert.True (pets.ElementAt (1).IsPicked); @@ -2643,8 +2641,8 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); - tv.NewKeyDownEvent (new Key (KeyCode.CursorUp)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorUp); + tv.NewKeyDownEvent (Key.Space); Assert.False (pets.ElementAt (0).IsPicked); Assert.True (pets.ElementAt (1).IsPicked); @@ -2688,10 +2686,10 @@ A B C │☑│1│2│"; //toggle top two at once - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.CursorDown.WithShift); Assert.True (tv.IsSelected (0, 0)); Assert.True (tv.IsSelected (0, 1)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); // Because at least 1 of the rows is not yet ticked we toggle them all to ticked TestHelpers.AssertDriverContentsAre (expected, output); @@ -2713,7 +2711,7 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); // Untoggle the top 2 - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); tv.Draw (); @@ -2740,8 +2738,8 @@ A B C tv.Table = wrapper; //toggle all cells - tv.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.CtrlMask)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.A.WithCtrl); + tv.NewKeyDownEvent (Key.Space); tv.Draw (); @@ -2760,7 +2758,7 @@ A B C Assert.Equal (3, wrapper.CheckedRows.Count); // Untoggle all again - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); tv.Draw (); @@ -2797,8 +2795,8 @@ A B C Assert.DoesNotContain (pets, p => p.IsPicked); //toggle all cells - tv.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.CtrlMask)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.A.WithCtrl); + tv.NewKeyDownEvent (Key.Space); Assert.True (pets.All (p => p.IsPicked)); @@ -2815,7 +2813,7 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); Assert.Empty (pets.Where (p => p.IsPicked)); @@ -2860,7 +2858,7 @@ A B C Assert.Empty (wrapper.CheckedRows); //toggle the top cell - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); Assert.Single (wrapper.CheckedRows, 0); @@ -2876,8 +2874,8 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorDown); + tv.NewKeyDownEvent (Key.Space); Assert.Contains (0, wrapper.CheckedRows); Assert.Contains (1, wrapper.CheckedRows); @@ -2896,8 +2894,8 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); // untoggle top one - tv.NewKeyDownEvent (new Key (KeyCode.CursorUp)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorUp); + tv.NewKeyDownEvent (Key.Space); Assert.Single (wrapper.CheckedRows, 1); @@ -2948,7 +2946,7 @@ A B C Assert.Empty (pets.Where (p => p.IsPicked)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); Assert.True (pets.First ().IsPicked); @@ -2965,8 +2963,8 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorDown); + tv.NewKeyDownEvent (Key.Space); Assert.False (pets.ElementAt (0).IsPicked); Assert.True (pets.ElementAt (1).IsPicked); @@ -2985,8 +2983,8 @@ A B C TestHelpers.AssertDriverContentsAre (expected, output); - tv.NewKeyDownEvent (new Key (KeyCode.CursorUp)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorUp); + tv.NewKeyDownEvent (Key.Space); Assert.True (pets.ElementAt (0).IsPicked); Assert.False (pets.ElementAt (1).IsPicked); @@ -3016,21 +3014,21 @@ A B C dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.MultiSelect = true; - tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + tableView.KeyBindings.Add (Key.Space, Command.Select); Point selectedCell = tableView.GetAllSelectedCells ().Single (); Assert.Equal (0, selectedCell.X); Assert.Equal (0, selectedCell.Y); // Go Right - tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (Key.CursorRight ); selectedCell = tableView.GetAllSelectedCells ().Single (); Assert.Equal (1, selectedCell.X); Assert.Equal (0, selectedCell.Y); // Toggle Select - tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (Key.Space); TableSelection m = tableView.MultiSelectedRegions.Single (); Assert.True (m.IsToggled); Assert.Equal (1, m.Origin.X); @@ -3040,7 +3038,7 @@ A B C Assert.Equal (0, selectedCell.Y); // Go Left - tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.CursorLeft }); + tableView.NewKeyDownEvent (Key.CursorLeft); // Both Toggled and Moved to should be selected Assert.Equal (2, tableView.GetAllSelectedCells ().Count ()); @@ -3052,7 +3050,7 @@ A B C Assert.Equal (0, s2.Y); // Go Down - tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.CursorDown }); + tableView.NewKeyDownEvent (Key.CursorDown ); // Both Toggled and Moved to should be selected but not 0,0 // which we moved down from @@ -3089,7 +3087,7 @@ A B C dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.FullRowSelect = true; tableView.MultiSelect = true; - tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + tableView.KeyBindings.Add (Key.Space, Command.Select); // Toggle Select Cell 0,0 tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.Space }); @@ -3126,7 +3124,7 @@ A B C dt.Rows.Add (1, 2, 3, 4, 5, 6); dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.MultiSelect = true; - tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + tableView.KeyBindings.Add (Key.Space, Command.Select); // Make a square selection tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); @@ -3168,7 +3166,7 @@ A B C dt.Rows.Add (1, 2, 3, 4, 5, 6); dt.Rows.Add (1, 2, 3, 4, 5, 6); tableView.MultiSelect = true; - tableView.KeyBindings.Add (KeyCode.Space, Command.ToggleChecked); + tableView.KeyBindings.Add (Key.Space, Command.Select); // Make first square selection (0,0 to 1,1) tableView.NewKeyDownEvent (new Key { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index c8cac5c2a..cd6cc88c6 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1,6 +1,8 @@ -using System.Globalization; +using System.ComponentModel; +using System.Globalization; using System.Reflection; using System.Text; +using CsvHelper; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -82,18 +84,18 @@ public class TextFieldTests { var tf = new TextField (); tf.EnsureFocus (); - tf.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.ShiftMask)); + tf.NewKeyDownEvent (Key.A.WithShift); Assert.Equal ("A", tf.Text); // cancel the next keystroke - tf.TextChanging += (s, e) => e.Cancel = e.NewText == "AB"; - tf.NewKeyDownEvent (new Key (KeyCode.B | KeyCode.ShiftMask)); + tf.TextChanging += (s, e) => e.Cancel = e.NewValue == "AB"; + tf.NewKeyDownEvent (Key.B.WithShift); // B was canceled so should just be A Assert.Equal ("A", tf.Text); // now delete the A - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("", tf.Text); } @@ -360,11 +362,11 @@ public class TextFieldTests _textField.TextChanging += _textField_TextChanging; - void _textField_TextChanging (object sender, TextChangingEventArgs e) + void _textField_TextChanging (object sender, StateEventArgs e) { - if (e.NewText.GetRuneCount () > 11) + if (e.NewValue.GetRuneCount () > 11) { - e.NewText = e.NewText [..11]; + e.NewValue = e.NewValue [..11]; } } @@ -426,7 +428,7 @@ public class TextFieldTests var oldText = ""; var tf = new TextField { Width = 10, Text = "-1" }; - tf.TextChanging += (s, e) => newText = e.NewText; + tf.TextChanging += (s, e) => newText = e.NewValue; tf.TextChanged += (s, e) => oldText = e.OldValue; Application.Top.Add (tf); @@ -439,7 +441,7 @@ public class TextFieldTests tf.CursorPosition = 2; Assert.Equal (1, tf.SelectedLength); Assert.Equal ("1", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (tf.NewKeyDownEvent (Key.D2)); Assert.Equal ("-2", newText); Assert.Equal ("-1", oldText); Assert.Equal ("-2", tf.Text); @@ -449,7 +451,7 @@ public class TextFieldTests tf.CursorPosition = 2; Assert.Equal (1, tf.SelectedLength); Assert.Equal ("2", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tf.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("-", newText); Assert.Equal ("-2", oldText); Assert.Equal ("-", tf.Text); @@ -460,7 +462,7 @@ public class TextFieldTests tf.CursorPosition = 2; Assert.Equal (1, tf.SelectedLength); Assert.Equal ("1", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal ("-", newText); Assert.Equal ("-1", oldText); Assert.Equal ("-", tf.Text); @@ -471,7 +473,7 @@ public class TextFieldTests tf.CursorPosition = 2; Assert.Equal (1, tf.SelectedLength); Assert.Equal ("1", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.X | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.X.WithCtrl)); Assert.Equal ("-", newText); Assert.Equal ("-1", oldText); Assert.Equal ("-", tf.Text); @@ -486,7 +488,7 @@ public class TextFieldTests ); Assert.Equal ("Misérables ", tf.SelectedText); Assert.Equal (11, tf.SelectedLength); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal ("Les movie.", newText); Assert.Equal ("Les Misérables movie.", oldText); Assert.Equal ("Les movie.", tf.Text); @@ -504,7 +506,7 @@ public class TextFieldTests tf.ClearHistoryChanges (); Assert.False (tf.IsDirty); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.A.WithShift)); Assert.Equal ($"{text}A", tf.Text); Assert.True (tf.IsDirty); } @@ -521,171 +523,191 @@ public class TextFieldTests Assert.Equal (15, tf.CursorPosition); Assert.False (tf.ReadOnly); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal ("This is a test.", tf.Text); tf.CursorPosition = 0; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal ("his is a test.", tf.Text); tf.ReadOnly = true; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.D.WithCtrl)); Assert.Equal ("his is a test.", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal ("his is a test.", tf.Text); tf.ReadOnly = false; tf.CursorPosition = 1; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tf.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("is is a test.", tf.Text); tf.CursorPosition = 5; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Home | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.Home.WithShift)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is is", tf.SelectedText); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Home | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Home.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is is", tf.SelectedText); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.A.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is is", tf.SelectedText); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.End.WithShift)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (" a test.", tf.SelectedText); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.End.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (" a test.", tf.SelectedText); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.E.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (" a test.", tf.SelectedText); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (tf.NewKeyDownEvent (Key.Home)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (0, tf.CursorPosition); tf.CursorPosition = 5; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Home.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (0, tf.CursorPosition); tf.CursorPosition = 5; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (0, tf.CursorPosition); tf.CursorPosition = 5; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithShift)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("s", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithShift)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("s", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorDown.WithShift)); Assert.Equal ("is is a test.", tf.Text); Assert.Null (tf.SelectedText); tf.CursorPosition = 7; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("a", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is a", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (('B' + KeyCode.ShiftMask) | KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.B.WithShift.WithAlt)); +#else + Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithShift.WithCtrl)); +#endif Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is is a", tf.SelectedText); tf.CursorPosition = 3; tf.SelectedStart = -1; Assert.Null (tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is ", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.ShiftMask | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorDown.WithShift.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is a ", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (('F' + KeyCode.ShiftMask) | KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.F.WithShift.WithAlt)); +#else + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl)); +#endif Assert.Equal ("is is a test.", tf.Text); Assert.Equal ("is a test.", tf.SelectedText); Assert.Equal (13, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal ("is is a test.", tf.Text); Assert.Null (tf.SelectedText); Assert.Equal (12, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (11, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (tf.NewKeyDownEvent (Key.End)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (13, tf.CursorPosition); tf.CursorPosition = 0; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (13, tf.CursorPosition); tf.CursorPosition = 0; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.E.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (13, tf.CursorPosition); tf.CursorPosition = 0; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (1, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.F | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.F.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); Assert.Equal (2, tf.CursorPosition); tf.CursorPosition = 9; tf.ReadOnly = true; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); tf.ReadOnly = false; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal ("est.", Clipboard.Contents); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("is is a test.", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ("is is a t", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.Backspace.WithAlt)); +#else + Assert.True (tf.NewKeyDownEvent (Key.Z.WithCtrl)); +#endif Assert.Equal ("is is a test.", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ("is is a t", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorUp.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key ('B' + KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.B.WithAlt)); +#else + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl)); +#endif Assert.Equal ("is is a t", tf.Text); Assert.Equal (3, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorDown.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key ('F' + KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.F.WithAlt)); +#else + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithCtrl)); +#endif Assert.Equal ("is is a t", tf.Text); Assert.Equal (9, tf.CursorPosition); Assert.True (tf.Used); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Insert))); + Assert.True (tf.NewKeyDownEvent (Key.InsertChar)); Assert.Equal ("is is a t", tf.Text); Assert.Equal (9, tf.CursorPosition); Assert.False (tf.Used); @@ -693,32 +715,107 @@ public class TextFieldTests tf.CursorPosition = 7; Assert.Equal ("is a", tf.SelectedText); Assert.Equal ("est.", Clipboard.Contents); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal ("is a", Clipboard.Contents); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.X | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.X.WithCtrl)); Assert.Equal ("is t", tf.Text); Assert.Equal ("is a", Clipboard.Contents); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.V.WithCtrl)); Assert.Equal ("is is a t", tf.Text); Assert.Equal ("is a", Clipboard.Contents); Assert.Equal (7, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.K.WithAlt)); +#else + Assert.True (tf.NewKeyDownEvent (Key.K.WithCtrl.WithShift)); +#endif Assert.Equal (" t", tf.Text); Assert.Equal ("is is a", Clipboard.Contents); tf.Text = "TAB to jump between text fields."; Assert.Equal (0, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("to jump between text fields.", tf.Text); tf.CursorPosition = tf.Text.Length; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("to jump between text fields", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.T.WithCtrl)); Assert.Equal ("to jump between text fields", tf.SelectedText); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.D.WithCtrl.WithShift)); Assert.Equal ("", tf.Text); } + + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new TextField (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } + + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var view = new TextField (); + var accepted = false; + view.Accept += OnAccept; + view.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + void OnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Command_Fires_Accept () + { + var view = new TextField (); + + var accepted = false; + view.Accept += Accept; + view.InvokeCommand (Command.Accept); + Assert.True (accepted); + + return; + + void Accept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Cancel_Event_HandlesCommand () + { + //var super = new View (); + var view = new TextField (); + //super.Add (view); + + //var superAcceptedInvoked = false; + + var tfAcceptedInvoked = false; + var cancel = false; + view.Accept += TextViewAccept; + Assert.True (view.InvokeCommand (Command.Accept)); + Assert.True (tfAcceptedInvoked); + + tfAcceptedInvoked = false; + cancel = true; + view.Accept += TextViewAccept; + Assert.False (view.InvokeCommand (Command.Accept)); + Assert.True (tfAcceptedInvoked); + + return; + + void TextViewAccept (object sender, CancelEventArgs e) + { + tfAcceptedInvoked = true; + e.Cancel = cancel; + } + } + [Fact] public void OnEnter_Does_Not_Throw_If_Not_IsInitialized_SetCursorVisibility () { @@ -743,7 +840,7 @@ public class TextFieldTests } [Fact] - public void ProcessKey_Backspace_From_End () + public void Backspace_From_End () { var tf = new TextField { Text = "ABC" }; tf.EnsureFocus (); @@ -754,23 +851,23 @@ public class TextFieldTests Assert.Equal (3, tf.CursorPosition); // now delete the C - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("AB", tf.Text); Assert.Equal (2, tf.CursorPosition); // then delete the B - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("A", tf.Text); Assert.Equal (1, tf.CursorPosition); // then delete the A - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("", tf.Text); Assert.Equal (0, tf.CursorPosition); } [Fact] - public void ProcessKey_Backspace_From_Middle () + public void Backspace_From_Middle () { var tf = new TextField { Text = "ABC" }; tf.EnsureFocus (); @@ -778,20 +875,20 @@ public class TextFieldTests Assert.Equal ("ABC", tf.Text); // now delete the B - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("AC", tf.Text); // then delete the A - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("C", tf.Text); // then delete nothing - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("C", tf.Text); // now delete the C tf.CursorPosition = 1; - tf.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tf.NewKeyDownEvent (Key.Backspace); Assert.Equal ("", tf.Text); } @@ -838,7 +935,7 @@ public class TextFieldTests // Cursor is at the end Assert.Equal (32, _textField.CursorPosition); _textField.CursorPosition = 0; - _textField.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask)); + _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); var first = true; Application.RunIteration (ref rs, ref first); @@ -867,7 +964,7 @@ public class TextFieldTests _textField.SelectedStart = 19; _textField.CursorPosition = 12; Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x75)); // u + _textField.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jump u text fields.", _textField.Text); } @@ -893,35 +990,40 @@ public class TextFieldTests } [Fact] - [AutoInitShutdown] - public void Test_RootKeyEvent_Cancel () + public void KeyDown_Handled_Prevents_Input () { - Application.KeyDown += SuppressKey; - var tf = new TextField (); + tf.KeyDown += HandleJKey; - Application.Top.Add (tf); - Application.Begin (Application.Top); - - Application.Driver.SendKeys ('a', ConsoleKey.A, false, false, false); + tf.NewKeyDownEvent (Key.A); Assert.Equal ("a", tf.Text); // SuppressKey suppresses the 'j' key - Application.Driver.SendKeys ('j', ConsoleKey.J, false, false, false); + tf.NewKeyDownEvent (Key.J); Assert.Equal ("a", tf.Text); - Application.KeyDown -= SuppressKey; + tf.KeyDown -= HandleJKey; // Now that the delegate has been removed we can type j again - Application.Driver.SendKeys ('j', ConsoleKey.J, false, false, false); + tf.NewKeyDownEvent (Key.J); Assert.Equal ("aj", tf.Text); + + return; + + void HandleJKey (object s, Key arg) + { + if (arg.AsRune == new Rune ('j')) + { + arg.Handled = true; + } + } } [Fact] [AutoInitShutdown] - public void Test_RootMouseKeyEvent_Cancel () + public void MouseEvent_Handled_Prevents_RightClick () { - Application.MouseEvent += SuppressRightClick; + Application.MouseEvent += HandleRightClick; var tf = new TextField { Width = 10 }; var clickCounter = 0; @@ -941,7 +1043,7 @@ public class TextFieldTests Application.OnMouseEvent (new MouseEventEventArgs (mouseEvent)); Assert.Equal (1, clickCounter); - Application.MouseEvent -= SuppressRightClick; + Application.MouseEvent -= HandleRightClick; // Get a fresh instance that represents a right click. // Should no longer be ignored as the callback was removed @@ -953,22 +1055,32 @@ public class TextFieldTests // Which is correct, because the user did NOT click with the left mouse button. Application.OnMouseEvent (new MouseEventEventArgs (mouseEvent)); Assert.Equal (1, clickCounter); + + return; + + void HandleRightClick (object sender, MouseEventEventArgs arg) + { + if (arg.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) + { + arg.Handled = true; + } + } } [InlineData ("a")] // Lower than selection [InlineData ("aaaaaaaaaaa")] // Greater than selection [InlineData ("aaaa")] // Equal than selection [Theory] - public void TestSetTextAndMoveCursorToEnd_WhenExistingSelection (string newText) + public void SetTextAndMoveCursorToEnd_WhenExistingSelection (string newText) { var tf = new TextField (); tf.Text = "fish"; tf.CursorPosition = tf.Text.Length; - tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + tf.NewKeyDownEvent (Key.CursorLeft); - tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask)); - tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask)); + tf.NewKeyDownEvent (Key.CursorLeft.WithShift); + tf.NewKeyDownEvent (Key.CursorLeft.WithShift); Assert.Equal (1, tf.CursorPosition); Assert.Equal (2, tf.SelectedLength); @@ -1012,7 +1124,7 @@ public class TextFieldTests _textField.TextChanging += (s, e) => { - Assert.Equal ("changing", e.NewText); + Assert.Equal ("changing", e.NewValue); if (cancel) { @@ -1029,7 +1141,7 @@ public class TextFieldTests [Fact] [TextFieldTestsAutoInitShutdown] - public void TextField_SpaceHandling () + public void SpaceHandling () { var tf = new TextField { Width = 10, Text = " " }; @@ -1051,13 +1163,13 @@ public class TextFieldTests _textField.Used = false; _textField.CursorPosition = 10; Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x75)); // u + _textField.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jumu between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x73)); // s + _textField.NewKeyDownEvent (Key.S); // s Assert.Equal ("TAB to jumusbetween text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x65)); // e + _textField.NewKeyDownEvent (Key.E); // e Assert.Equal ("TAB to jumuseetween text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x64)); // d + _textField.NewKeyDownEvent (Key.D); // d Assert.Equal ("TAB to jumusedtween text fields.", _textField.Text); } @@ -1067,13 +1179,13 @@ public class TextFieldTests { _textField.CursorPosition = 10; Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x75)); // u + _textField.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jumup between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x73)); // s + _textField.NewKeyDownEvent (Key.S); // s Assert.Equal ("TAB to jumusp between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x65)); // e + _textField.NewKeyDownEvent (Key.E); // e Assert.Equal ("TAB to jumusep between text fields.", _textField.Text); - _textField.NewKeyDownEvent (new Key ((KeyCode)0x64)); // d + _textField.NewKeyDownEvent (Key.D); // d Assert.Equal ("TAB to jumusedp between text fields.", _textField.Text); } @@ -1086,7 +1198,7 @@ public class TextFieldTests while (_textField.CursorPosition > 0) { - _textField.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask)); + _textField.NewKeyDownEvent (Key.CursorLeft.WithCtrl); switch (iteration) { @@ -1157,7 +1269,7 @@ public class TextFieldTests while (_textField.CursorPosition > 0) { - _textField.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask)); + _textField.NewKeyDownEvent (Key.CursorLeft.WithCtrl); switch (iteration) { @@ -1370,26 +1482,26 @@ public class TextFieldTests tf.BeginInit (); tf.EndInit (); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft)); + tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl); Assert.Equal (15, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft)); + tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl); Assert.Equal (12, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft)); + tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl); Assert.Equal (10, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft)); + tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl); Assert.Equal (5, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft)); + tf.NewKeyDownEvent (Key.CursorLeft.WithCtrl); Assert.Equal (0, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight)); + tf.NewKeyDownEvent (Key.CursorRight.WithCtrl); Assert.Equal (5, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight)); + tf.NewKeyDownEvent (Key.CursorRight.WithCtrl); Assert.Equal (10, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight)); + tf.NewKeyDownEvent (Key.CursorRight.WithCtrl); Assert.Equal (12, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight)); + tf.NewKeyDownEvent (Key.CursorRight.WithCtrl); Assert.Equal (15, tf.CursorPosition); - tf.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight)); + tf.NewKeyDownEvent (Key.CursorRight.WithCtrl); Assert.Equal (22, tf.CursorPosition); } @@ -1443,7 +1555,7 @@ public class TextFieldTests while (_textField.CursorPosition < _textField.Text.Length) { - _textField.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask)); + _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl); switch (iteration) { @@ -1507,7 +1619,7 @@ public class TextFieldTests while (_textField.CursorPosition < _textField.Text.Length) { - _textField.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask)); + _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl); switch (iteration) { @@ -1604,9 +1716,7 @@ public class TextFieldTests while (_textField.CursorPosition < _textField.Text.Length) { - _textField.NewKeyDownEvent ( - new Key (KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask) - ); + _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); switch (iteration) { @@ -1669,9 +1779,7 @@ public class TextFieldTests while (_textField.CursorPosition < _textField.Text.Length) { - _textField.NewKeyDownEvent ( - new Key (KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask) - ); + _textField.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); switch (iteration) { @@ -1760,22 +1868,6 @@ Les Miśerables", return tf; } - private void SuppressKey (object s, Key arg) - { - if (arg.AsRune == new Rune ('j')) - { - arg.Handled = true; - } - } - - private void SuppressRightClick (object sender, MouseEventEventArgs arg) - { - if (arg.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) - { - arg.Handled = true; - } - } - // This class enables test functions annotated with the [InitShutdown] attribute // to have a function called before the test function is called and after. // diff --git a/UnitTests/Views/TextValidateFieldTests.cs b/UnitTests/Views/TextValidateFieldTests.cs index 1f5845529..162172ce5 100644 --- a/UnitTests/Views/TextValidateFieldTests.cs +++ b/UnitTests/Views/TextValidateFieldTests.cs @@ -19,22 +19,22 @@ public class TextValidateField_NET_Provider_Tests }; // Go to the end. - field.NewKeyDownEvent (new Key (KeyCode.End)); + field.NewKeyDownEvent (Key.End); - field.NewKeyDownEvent (new Key (KeyCode.Backspace)); + field.NewKeyDownEvent (Key.Backspace); Assert.Equal ("--(12_4)--", field.Provider.DisplayText); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.Backspace)); + field.NewKeyDownEvent (Key.Backspace); Assert.Equal ("--(1__4)--", field.Provider.DisplayText); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.Backspace)); + field.NewKeyDownEvent (Key.Backspace); Assert.Equal ("--(___4)--", field.Provider.DisplayText); Assert.False (field.IsValid); // One more - field.NewKeyDownEvent (new Key (KeyCode.Backspace)); + field.NewKeyDownEvent (Key.Backspace); Assert.Equal ("--(___4)--", field.Provider.DisplayText); Assert.False (field.IsValid); } @@ -92,19 +92,19 @@ public class TextValidateField_NET_Provider_Tests Assert.Equal ("--(1234)--", field.Provider.DisplayText); Assert.True (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.Delete)); - field.NewKeyDownEvent (new Key (KeyCode.Delete)); - field.NewKeyDownEvent (new Key (KeyCode.Delete)); + field.NewKeyDownEvent (Key.Delete); + field.NewKeyDownEvent (Key.Delete); + field.NewKeyDownEvent (Key.Delete); Assert.Equal ("--(_234)--", field.Provider.DisplayText); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.CursorRight)); - field.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + field.NewKeyDownEvent (Key.CursorRight); + field.NewKeyDownEvent (Key.CursorRight); - field.NewKeyDownEvent (new Key (KeyCode.Delete)); - field.NewKeyDownEvent (new Key (KeyCode.Delete)); - field.NewKeyDownEvent (new Key (KeyCode.Delete)); + field.NewKeyDownEvent (Key.Delete); + field.NewKeyDownEvent (Key.Delete); + field.NewKeyDownEvent (Key.Delete); Assert.Equal ("--(_2_4)--", field.Provider.DisplayText); Assert.False (field.IsValid); @@ -123,9 +123,9 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(0000)--") }; - field.NewKeyDownEvent (new Key (KeyCode.End)); + field.NewKeyDownEvent (Key.End); - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(___1)--", field.Provider.DisplayText); Assert.Equal ("--( 1)--", field.Text); @@ -145,11 +145,11 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(0000)--") }; - field.NewKeyDownEvent (new Key (KeyCode.CursorRight)); - field.NewKeyDownEvent (new Key (KeyCode.CursorRight)); - field.NewKeyDownEvent (new Key (KeyCode.Home)); + field.NewKeyDownEvent (Key.CursorRight); + field.NewKeyDownEvent (Key.CursorRight); + field.NewKeyDownEvent (Key.Home); - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1___)--", field.Provider.DisplayText); Assert.Equal ("--(1 )--", field.Text); @@ -222,7 +222,7 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(0000)--") }; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1___)--", field.Provider.DisplayText); Assert.Equal ("--(1 )--", field.Text); @@ -241,7 +241,7 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(0000)--") }; - field.NewKeyDownEvent (new Key (KeyCode.A)); + field.NewKeyDownEvent (Key.A); Assert.Equal ("--( )--", field.Text); Assert.Equal ("--(____)--", field.Provider.DisplayText); @@ -261,19 +261,19 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(00-00)--") }; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1_-__)--", field.Provider.DisplayText); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D2)); + field.NewKeyDownEvent (Key.D2); Assert.Equal ("--(12-__)--", field.Provider.DisplayText); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D3)); + field.NewKeyDownEvent (Key.D3); Assert.Equal ("--(12-3_)--", field.Provider.DisplayText); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D4)); + field.NewKeyDownEvent (Key.D4); Assert.Equal ("--(12-34)--", field.Provider.DisplayText); Assert.True (field.IsValid); } @@ -293,10 +293,10 @@ public class TextValidateField_NET_Provider_Tests for (var i = 0; i < 10; i++) { - field.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + field.NewKeyDownEvent (Key.CursorLeft); } - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1___)--", field.Provider.DisplayText); Assert.Equal ("--(1 )--", field.Text); @@ -316,7 +316,7 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(0000)--") }; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1___)--", field.Provider.DisplayText); Assert.False (field.IsValid); @@ -324,7 +324,7 @@ public class TextValidateField_NET_Provider_Tests field.MouseEvent (new MouseEvent { X = 25, Flags = MouseFlags.Button1Pressed }); - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1__1)--", field.Provider.DisplayText); Assert.False (field.IsValid); @@ -343,7 +343,7 @@ public class TextValidateField_NET_Provider_Tests field.Provider.TextChanged += (sender, e) => wasTextChanged = true; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1___)--", field.Provider.DisplayText); Assert.False (field.IsValid); @@ -366,10 +366,10 @@ public class TextValidateField_NET_Provider_Tests for (var i = 0; i < 10; i++) { - field.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + field.NewKeyDownEvent (Key.CursorRight); } - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(___1)--", field.Provider.DisplayText); Assert.Equal ("--( 1)--", field.Text); @@ -408,19 +408,19 @@ public class TextValidateField_NET_Provider_Tests Provider = new NetMaskedTextProvider ("--(0000)--") }; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("--(1 )--", field.Text); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D2)); + field.NewKeyDownEvent (Key.D2); Assert.Equal ("--(12 )--", field.Text); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D3)); + field.NewKeyDownEvent (Key.D3); Assert.Equal ("--(123 )--", field.Text); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D4)); + field.NewKeyDownEvent (Key.D4); Assert.Equal ("--(1234)--", field.Text); Assert.True (field.IsValid); } @@ -439,26 +439,26 @@ public class TextValidateField_Regex_Provider_Tests for (var i = 0; i < 4; i++) { - field.NewKeyDownEvent (new Key (KeyCode.D0)); + field.NewKeyDownEvent (Key.D0); } Assert.Equal ("0000", field.Text); Assert.False (field.IsValid); // HOME KEY - field.NewKeyDownEvent (new Key (KeyCode.Home)); + field.NewKeyDownEvent (Key.Home); // END KEY - field.NewKeyDownEvent (new Key (KeyCode.End)); + field.NewKeyDownEvent (Key.End); // Insert 9 - field.NewKeyDownEvent (new Key (KeyCode.D9)); + field.NewKeyDownEvent (Key.D9); Assert.Equal ("00009", field.Text); Assert.True (field.IsValid); // Insert 9 - field.NewKeyDownEvent (new Key (KeyCode.D9)); + field.NewKeyDownEvent (Key.D9); Assert.Equal ("000099", field.Text); Assert.False (field.IsValid); @@ -471,19 +471,19 @@ public class TextValidateField_Regex_Provider_Tests // Accepts 001 too. var field = new TextValidateField { Width = 20, Provider = new TextRegexProvider ("^[0-9]?[0-9]?[0-9]|1000$") }; - field.NewKeyDownEvent (new Key (KeyCode.D1)); - field.NewKeyDownEvent (new Key (KeyCode.D0)); - field.NewKeyDownEvent (new Key (KeyCode.D0)); - field.NewKeyDownEvent (new Key (KeyCode.D0)); + field.NewKeyDownEvent (Key.D1); + field.NewKeyDownEvent (Key.D0); + field.NewKeyDownEvent (Key.D0); + field.NewKeyDownEvent (Key.D0); Assert.Equal ("1000", field.Text); Assert.True (field.IsValid); // HOME KEY - field.NewKeyDownEvent (new Key (KeyCode.Home)); + field.NewKeyDownEvent (Key.Home); // DELETE - field.NewKeyDownEvent (new Key (KeyCode.Delete)); + field.NewKeyDownEvent (Key.Delete); Assert.Equal ("000", field.Text); Assert.True (field.IsValid); @@ -495,7 +495,7 @@ public class TextValidateField_Regex_Provider_Tests var field = new TextValidateField { Width = 20, Provider = new TextRegexProvider ("^[0-9][0-9][0-9]$") }; // Input dosen't validates the pattern. - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("", field.Text); Assert.False (field.IsValid); @@ -518,19 +518,19 @@ public class TextValidateField_Regex_Provider_Tests Width = 20, Provider = new TextRegexProvider ("^[0-9][0-9][0-9]$") { ValidateOnInput = false } }; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("1", field.Text); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D2)); + field.NewKeyDownEvent (Key.D2); Assert.Equal ("12", field.Text); Assert.False (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D3)); + field.NewKeyDownEvent (Key.D3); Assert.Equal ("123", field.Text); Assert.True (field.IsValid); - field.NewKeyDownEvent (new Key (KeyCode.D4)); + field.NewKeyDownEvent (Key.D4); Assert.Equal ("1234", field.Text); Assert.False (field.IsValid); } @@ -549,14 +549,14 @@ public class TextValidateField_Regex_Provider_Tests for (var i = 0; i < 10; i++) { - field.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + field.NewKeyDownEvent (Key.CursorLeft); } Assert.Equal ("123", field.Text); Assert.True (field.IsValid); // Insert 4 - field.NewKeyDownEvent (new Key (KeyCode.D4)); + field.NewKeyDownEvent (Key.D4); Assert.Equal ("4123", field.Text); Assert.False (field.IsValid); @@ -603,7 +603,7 @@ public class TextValidateField_Regex_Provider_Tests field.Provider.TextChanged += (sender, e) => wasTextChanged = true; - field.NewKeyDownEvent (new Key (KeyCode.D1)); + field.NewKeyDownEvent (Key.D1); Assert.Equal ("1", field.Provider.DisplayText); Assert.False (field.IsValid); @@ -625,14 +625,14 @@ public class TextValidateField_Regex_Provider_Tests for (var i = 0; i < 10; i++) { - field.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + field.NewKeyDownEvent (Key.CursorRight); } Assert.Equal ("123", field.Text); Assert.True (field.IsValid); // Insert 4 - field.NewKeyDownEvent (new Key (KeyCode.D4)); + field.NewKeyDownEvent (Key.D4); Assert.Equal ("1234", field.Text); Assert.False (field.IsValid); diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index ba8d74b88..e42632c9f 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -19,7 +19,7 @@ public class TextViewTests Assert.True (_textView.Multiline); Assert.Equal (4, _textView.TabWidth); Assert.True (_textView.AllowsTab); - _textView.NewKeyDownEvent (new Key (KeyCode.Enter)); + _textView.NewKeyDownEvent (Key.Enter); Assert.Equal ( Environment.NewLine + "TAB to jump between text fields.", @@ -31,7 +31,7 @@ public class TextViewTests Assert.False (_textView.Multiline); Assert.Equal (0, _textView.TabWidth); Assert.False (_textView.AllowsTab); - _textView.NewKeyDownEvent (new Key (KeyCode.Enter)); + _textView.NewKeyDownEvent (Key.Enter); Assert.Equal ( Environment.NewLine + "TAB to jump between text fields.", @@ -84,7 +84,7 @@ public class TextViewTests while (col > 0) { col--; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -93,7 +93,7 @@ public class TextViewTests while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -120,7 +120,7 @@ public class TextViewTests var tv = new TextView { Width = 10, Height = 10, BottomOffset = 1 }; tv.Text = text; - tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.End)); + tv.NewKeyDownEvent (Key.End.WithCtrl); Assert.Equal (4, tv.TopRow); Assert.Equal (1, tv.BottomOffset); @@ -221,7 +221,7 @@ public class TextViewTests var tv = new TextView { Width = 50, Height = 10, Text = text }; tv.ContentsChanged += (s, e) => { eventcount++; }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"{ @@ -405,7 +405,7 @@ public class TextViewTests Assert.Equal (2, eventcount); expectedCol = 1; - tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.ShiftMask)); + tv.NewKeyDownEvent (Key.Y.WithShift); Assert.Equal (3, eventcount); Assert.Equal ("Yay", tv.Text); } @@ -424,27 +424,27 @@ public class TextViewTests Assert.Equal (expectedEventCount, eventcount); expectedEventCount++; - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (_textView.NewKeyDownEvent (Key.Enter)); Assert.Equal (expectedEventCount, eventcount); // Undo expectedEventCount++; - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal (expectedEventCount, eventcount); // Redo expectedEventCount++; - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal (expectedEventCount, eventcount); // Undo expectedEventCount++; - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (_textView.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal (expectedEventCount, eventcount); // Redo expectedEventCount++; - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (_textView.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal (expectedEventCount, eventcount); } @@ -560,7 +560,7 @@ public class TextViewTests _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; _textView.CursorPosition = new Point (24, 0); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); Assert.Equal ("TAB to jump between text fields.", _textView.Text); _textView.SelectionStartColumn = 0; @@ -568,13 +568,13 @@ public class TextViewTests Assert.Equal (new Point (24, 0), _textView.CursorPosition); Assert.True (_textView.Selecting); _textView.Selecting = false; - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal (new Point (28, 0), _textView.CursorPosition); Assert.False (_textView.Selecting); Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); _textView.SelectionStartColumn = 24; _textView.SelectionStartRow = 0; - _textView.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask)); // Cut + _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut Assert.Equal (new Point (24, 0), _textView.CursorPosition); Assert.False (_textView.Selecting); Assert.Equal ("", _textView.SelectedText); @@ -582,7 +582,7 @@ public class TextViewTests _textView.SelectionStartColumn = 0; _textView.SelectionStartRow = 0; _textView.Selecting = false; - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal (new Point (28, 0), _textView.CursorPosition); Assert.False (_textView.Selecting); Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); @@ -595,15 +595,15 @@ public class TextViewTests _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; _textView.CursorPosition = new Point (24, 0); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ("TAB to jump between text fields.", _textView.Text); _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; - _textView.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask)); // Cut - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ("TAB to jump between text fields.", _textView.Text); } @@ -614,9 +614,9 @@ public class TextViewTests _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; _textView.CursorPosition = new Point (24, 0); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); - _textView.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask)); // Cut + _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut Assert.Equal ("", _textView.SelectedText); } @@ -626,9 +626,9 @@ public class TextViewTests { _textView.SelectionStartColumn = 0; _textView.SelectionStartRow = 0; - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("", _textView.SelectedText); - _textView.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask)); // Cut + _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut Assert.Equal ("", _textView.SelectedText); } @@ -655,8 +655,8 @@ public class TextViewTests { _textView.Text = "This is the first line.\nThis is the second line.\n"; _textView.CursorPosition = new Point (0, _textView.Lines - 1); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ( $"This is the first line.{ @@ -669,8 +669,8 @@ public class TextViewTests _textView.Text ); _textView.CursorPosition = new Point (3, 1); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ( $"This is the first line.{ @@ -685,7 +685,7 @@ public class TextViewTests _textView.Text ); Assert.Equal (new Point (3, 2), _textView.CursorPosition); - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ( $"This is the first line.{ @@ -748,19 +748,19 @@ public class TextViewTests _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; _textView.CursorPosition = new Point (24, 0); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); _textView.NewKeyDownEvent ( - new Key (KeyCode.W | KeyCode.CtrlMask) + Key.W.WithCtrl ); // Selecting is set to false after Cut. Assert.Equal ("", _textView.SelectedText); _textView.ReadOnly = false; Assert.False (_textView.Selecting); _textView.Selecting = true; // Needed to set Selecting to true. - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); - _textView.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask)); // Cut + _textView.NewKeyDownEvent (Key.W.WithCtrl); // Cut Assert.Equal ("", _textView.SelectedText); } @@ -787,7 +787,7 @@ This is the second line. tv.CursorPosition = new Point (3, 0); Assert.Equal (new Point (3, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); tv.Draw (); Assert.Equal (new Point (2, 0), tv.CursorPosition); @@ -801,7 +801,7 @@ This is the second line. tv.CursorPosition = new Point (0, 1); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); tv.Draw (); Assert.Equal (new Point (22, 0), tv.CursorPosition); @@ -812,7 +812,7 @@ Ths is the first line.This is the second line. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); tv.Draw (); Assert.Equal (new Point (0, 1), tv.CursorPosition); @@ -826,7 +826,7 @@ This is the second line. while (tv.Text != envText) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal (envText, tv.Text); @@ -857,7 +857,7 @@ This is the second line. tv.CursorPosition = new Point (3, 0); Assert.Equal (new Point (3, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); tv.Draw (); Assert.Equal (new Point (2, 0), tv.CursorPosition); @@ -871,7 +871,7 @@ This is the second line. tv.CursorPosition = new Point (0, 1); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); tv.Draw (); Assert.Equal (new Point (22, 0), tv.CursorPosition); @@ -882,7 +882,7 @@ Ths is the first line.This is the second line. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); tv.Draw (); Assert.Equal (new Point (0, 1), tv.CursorPosition); @@ -896,7 +896,7 @@ This is the second line. while (tv.Text != envText) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal (envText, tv.Text); @@ -927,7 +927,7 @@ This is the second line. tv.CursorPosition = new Point (2, 0); Assert.Equal (new Point (2, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); tv.Draw (); Assert.Equal (new Point (2, 0), tv.CursorPosition); @@ -941,7 +941,7 @@ This is the second line. tv.CursorPosition = new Point (22, 0); Assert.Equal (new Point (22, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); tv.Draw (); Assert.Equal (new Point (22, 0), tv.CursorPosition); @@ -952,7 +952,7 @@ Ths is the first line.This is the second line. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); tv.Draw (); Assert.Equal (new Point (0, 1), tv.CursorPosition); @@ -966,7 +966,7 @@ This is the second line. while (tv.Text != envText) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal (envText, tv.Text); @@ -997,7 +997,7 @@ This is the second line. tv.CursorPosition = new Point (2, 0); Assert.Equal (new Point (2, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); tv.Draw (); Assert.Equal (new Point (2, 0), tv.CursorPosition); @@ -1011,7 +1011,7 @@ This is the second line. tv.CursorPosition = new Point (22, 0); Assert.Equal (new Point (22, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); tv.Draw (); Assert.Equal (new Point (22, 0), tv.CursorPosition); @@ -1022,7 +1022,7 @@ Ths is the first line.This is the second line. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); tv.Draw (); Assert.Equal (new Point (0, 1), tv.CursorPosition); @@ -1036,7 +1036,7 @@ This is the second line. while (tv.Text != envText) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal (envText, tv.Text); @@ -1149,7 +1149,7 @@ This is the second line. var text = "This is the first line.\nThis is the second line.\nThis is the third line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"{ @@ -1217,42 +1217,42 @@ This is the second line. Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ("1", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"1{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ($"1{Environment.NewLine}2", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ($"1{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("1", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -1270,34 +1270,34 @@ This is the second line. { var tv = new TextView (); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ("1", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ("12", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D3))); + Assert.True (tv.NewKeyDownEvent (Key.D3)); Assert.Equal ("123", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("12", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D4))); + Assert.True (tv.NewKeyDownEvent (Key.D4)); Assert.Equal ("124", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("124", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); @@ -1312,7 +1312,7 @@ This is the second line. tv.CursorPosition = new Point (23, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1327,7 +1327,7 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (23, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1343,7 +1343,7 @@ This is the second line. Assert.Equal (new Point (23, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1357,7 +1357,7 @@ This is the second line. Assert.Equal (new Point (23, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1383,7 +1383,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (17, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1401,7 +1401,7 @@ This is the second line. tv.SelectionStartRow = 1; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1415,7 +1415,7 @@ This is the second line. Assert.Equal (new Point (17, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1428,7 +1428,7 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (12, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1442,7 +1442,7 @@ This is the second line. Assert.Equal (new Point (12, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1455,7 +1455,7 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (12, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1479,7 +1479,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (17, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1496,13 +1496,13 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (11, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (17, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the line.{ @@ -1516,7 +1516,7 @@ This is the second line. Assert.Equal (new Point (12, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (17, 0), tv.CursorPosition); @@ -1532,7 +1532,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); @@ -1540,7 +1540,7 @@ This is the second line. tv.Selecting = false; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1554,13 +1554,13 @@ This is the second line. Assert.Equal (new Point (18, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (12, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1586,23 +1586,23 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (12, 2); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'a'))); + Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); @@ -1615,7 +1615,7 @@ This is the second line. var text = "\nThis is the first line.\nThis is the second line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", @@ -1625,7 +1625,7 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"{ @@ -1641,7 +1641,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the first line.{Environment.NewLine}This is the second line.", @@ -1651,7 +1651,7 @@ This is the second line. Assert.Equal (new Point (0, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"{ @@ -1676,24 +1676,24 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (12, 2); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'a'))); + Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1710,24 +1710,24 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1744,12 +1744,12 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}third line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine}athird line.{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); @@ -1764,7 +1764,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (17, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"This is the { @@ -1779,7 +1779,7 @@ This is the second line. Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'a'))); + Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ( $"This is the { @@ -1795,7 +1795,7 @@ This is the second line. Assert.Equal (new Point (1, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the { @@ -1811,7 +1811,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1826,7 +1826,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the { @@ -1841,7 +1841,7 @@ This is the second line. Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the { @@ -1857,7 +1857,7 @@ This is the second line. Assert.Equal (new Point (1, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the { @@ -1873,7 +1873,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -1888,7 +1888,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the { @@ -1903,7 +1903,7 @@ This is the second line. Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the { @@ -1926,21 +1926,21 @@ This is the second line. var text = "First line.\nSecond line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ("First line.", Clipboard.Contents); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents); @@ -1948,33 +1948,33 @@ This is the second line. Assert.Equal (new Point (0, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -1987,27 +1987,27 @@ This is the second line. var text = "First line.\nSecond line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (12, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithAlt)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ("Second line.", Clipboard.Contents); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithAlt)); Assert.Equal ("First line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"Second line.{Environment.NewLine}", Clipboard.Contents); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (11, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithAlt)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents); @@ -2015,33 +2015,33 @@ This is the second line. Assert.Equal (new Point (0, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (11, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (12, 1), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (11, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -2053,122 +2053,122 @@ This is the second line. var text = "First line.\nSecond line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (12, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (11, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (7, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (11, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("First line", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (10, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("First ", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (6, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First ", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (6, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First line", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (10, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (11, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (7, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (11, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (12, 1), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (11, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second ", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (7, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (11, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (10, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First ", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (6, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -2180,80 +2180,80 @@ This is the second line. var text = "First line.\nSecond line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -2333,7 +2333,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); switch (i) { @@ -2389,7 +2389,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); switch (i) { @@ -2445,7 +2445,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); switch (i) { @@ -2501,7 +2501,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2517,7 +2517,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2533,7 +2533,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2618,7 +2618,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -2634,7 +2634,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -2650,7 +2650,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -2666,7 +2666,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2682,7 +2682,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2698,7 +2698,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2775,7 +2775,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -2791,7 +2791,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -2807,7 +2807,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -2823,7 +2823,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2839,7 +2839,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2855,7 +2855,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -2876,7 +2876,7 @@ This is the second line. var text = "This is the first line.\nThis is the second line.\nThis is the third line."; var tv = new TextView { Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift)); Assert.Equal ( $"This is the first line.{ @@ -2889,24 +2889,24 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (23, 2), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'a'))); + Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ($"{Environment.NewLine}a", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -2921,24 +2921,24 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}a", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -2953,12 +2953,12 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}a", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); @@ -2974,7 +2974,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -2991,7 +2991,7 @@ This is the second line. tv.Selecting = false; tv.CursorPosition = new Point (17, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3007,7 +3007,7 @@ This is the second line. Assert.Equal (new Point (18, 2), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3021,7 +3021,7 @@ This is the second line. Assert.Equal (new Point (17, 1), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3047,7 +3047,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3063,7 +3063,7 @@ This is the second line. tv.Selecting = false; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3079,7 +3079,7 @@ This is the second line. Assert.Equal (new Point (18, 2), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3093,7 +3093,7 @@ This is the second line. Assert.Equal (new Point (18, 1), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3128,7 +3128,7 @@ This is the second line. Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift)); Assert.Equal ( $"This is the first line.{ @@ -3153,7 +3153,7 @@ This is the second line. Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); @@ -3163,7 +3163,7 @@ This is the second line. Assert.True (tv.HasHistoryChanges); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3181,7 +3181,7 @@ This is the second line. Assert.True (tv.HasHistoryChanges); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); @@ -3210,7 +3210,7 @@ This is the second line. Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl.WithShift)); Assert.Equal ( $"This is the first line.{ @@ -3235,7 +3235,7 @@ This is the second line. Assert.False (tv.IsDirty); Assert.False (tv.HasHistoryChanges); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); @@ -3245,7 +3245,7 @@ This is the second line. Assert.True (tv.HasHistoryChanges); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -3263,7 +3263,7 @@ This is the second line. Assert.True (tv.HasHistoryChanges); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); @@ -3349,7 +3349,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); switch (i) { @@ -3409,7 +3409,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); switch (i) { @@ -3474,7 +3474,7 @@ This is the second line. tv.CursorPosition = new Point (0, 1); Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); @@ -3485,32 +3485,32 @@ This is the second line. tv.CursorPosition = new Point (1, 1); Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ("12hree", tv.Text); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("12hree", tv.Text); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); @@ -3537,7 +3537,7 @@ This is the second line. tv.CursorPosition = new Point (0, 1); Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); @@ -3548,32 +3548,32 @@ This is the second line. tv.CursorPosition = new Point (1, 1); Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); @@ -3594,85 +3594,85 @@ This is the second line. Assert.Equal (Point.Empty, tv.CursorPosition); Assert.False (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.O | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.O.WithShift)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'n'))); + Assert.True (tv.NewKeyDownEvent (Key.N)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'e'))); + Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'w'))); + Assert.True (tv.NewKeyDownEvent (Key.W)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'o'))); + Assert.True (tv.NewKeyDownEvent (Key.O)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'h'))); + Assert.True (tv.NewKeyDownEvent (Key.H)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'r'))); + Assert.True (tv.NewKeyDownEvent (Key.R)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'e'))); + Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'e'))); + Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 3), tv.CursorPosition); @@ -3683,7 +3683,7 @@ This is the second line. tv.CursorPosition = new Point (0, 1); Assert.Equal (3 + Environment.NewLine.Length, tv.SelectedLength); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tv.NewKeyDownEvent (Key.D1)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); @@ -3695,7 +3695,7 @@ This is the second line. tv.CursorPosition = new Point (1, 1); Assert.Equal (4 + Environment.NewLine.Length, tv.SelectedLength); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D2))); + Assert.True (tv.NewKeyDownEvent (Key.D2)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); @@ -3703,118 +3703,118 @@ This is the second line. Assert.True (tv.IsDirty); // Undoing - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (5, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (3, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (2, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (3, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -3822,112 +3822,112 @@ This is the second line. Assert.False (tv.IsDirty); // Redoing - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (3, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (2, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (3, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (4, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (5, 2), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 3), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"1Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"12hree{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); @@ -3949,267 +3949,267 @@ This is the second line. Assert.Equal (Point.Empty, tv.CursorPosition); Assert.False (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.O | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.O.WithShift)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'n'))); + Assert.True (tv.NewKeyDownEvent (Key.N)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'e'))); + Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'w'))); + Assert.True (tv.NewKeyDownEvent (Key.W)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'o'))); + Assert.True (tv.NewKeyDownEvent (Key.O)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.T.WithShift)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'h'))); + Assert.True (tv.NewKeyDownEvent (Key.H)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'r'))); + Assert.True (tv.NewKeyDownEvent (Key.R)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'e'))); + Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'e'))); + Assert.True (tv.NewKeyDownEvent (Key.E)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 3), tv.CursorPosition); Assert.True (tv.IsDirty); // Undoing - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.False (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redoing - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("O", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("On", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (2, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("One", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (3, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}T", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (1, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Tw", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (2, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (3, 1), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}T", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Th", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (2, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thr", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (3, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Thre", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (4, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (5, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 3), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"One{Environment.NewLine}Two{Environment.NewLine}Three{Environment.NewLine}", tv.Text); Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 3), tv.CursorPosition); @@ -4225,36 +4225,36 @@ This is the second line. tv.SelectionStartColumn = 6; tv.CursorPosition = new Point (6, 2); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (tv.NewKeyDownEvent (Key.Tab)); Assert.Equal ("First \tline.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (7, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (6, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("First \tline.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (7, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (6, 2), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First \tline.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (7, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("First line.", tv.Text); Assert.Equal (1, tv.Lines); Assert.Equal (new Point (6, 0), tv.CursorPosition); @@ -4266,7 +4266,7 @@ This is the second line. var text = "First line.\nSecond line.\nThird line."; var tv = new TextView { Width = 80, Height = 5, Text = text }; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (tv.NewKeyDownEvent (Key.Tab)); Assert.Equal ( $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", @@ -4275,13 +4275,13 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", @@ -4291,14 +4291,14 @@ This is the second line. Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", @@ -4307,7 +4307,7 @@ This is the second line. Assert.Equal (3, tv.Lines); Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); @@ -4327,7 +4327,7 @@ This is the second line. Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", @@ -4337,13 +4337,13 @@ This is the second line. Assert.Equal (new Point (7, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"Inserted{Environment.NewLine}NewLineThis is the first line.{Environment.NewLine}This is the second line.", @@ -4363,7 +4363,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (17, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -4380,13 +4380,13 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (11, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (17, 0), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -4400,7 +4400,7 @@ This is the second line. Assert.Equal (new Point (12, 0), tv.CursorPosition); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (17, 0), tv.CursorPosition); @@ -4448,7 +4448,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -4464,7 +4464,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -4521,7 +4521,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -4537,7 +4537,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -4590,7 +4590,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -4606,7 +4606,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -4669,7 +4669,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -4688,7 +4688,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -4754,7 +4754,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -4773,7 +4773,7 @@ This is the second line. for (var i = 0; i < ntimes; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -4835,7 +4835,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); } Assert.Equal ( @@ -4854,7 +4854,7 @@ This is the second line. for (var i = 0; i < messy.Length; i++) { - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); } Assert.Equal ( @@ -4881,7 +4881,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (17, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"This is the { @@ -4897,7 +4897,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -4912,7 +4912,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the { @@ -4928,7 +4928,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -4943,7 +4943,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the { @@ -4969,7 +4969,7 @@ This is the second line. tv.SelectionStartRow = 1; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"This is the first line.{ @@ -4985,7 +4985,7 @@ This is the second line. Assert.Equal (new Point (0, 2), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5000,7 +5000,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5016,7 +5016,7 @@ This is the second line. Assert.Equal (new Point (0, 2), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5031,7 +5031,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5057,7 +5057,7 @@ This is the second line. tv.SelectionStartRow = 1; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"This is the first line.{ @@ -5072,7 +5072,7 @@ This is the second line. Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key ((KeyCode)'a'))); + Assert.True (tv.NewKeyDownEvent (Key.A)); Assert.Equal ( $"This is the first line.{ @@ -5088,7 +5088,7 @@ This is the second line. Assert.Equal (new Point (1, 2), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5104,7 +5104,7 @@ This is the second line. Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5119,7 +5119,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5134,7 +5134,7 @@ This is the second line. Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5150,7 +5150,7 @@ This is the second line. Assert.Equal (new Point (1, 2), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5166,7 +5166,7 @@ This is the second line. Assert.Equal (new Point (0, 2), tv.CursorPosition); Assert.True (tv.IsDirty); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5181,7 +5181,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5196,7 +5196,7 @@ This is the second line. Assert.Equal (4, tv.Lines); Assert.Equal (new Point (0, 2), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5221,13 +5221,13 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (17, 2); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5242,13 +5242,13 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5263,7 +5263,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"This is the {Environment.NewLine} line.", tv.Text); Assert.Equal (2, tv.Lines); Assert.Equal (new Point (0, 1), tv.CursorPosition); @@ -5278,7 +5278,7 @@ This is the second line. tv.SelectionStartColumn = 12; tv.CursorPosition = new Point (18, 1); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", @@ -5288,7 +5288,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5303,7 +5303,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", @@ -5313,7 +5313,7 @@ This is the second line. Assert.Equal (new Point (0, 1), tv.CursorPosition); // Undo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ( $"This is the first line.{ @@ -5328,7 +5328,7 @@ This is the second line. Assert.False (tv.IsDirty); // Redo - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ( $"This is the {Environment.NewLine} line.{Environment.NewLine}This is the third line.", @@ -5443,20 +5443,20 @@ This is the second line. var g = (SingleWordSuggestionGenerator)tv.Autocomplete.SuggestionGenerator; tv.CanFocus = false; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); tv.CanFocus = true; - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.False (tv.NewKeyDownEvent (Key.CursorLeft)); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal (2, tv.CurrentRow); Assert.Equal (23, tv.CurrentColumn); Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 2), tv.CursorPosition); - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.False (tv.NewKeyDownEvent (Key.CursorRight)); Assert.NotNull (tv.Autocomplete); Assert.Empty (g.AllSuggestions); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.F | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithShift)); tv.Draw (); Assert.Equal ( @@ -5469,7 +5469,7 @@ This is the second line. ); Assert.Equal (new Point (24, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); tv.Draw (); Assert.Equal ( @@ -5482,7 +5482,7 @@ This is the second line. ); Assert.Equal (new Point (23, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.R | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); tv.Draw (); Assert.Equal ( @@ -5495,7 +5495,7 @@ This is the second line. ); Assert.Equal (new Point (24, 2), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ( $"This is the first line.{ @@ -5519,7 +5519,7 @@ This is the second line. Assert.Equal ("line", g.AllSuggestions [4]); Assert.Equal ("second", g.AllSuggestions [5]); Assert.Equal ("third", g.AllSuggestions [^1]); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.F | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithShift)); tv.Draw (); Assert.Equal ( @@ -5533,7 +5533,7 @@ This is the second line. Assert.Equal (new Point (24, 2), tv.CursorPosition); Assert.Single (tv.Autocomplete.Suggestions); Assert.Equal ("first", tv.Autocomplete.Suggestions [0].Replacement); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"This is the first line.{ @@ -5550,84 +5550,84 @@ This is the second line. tv.Autocomplete.ClearSuggestions (); Assert.Empty (g.AllSuggestions); Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.PageUp))); + Assert.True (tv.NewKeyDownEvent (Key.PageUp)); Assert.Equal (24, tv.GetCurrentLine ().Count); Assert.Equal (new Point (24, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key ('V' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.V.WithAlt))); Assert.Equal (23, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.PageDown))); + Assert.True (tv.NewKeyDownEvent (Key.PageDown)); Assert.Equal (24, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.V.WithCtrl)); Assert.Equal (28, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.PageUp | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.PageUp.WithShift)); Assert.Equal (24, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.PageDown | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.PageDown.WithShift)); Assert.Equal (28, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl)); Assert.Equal (Point.Empty, tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.N | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.N.WithCtrl)); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.P | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.P.WithCtrl)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (tv.NewKeyDownEvent (Key.CursorDown)); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (tv.NewKeyDownEvent (Key.CursorUp)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorDown | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.CursorDown.WithShift)); Assert.Equal (new Point (0, 1), tv.CursorPosition); Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorUp | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.CursorUp.WithShift)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.F | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithCtrl)); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.B | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.B.WithCtrl)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal (new Point (1, 0), tv.CursorPosition); Assert.Equal (1, tv.SelectedLength); Assert.Equal ("T", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); Assert.Equal ( $"This is the first line.{ @@ -5641,7 +5641,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tv.NewKeyDownEvent (Key.Delete)); Assert.Equal ( $"his is the first line.{ @@ -5655,7 +5655,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.D.WithCtrl)); Assert.Equal ( $"is is the first line.{ @@ -5666,7 +5666,7 @@ This is the second line. tv.Text ); Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (tv.NewKeyDownEvent (Key.End)); Assert.Equal ( $"is is the first line.{ @@ -5677,7 +5677,7 @@ This is the second line. tv.Text ); Assert.Equal (new Point (21, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ( $"is is the first line{ @@ -5688,7 +5688,7 @@ This is the second line. tv.Text ); Assert.Equal (new Point (20, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ( $"is is the first lin{ @@ -5699,32 +5699,32 @@ This is the second line. tv.Text ); Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (tv.NewKeyDownEvent (Key.Home)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithShift)); Assert.Equal (new Point (19, 0), tv.CursorPosition); Assert.Equal (19, tv.SelectedLength); Assert.Equal ("is is the first lin", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Home | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.E.WithCtrl)); Assert.Equal (new Point (19, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl)); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5735,7 +5735,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"is is the first lin{ @@ -5751,7 +5751,7 @@ This is the second line. Assert.False (tv.Selecting); Assert.Equal ("is is the first lin", Clipboard.Contents); tv.CursorPosition = Point.Empty; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl.WithShift)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5762,7 +5762,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"is is the first lin{ @@ -5777,7 +5777,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (Key.K.WithAlt)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5788,7 +5788,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); tv.ReadOnly = true; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5799,7 +5799,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); tv.ReadOnly = false; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); Assert.Equal ( $"is is the first lin{ @@ -5815,7 +5815,7 @@ This is the second line. Assert.False (tv.Selecting); Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Space | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl)); Assert.Equal ( $"is is the first lin{ @@ -5831,7 +5831,7 @@ This is the second line. Assert.True (tv.Selecting); Assert.Equal (19, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Space | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Space.WithCtrl)); Assert.Equal ( $"is is the first lin{ @@ -5848,7 +5848,7 @@ This is the second line. Assert.Equal (19, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); tv.SelectionStartColumn = 0; - Assert.True (tv.NewKeyDownEvent (new Key ('C' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.C.WithAlt))); Assert.Equal ( $"is is the first lin{ @@ -5864,7 +5864,7 @@ This is the second line. Assert.True (tv.Selecting); Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithCtrl)); Assert.Equal ( $"is is the first lin{ @@ -5880,7 +5880,7 @@ This is the second line. Assert.True (tv.Selecting); Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.NewKeyDownEvent (new Key ('W' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.W.WithAlt))); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5893,7 +5893,7 @@ This is the second line. Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.W | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.W.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5906,7 +5906,7 @@ This is the second line. Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); Assert.Equal ("", Clipboard.Contents); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.X | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.X.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5919,7 +5919,7 @@ This is the second line. Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); Assert.Equal ("", Clipboard.Contents); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5929,7 +5929,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5939,7 +5939,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorLeft | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5949,7 +5949,7 @@ This is the second line. Assert.Equal (6, tv.SelectedLength); Assert.Equal ("third ", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key ('B' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.B.WithAlt))); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5959,7 +5959,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5969,7 +5969,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight.WithShift.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5979,7 +5979,7 @@ This is the second line. Assert.Equal (6, tv.SelectedLength); Assert.Equal ("third ", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key ('F' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.F.WithAlt))); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5989,7 +5989,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key ('F' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.F.WithAlt))); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5999,7 +5999,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key ('F' + KeyCode.AltMask))); + Assert.True (tv.NewKeyDownEvent (new Key (Key.F.WithAlt))); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -6009,7 +6009,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Home | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Home.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -6019,20 +6019,20 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithCtrl)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); Assert.Equal (new Point (28, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace.WithCtrl)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); Assert.Equal (new Point (18, 1), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); @@ -6042,7 +6042,7 @@ This is the second line. tv.AllowsReturn = false; Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.False (tv.Selecting); - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.False (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); Assert.Equal (new Point (0, 0), tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); @@ -6051,7 +6051,7 @@ This is the second line. Assert.False (tv.AllowsReturn); tv.AllowsReturn = true; Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Enter))); + Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", @@ -6062,7 +6062,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.True (tv.AllowsReturn); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.End | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.End.WithShift.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", @@ -6072,7 +6072,7 @@ This is the second line. Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.Home | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", @@ -6082,7 +6082,7 @@ This is the second line. Assert.Equal (Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"{Environment.NewLine}", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.T | KeyCode.CtrlMask))); + Assert.True (tv.NewKeyDownEvent (Key.T.WithCtrl)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", @@ -6097,12 +6097,12 @@ This is the second line. ); Assert.True (tv.Selecting); Assert.True (tv.Used); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Insert))); + Assert.True (tv.NewKeyDownEvent (Key.InsertChar)); Assert.False (tv.Used); Assert.True (tv.AllowsTab); Assert.Equal (new Point (18, 2), tv.CursorPosition); tv.AllowsTab = false; - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.False (tv.NewKeyDownEvent (Key.Tab)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", @@ -6113,7 +6113,7 @@ This is the second line. Assert.Equal (new Point (18, 2), tv.CursorPosition); Assert.True (tv.Selecting); tv.Selecting = false; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (tv.NewKeyDownEvent (Key.Tab)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", @@ -6121,7 +6121,7 @@ This is the second line. ); Assert.True (tv.AllowsTab); tv.AllowsTab = false; - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask))); + Assert.False (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", @@ -6129,16 +6129,16 @@ This is the second line. ); Assert.False (tv.AllowsTab); tv.AllowsTab = true; - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask))); + Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text ); Assert.True (tv.AllowsTab); - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.False (tv.NewKeyDownEvent (Key.Tab.WithCtrl)); Assert.False (tv.NewKeyDownEvent (Application.AlternateForwardKey)); - Assert.False (tv.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.False (tv.NewKeyDownEvent (Key.Tab.WithCtrl.WithShift)); Assert.False (tv.NewKeyDownEvent (Application.AlternateBackwardKey)); Assert.True (tv.NewKeyDownEvent (ContextMenu.DefaultKey)); @@ -6156,7 +6156,7 @@ This is the second line. while (!iterationsFinished) { - _textView.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.Backspace.WithCtrl); switch (iteration) { @@ -6218,7 +6218,7 @@ This is the second line. while (!iterationsFinished) { - _textView.NewKeyDownEvent (new Key (KeyCode.Backspace | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.Backspace.WithCtrl); switch (iteration) { @@ -6350,7 +6350,7 @@ This is the second line. while (!iterationsFinished) { - _textView.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.Delete.WithCtrl); switch (iteration) { @@ -6405,7 +6405,7 @@ This is the second line. while (!iterationsFinished) { - _textView.NewKeyDownEvent (new Key (KeyCode.Delete | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.Delete.WithCtrl); switch (iteration) { @@ -6528,7 +6528,7 @@ This is the second line. switch (iteration) { case 0: - _textView.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.K.WithCtrl); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text); @@ -6548,7 +6548,7 @@ This is the second line. break; case 2: - _textView.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.K.WithCtrl); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal ("", _textView.Text); @@ -6559,7 +6559,7 @@ This is the second line. ); // Paste - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.Y.WithCtrl); Assert.Equal ( $"This is the first line.{Environment.NewLine}This is the second line.", @@ -6591,7 +6591,7 @@ This is the second line. switch (iteration) { case 0: - _textView.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); + _textView.NewKeyDownEvent (Key.K.WithAlt); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (1, _textView.CursorPosition.Y); Assert.Equal ($"This is the first line.{Environment.NewLine}", _textView.Text); @@ -6611,7 +6611,7 @@ This is the second line. break; case 2: - _textView.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); + _textView.NewKeyDownEvent (Key.K.WithAlt); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal ("", _textView.Text); @@ -6622,7 +6622,7 @@ This is the second line. ); // Paste inverted - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.Y.WithCtrl); Assert.Equal ( $"This is the second line.{Environment.NewLine}This is the first line.", @@ -6652,7 +6652,7 @@ This is the second line. Assert.Equal (new Point (9, 0), tv.CursorPosition); Assert.Equal (0, tv.LeftColumn); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); tv.CursorPosition = new Point (10, 0); Assert.Equal (new Point (10, 0), tv.CursorPosition); Assert.Equal (1, tv.LeftColumn); @@ -6903,9 +6903,9 @@ This is the second line. _textView.SelectionStartColumn = 20; _textView.SelectionStartRow = 0; _textView.CursorPosition = new Point (24, 0); - _textView.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask)); // Copy + _textView.NewKeyDownEvent (Key.C.WithCtrl); // Copy Assert.Equal ("text", _textView.SelectedText); - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.CtrlMask)); // Paste + _textView.NewKeyDownEvent (Key.Y.WithCtrl); // Paste Assert.Equal ("", _textView.SelectedText); } @@ -6935,7 +6935,7 @@ This is the second line. var tv = new TextView { Width = 10, Height = 10, RightOffset = 1 }; tv.Text = text; - tv.NewKeyDownEvent (new Key (KeyCode.End)); + tv.NewKeyDownEvent (Key.End); Assert.Equal (4, tv.LeftColumn); Assert.Equal (1, tv.RightOffset); @@ -6969,7 +6969,7 @@ This is the second line. tv.ScrollTo (50); Assert.Equal (0, tv.CursorPosition.Y); - tv.NewKeyDownEvent (new Key (KeyCode.P)); + tv.NewKeyDownEvent (Key.P); } [Fact] @@ -7013,7 +7013,7 @@ This is the second line. // TAB to jump between text fields. TestHelpers.AssertDriverAttributesAre ("0000000", Application.Driver, attributes); - _textView.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); var first = true; Application.RunIteration (ref rs, ref first); @@ -7122,7 +7122,7 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7131,7 +7131,7 @@ This is the second line. while (col > 0) { col--; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7163,7 +7163,7 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7172,7 +7172,7 @@ This is the second line. while (col > 0) { col--; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7204,7 +7204,7 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7213,7 +7213,7 @@ This is the second line. while (col > 0) { col--; - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + _textView.NewKeyDownEvent (Key.CursorLeft); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7222,7 +7222,7 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + _textView.NewKeyDownEvent (Key.CursorRight); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7254,7 +7254,7 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7265,7 +7265,7 @@ This is the second line. while (col > 0) { col--; - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + _textView.NewKeyDownEvent (Key.CursorLeft); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7274,7 +7274,7 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + _textView.NewKeyDownEvent (Key.CursorRight); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7308,19 +7308,19 @@ This is the second line. while (col < 100) { col++; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); } - _textView.NewKeyDownEvent (new Key (KeyCode.Home)); + _textView.NewKeyDownEvent (Key.Home); col = 0; Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = 0; Assert.Equal (leftCol, _textView.LeftColumn); - _textView.NewKeyDownEvent (new Key (KeyCode.End)); + _textView.NewKeyDownEvent (Key.End); col = _textView.Text.Length; Assert.Equal (132, _textView.Text.Length); Assert.Equal (new Point (col, 0), _textView.CursorPosition); @@ -7339,7 +7339,7 @@ This is the second line. while (col > 0) { col--; - _textView.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal (new Point (col, 0), _textView.CursorPosition); leftCol = GetLeftCol (leftCol); Assert.Equal (leftCol, _textView.LeftColumn); @@ -7371,7 +7371,7 @@ This is the second line. Assert.True (_textView.AllowsTab); Assert.True (_textView.AllowsReturn); Assert.True (_textView.Multiline); - _textView.NewKeyDownEvent (new Key (KeyCode.Tab)); + _textView.NewKeyDownEvent (Key.Tab); Assert.Equal ("\tTAB to jump between text fields.", _textView.Text); Application.Refresh (); @@ -7390,7 +7390,7 @@ TAB to jump between text field", _output ); - _textView.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.Tab.WithShift); Assert.Equal ("TAB to jump between text fields.", _textView.Text); Assert.True (_textView.NeedsDisplay); Application.Refresh (); @@ -7428,7 +7428,7 @@ TAB to jump between text field", _textView.Text = "ay"; Assert.Equal (1, eventcount); - _textView.NewKeyDownEvent (new Key (KeyCode.Y | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.Y.WithShift); Assert.Equal (1, eventcount); Assert.Equal ("Yay", _textView.Text); } @@ -7680,7 +7680,7 @@ line. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); tv.Draw (); Assert.Equal (new Point (0, 3), tv.CursorPosition); Assert.Equal (new Point (12, 0), cp); @@ -7703,7 +7703,7 @@ line. _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); tv.Draw (); Assert.Equal (new Point (1, 3), tv.CursorPosition); Assert.Equal (new Point (13, 0), cp); @@ -7757,13 +7757,13 @@ line. _textView.Used = false; _textView.CursorPosition = new Point (10, 0); Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x75)); // u + _textView.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jumu between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x73)); // s + _textView.NewKeyDownEvent (Key.S); // s Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x65)); // e + _textView.NewKeyDownEvent (Key.E); // e Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x64)); // d + _textView.NewKeyDownEvent (Key.D); // d Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text); } @@ -7773,13 +7773,13 @@ line. { _textView.CursorPosition = new Point (10, 0); Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x75)); // u + _textView.NewKeyDownEvent (Key.U); // u Assert.Equal ("TAB to jumup between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x73)); // s + _textView.NewKeyDownEvent (Key.S); // s Assert.Equal ("TAB to jumusp between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x65)); // e + _textView.NewKeyDownEvent (Key.E); // e Assert.Equal ("TAB to jumusep between text fields.", _textView.Text); - _textView.NewKeyDownEvent (new Key ((KeyCode)0x64)); // d + _textView.NewKeyDownEvent (Key.D); // d Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text); } @@ -7801,7 +7801,7 @@ line. while (!iterationsFinished) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift); switch (iteration) { @@ -7965,7 +7965,7 @@ line. while (_textView.CursorPosition.X > 0) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl); switch (iteration) { @@ -8050,7 +8050,7 @@ line. while (_textView.CursorPosition.X > 0) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl); switch (iteration) { @@ -8170,7 +8170,7 @@ line. while (_textView.CursorPosition.X > 0) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift); switch (iteration) { @@ -8255,7 +8255,7 @@ line. while (_textView.CursorPosition.X > 0) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask)); + _textView.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift); switch (iteration) { @@ -8466,7 +8466,7 @@ line. while (_textView.CursorPosition.X < _textView.Text.Length) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl); switch (iteration) { @@ -8542,7 +8542,7 @@ line. while (_textView.CursorPosition.X < _textView.Text.Length) { - _textView.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.CtrlMask)); + _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl); switch (iteration) { @@ -8811,7 +8811,7 @@ aaaa ); tv.CursorPosition = new Point (5, 0); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.Refresh (); Assert.Equal (0, tv.LeftColumn); @@ -8822,7 +8822,7 @@ aaa _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.Refresh (); Assert.Equal (0, tv.LeftColumn); @@ -8833,7 +8833,7 @@ aa _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.Refresh (); Assert.Equal (0, tv.LeftColumn); @@ -8844,7 +8844,7 @@ a _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.Refresh (); Assert.Equal (0, tv.LeftColumn); @@ -8855,7 +8855,7 @@ a _output ); - Assert.True (tv.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Application.Refresh (); Assert.Equal (0, tv.LeftColumn); @@ -8886,14 +8886,14 @@ Line 2.", _output ); - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.ShiftMask))); + Assert.True (_textView.NewKeyDownEvent (Key.End.WithShift)); Assert.Equal ("Line 1.", _textView.SelectedText); Assert.True (_textView.NewKeyDownEvent (new Key (del))); Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ("Line 2.", _output); - Assert.True (_textView.NewKeyDownEvent (new Key (KeyCode.H | KeyCode.ShiftMask))); + Assert.True (_textView.NewKeyDownEvent (Key.H.WithShift)); Assert.NotEqual (Rect.Empty, _textView._needsDisplayRect); Application.Refresh (); diff --git a/UnitTests/Views/TileViewTests.cs b/UnitTests/Views/TileViewTests.cs index 7367199a2..1ad1d52aa 100644 --- a/UnitTests/Views/TileViewTests.cs +++ b/UnitTests/Views/TileViewTests.cs @@ -1689,7 +1689,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Keyboard movement on splitter should have no effect if it is not focused - bool handled = tileView.NewKeyDownEvent (new Key (KeyCode.CursorDown)); + bool handled = tileView.NewKeyDownEvent (Key.CursorDown); Assert.False (handled); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -1717,7 +1717,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Now move splitter line down - tileView.NewKeyDownEvent (new Key (KeyCode.CursorDown)); + tileView.NewKeyDownEvent (Key.CursorDown); tileView.Draw (); @@ -1729,8 +1729,8 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // And 2 up - line.NewKeyDownEvent (new Key (KeyCode.CursorUp)); - line.NewKeyDownEvent (new Key (KeyCode.CursorUp)); + line.NewKeyDownEvent (Key.CursorUp); + line.NewKeyDownEvent (Key.CursorUp); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -1768,7 +1768,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Now move splitter line down (allowed - line.NewKeyDownEvent (new Key (KeyCode.CursorDown)); + line.NewKeyDownEvent (Key.CursorDown); tileView.Draw (); looksLike = @@ -1779,8 +1779,8 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // And up 2 (only 1 is allowed because of minimum size of 1 on view1) - line.NewKeyDownEvent (new Key (KeyCode.CursorUp)); - line.NewKeyDownEvent (new Key (KeyCode.CursorUp)); + line.NewKeyDownEvent (Key.CursorUp); + line.NewKeyDownEvent (Key.CursorUp); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -1905,7 +1905,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Keyboard movement on splitter should have no effect if it is not focused - tileView.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + tileView.NewKeyDownEvent (Key.CursorRight); tileView.SetNeedsDisplay (); tileView.Draw (); TestHelpers.AssertDriverContentsAre (looksLike, _output); @@ -1928,7 +1928,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Now while focused move the splitter 1 unit right - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.Draw (); looksLike = @@ -1939,8 +1939,8 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // and 2 to the left - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); + line.NewKeyDownEvent (Key.CursorLeft); tileView.Draw (); looksLike = @@ -1970,7 +1970,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Now while focused move the splitter 1 unit right - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.Draw (); looksLike = @@ -1984,8 +1984,8 @@ public class TileViewTests Assert.IsType (tileView.SplitterDistances.ElementAt (0)); // and 2 to the left - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); + line.NewKeyDownEvent (Key.CursorLeft); tileView.Draw (); looksLike = @@ -2016,7 +2016,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Now while focused move the splitter 1 unit right - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.Draw (); looksLike = @@ -2027,8 +2027,8 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // and 2 to the left - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); + line.NewKeyDownEvent (Key.CursorLeft); tileView.Draw (); looksLike = @@ -2065,13 +2065,13 @@ public class TileViewTests // Keyboard movement on splitter should have no effect because it // would take us below the minimum splitter size - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); tileView.SetNeedsDisplay (); tileView.Draw (); TestHelpers.AssertDriverContentsAre (looksLike, _output); // but we can continue to move the splitter right if we want - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -2110,13 +2110,13 @@ public class TileViewTests // Keyboard movement on splitter should have no effect because it // would take us below the minimum splitter size - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); tileView.SetNeedsDisplay (); tileView.Draw (); TestHelpers.AssertDriverContentsAre (looksLike, _output); // but we can continue to move the splitter right if we want - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -2155,13 +2155,13 @@ public class TileViewTests // Keyboard movement on splitter should have no effect because it // would take us below the minimum splitter size - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.SetNeedsDisplay (); tileView.Draw (); TestHelpers.AssertDriverContentsAre (looksLike, _output); // but we can continue to move the splitter left if we want - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -2200,13 +2200,13 @@ public class TileViewTests // Keyboard movement on splitter should have no effect because it // would take us below the minimum splitter size - line.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + line.NewKeyDownEvent (Key.CursorRight); tileView.SetNeedsDisplay (); tileView.Draw (); TestHelpers.AssertDriverContentsAre (looksLike, _output); // but we can continue to move the splitter left if we want - line.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + line.NewKeyDownEvent (Key.CursorLeft); tileView.SetNeedsDisplay (); tileView.Draw (); @@ -2235,7 +2235,7 @@ public class TileViewTests TestHelpers.AssertDriverContentsAre (looksLike, _output); // Keyboard movement on splitter should have no effect if it is not focused - tileView.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + tileView.NewKeyDownEvent (Key.CursorRight); tileView.SetNeedsDisplay (); tileView.Draw (); TestHelpers.AssertDriverContentsAre (looksLike, _output); diff --git a/UnitTests/Views/TimeFieldTests.cs b/UnitTests/Views/TimeFieldTests.cs index 7c1b9ea6d..ef33ed98d 100644 --- a/UnitTests/Views/TimeFieldTests.cs +++ b/UnitTests/Views/TimeFieldTests.cs @@ -43,16 +43,16 @@ public class TimeFieldTests var tf2 = new TimeField { Time = TimeSpan.Parse ("12:59:01") }; // Select all text - Assert.True (tf2.NewKeyDownEvent (new Key (KeyCode.End | KeyCode.ShiftMask))); + Assert.True (tf2.NewKeyDownEvent (Key.End.WithShift)); Assert.Equal (1, tf2.SelectedStart); Assert.Equal (8, tf2.SelectedLength); Assert.Equal (9, tf2.CursorPosition); // Copy from tf2 - Assert.True (tf2.NewKeyDownEvent (new Key (KeyCode.C | KeyCode.CtrlMask))); + Assert.True (tf2.NewKeyDownEvent (Key.C.WithCtrl)); // Paste into tf1 - Assert.True (tf1.NewKeyDownEvent (new Key (KeyCode.V | KeyCode.CtrlMask))); + Assert.True (tf1.NewKeyDownEvent (Key.V.WithCtrl)); Assert.Equal (" 12:59:01", tf1.Text); Assert.Equal (9, tf1.CursorPosition); } @@ -79,22 +79,22 @@ public class TimeFieldTests var tf = new TimeField (); // Start selection - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft.WithShift)); Assert.Equal (1, tf.SelectedStart); Assert.Equal (1, tf.SelectedLength); Assert.Equal (0, tf.CursorPosition); // Without selection - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (-1, tf.SelectedStart); Assert.Equal (0, tf.SelectedLength); Assert.Equal (1, tf.CursorPosition); tf.CursorPosition = 8; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal (8, tf.SelectedStart); Assert.Equal (1, tf.SelectedLength); Assert.Equal (9, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (-1, tf.SelectedStart); Assert.Equal (0, tf.SelectedLength); Assert.Equal (8, tf.CursorPosition); @@ -106,11 +106,11 @@ public class TimeFieldTests Assert.Equal (5, tf.CursorPosition); // Start selection - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal (5, tf.SelectedStart); Assert.Equal (1, tf.SelectedLength); Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (-1, tf.SelectedStart); Assert.Equal (0, tf.SelectedLength); Assert.Equal (5, tf.CursorPosition); @@ -125,43 +125,45 @@ public class TimeFieldTests Assert.Equal (9, tf.CursorPosition); tf.CursorPosition = 1; tf.ReadOnly = true; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal (" 12:12:19", tf.Text); tf.ReadOnly = false; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.D.WithCtrl)); Assert.Equal (" 02:12:19", tf.Text); tf.CursorPosition = 4; tf.ReadOnly = true; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Delete))); + Assert.True (tf.NewKeyDownEvent (Key.Delete)); Assert.Equal (" 02:12:19", tf.Text); tf.ReadOnly = false; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Backspace))); + Assert.True (tf.NewKeyDownEvent (Key.Backspace)); Assert.Equal (" 02:02:19", tf.Text); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.Home))); + Assert.True (tf.NewKeyDownEvent (Key.Home)); Assert.Equal (1, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.End))); + Assert.True (tf.NewKeyDownEvent (Key.End)); Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.A | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl)); Assert.Equal (1, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.CtrlMask))); + Assert.True (tf.NewKeyDownEvent (Key.E.WithCtrl)); Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (tf.NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (7, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight)); Assert.Equal (8, tf.CursorPosition); // Non-numerics are ignored - Assert.False (tf.NewKeyDownEvent (new Key (KeyCode.A))); + Assert.False (tf.NewKeyDownEvent (Key.A)); tf.ReadOnly = true; tf.CursorPosition = 1; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tf.NewKeyDownEvent (Key.D1)); Assert.Equal (" 02:02:19", tf.Text); tf.ReadOnly = false; - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D1))); + Assert.True (tf.NewKeyDownEvent (Key.D1)); Assert.Equal (" 12:02:19", tf.Text); Assert.Equal (2, tf.CursorPosition); - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D | KeyCode.AltMask))); +#if UNIX_KEY_BINDINGS + Assert.True (tf.NewKeyDownEvent (Key.D.WithAlt)); Assert.Equal (" 10:02:19", tf.Text); +#endif } [Fact] @@ -173,13 +175,13 @@ public class TimeFieldTests tf.CursorPosition = 2; // Now select the separator : - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.CursorRight | KeyCode.ShiftMask))); + Assert.True (tf.NewKeyDownEvent (Key.CursorRight.WithShift)); Assert.Equal (2, tf.SelectedStart); Assert.Equal (1, tf.SelectedLength); Assert.Equal (3, tf.CursorPosition); // Type 3 over the separator - Assert.True (tf.NewKeyDownEvent (new Key (KeyCode.D3))); + Assert.True (tf.NewKeyDownEvent (Key.D3)); // The format was normalized and replaced again with : Assert.Equal (" 12:12:19", tf.Text); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index b1f312644..cbf3f7cf5 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -475,47 +475,47 @@ public class ToplevelTests Assert.True (isRunning); Assert.True (Application.OnKeyDown (Application.QuitKey)); Assert.False (isRunning); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Z | KeyCode.CtrlMask))); + Assert.True (Application.OnKeyDown (Key.Z.WithCtrl)); - Assert.True (Application.OnKeyDown (new Key (KeyCode.F5))); // refresh + Assert.True (Application.OnKeyDown (Key.F5)); // refresh - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab))); + Assert.True (Application.OnKeyDown (Key.Tab)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab))); + Assert.True (Application.OnKeyDown (Key.Tab)); Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab | KeyCode.ShiftMask))); + Assert.True (Application.OnKeyDown (Key.Tab.WithShift)); Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab))); + Assert.True (Application.OnKeyDown (Key.Tab)); Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (Application.OnKeyDown (Key.CursorRight)); Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (Application.OnKeyDown (Key.CursorDown)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); #if UNIX_KEY_BINDINGS - Assert.True (Application.OnKeyDown (new (Key.I | Key.CtrlMask))); + Assert.True (Application.OnKeyDown (new (Key.I.WithCtrl))); Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.MostFocused); #endif - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab | KeyCode.ShiftMask))); + Assert.True (Application.OnKeyDown (Key.Tab.WithShift)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorLeft))); + Assert.True (Application.OnKeyDown (Key.CursorLeft)); Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorUp))); + Assert.True (Application.OnKeyDown (Key.CursorUp)); Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab | KeyCode.CtrlMask))); + Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); Assert.Equal (win2, top.Focused); Assert.Equal (tf1W2, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.Tab | KeyCode.CtrlMask | KeyCode.ShiftMask))); + Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift)); Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.MostFocused); Assert.True (Application.OnKeyDown (Application.AlternateForwardKey)); @@ -524,37 +524,37 @@ public class ToplevelTests Assert.True (Application.OnKeyDown (Application.AlternateBackwardKey)); Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorUp))); + Assert.True (Application.OnKeyDown (Key.CursorUp)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); #if UNIX_KEY_BINDINGS - Assert.True (Application.OnKeyDown (new (Key.B | Key.CtrlMask))); + Assert.True (Application.OnKeyDown (new (Key.B.WithCtrl))); #else - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorLeft))); + Assert.True (Application.OnKeyDown (Key.CursorLeft)); #endif Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.MostFocused); - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.True (Application.OnKeyDown (Key.CursorDown)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); Assert.Equal (new Point (0, 0), tvW1.CursorPosition); - Assert.True (Application.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); + Assert.True (Application.OnKeyDown (Key.End.WithCtrl)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); Assert.Equal (new Point (16, 1), tvW1.CursorPosition); #if UNIX_KEY_BINDINGS - Assert.True (Application.OnKeyDown (new (Key.F | Key.CtrlMask))); + Assert.True (Application.OnKeyDown (new (Key.F.WithCtrl))); #else - Assert.True (Application.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (Application.OnKeyDown (Key.CursorRight)); #endif Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.MostFocused); #if UNIX_KEY_BINDINGS - Assert.True (Application.OnKeyDown (new (Key.L | Key.CtrlMask))); + Assert.True (Application.OnKeyDown (new (Key.L.WithCtrl))); #else - Assert.True (Application.OnKeyDown (new Key (KeyCode.F5))); + Assert.True (Application.OnKeyDown (Key.F5)); #endif } @@ -635,62 +635,62 @@ public class ToplevelTests Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.True ( - Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.Z | KeyCode.CtrlMask)) + Application.OverlappedChildren [0].NewKeyDownEvent (Key.Z.WithCtrl) ); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.F5))); // refresh + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.F5)); // refresh - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.Tab)); Assert.True (win1.IsCurrentTop); Assert.Equal (tvW1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.Tab)); Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text); Assert.True ( Application.OverlappedChildren [0] - .NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)) + .NewKeyDownEvent (Key.Tab.WithShift) ); Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text); Assert.True ( Application.OverlappedChildren [0] - .NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)) + .NewKeyDownEvent (Key.Tab.WithCtrl) ); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf2W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.Tab)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorRight)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorDown)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tvW1, win1.MostFocused); #if UNIX_KEY_BINDINGS - Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.I | Key.CtrlMask))); + Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.I.WithCtrl))); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf2W1, win1.MostFocused); #endif Assert.True ( Application.OverlappedChildren [0] - .NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask)) + .NewKeyDownEvent (Key.Tab.WithShift) ); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tvW1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorLeft)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorUp))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorUp)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf2W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.Tab))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.Tab)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); Assert.True ( Application.OverlappedChildren [0] - .NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)) + .NewKeyDownEvent (Key.Tab.WithCtrl) ); Assert.Equal (win2, Application.OverlappedChildren [0]); Assert.Equal (tf1W2, win2.MostFocused); @@ -699,7 +699,7 @@ public class ToplevelTests Assert.True ( Application.OverlappedChildren [0] - .NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask | KeyCode.ShiftMask)) + .NewKeyDownEvent (Key.Tab.WithCtrl.WithShift) ); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); @@ -709,38 +709,38 @@ public class ToplevelTests Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Application.AlternateBackwardKey)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorDown)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tvW1, win1.MostFocused); #if UNIX_KEY_BINDINGS - Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.B | Key.CtrlMask))); + Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.B.WithCtrl))); #else - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorLeft))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorLeft)); #endif Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf1W1, win1.MostFocused); - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorDown))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorDown)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tvW1, win1.MostFocused); Assert.Equal (new Point (0, 0), tvW1.CursorPosition); Assert.True ( Application.OverlappedChildren [0] - .NewKeyDownEvent (new Key (KeyCode.End | KeyCode.CtrlMask)) + .NewKeyDownEvent (Key.End.WithCtrl) ); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tvW1, win1.MostFocused); Assert.Equal (new Point (16, 1), tvW1.CursorPosition); #if UNIX_KEY_BINDINGS - Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.F | Key.CtrlMask))); + Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.F.WithCtrl))); #else - Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (new Key (KeyCode.CursorRight))); + Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorRight)); #endif Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tf2W1, win1.MostFocused); #if UNIX_KEY_BINDINGS - Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.L | Key.CtrlMask))); + Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.L.WithCtrl))); #endif } @@ -835,9 +835,9 @@ public class ToplevelTests Assert.Equal (KeyCode.C, Application.QuitKey); // Replacing the defaults keys to avoid errors on others unit tests that are using it. - Application.AlternateForwardKey = KeyCode.PageDown | KeyCode.CtrlMask; - Application.AlternateBackwardKey = KeyCode.PageUp | KeyCode.CtrlMask; - Application.QuitKey = KeyCode.Q | KeyCode.CtrlMask; + Application.AlternateForwardKey = Key.PageDown.WithCtrl; + Application.AlternateBackwardKey = Key.PageUp.WithCtrl; + Application.QuitKey = Key.Q.WithCtrl; Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey); Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey); @@ -1806,7 +1806,7 @@ public class ToplevelTests var testWindow = new Window { X = 2, Y = 1, Width = 15, Height = 10 }; testWindow.Add (btnPopup); - btnPopup.Clicked += (s, e) => + btnPopup.Accept += (s, e) => { Rect viewToScreen = btnPopup.BoundsToScreen (top.Frame); @@ -1932,7 +1932,7 @@ public class ToplevelTests Application.Top.Add (topChild); Application.Begin (Application.Top); - Exception exception = Record.Exception (() => topChild.NewKeyDownEvent (new Key (KeyCode.AltMask))); + Exception exception = Record.Exception (() => topChild.NewKeyDownEvent (KeyCode.AltMask)); Assert.Null (exception); } diff --git a/UnitTests/Views/TreeTableSourceTests.cs b/UnitTests/Views/TreeTableSourceTests.cs index 95ac287c6..6027e779f 100644 --- a/UnitTests/Views/TreeTableSourceTests.cs +++ b/UnitTests/Views/TreeTableSourceTests.cs @@ -51,7 +51,7 @@ public class TreeTableSourceTests : IDisposable Assert.Equal (0, tv.SelectedColumn); // when pressing right we should expand the top route - tv.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + tv.NewKeyDownEvent (Key.CursorRight); tv.Draw (); @@ -68,7 +68,7 @@ public class TreeTableSourceTests : IDisposable TestHelpers.AssertDriverContentsAre (expected, _output); // when pressing left we should collapse the top route again - tv.NewKeyDownEvent (new Key (KeyCode.CursorLeft)); + tv.NewKeyDownEvent (Key.CursorLeft); tv.Draw (); @@ -175,13 +175,13 @@ public class TreeTableSourceTests : IDisposable Assert.Equal (0, tv.SelectedColumn); // when pressing right we move to tree column - tv.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + tv.NewKeyDownEvent (Key.CursorRight); // now we are in tree column Assert.Equal (0, tv.SelectedRow); Assert.Equal (1, tv.SelectedColumn); - Application.Top.NewKeyDownEvent (new Key (KeyCode.CursorRight)); + Application.Top.NewKeyDownEvent (Key.CursorRight); tv.Draw (); @@ -198,8 +198,8 @@ public class TreeTableSourceTests : IDisposable TestHelpers.AssertDriverContentsAre (expected, _output); - tv.NewKeyDownEvent (new Key (KeyCode.CursorDown)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.CursorDown); + tv.NewKeyDownEvent (Key.Space); tv.Draw (); expected = diff --git a/UnitTests/Views/TreeViewTests.cs b/UnitTests/Views/TreeViewTests.cs index 3fc4897f3..9e1694b92 100644 --- a/UnitTests/Views/TreeViewTests.cs +++ b/UnitTests/Views/TreeViewTests.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.ComponentModel; +using System.Text; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; @@ -371,15 +372,15 @@ public class TreeViewTests Assert.False (called); // no object is selected yet so no event should happen - tree.NewKeyDownEvent (new Key (KeyCode.Enter)); + tree.NewKeyDownEvent (Key.Enter); Assert.Null (activated); Assert.False (called); // down to select factory - tree.NewKeyDownEvent (new Key (KeyCode.CursorDown)); + tree.NewKeyDownEvent (Key.CursorDown); - tree.NewKeyDownEvent (new Key (KeyCode.Enter)); + tree.NewKeyDownEvent (Key.Enter); Assert.True (called); Assert.Same (f, activated); @@ -408,22 +409,22 @@ public class TreeViewTests Assert.False (called); // no object is selected yet so no event should happen - tree.NewKeyDownEvent (new Key (KeyCode.Enter)); + tree.NewKeyDownEvent (Key.Enter); Assert.Null (activated); Assert.False (called); // down to select factory - tree.NewKeyDownEvent (new Key (KeyCode.CursorDown)); + tree.NewKeyDownEvent (Key.CursorDown); - tree.NewKeyDownEvent (new Key (KeyCode.Enter)); + tree.NewKeyDownEvent (Key.Enter); // Enter is not the activation key in this unit test Assert.Null (activated); Assert.False (called); // Delete is the activation key in this test so should result in activation occurring - tree.NewKeyDownEvent (new Key (KeyCode.Delete)); + tree.NewKeyDownEvent (Key.Delete); Assert.True (called); Assert.Same (f, activated); @@ -1347,4 +1348,95 @@ oot two } #endregion + + + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new TreeView (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } + + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var treeView = new TreeView (); + var accepted = false; + + treeView.Accept += OnAccept; + treeView.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + void OnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + + [Fact] + public void Accept_Command_Accepts_and_ActivatesObject () + { + var treeView = CreateTree (out Factory f, out Car car1, out _); + Assert.NotNull (car1); + treeView.SelectedObject = car1; + + var accepted = false; + var activated = false; + object selectedObject = null; + + treeView.Accept += Accept; + treeView.ObjectActivated += ObjectActivated; + + treeView.InvokeCommand (Command.Accept); + + Assert.True (accepted); + Assert.True (activated); + Assert.Equal (car1, selectedObject); + + return; + + void ObjectActivated (object sender, ObjectActivatedEventArgs e) + { + activated = true; + selectedObject = e.ActivatedObject; + } + void Accept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void Accept_Cancel_Event_Prevents_ObjectActivated () + { + var treeView = CreateTree (out Factory f, out Car car1, out _); + treeView.SelectedObject = car1; + var accepted = false; + var activated = false; + object selectedObject = null; + + treeView.Accept += Accept; + treeView.ObjectActivated += ObjectActivated; + + treeView.InvokeCommand (Command.Accept); + + Assert.True (accepted); + Assert.False (activated); + Assert.Equal (null, selectedObject); + + return; + + void ObjectActivated (object sender, ObjectActivatedEventArgs e) + { + activated = true; + selectedObject = e.ActivatedObject; + } + + void Accept (object sender, CancelEventArgs e) + { + accepted = true; + e.Cancel = true; + } + } } diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs index 08b327724..a8979a658 100644 --- a/UnitTests/Views/WindowTests.cs +++ b/UnitTests/Views/WindowTests.cs @@ -23,7 +23,7 @@ public class WindowTests Application.Top.Add (win); Application.Begin (Application.Top); - Exception exception = Record.Exception (() => win.NewKeyDownEvent (new Key (KeyCode.AltMask))); + Exception exception = Record.Exception (() => win.NewKeyDownEvent (KeyCode.AltMask)); Assert.Null (exception); } @@ -46,9 +46,9 @@ public class WindowTests var sb = new StatusBar ( new StatusItem [] { - new (KeyCode.CtrlMask | KeyCode.Q, "~^Q~ Quit", null), - new (KeyCode.CtrlMask | KeyCode.O, "~^O~ Open", null), - new (KeyCode.CtrlMask | KeyCode.C, "~^C~ Copy", null) + new ((KeyCode)Key.Q.WithCtrl, "~^Q~ Quit", null), + new ((KeyCode)Key.O.WithCtrl, "~^O~ Open", null), + new ((KeyCode)Key.C.WithCtrl, "~^C~ Copy", null) } );