Browse Source

Fixed unit tests

Tig 7 months ago
parent
commit
3edcf643dc

+ 24 - 13
Terminal.Gui/Input/Keyboard/KeyBindings.cs

@@ -15,9 +15,20 @@ public class KeyBindings
     /// <summary>Adds a <see cref="KeyBinding"/> to the collection.</summary>
     /// <summary>Adds a <see cref="KeyBinding"/> to the collection.</summary>
     /// <param name="key"></param>
     /// <param name="key"></param>
     /// <param name="binding"></param>
     /// <param name="binding"></param>
+    /// <exception cref="ArgumentException">If <paramref name="binding"/> has no Commands or <paramref name="key"/> is invalid.</exception>
     public void Add (Key key, KeyBinding binding)
     public void Add (Key key, KeyBinding binding)
     {
     {
 
 
+        if (!key.IsValid)
+        {
+            throw new ArgumentException (nameof (key));
+        }
+
+        if (binding.Commands.Length == 0)
+        {
+            throw new ArgumentException (nameof (binding));
+        }
+
         if (TryGet (key, out KeyBinding _))
         if (TryGet (key, out KeyBinding _))
         {
         {
             throw new InvalidOperationException (@$"A key binding for {key} exists ({binding}).");
             throw new InvalidOperationException (@$"A key binding for {key} exists ({binding}).");
@@ -37,7 +48,6 @@ public class KeyBindings
         Bindings.Add (new (key), binding);
         Bindings.Add (new (key), binding);
     }
     }
 
 
-
     /// <summary>
     /// <summary>
     ///     <para>
     ///     <para>
     ///         Adds a new key combination that will trigger the commands in <paramref name="commands"/> (if supported by the
     ///         Adds a new key combination that will trigger the commands in <paramref name="commands"/> (if supported by the
@@ -63,9 +73,10 @@ public class KeyBindings
     ///     multiple commands are provided,they will be applied in sequence. The bound <paramref name="key"/> strike will be
     ///     multiple commands are provided,they will be applied in sequence. The bound <paramref name="key"/> strike will be
     ///     consumed if any took effect.
     ///     consumed if any took effect.
     /// </param>
     /// </param>
+    /// <exception cref="ArgumentException">If <paramref name="commands"/> is empty.</exception>
     public void Add (Key key, params Command [] commands)
     public void Add (Key key, params Command [] commands)
     {
     {
-        Add (key, new KeyBinding(commands));
+        Add (key, new KeyBinding (commands));
     }
     }
 
 
     // TODO: Add a dictionary comparer that ignores Scope
     // TODO: Add a dictionary comparer that ignores Scope
@@ -77,10 +88,7 @@ public class KeyBindings
     ///     Gets the keys that are bound.
     ///     Gets the keys that are bound.
     /// </summary>
     /// </summary>
     /// <returns></returns>
     /// <returns></returns>
-    public IEnumerable<Key> GetBoundKeys ()
-    {
-        return Bindings.Keys;
-    }
+    public IEnumerable<Key> GetBoundKeys () { return Bindings.Keys; }
 
 
     /// <summary>
     /// <summary>
     ///     The view that the <see cref="KeyBindings"/> are bound to.
     ///     The view that the <see cref="KeyBindings"/> are bound to.
@@ -136,20 +144,23 @@ public class KeyBindings
             return bindings.Commands;
             return bindings.Commands;
         }
         }
 
 
-        return Array.Empty<Command> ();
+        return [];
     }
     }
 
 
     /// <summary>Gets the first Key bound to the set of commands specified by <paramref name="commands"/>.</summary>
     /// <summary>Gets the first Key bound to the set of commands specified by <paramref name="commands"/>.</summary>
     /// <param name="commands">The set of commands to search.</param>
     /// <param name="commands">The set of commands to search.</param>
-    /// <returns>The first <see cref="Key"/> bound to the set of commands specified by <paramref name="commands"/>. <see langword="null"/> if the set of caommands was not found.</returns>
-    public Key? GetKeyFromCommands (params Command [] commands)
-    {
-        return Bindings.FirstOrDefault (a => a.Value.Commands.SequenceEqual (commands)).Key;
-    }
+    /// <returns>
+    ///     The first <see cref="Key"/> bound to the set of commands specified by <paramref name="commands"/>.
+    ///     <see langword="null"/> if the set of caommands was not found.
+    /// </returns>
+    public Key? GetKeyFromCommands (params Command [] commands) { return Bindings.FirstOrDefault (a => a.Value.Commands.SequenceEqual (commands)).Key; }
 
 
     /// <summary>Gets Keys bound to the set of commands specified by <paramref name="commands"/>.</summary>
     /// <summary>Gets Keys bound to the set of commands specified by <paramref name="commands"/>.</summary>
     /// <param name="commands">The set of commands to search.</param>
     /// <param name="commands">The set of commands to search.</param>
-    /// <returns>The <see cref="Key"/>s bound to the set of commands specified by <paramref name="commands"/>. An empty list if the set of caommands was not found.</returns>
+    /// <returns>
+    ///     The <see cref="Key"/>s bound to the set of commands specified by <paramref name="commands"/>. An empty list if the
+    ///     set of caommands was not found.
+    /// </returns>
     public IEnumerable<Key> GetKeysFromCommands (params Command [] commands)
     public IEnumerable<Key> GetKeysFromCommands (params Command [] commands)
     {
     {
         return Bindings.Where (a => a.Value.Commands.SequenceEqual (commands)).Select (a => a.Key);
         return Bindings.Where (a => a.Value.Commands.SequenceEqual (commands)).Select (a => a.Key);

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

@@ -187,7 +187,8 @@ public partial class View // Keyboard APIs
             KeyBinding keyBinding = new ()
             KeyBinding keyBinding = new ()
             {
             {
                 Commands = [Command.HotKey],
                 Commands = [Command.HotKey],
-                Data = context
+                Key = newKey,
+                Data = context,
             };
             };
 
 
             // Add the base and Alt key
             // Add the base and Alt key

+ 1 - 1
Terminal.Gui/Views/Menu/ContextMenu.cs

@@ -150,7 +150,7 @@ public sealed class ContextMenu : IDisposable
                 if (menuItem.ShortcutKey != Key.Empty)
                 if (menuItem.ShortcutKey != Key.Empty)
                 {
                 {
                     // Remove an existent ShortcutKey
                     // Remove an existent ShortcutKey
-                    _menuBar?.KeyBindings.Remove (menuItem.ShortcutKey!);
+                    _menuBar?.HotKeyBindings.Remove (menuItem.ShortcutKey!);
                 }
                 }
             }
             }
         }
         }

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

