mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
KeyBindings cleanup
This commit is contained in:
@@ -45,7 +45,7 @@ public class KeyBindings
|
||||
// IMPORTANT: update the memory referenced by the key, and Dictionary uses caching for performance, and thus
|
||||
// IMPORTANT: Apply will update the Dictionary with the new key, but the old key will still be in the dictionary.
|
||||
// IMPORTANT: See the ConfigurationManager.Illustrate_DeepMemberWiseCopy_Breaks_Dictionary test for details.
|
||||
Bindings.Add (new (key), binding);
|
||||
_bindings.Add (new (key), binding);
|
||||
}
|
||||
|
||||
#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
|
||||
@@ -102,26 +102,27 @@ public class KeyBindings
|
||||
Add (key, binding);
|
||||
}
|
||||
|
||||
// TODO: Add a dictionary comparer that ignores Scope
|
||||
// TODO: This should not be public!
|
||||
/// <summary>The collection of <see cref="KeyBinding"/> objects.</summary>
|
||||
public Dictionary<Key, KeyBinding> Bindings { get; } = new (new KeyEqualityComparer ());
|
||||
private readonly Dictionary<Key, KeyBinding> _bindings = new (new KeyEqualityComparer ());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bindings bound to <paramref name="key"/>.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<KeyValuePair<Key, KeyBinding>> GetBindings (Key key)
|
||||
public IEnumerable<KeyValuePair<Key, KeyBinding>> GetBindings (Key? key = null)
|
||||
{
|
||||
return Bindings.Where (b => b.Key == key.KeyCode);
|
||||
if (key is null)
|
||||
{
|
||||
return _bindings;
|
||||
}
|
||||
return _bindings.Where (b => b.Key == key.KeyCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keys that are bound.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<Key> GetBoundKeys () { return Bindings.Keys; }
|
||||
public IEnumerable<Key> GetBoundKeys () { return _bindings.Keys; }
|
||||
|
||||
/// <summary>
|
||||
/// The view that the <see cref="KeyBindings"/> are bound to.
|
||||
@@ -132,7 +133,7 @@ public class KeyBindings
|
||||
public View? Target { get; init; }
|
||||
|
||||
/// <summary>Removes all <see cref="KeyBinding"/> objects from the collection.</summary>
|
||||
public void Clear () { Bindings.Clear (); }
|
||||
public void Clear () { _bindings.Clear (); }
|
||||
|
||||
/// <summary>
|
||||
/// Removes all key bindings that trigger the given command set. Views can have multiple different keys bound to
|
||||
@@ -141,7 +142,7 @@ public class KeyBindings
|
||||
/// <param name="command"></param>
|
||||
public void Clear (params Command [] command)
|
||||
{
|
||||
KeyValuePair<Key, KeyBinding> [] kvps = Bindings
|
||||
KeyValuePair<Key, KeyBinding> [] kvps = _bindings
|
||||
.Where (kvp => kvp.Value.Commands.SequenceEqual (command))
|
||||
.ToArray ();
|
||||
|
||||
@@ -186,7 +187,7 @@ public class KeyBindings
|
||||
/// 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; }
|
||||
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>
|
||||
/// <param name="commands">The set of commands to search.</param>
|
||||
@@ -196,7 +197,7 @@ public class KeyBindings
|
||||
/// </returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>Removes a <see cref="KeyBinding"/> from the collection.</summary>
|
||||
@@ -208,7 +209,7 @@ public class KeyBindings
|
||||
return;
|
||||
}
|
||||
|
||||
Bindings.Remove (key);
|
||||
_bindings.Remove (key);
|
||||
}
|
||||
|
||||
/// <summary>Replaces the commands already bound to a key.</summary>
|
||||
@@ -275,7 +276,7 @@ public class KeyBindings
|
||||
|
||||
if (key.IsValid)
|
||||
{
|
||||
return Bindings.TryGetValue (key, out binding);
|
||||
return _bindings.TryGetValue (key, out binding);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -80,7 +80,7 @@ public sealed class KeyBindings : Scenario
|
||||
};
|
||||
appWindow.Add (appBindingsListView);
|
||||
|
||||
foreach (var key in Application.KeyBindings.GetBoundKeys())
|
||||
foreach (var key in Application.KeyBindings.GetBoundKeys ())
|
||||
{
|
||||
var binding = Application.KeyBindings.Get (key);
|
||||
appBindings.Add ($"{key} -> {binding.Target?.GetType ().Name} - {binding.Commands [0]}");
|
||||
@@ -104,7 +104,7 @@ public sealed class KeyBindings : Scenario
|
||||
|
||||
foreach (var subview in appWindow.Subviews)
|
||||
{
|
||||
foreach (var binding in subview.HotKeyBindings.Bindings)
|
||||
foreach (KeyValuePair<Key, KeyBinding> binding in subview.HotKeyBindings.GetBindings ())
|
||||
{
|
||||
hotkeyBindings.Add ($"{binding.Key} -> {subview.GetType ().Name} - {binding.Value.Commands [0]}");
|
||||
}
|
||||
@@ -148,8 +148,8 @@ public sealed class KeyBindings : Scenario
|
||||
|
||||
_focusedBindingsListView.Title = $"_Focused ({focused?.GetType ().Name}) Bindings";
|
||||
|
||||
_focusedBindings.Clear();
|
||||
foreach (var binding in focused?.KeyBindings!.Bindings)
|
||||
_focusedBindings.Clear ();
|
||||
foreach (var binding in focused?.KeyBindings!.GetBindings ())
|
||||
{
|
||||
_focusedBindings.Add ($"{binding.Key} -> {binding.Value.Commands [0]}");
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class KeyBindingsTests ()
|
||||
public void Defaults ()
|
||||
{
|
||||
var keyBindings = new KeyBindings (new ());
|
||||
Assert.Empty (keyBindings.Bindings);
|
||||
Assert.Empty (keyBindings.GetBindings ());
|
||||
Assert.Null (keyBindings.GetKeyFromCommands (Command.Accept));
|
||||
Assert.NotNull (keyBindings.Target);
|
||||
}
|
||||
@@ -305,9 +305,6 @@ public class KeyBindingsTests ()
|
||||
var key = new Key (Key.Q.WithCtrl);
|
||||
bool result = keyBindings.TryGet (key, out KeyBinding _);
|
||||
Assert.True (result); ;
|
||||
|
||||
result = keyBindings.Bindings.TryGetValue (key, out KeyBinding _);
|
||||
Assert.True (result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -72,7 +72,8 @@ public class HotKeyTests
|
||||
Assert.Equal (KeyCode.Z, view.HotKey);
|
||||
|
||||
view.AddKeyBindingsForHotKey (view.HotKey, Key.A);
|
||||
Assert.Equal (Key.A, view.HotKeyBindings.Bindings [Key.A].Key);
|
||||
view.HotKeyBindings.TryGet (Key.A, out var binding);
|
||||
Assert.Equal (Key.A, binding.Key);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -83,7 +84,8 @@ public class HotKeyTests
|
||||
Assert.Equal (KeyCode.Z, view.HotKey);
|
||||
|
||||
view.AddKeyBindingsForHotKey (view.HotKey, Key.A, "data");
|
||||
Assert.Equal ("data", view.HotKeyBindings.Bindings [Key.A].Data);
|
||||
view.HotKeyBindings.TryGet (Key.A, out var binding);
|
||||
Assert.Equal ("data", binding.Data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1483,9 +1483,9 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.False (deleteFile);
|
||||
|
||||
cm.Show (menuItems);
|
||||
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 (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.True (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
Assert.True (cm.MenuBar.HotKeyBindings.TryGet (Key.D.WithCtrl, out _));
|
||||
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
|
||||
Application.MainLoop!.RunIteration ();
|
||||
@@ -1502,9 +1502,9 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.True (deleteFile);
|
||||
Assert.False (cm.MenuBar.IsMenuOpen);
|
||||
|
||||
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));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.WithCtrl, out _));
|
||||
|
||||
newFile = false;
|
||||
renameFile = false;
|
||||
@@ -1555,8 +1555,8 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
top.Add (menuBar);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
|
||||
Assert.False (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.R.WithCtrl));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
Assert.Null (cm.MenuBar);
|
||||
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
|
||||
@@ -1568,10 +1568,10 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
newFile = false;
|
||||
|
||||
cm.Show (menuItems);
|
||||
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 (menuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.True (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
|
||||
Assert.True (cm.MenuBar.IsMenuOpen);
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
|
||||
@@ -1584,10 +1584,10 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.True (renameFile);
|
||||
Assert.False (cm.MenuBar.IsMenuOpen);
|
||||
|
||||
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));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithCtrl, out _));
|
||||
|
||||
newFile = false;
|
||||
renameFile = false;
|
||||
@@ -1634,7 +1634,7 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
top.Add (menuBar);
|
||||
Application.Begin (top);
|
||||
|
||||
Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.Null (cm.MenuBar);
|
||||
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
|
||||
@@ -1645,8 +1645,8 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
newMenuBar = false;
|
||||
|
||||
cm.Show (menuItems);
|
||||
Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
|
||||
Assert.True (cm.MenuBar!.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.True (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
|
||||
Assert.True (cm.MenuBar.IsMenuOpen);
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithCtrl));
|
||||
@@ -1657,8 +1657,8 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.True (newContextMenu);
|
||||
Assert.False (cm.MenuBar!.IsMenuOpen);
|
||||
|
||||
Assert.True (menuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.Bindings.ContainsKey (Key.N.WithCtrl));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.N.WithCtrl, out _));
|
||||
|
||||
newMenuBar = false;
|
||||
newContextMenu = false;
|
||||
@@ -1704,20 +1704,20 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
|
||||
cm.Show (menuItems);
|
||||
Assert.True (cm.MenuBar!.IsMenuOpen);
|
||||
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.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.NoShift, out _));
|
||||
Assert.Single (Application.Top!.Subviews);
|
||||
View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
|
||||
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 (menus [0].HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.N.NoShift, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.D.WithAlt, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.D.NoShift, out _));
|
||||
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt));
|
||||
Assert.False (cm.MenuBar!.IsMenuOpen);
|
||||
@@ -1734,12 +1734,12 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Application.MainLoop!.RunIteration ();
|
||||
Assert.True (deleteFile);
|
||||
|
||||
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.False (cm.MenuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.N.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.D.NoShift, out _));
|
||||
|
||||
newFile = false;
|
||||
renameFile = false;
|
||||
@@ -1796,9 +1796,9 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
top.Add (menuBar);
|
||||
Application.Begin (top);
|
||||
|
||||
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));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
View [] menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray ();
|
||||
Assert.Empty (menus);
|
||||
Assert.Null (cm.MenuBar);
|
||||
@@ -1807,7 +1807,7 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.True (menuBar.IsMenuOpen);
|
||||
Assert.Equal (2, Application.Top!.Subviews.Count);
|
||||
menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == menuBar).ToArray ();
|
||||
Assert.True (menus [0].HotKeyBindings.Bindings.ContainsKey (Key.N.WithAlt));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.N.WithAlt));
|
||||
Assert.False (menuBar.IsMenuOpen);
|
||||
Assert.False (Application.RaiseKeyDownEvent (Key.R.WithAlt));
|
||||
@@ -1818,29 +1818,29 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
newFile = false;
|
||||
|
||||
cm.Show (menuItems);
|
||||
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 (menuBar.HotKeyBindings.TryGet (Key.F.WithAlt, out _));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.NoShift, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.NoShift, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.E.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.E.NoShift, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.True (cm.MenuBar!.IsMenuOpen);
|
||||
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.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.F.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.F.NoShift, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.N.NoShift, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.E.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar!.HotKeyBindings.TryGet (Key.E.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.Equal (3, Application.Top!.Subviews.Count);
|
||||
menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
|
||||
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 (menus [0].HotKeyBindings.TryGet (Key.E.WithAlt, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.E.NoShift, out _));
|
||||
Assert.True (menus [1].HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.True (menus [1].HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.True (cm.MenuBar.IsMenuOpen);
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.F.WithAlt));
|
||||
Assert.False (cm.MenuBar.IsMenuOpen);
|
||||
@@ -1852,14 +1852,14 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.True (cm.MenuBar.IsMenuOpen);
|
||||
Assert.Equal (3, Application.Top!.Subviews.Count);
|
||||
menus = Application.Top!.Subviews.Where (v => v is Menu m && m.Host == cm.MenuBar).ToArray ();
|
||||
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 (menus [0].HotKeyBindings.TryGet (Key.E.WithAlt, out _));
|
||||
Assert.True (menus [0].HotKeyBindings.TryGet (Key.E.NoShift, out _));
|
||||
Assert.False (menus [0].HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.False (menus [0].HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.False (menus [1].HotKeyBindings.TryGet (Key.E.WithAlt, out _));
|
||||
Assert.False (menus [1].HotKeyBindings.TryGet (Key.E.NoShift, out _));
|
||||
Assert.True (menus [1].HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.True (menus [1].HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.E.NoShift));
|
||||
Assert.True (Application.RaiseKeyDownEvent (Key.R.WithAlt));
|
||||
Assert.False (cm.MenuBar.IsMenuOpen);
|
||||
@@ -1867,14 +1867,14 @@ public class ContextMenuTests (ITestOutputHelper output)
|
||||
Assert.True (renameFile);
|
||||
|
||||
Assert.Single (Application.Top!.Subviews);
|
||||
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));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.WithAlt, out _));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.F.NoShift, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.E.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.E.NoShift, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.WithAlt, out _));
|
||||
Assert.False (cm.MenuBar.HotKeyBindings.TryGet (Key.R.NoShift, out _));
|
||||
|
||||
newFile = false;
|
||||
renameFile = false;
|
||||
|
||||
@@ -19,8 +19,9 @@ public class MenuBarTests (ITestOutputHelper output)
|
||||
menuBar.Menus = [menuBarItem];
|
||||
Assert.Single (menuBar.Menus);
|
||||
Assert.Single (menuBar.Menus [0].Children!);
|
||||
Assert.Contains (Key.N.WithAlt, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.DoesNotContain (Key.I, menuBar.HotKeyBindings.Bindings);
|
||||
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.I, out _));
|
||||
|
||||
var top = new Toplevel ();
|
||||
top.Add (menuBar);
|
||||
@@ -39,12 +40,12 @@ public class MenuBarTests (ITestOutputHelper output)
|
||||
menuItem.RemoveMenuItem ();
|
||||
Assert.Single (menuBar.Menus);
|
||||
Assert.Null (menuBar.Menus [0].Children);
|
||||
Assert.Contains (Key.N.WithAlt, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.DoesNotContain (Key.I, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.I, out _));
|
||||
|
||||
menuBarItem.RemoveMenuItem ();
|
||||
Assert.Empty (menuBar.Menus);
|
||||
Assert.DoesNotContain (Key.N.WithAlt, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.N.WithAlt, out _));
|
||||
|
||||
top.Dispose ();
|
||||
}
|
||||
@@ -2998,12 +2999,12 @@ Edit
|
||||
]
|
||||
};
|
||||
|
||||
Assert.Contains (Key.A.WithCtrl, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.A.WithCtrl, out _));
|
||||
|
||||
menuBar.Menus [0].Children! [0].ShortcutKey = Key.B.WithCtrl;
|
||||
|
||||
Assert.DoesNotContain (Key.A.WithCtrl, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.Contains (Key.B.WithCtrl, menuBar.HotKeyBindings.Bindings);
|
||||
Assert.False (menuBar.HotKeyBindings.TryGet (Key.A.WithCtrl, out _));
|
||||
Assert.True (menuBar.HotKeyBindings.TryGet (Key.B.WithCtrl, out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -281,11 +281,11 @@ public class ShortcutTests
|
||||
var shortcut = new Shortcut ();
|
||||
|
||||
shortcut.Key = Key.A;
|
||||
Assert.Contains (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
|
||||
Assert.True(shortcut.HotKeyBindings.TryGet(Key.A, out _));
|
||||
|
||||
shortcut.Key = Key.B;
|
||||
Assert.DoesNotContain (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
|
||||
Assert.Contains (Key.B, shortcut.HotKeyBindings.Bindings.Keys);
|
||||
Assert.False (shortcut.HotKeyBindings.TryGet (Key.A, out _));
|
||||
Assert.True (shortcut.HotKeyBindings.TryGet (Key.B, out _));
|
||||
}
|
||||
|
||||
// Test Key gets bound correctly
|
||||
@@ -313,14 +313,14 @@ public class ShortcutTests
|
||||
var shortcut = new Shortcut ();
|
||||
|
||||
shortcut.Key = Key.A;
|
||||
Assert.Contains (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
|
||||
Assert.True (shortcut.HotKeyBindings.TryGet(Key.A, out _));
|
||||
|
||||
shortcut.BindKeyToApplication = true;
|
||||
Assert.DoesNotContain (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
|
||||
Assert.False (shortcut.HotKeyBindings.TryGet (Key.A, out _));
|
||||
Assert.NotEmpty (Application.KeyBindings.GetBindings(Key.A));
|
||||
|
||||
shortcut.BindKeyToApplication = false;
|
||||
Assert.Contains (Key.A, shortcut.HotKeyBindings.Bindings.Keys);
|
||||
Assert.True (shortcut.HotKeyBindings.TryGet (Key.A, out _));
|
||||
Assert.Empty (Application.KeyBindings.GetBindings (Key.A));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user