Bläddra i källkod

keyEvent -> key

Tig 9 månader sedan
förälder
incheckning
f503a5c06f

+ 19 - 19
Terminal.Gui/Application/Application.Keyboard.cs

@@ -5,17 +5,17 @@ public static partial class Application // Keyboard handling
 {
     /// <summary>
     ///     Called when the user presses a key (by the <see cref="ConsoleDriver"/>). Raises the cancelable
-    ///     <see cref="KeyDown"/> event
-    ///     then calls <see cref="View.NewKeyDownEvent"/> on all top level views. Called before <see cref="RaiseKeyUpEvent"/>.
+    ///     <see cref="KeyDown"/> event, then calls <see cref="View.NewKeyDownEvent"/> on all top level views, and finally
+    ///     if the key was not handled, invokes any Application-scoped <see cref="KeyBindings"/>.
     /// </summary>
     /// <remarks>Can be used to simulate key press events.</remarks>
-    /// <param name="keyEvent"></param>
+    /// <param name="key"></param>
     /// <returns><see langword="true"/> if the key was handled.</returns>
-    public static bool RaiseKeyDownEvent (Key keyEvent)
+    public static bool RaiseKeyDownEvent (Key key)
     {
-        KeyDown?.Invoke (null, keyEvent);
+        KeyDown?.Invoke (null, key);
 
-        if (keyEvent.Handled)
+        if (key.Handled)
         {
             return true;
         }
@@ -24,7 +24,7 @@ public static partial class Application // Keyboard handling
         {
             foreach (Toplevel topLevel in TopLevels.ToList ())
             {
-                if (topLevel.NewKeyDownEvent (keyEvent))
+                if (topLevel.NewKeyDownEvent (key))
                 {
                     return true;
                 }
@@ -37,7 +37,7 @@ public static partial class Application // Keyboard handling
         }
         else
         {
-            if (Top.NewKeyDownEvent (keyEvent))
+            if (Top.NewKeyDownEvent (key))
             {
                 return true;
             }
@@ -45,7 +45,7 @@ public static partial class Application // Keyboard handling
 
         // Invoke any Application-scoped KeyBindings.
         // The first view that handles the key will stop the loop.
-        foreach (KeyValuePair<Key, KeyBinding> binding in KeyBindings.Bindings.Where (b => b.Key == keyEvent.KeyCode))
+        foreach (KeyValuePair<Key, KeyBinding> binding in KeyBindings.Bindings.Where (b => b.Key == key.KeyCode))
         {
             if (binding.Value.BoundView is { })
             {
@@ -58,7 +58,7 @@ public static partial class Application // Keyboard handling
             }
             else
             {
-                if (!KeyBindings.TryGet (keyEvent, KeyBindingScope.Application, out KeyBinding appBinding))
+                if (!KeyBindings.TryGet (key, KeyBindingScope.Application, out KeyBinding appBinding))
                 {
                     continue;
                 }
@@ -67,7 +67,7 @@ public static partial class Application // Keyboard handling
 
                 foreach (Command command in appBinding.Commands)
                 {
-                    toReturn = InvokeCommand (command, keyEvent, appBinding);
+                    toReturn = InvokeCommand (command, key, appBinding);
                 }
 
                 return toReturn ?? true;
@@ -76,18 +76,18 @@ public static partial class Application // Keyboard handling
 
         return false;
 
-        static bool? InvokeCommand (Command command, Key keyEvent, KeyBinding appBinding)
+        static bool? InvokeCommand (Command command, Key key, KeyBinding appBinding)
         {
             if (!CommandImplementations!.ContainsKey (command))
             {
                 throw new NotSupportedException (
-                                                 @$"A KeyBinding was set up for the command {command} ({keyEvent}) but that command is not supported by Application."
+                                                 @$"A KeyBinding was set up for the command {command} ({key}) but that command is not supported by Application."
                                                 );
             }
 
             if (CommandImplementations.TryGetValue (command, out View.CommandImplementation? implementation))
             {
-                var context = new CommandContext (command, keyEvent, appBinding); // Create the context here
+                var context = new CommandContext (command, key, appBinding); // Create the context here
 
                 return implementation (context);
             }
@@ -116,25 +116,25 @@ public static partial class Application // Keyboard handling
     ///     then calls <see cref="View.NewKeyUpEvent"/> on all top level views. Called after <see cref="RaiseKeyDownEvent"/>.
     /// </summary>
     /// <remarks>Can be used to simulate key release events.</remarks>
-    /// <param name="a"></param>
+    /// <param name="key"></param>
     /// <returns><see langword="true"/> if the key was handled.</returns>
-    public static bool RaiseKeyUpEvent (Key a)
+    public static bool RaiseKeyUpEvent (Key key)
     {
         if (!IsInitialized)
         {
             return true;
         }
 
-        KeyUp?.Invoke (null, a);
+        KeyUp?.Invoke (null, key);
 
-        if (a.Handled)
+        if (key.Handled)
         {
             return true;
         }
 
         foreach (Toplevel topLevel in TopLevels.ToList ())
         {
-            if (topLevel.NewKeyUpEvent (a))
+            if (topLevel.NewKeyUpEvent (key))
             {
                 return true;
             }

+ 1 - 1
Terminal.Gui/View/View.Keyboard.cs

@@ -426,7 +426,7 @@ public partial class View // Keyboard APIs
     ///     <para>
     ///         If the focused sub view does not handle the key press, this method raises <see cref="OnKeyUp"/>/
     ///         <see cref="KeyUp"/> to allow the
-    ///         view to pre-process the key press. If <see cref="OnKeyUp"/>/<see cref="KeyUp"/>.
+    ///         view to pre-process the key press.
     ///     </para>
     ///     <para>See <see href="../docs/keyboard.md">for an overview of Terminal.Gui keyboard APIs.</see></para>
     /// </remarks>

+ 3 - 3
Terminal.Gui/Views/FileDialog.cs

@@ -670,11 +670,11 @@ public class FileDialog : Dialog
         FinishAccept ();
     }
 
-    private void AcceptIf (Key keyEvent, KeyCode isKey)
+    private void AcceptIf (Key key, KeyCode isKey)
     {
-        if (!keyEvent.Handled && keyEvent.KeyCode == isKey)
+        if (!key.Handled && key.KeyCode == isKey)
         {
-            keyEvent.Handled = true;
+            key.Handled = true;
 
             // User hit Enter in text box so probably wants the
             // contents of the text box as their selection not

+ 2 - 2
Terminal.Gui/Views/TableView/TableView.cs

@@ -1563,7 +1563,7 @@ public class TableView : View
     /// <returns></returns>
     private TableSelection CreateTableSelection (int x, int y) { return CreateTableSelection (x, y, x, y); }
 
-    private bool CycleToNextTableEntryBeginningWith (Key keyEvent)
+    private bool CycleToNextTableEntryBeginningWith (Key key)
     {
         int row = SelectedRow;
 
@@ -1573,7 +1573,7 @@ public class TableView : View
             return false;
         }
 
-        int match = CollectionNavigator.GetNextMatchingItem (row, (char)keyEvent);
+        int match = CollectionNavigator.GetNextMatchingItem (row, (char)key);
 
         if (match != -1)
         {

+ 2 - 2
Terminal.Gui/Views/TileView.cs

@@ -286,11 +286,11 @@ public class TileView : View
 
     //// BUGBUG: Why is this not handled by a key binding???
     /// <inheritdoc/>
-    protected override bool OnKeyDownNotHandled (Key keyEvent)
+    protected override bool OnKeyDownNotHandled (Key key)
     {
         var focusMoved = false;
 
-        if (keyEvent.KeyCode == ToggleResizable)
+        if (key.KeyCode == ToggleResizable)
         {
             foreach (TileViewLineView l in _splitterLines)
             {

+ 3 - 3
Terminal.Gui/Views/TreeView/TreeView.cs

@@ -1182,7 +1182,7 @@ public class TreeView<T> : View, ITreeView where T : class
     }
 
     /// <inheritdoc/>
-    protected override bool OnKeyDown (Key keyEvent)
+    protected override bool OnKeyDown (Key key)
     {
         if (!Enabled)
         {
@@ -1190,7 +1190,7 @@ public class TreeView<T> : View, ITreeView where T : class
         }
 
         // If not a keybinding, is the key a searchable key press?
-        if (CollectionNavigatorBase.IsCompatibleKey (keyEvent) && AllowLetterBasedNavigation)
+        if (CollectionNavigatorBase.IsCompatibleKey (key) && AllowLetterBasedNavigation)
         {
             // If there has been a call to InvalidateMap since the last time
             // we need a new one to reflect the new exposed tree state
@@ -1198,7 +1198,7 @@ public class TreeView<T> : View, ITreeView where T : class
 
             // Find the current selected object within the tree
             int current = map.IndexOf (b => b.Model == SelectedObject);
-            int? newIndex = KeystrokeNavigator?.GetNextMatchingItem (current, (char)keyEvent);
+            int? newIndex = KeystrokeNavigator?.GetNextMatchingItem (current, (char)key);
 
             if (newIndex is int && newIndex != -1)
             {

+ 8 - 9
UICatalog/Scenarios/Keys.cs

@@ -76,18 +76,18 @@ public class Keys : Scenario
         win.Add (label);
         int maxKeyString = Key.CursorRight.WithAlt.WithCtrl.WithShift.ToString ().Length;
 
-        ObservableCollection<string> keyEventList = new ();
+        ObservableCollection<string> keyList = new ();
 
-        var appKeyEventListView = new ListView
+        var appKeyListView = new ListView
         {
             X = 0,
             Y = Pos.Bottom (label),
             Width = "KeyDown:".Length + maxKeyString,
             Height = Dim.Fill (),
-            Source = new ListWrapper<string> (keyEventList)
+            Source = new ListWrapper<string> (keyList)
         };
-        appKeyEventListView.ColorScheme = Colors.ColorSchemes ["TopLevel"];
-        win.Add (appKeyEventListView);
+        appKeyListView.ColorScheme = Colors.ColorSchemes ["TopLevel"];
+        win.Add (appKeyListView);
 
         // View key events...
         edit.KeyDown += (s, a) => { keyDownList.Add (a.ToString ()); };
@@ -100,7 +100,7 @@ public class Keys : Scenario
         // KeyDown
         label = new Label
         {
-            X = Pos.Right (appKeyEventListView) + 1,
+            X = Pos.Right (appKeyListView) + 1,
             Y = Pos.Top (label),
             Text = "TextView Key Down:"
         };
@@ -142,10 +142,9 @@ public class Keys : Scenario
 
         void KeyDownPressUp (Key args, string updown)
         {
-            // BUGBUG: KeyEvent.ToString is badly broken
             var msg = $"Key{updown,-7}: {args}";
-            keyEventList.Add (msg);
-            appKeyEventListView.MoveDown ();
+            keyList.Add (msg);
+            appKeyListView.MoveDown ();
             onKeyDownNotHandledListView.MoveDown ();
         }
 

+ 5 - 5
UICatalog/Scenarios/Snake.cs

@@ -357,30 +357,30 @@ public class Snake : Scenario
         }
 
         // BUGBUG: Should (can) this use key bindings instead.
-        protected override bool OnKeyDown (Key keyEvent)
+        protected override bool OnKeyDown (Key key)
         {
-            if (keyEvent.KeyCode == KeyCode.CursorUp)
+            if (key.KeyCode == KeyCode.CursorUp)
             {
                 State.PlannedDirection = Direction.Up;
 
                 return true;
             }
 
-            if (keyEvent.KeyCode == KeyCode.CursorDown)
+            if (key.KeyCode == KeyCode.CursorDown)
             {
                 State.PlannedDirection = Direction.Down;
 
                 return true;
             }
 
-            if (keyEvent.KeyCode == KeyCode.CursorLeft)
+            if (key.KeyCode == KeyCode.CursorLeft)
             {
                 State.PlannedDirection = Direction.Left;
 
                 return true;
             }
 
-            if (keyEvent.KeyCode == KeyCode.CursorRight)
+            if (key.KeyCode == KeyCode.CursorRight)
             {
                 State.PlannedDirection = Direction.Right;