@@ -133,8 +133,8 @@ internal sealed class Menu : View
                         KeyBinding keyBinding = new ([Command.Select], this, data: menuItem);
                         KeyBinding keyBinding = new ([Command.Select], this, data: menuItem);
 
 
                         // Remove an existent ShortcutKey
                         // Remove an existent ShortcutKey
-                        menuItem._menuBar.KeyBindings.Remove (menuItem.ShortcutKey!);
-                        menuItem._menuBar.KeyBindings.Add (menuItem.ShortcutKey!, keyBinding);
+                        menuItem._menuBar.HotKeyBindings.Remove (menuItem.ShortcutKey!);
+                        menuItem._menuBar.HotKeyBindings.Add (menuItem.ShortcutKey!, keyBinding);
                     }
                     }
                 }
                 }
             }
             }

+ 2 - 2
Terminal.Gui/Views/Menu/MenuBar.cs

@@ -166,9 +166,9 @@ public class MenuBar : View, IDesignable
         HotKeyBindings.Add (Key, keyBinding);
         HotKeyBindings.Add (Key, keyBinding);
 
 
         // TODO: Why do we have two keybindings for opening the menu? Ctrl-Space and Key?
         // TODO: Why do we have two keybindings for opening the menu? Ctrl-Space and Key?
-        KeyBindings.Add (Key.Space.WithCtrl, keyBinding);
+        HotKeyBindings.Add (Key.Space.WithCtrl, keyBinding);
         // This is needed for macOS because Key.Space.WithCtrl doesn't work
         // This is needed for macOS because Key.Space.WithCtrl doesn't work
-        KeyBindings.Add (Key.Space.WithAlt, keyBinding);
+        HotKeyBindings.Add (Key.Space.WithAlt, keyBinding);
 
 
         // TODO: Figure out how to make Alt work (on Windows)
         // TODO: Figure out how to make Alt work (on Windows)
         //KeyBindings.Add (Key.WithAlt, keyBinding);
         //KeyBindings.Add (Key.WithAlt, keyBinding);

+ 2 - 2
Terminal.Gui/Views/Menu/MenuBarItem.cs

@@ -222,7 +222,7 @@ public class MenuBarItem : MenuItem
                 if (menuItem?.ShortcutKey != Key.Empty)
                 if (menuItem?.ShortcutKey != Key.Empty)
                 {
                 {
                     // Remove an existent ShortcutKey
                     // Remove an existent ShortcutKey
-                    _menuBar?.KeyBindings.Remove (menuItem?.ShortcutKey!);
+                    _menuBar?.HotKeyBindings.Remove (menuItem?.ShortcutKey!);
                 }
                 }
             }
             }
         }
         }
@@ -230,7 +230,7 @@ public class MenuBarItem : MenuItem
         if (ShortcutKey != Key.Empty)
         if (ShortcutKey != Key.Empty)
         {
         {
             // Remove an existent ShortcutKey
             // Remove an existent ShortcutKey
-            _menuBar?.KeyBindings.Remove (ShortcutKey!);
+            _menuBar?.HotKeyBindings.Remove (ShortcutKey!);
         }
         }
 
 
         var index = _menuBar!.Menus.IndexOf (this);
         var index = _menuBar!.Menus.IndexOf (this);

+ 4 - 4
Terminal.Gui/Views/Menu/MenuItem.cs

@@ -289,15 +289,15 @@ public class MenuItem
     {
     {
         if (key != Key.Empty)
         if (key != Key.Empty)
         {
         {
-            _menuBar.KeyBindings.Remove (key);
+            _menuBar.HotKeyBindings.Remove (key);
         }
         }
 
 
         if (ShortcutKey != Key.Empty)
         if (ShortcutKey != Key.Empty)
         {
         {
             KeyBinding keyBinding = new ([Command.Select], null, data: this);
             KeyBinding keyBinding = new ([Command.Select], null, data: this);
             // Remove an existent ShortcutKey
             // Remove an existent ShortcutKey
-            _menuBar.KeyBindings.Remove (ShortcutKey!);
-            _menuBar.KeyBindings.Add (ShortcutKey!, keyBinding);
+            _menuBar.HotKeyBindings.Remove (ShortcutKey!);
+            _menuBar.HotKeyBindings.Add (ShortcutKey!, keyBinding);
         }
         }
     }
     }
 
 
@@ -378,7 +378,7 @@ public class MenuItem
         if (ShortcutKey != Key.Empty)
         if (ShortcutKey != Key.Empty)
         {
         {
             // Remove an existent ShortcutKey
             // Remove an existent ShortcutKey
-            _menuBar.KeyBindings.Remove (ShortcutKey!);
+            _menuBar.HotKeyBindings.Remove (ShortcutKey!);
         }
         }
     }
     }
 }
 }

+ 5 - 34
UnitTests/Input/Keyboard/KeyBindingsTests.cs

@@ -257,10 +257,8 @@ public class KeyBindingsTests ()
         Assert.Throws<InvalidOperationException> (() => keyBindings.ReplaceKey (Key.A, Key.Empty));
         Assert.Throws<InvalidOperationException> (() => keyBindings.ReplaceKey (Key.A, Key.Empty));
     }
     }
 
 
-    // Add with scope does the right things
-    [Theory]
-    [InlineData (KeyBindingScope.Focused)]
-    public void Scope_Add_Adds (KeyBindingScope scope)
+    [Fact]
+    public void Add_Adds ()
     {
     {
         var keyBindings = new KeyBindings (new ());
         var keyBindings = new KeyBindings (new ());
         Command [] commands = { Command.Right, Command.Left };
         Command [] commands = { Command.Right, Command.Left };
@@ -280,12 +278,11 @@ public class KeyBindingsTests ()
         Assert.Contains (Command.Left, resultCommands);
         Assert.Contains (Command.Left, resultCommands);
     }
     }
 
 
-    [Theory]
-    [InlineData (KeyBindingScope.Focused)]
-    public void Scope_Get_Filters (KeyBindingScope scope)
+    [Fact]
+    public void Get_Gets ()
     {
     {
         var keyBindings = new KeyBindings (new ());
         var keyBindings = new KeyBindings (new ());
-        Command [] commands = { Command.Right, Command.Left };
+        Command [] commands = [Command.Right, Command.Left];
 
 
         var key = new Key (Key.A);
         var key = new Key (Key.A);
         keyBindings.Add (key, commands);
         keyBindings.Add (key, commands);
@@ -298,32 +295,6 @@ public class KeyBindingsTests ()
         Assert.Contains (Command.Left, binding.Commands);
         Assert.Contains (Command.Left, binding.Commands);
     }
     }
 
 
-    [Theory]
-    [InlineData (KeyBindingScope.Focused)]
-    public void Scope_TryGet_Filters (KeyBindingScope scope)
-    {
-        var keyBindings = new KeyBindings (new ());
-        Command [] commands = { Command.Right, Command.Left };
-
-        var key = new Key (Key.A);
-        keyBindings.Add (key, 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, out binding);
-        Assert.Contains (Command.Right, binding.Commands);
-        Assert.Contains (Command.Left, binding.Commands);
-
-        // negative test
-        success = keyBindings.TryGet (key, out binding);
-        Assert.False (success);
-
-        Command [] resultCommands = keyBindings.GetCommands (key);
-        Assert.Contains (Command.Right, resultCommands);
-        Assert.Contains (Command.Left, resultCommands);
-    }
-
     // TryGet
     // TryGet
     [Fact]
     [Fact]
     public void TryGet_Succeeds ()
     public void TryGet_Succeeds ()

+ 54 - 25
UnitTests/View/Keyboard/HotKeyTests.cs

@@ -1,4 +1,5 @@
 using System.Text;
 using System.Text;
+using UICatalog.Scenarios;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
 namespace Terminal.Gui.ViewTests;
 namespace Terminal.Gui.ViewTests;
@@ -27,9 +28,9 @@ public class HotKeyTests
         // Verify key bindings were set
         // Verify key bindings were set
 
 
         // As passed
         // As passed
-        Command [] commands = view.KeyBindings.GetCommands (key);
+        Command [] commands = view.HotKeyBindings.GetCommands (key);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
-        commands = view.KeyBindings.GetCommands (key | KeyCode.AltMask);
+        commands = view.HotKeyBindings.GetCommands (key | KeyCode.AltMask);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
 
 
         KeyCode baseKey = key & ~KeyCode.ShiftMask;
         KeyCode baseKey = key & ~KeyCode.ShiftMask;
@@ -37,13 +38,13 @@ public class HotKeyTests
         // If A...Z, with and without shift
         // If A...Z, with and without shift
         if (baseKey is >= KeyCode.A and <= KeyCode.Z)
         if (baseKey is >= KeyCode.A and <= KeyCode.Z)
         {
         {
-            commands = view.KeyBindings.GetCommands (key | KeyCode.ShiftMask);
+            commands = view.HotKeyBindings.GetCommands (key | KeyCode.ShiftMask);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
-            commands = view.KeyBindings.GetCommands (key & ~KeyCode.ShiftMask);
+            commands = view.HotKeyBindings.GetCommands (key & ~KeyCode.ShiftMask);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
-            commands = view.KeyBindings.GetCommands (key | KeyCode.AltMask);
+            commands = view.HotKeyBindings.GetCommands (key | KeyCode.AltMask);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
-            commands = view.KeyBindings.GetCommands ((key & ~KeyCode.ShiftMask) | KeyCode.AltMask);
+            commands = view.HotKeyBindings.GetCommands ((key & ~KeyCode.ShiftMask) | KeyCode.AltMask);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
         }
         }
         else
         else
@@ -51,17 +52,40 @@ public class HotKeyTests
             // Non A..Z keys should not have shift bindings
             // Non A..Z keys should not have shift bindings
             if (key.HasFlag (KeyCode.ShiftMask))
             if (key.HasFlag (KeyCode.ShiftMask))
             {
             {
-                commands = view.KeyBindings.GetCommands (key & ~KeyCode.ShiftMask);
+                commands = view.HotKeyBindings.GetCommands (key & ~KeyCode.ShiftMask);
                 Assert.Empty (commands);
                 Assert.Empty (commands);
             }
             }
             else
             else
             {
             {
-                commands = view.KeyBindings.GetCommands (key | KeyCode.ShiftMask);
+                commands = view.HotKeyBindings.GetCommands (key | KeyCode.ShiftMask);
                 Assert.Empty (commands);
                 Assert.Empty (commands);
             }
             }
         }
         }
     }
     }
 
 
+    [Fact]
+    public void AddKeyBindingsForHotKey_SetsBinding_Key ()
+    {
+        var view = new View ();
+        view.HotKey = KeyCode.Z;
+        Assert.Equal (string.Empty, view.Title);
+        Assert.Equal (KeyCode.Z, view.HotKey);
+
+        view.AddKeyBindingsForHotKey (view.HotKey, Key.A);
+        Assert.Equal (Key.A, view.HotKeyBindings.Bindings [Key.A].Key);
+    }
+
+    [Fact]
+    public void AddKeyBindingsForHotKey_SetsBinding_Data ()
+    {
+        var view = new View ();
+        view.HotKey = KeyCode.Z;
+        Assert.Equal (KeyCode.Z, view.HotKey);
+
+        view.AddKeyBindingsForHotKey (view.HotKey, Key.A, "data");
+        Assert.Equal ("data", view.HotKeyBindings.Bindings [Key.A].Data);
+    }
+
     [Fact]
     [Fact]
     public void Defaults ()
     public void Defaults ()
     {
     {
@@ -72,6 +96,11 @@ public class HotKeyTests
         // Verify key bindings were set
         // Verify key bindings were set
         Command [] commands = view.KeyBindings.GetCommands (KeyCode.Null);
         Command [] commands = view.KeyBindings.GetCommands (KeyCode.Null);
         Assert.Empty (commands);
         Assert.Empty (commands);
+
+        commands = view.HotKeyBindings.GetCommands (KeyCode.Null);
+        Assert.Empty (commands);
+
+        Assert.Empty (view.HotKeyBindings.GetBoundKeys ());
     }
     }
 
 
     [Theory]
     [Theory]
@@ -94,7 +123,7 @@ public class HotKeyTests
     public void NewKeyDownEvent_Ignores_Focus_KeyBindings_SuperView ()
     public void NewKeyDownEvent_Ignores_Focus_KeyBindings_SuperView ()
     {
     {
         var view = new View ();
         var view = new View ();
-        view.KeyBindings.Add (Key.A, Command.HotKey); // implies KeyBindingScope.Focused - so this should not be invoked
+        view.HotKeyBindings.Add (Key.A, Command.HotKey);
         view.KeyDownNotHandled += (s, e) => { Assert.Fail (); };
         view.KeyDownNotHandled += (s, e) => { Assert.Fail (); };
 
 
         var superView = new View ();
         var superView = new View ();
@@ -167,16 +196,16 @@ public class HotKeyTests
         Assert.Equal (KeyCode.A, view.HotKey);
         Assert.Equal (KeyCode.A, view.HotKey);
 
 
         // Verify key bindings were set
         // Verify key bindings were set
-        Command [] commands = view.KeyBindings.GetCommands (KeyCode.A);
+        Command [] commands = view.HotKeyBindings.GetCommands (KeyCode.A);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.AltMask);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A | KeyCode.AltMask);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask | KeyCode.AltMask);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask | KeyCode.AltMask);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
 
 
         // Now set again
         // Now set again
@@ -184,16 +213,16 @@ public class HotKeyTests
         Assert.Equal (string.Empty, view.Title);
         Assert.Equal (string.Empty, view.Title);
         Assert.Equal (KeyCode.B, view.HotKey);
         Assert.Equal (KeyCode.B, view.HotKey);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A);
         Assert.DoesNotContain (Command.HotKey, commands);
         Assert.DoesNotContain (Command.HotKey, commands);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask);
         Assert.DoesNotContain (Command.HotKey, commands);
         Assert.DoesNotContain (Command.HotKey, commands);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.AltMask);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A | KeyCode.AltMask);
         Assert.DoesNotContain (Command.HotKey, commands);
         Assert.DoesNotContain (Command.HotKey, commands);
 
 
-        commands = view.KeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask | KeyCode.AltMask);
+        commands = view.HotKeyBindings.GetCommands (KeyCode.A | KeyCode.ShiftMask | KeyCode.AltMask);
         Assert.DoesNotContain (Command.HotKey, commands);
         Assert.DoesNotContain (Command.HotKey, commands);
     }
     }
 
 
@@ -232,7 +261,7 @@ public class HotKeyTests
         // Verify key bindings were set
         // Verify key bindings were set
 
 
         // As passed
         // As passed
-        Command [] commands = view.KeyBindings.GetCommands (view.HotKey);
+        Command [] commands = view.HotKeyBindings.GetCommands (view.HotKey);
         Assert.Contains (Command.HotKey, commands);
         Assert.Contains (Command.HotKey, commands);
 
 
         Key baseKey = view.HotKey.NoShift;
         Key baseKey = view.HotKey.NoShift;
@@ -240,13 +269,13 @@ public class HotKeyTests
         // If A...Z, with and without shift
         // If A...Z, with and without shift
         if (baseKey.IsKeyCodeAtoZ)
         if (baseKey.IsKeyCodeAtoZ)
         {
         {
-            commands = view.KeyBindings.GetCommands (view.HotKey.WithShift);
+            commands = view.HotKeyBindings.GetCommands (view.HotKey.WithShift);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
-            commands = view.KeyBindings.GetCommands (view.HotKey.NoShift);
+            commands = view.HotKeyBindings.GetCommands (view.HotKey.NoShift);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
-            commands = view.KeyBindings.GetCommands (view.HotKey.WithAlt);
+            commands = view.HotKeyBindings.GetCommands (view.HotKey.WithAlt);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
-            commands = view.KeyBindings.GetCommands (view.HotKey.NoShift.WithAlt);
+            commands = view.HotKeyBindings.GetCommands (view.HotKey.NoShift.WithAlt);
             Assert.Contains (Command.HotKey, commands);
             Assert.Contains (Command.HotKey, commands);
         }
         }
         else
         else
@@ -254,12 +283,12 @@ public class HotKeyTests
             // Non A..Z keys should not have shift bindings
             // Non A..Z keys should not have shift bindings
             if (view.HotKey.IsShift)
             if (view.HotKey.IsShift)
             {
             {
-                commands = view.KeyBindings.GetCommands (view.HotKey.NoShift);
+                commands = view.HotKeyBindings.GetCommands (view.HotKey.NoShift);
                 Assert.Empty (commands);
                 Assert.Empty (commands);
             }
             }
             else
             else
             {
             {
-                commands = view.KeyBindings.GetCommands (view.HotKey.WithShift);
+                commands = view.HotKeyBindings.GetCommands (view.HotKey.WithShift);
                 Assert.Empty (commands);
                 Assert.Empty (commands);
             }
             }
         }
         }
@@ -366,7 +395,7 @@ public class HotKeyTests
         view.Selecting += (s, e) => selectRaised = true;
         view.Selecting += (s, e) => selectRaised = true;
 
 
         Assert.Equal (KeyCode.T, view.HotKey);
         Assert.Equal (KeyCode.T, view.HotKey);
-        Assert.True (Application.RaiseKeyDownEvent (Key.T)); 
+        Assert.True (Application.RaiseKeyDownEvent (Key.T));
         Assert.True (hotKeyRaised);
         Assert.True (hotKeyRaised);
         Assert.False (acceptRaised);
         Assert.False (acceptRaised);
         Assert.False (selectRaised);
         Assert.False (selectRaised);

+ 6 - 5
UnitTests/View/Keyboard/ViewKeyBindingTests.cs → UnitTests/View/Keyboard/KeyBindingsTests.cs

@@ -2,13 +2,14 @@
 
 
 namespace Terminal.Gui.ViewTests;
 namespace Terminal.Gui.ViewTests;
 
 
-public class ViewKeyBindingTests (ITestOutputHelper output)
+/// <summary>
+///     Tests for View.KeyBindings
+/// </summary>
+public class KeyBindingsTests ()
 {
 {
-    private readonly ITestOutputHelper _output = output;
-
     [Fact]
     [Fact]
     [AutoInitShutdown]
     [AutoInitShutdown]
-    public void Focus_KeyBinding ()
+    public void Focused_HotKey_Application_All_Work ()
     {
     {
         var view = new ScopedKeyBindingView ();
         var view = new ScopedKeyBindingView ();
         var keyWasHandled = false;
         var keyWasHandled = false;
@@ -48,7 +49,7 @@ public class ViewKeyBindingTests (ITestOutputHelper output)
 
 
     [Fact]
     [Fact]
     [AutoInitShutdown]
     [AutoInitShutdown]
-    public void Focus_KeyBinding_Negative ()
+    public void KeyBinding_Negative ()
     {
     {
         var view = new ScopedKeyBindingView ();
         var view = new ScopedKeyBindingView ();
         var keyWasHandled = false;
         var keyWasHandled = false;

+ 79 - 79
UnitTests/Views/ContextMenuTests.cs

@@ -1483,9 +1483,9 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.False (deleteFile);
         Assert.False (deleteFile);
 
 
         cm.Show (menuItems);
         cm.Show (menuItems);
-        Assert.True (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.True (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
-        Assert.True (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.D.WithCtrl));
+        Assert.True (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.True (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.True (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.D.WithCtrl));
 
 
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
         Application.MainLoop!.RunIteration ();
         Application.MainLoop!.RunIteration ();
@@ -1502,9 +1502,9 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.True (deleteFile);
         Assert.True (deleteFile);
         Assert.False (cm.MenuBar.IsMenuOpen);
         Assert.False (cm.MenuBar.IsMenuOpen);
 
 
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.D.WithCtrl));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.D.WithCtrl));
 
 
         newFile = false;
         newFile = false;
         renameFile = false;
         renameFile = false;
@@ -1555,8 +1555,8 @@ public class ContextMenuTests (ITestOutputHelper output)
         top.Add (menuBar);
         top.Add (menuBar);
         Application.Begin (top);
         Application.Begin (top);
 
 
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
         Assert.Null (cm.MenuBar);
         Assert.Null (cm.MenuBar);
 
 
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
@@ -1568,10 +1568,10 @@ public class ContextMenuTests (ITestOutputHelper output)
         newFile = false;
         newFile = false;
 
 
         cm.Show (menuItems);
         cm.Show (menuItems);
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.True (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.True (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
 
 
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
@@ -1584,10 +1584,10 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.True (renameFile);
         Assert.True (renameFile);
         Assert.False (cm.MenuBar.IsMenuOpen);
         Assert.False (cm.MenuBar.IsMenuOpen);
 
 
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
 
 
         newFile = false;
         newFile = false;
         renameFile = false;
         renameFile = false;
@@ -1634,7 +1634,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         top.Add (menuBar);
         top.Add (menuBar);
         Application.Begin (top);
         Application.Begin (top);
 
 
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
         Assert.Null (cm.MenuBar);
         Assert.Null (cm.MenuBar);
 
 
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
@@ -1645,8 +1645,8 @@ public class ContextMenuTests (ITestOutputHelper output)
         newMenuBar = false;
         newMenuBar = false;
 
 
         cm.Show (menuItems);
         cm.Show (menuItems);
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.True (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.True (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
 
 
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
@@ -1657,8 +1657,8 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.True (newContextMenu);
         Assert.True (newContextMenu);
         Assert.False (cm.MenuBar!.IsMenuOpen);
         Assert.False (cm.MenuBar!.IsMenuOpen);
 
 
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
 
 
         newMenuBar = false;
         newMenuBar = false;
         newContextMenu = false;
         newContextMenu = false;
@@ -1704,20 +1704,20 @@ public class ContextMenuTests (ITestOutputHelper output)
 
 
         cm.Show (menuItems);
         cm.Show (menuItems);
         Assert.True (cm.MenuBar!.IsMenuOpen);
         Assert.True (cm.MenuBar!.IsMenuOpen);
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.D.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.D.NoShift));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.D.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.D.NoShift));
         Assert.Single (Application.Top!.Subviews);
         Assert.Single (Application.Top!.Subviews);
         View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
         View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.N.NoShift));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.D.WithAlt));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.D.NoShift));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.N.NoShift));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.D.WithAlt));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.D.NoShift));
 
 
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt));
         Assert.False (cm.MenuBar!.IsMenuOpen);
         Assert.False (cm.MenuBar!.IsMenuOpen);
@@ -1734,12 +1734,12 @@ public class ContextMenuTests (ITestOutputHelper output)
         Application.MainLoop!.RunIteration ();
         Application.MainLoop!.RunIteration ();
         Assert.True (deleteFile);
         Assert.True (deleteFile);
 
 
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.N.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.D.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.D.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.D.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.D.NoShift));
 
 
         newFile = false;
         newFile = false;
         renameFile = false;
         renameFile = false;
@@ -1796,9 +1796,9 @@ public class ContextMenuTests (ITestOutputHelper output)
         top.Add (menuBar);
         top.Add (menuBar);
         Application.Begin (top);
         Application.Begin (top);
 
 
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
         View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray ();
         View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray ();
         Assert.Empty (menus);
         Assert.Empty (menus);
         Assert.Null (cm.MenuBar);
         Assert.Null (cm.MenuBar);
@@ -1807,7 +1807,7 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.True (menuBar.IsMenuOpen);
         Assert.True (menuBar.IsMenuOpen);
         Assert.Equal (2, Application.Top!.Subviews.Count);
         Assert.Equal (2, Application.Top!.Subviews.Count);
         menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray ();
         menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray ();
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt));
         Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt));
         Assert.False (menuBar.IsMenuOpen);
         Assert.False (menuBar.IsMenuOpen);
         Assert.False (Application.RaiseKeyDownEvent (Key.R.WithAlt));
         Assert.False (Application.RaiseKeyDownEvent (Key.R.WithAlt));
@@ -1818,29 +1818,29 @@ public class ContextMenuTests (ITestOutputHelper output)
         newFile = false;
         newFile = false;
 
 
         cm.Show (menuItems);
         cm.Show (menuItems);
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.F.NoShift));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.NoShift));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.E.NoShift));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.F.NoShift));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.NoShift));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.E.NoShift));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
         Assert.True (cm.MenuBar!.IsMenuOpen);
         Assert.True (cm.MenuBar!.IsMenuOpen);
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.F.NoShift));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.N.NoShift));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
-        Assert.False (cm.MenuBar!.KeyBindings.Bindings.ContainsKey (Key.E.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.F.NoShift));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.NoShift));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
+        Assert.False (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.E.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
         Assert.Equal (3, Application.Top!.Subviews.Count);
         Assert.Equal (3, Application.Top!.Subviews.Count);
         menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
         menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.E.NoShift));
-        Assert.True (menus [1].KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.True (menus [1].KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.E.NoShift));
+        Assert.True (menus [1].HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.True (menus [1].HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (Application.RaiseKeyDownEvent (Key.F.WithAlt));
         Assert.True (Application.RaiseKeyDownEvent (Key.F.WithAlt));
         Assert.False (cm.MenuBar.IsMenuOpen);
         Assert.False (cm.MenuBar.IsMenuOpen);
@@ -1852,14 +1852,14 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.True (cm.MenuBar.IsMenuOpen);
         Assert.Equal (3, Application.Top!.Subviews.Count);
         Assert.Equal (3, Application.Top!.Subviews.Count);
         menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
         menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
-        Assert.True (menus [0].KeyBindings.Bindings.ContainsKey (Key.E.NoShift));
-        Assert.False (menus [0].KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.False (menus [0].KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
-        Assert.False (menus [1].KeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
-        Assert.False (menus [1].KeyBindings.Bindings.ContainsKey (Key.E.NoShift));
-        Assert.True (menus [1].KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.True (menus [1].KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
+        Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.E.NoShift));
+        Assert.False (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.False (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.False (menus [1].HotKeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
+        Assert.False (menus [1].HotKeyBindings.Bindings.ContainsKey (Key.E.NoShift));
+        Assert.True (menus [1].HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.True (menus [1].HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
         Assert.True (Application.RaiseKeyDownEvent (Key.E.NoShift));
         Assert.True (Application.RaiseKeyDownEvent (Key.E.NoShift));
         Assert.True (Application.RaiseKeyDownEvent (Key.R.WithAlt));
         Assert.True (Application.RaiseKeyDownEvent (Key.R.WithAlt));
         Assert.False (cm.MenuBar.IsMenuOpen);
         Assert.False (cm.MenuBar.IsMenuOpen);
@@ -1867,14 +1867,14 @@ public class ContextMenuTests (ITestOutputHelper output)
         Assert.True (renameFile);
         Assert.True (renameFile);
 
 
         Assert.Single (Application.Top!.Subviews);
         Assert.Single (Application.Top!.Subviews);
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
-        Assert.True (menuBar.KeyBindings.Bindings.ContainsKey (Key.F.NoShift));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
-        Assert.False (menuBar.KeyBindings.Bindings.ContainsKey (Key.N.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.E.NoShift));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
-        Assert.False (cm.MenuBar.KeyBindings.Bindings.ContainsKey (Key.R.NoShift));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.F.WithAlt));
+        Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.F.NoShift));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
+        Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.E.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.E.NoShift));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithAlt));
+        Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.NoShift));
 
 
         newFile = false;
         newFile = false;
         renameFile = false;
         renameFile = false;

+ 8 - 8
UnitTests/Views/MenuBarTests.cs

@@ -19,8 +19,8 @@ public class MenuBarTests (ITestOutputHelper output)
         menuBar.Menus = [menuBarItem];
         menuBar.Menus = [menuBarItem];
         Assert.Single (menuBar.Menus);
         Assert.Single (menuBar.Menus);
         Assert.Single (menuBar.Menus [0].Children!);
         Assert.Single (menuBar.Menus [0].Children!);
-        Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings);
-        Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings);
+        Assert.Contains (Key.N.WithAlt, menuBar.HotKeyBindings.Bindings);
+        Assert.DoesNotContain (Key.I, menuBar.HotKeyBindings.Bindings);
 
 
         var top = new Toplevel ();
         var top = new Toplevel ();
         top.Add (menuBar);
         top.Add (menuBar);
@@ -39,12 +39,12 @@ public class MenuBarTests (ITestOutputHelper output)
         menuItem.RemoveMenuItem ();
         menuItem.RemoveMenuItem ();
         Assert.Single (menuBar.Menus);
         Assert.Single (menuBar.Menus);
         Assert.Null (menuBar.Menus [0].Children);
         Assert.Null (menuBar.Menus [0].Children);
-        Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings);
-        Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings);
+        Assert.Contains (Key.N.WithAlt, menuBar.HotKeyBindings.Bindings);
+        Assert.DoesNotContain (Key.I, menuBar.HotKeyBindings.Bindings);
 
 
         menuBarItem.RemoveMenuItem ();
         menuBarItem.RemoveMenuItem ();
         Assert.Empty (menuBar.Menus);
         Assert.Empty (menuBar.Menus);
-        Assert.DoesNotContain (Key.N.WithAlt, menuBar.KeyBindings.Bindings);
+        Assert.DoesNotContain (Key.N.WithAlt, menuBar.HotKeyBindings.Bindings);
 
 
         top.Dispose ();
         top.Dispose ();
     }
     }
@@ -2998,12 +2998,12 @@ Edit
             ]
             ]
         };
         };
 
 
-        Assert.Contains (Key.A.WithCtrl, menuBar.KeyBindings.Bindings);
+        Assert.Contains (Key.A.WithCtrl, menuBar.HotKeyBindings.Bindings);
 
 
         menuBar.Menus [0].Children! [0].ShortcutKey = Key.B.WithCtrl;
         menuBar.Menus [0].Children! [0].ShortcutKey = Key.B.WithCtrl;
 
 
-        Assert.DoesNotContain (Key.A.WithCtrl, menuBar.KeyBindings.Bindings);
-        Assert.Contains (Key.B.WithCtrl, menuBar.KeyBindings.Bindings);
+        Assert.DoesNotContain (Key.A.WithCtrl, menuBar.HotKeyBindings.Bindings);
+        Assert.Contains (Key.B.WithCtrl, menuBar.HotKeyBindings.Bindings);
     }
     }
 
 
     [Fact]
     [Fact]

+ 24 - 20
UnitTests/Views/RadioGroupTests.cs

@@ -64,24 +64,28 @@ public class RadioGroupTests (ITestOutputHelper output)
     }
     }
 
 
     [Fact]
     [Fact]
-    public void KeyBindings_Are_Added_Correctly ()
+    public void HotKeyBindings_Are_Added_Correctly ()
     {
     {
         var rg = new RadioGroup { RadioLabels = new [] { "_Left", "_Right" } };
         var rg = new RadioGroup { RadioLabels = new [] { "_Left", "_Right" } };
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.L));
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.R));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (Key.L));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (Key.R));
 
 
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.L.WithShift));
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.L.WithAlt));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (Key.L.WithShift));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (Key.L.WithAlt));
 
 
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.R.WithShift));
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (Key.R.WithAlt));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (Key.R.WithShift));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (Key.R.WithAlt));
     }
     }
 
 
     [Fact]
     [Fact]
     public void Commands_HasFocus ()
     public void Commands_HasFocus ()
     {
     {
         Application.Navigation = new ();
         Application.Navigation = new ();
-        var rg = new RadioGroup { RadioLabels = new [] { "Test", "New Test" } };
+        var rg = new RadioGroup
+        {
+            Id = "rg",
+            RadioLabels = ["Test", "New Test"]
+        };
         Application.Top = new ();
         Application.Top = new ();
         Application.Top.Add (rg);
         Application.Top.Add (rg);
         rg.SetFocus ();
         rg.SetFocus ();
@@ -201,7 +205,7 @@ public class RadioGroupTests (ITestOutputHelper output)
     public void HotKey_HasFocus_False ()
     public void HotKey_HasFocus_False ()
     {
     {
         Application.Navigation = new ();
         Application.Navigation = new ();
-        var rg = new RadioGroup { RadioLabels = new [] { "Test", "New Test" } };
+        var rg = new RadioGroup { RadioLabels = ["Test", "New Test"] };
         Application.Top = new ();
         Application.Top = new ();
 
 
         // With !HasFocus
         // With !HasFocus
@@ -278,7 +282,7 @@ public class RadioGroupTests (ITestOutputHelper output)
     public void HotKeys_HasFocus_False_Does_Not_SetFocus_Selects ()
     public void HotKeys_HasFocus_False_Does_Not_SetFocus_Selects ()
     {
     {
         Application.Navigation = new ();
         Application.Navigation = new ();
-        var rg = new RadioGroup { RadioLabels = new [] { "Item _A", "Item _B" } };
+        var rg = new RadioGroup { RadioLabels = ["Item _A", "Item _B"] };
         Application.Top = new ();
         Application.Top = new ();
 
 
         // With !HasFocus
         // With !HasFocus
@@ -363,14 +367,14 @@ public class RadioGroupTests (ITestOutputHelper output)
     [Fact]
     [Fact]
     public void HotKeys_HasFocus_True_Selects ()
     public void HotKeys_HasFocus_True_Selects ()
     {
     {
-        var rg = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } };
+        var rg = new RadioGroup { RadioLabels = ["_Left", "_Right", "Cen_tered", "_Justified"] };
         Application.Top = new ();
         Application.Top = new ();
         Application.Top.Add (rg);
         Application.Top.Add (rg);
         rg.SetFocus ();
         rg.SetFocus ();
 
 
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L));
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.ShiftMask));
-        Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (KeyCode.L));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (KeyCode.L | KeyCode.ShiftMask));
+        Assert.NotEmpty (rg.HotKeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask));
 
 
         Assert.True (Application.RaiseKeyDownEvent (Key.T));
         Assert.True (Application.RaiseKeyDownEvent (Key.T));
         Assert.Equal (2, rg.SelectedItem);
         Assert.Equal (2, rg.SelectedItem);
@@ -425,7 +429,7 @@ public class RadioGroupTests (ITestOutputHelper output)
         var group = new RadioGroup
         var group = new RadioGroup
         {
         {
             Title = "Radio_Group",
             Title = "Radio_Group",
-            RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" }
+            RadioLabels = ["_Left", "_Right", "Cen_tered", "_Justified"]
         };
         };
         superView.Add (group);
         superView.Add (group);
 
 
@@ -450,7 +454,7 @@ public class RadioGroupTests (ITestOutputHelper output)
         var group = new RadioGroup
         var group = new RadioGroup
         {
         {
             Title = "Radio_Group",
             Title = "Radio_Group",
-            RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" }
+            RadioLabels = ["_Left", "_Right", "Cen_tered", "_Justified"]
         };
         };
         group.SelectedItem = -1;
         group.SelectedItem = -1;
 
 
@@ -488,7 +492,7 @@ public class RadioGroupTests (ITestOutputHelper output)
     [Fact]
     [Fact]
     public void HotKey_Command_Does_Not_Accept ()
     public void HotKey_Command_Does_Not_Accept ()
     {
     {
-        var group = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } };
+        var group = new RadioGroup { RadioLabels = ["_Left", "_Right", "Cen_tered", "_Justified"] };
         var accepted = false;
         var accepted = false;
 
 
         group.Accepting += OnAccept;
         group.Accepting += OnAccept;
@@ -504,7 +508,7 @@ public class RadioGroupTests (ITestOutputHelper output)
     [Fact]
     [Fact]
     public void Accept_Command_Fires_Accept ()
     public void Accept_Command_Fires_Accept ()
     {
     {
-        var group = new RadioGroup { RadioLabels = new [] { "_Left", "_Right", "Cen_tered", "_Justified" } };
+        var group = new RadioGroup { RadioLabels = ["_Left", "_Right", "Cen_tered", "_Justified"] };
         var accepted = false;
         var accepted = false;
 
 
         group.Accepting += OnAccept;
         group.Accepting += OnAccept;
@@ -521,7 +525,7 @@ public class RadioGroupTests (ITestOutputHelper output)
     [AutoInitShutdown]
     [AutoInitShutdown]
     public void Orientation_Width_Height_Vertical_Horizontal_Space ()
     public void Orientation_Width_Height_Vertical_Horizontal_Space ()
     {
     {
-        var rg = new RadioGroup { RadioLabels = new [] { "Test", "New Test 你" } };
+        var rg = new RadioGroup { RadioLabels = ["Test", "New Test 你"] };
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
         win.Add (rg);
         win.Add (rg);
         var top = new Toplevel ();
         var top = new Toplevel ();
@@ -597,7 +601,7 @@ public class RadioGroupTests (ITestOutputHelper output)
     {
     {
         int previousSelectedItem = -1;
         int previousSelectedItem = -1;
         int selectedItem = -1;
         int selectedItem = -1;
-        var rg = new RadioGroup { RadioLabels = new [] { "Test", "New Test" } };
+        var rg = new RadioGroup { RadioLabels = ["Test", "New Test"] };
 
 
         rg.SelectedItemChanged += (s, e) =>
         rg.SelectedItemChanged += (s, e) =>
                                   {
                                   {

+ 9 - 9
UnitTests/Views/ShortcutTests.cs

@@ -281,16 +281,16 @@ public class ShortcutTests
         var shortcut = new Shortcut ();
         var shortcut = new Shortcut ();
 
 
         shortcut.Key = Key.A;
         shortcut.Key = Key.A;
-        Assert.Contains (Key.A, shortcut.KeyBindings.Bindings.Keys);
+        Assert.Contains (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
 
 
         shortcut.Key = Key.B;
         shortcut.Key = Key.B;
-        Assert.DoesNotContain (Key.A, shortcut.KeyBindings.Bindings.Keys);
-        Assert.Contains (Key.B, shortcut.KeyBindings.Bindings.Keys);
+        Assert.DoesNotContain (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
+        Assert.Contains (Key.B, shortcut.HotKeyBindings.Bindings.Keys);
     }
     }
 
 
     // Test Key gets bound correctly
     // Test Key gets bound correctly
     [Fact]
     [Fact]
-    public void KeyBindingScope_Defaults_To_HotKey ()
+    public void BindKeyToApplication_Defaults_To_HotKey ()
     {
     {
         var shortcut = new Shortcut ();
         var shortcut = new Shortcut ();
 
 
@@ -298,7 +298,7 @@ public class ShortcutTests
     }
     }
 
 
     [Fact]
     [Fact]
-    public void KeyBindingScope_Can_Be_Set ()
+    public void BindKeyToApplication_Can_Be_Set ()
     {
     {
         var shortcut = new Shortcut ();
         var shortcut = new Shortcut ();
 
 
@@ -308,19 +308,19 @@ public class ShortcutTests
     }
     }
 
 
     [Fact]
     [Fact]
-    public void KeyBindingScope_Changing_Adjusts_KeyBindings ()
+    public void BindKeyToApplication_Changing_Adjusts_KeyBindings ()
     {
     {
         var shortcut = new Shortcut ();
         var shortcut = new Shortcut ();
 
 
         shortcut.Key = Key.A;
         shortcut.Key = Key.A;
-        Assert.Contains (Key.A, shortcut.KeyBindings.Bindings.Keys);
+        Assert.Contains (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
 
 
         shortcut.BindKeyToApplication = true;
         shortcut.BindKeyToApplication = true;
-        Assert.DoesNotContain (Key.A, shortcut.KeyBindings.Bindings.Keys);
+        Assert.DoesNotContain (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
         Assert.NotEmpty (Application.KeyBindings.GetBindings(Key.A));
         Assert.NotEmpty (Application.KeyBindings.GetBindings(Key.A));
 
 
         shortcut.BindKeyToApplication = false;
         shortcut.BindKeyToApplication = false;
-        Assert.Contains (Key.A, shortcut.KeyBindings.Bindings.Keys);
+        Assert.Contains (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
         Assert.Empty (Application.KeyBindings.GetBindings (Key.A));
         Assert.Empty (Application.KeyBindings.GetBindings (Key.A));
     }
     }