diff --git a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs index d2e70ae283..4b872ab626 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs @@ -21,7 +21,7 @@ public class AnsiEscapeSequenceRequest : AnsiEscapeSequence /// - /// Sends the to the raw output stream of the current . + /// Sends the to the raw output stream of the current . /// Only call this method from the main UI thread. You should use if /// sending many requests. /// diff --git a/Terminal.Gui/Input/ICommandContext.cs b/Terminal.Gui/Input/ICommandContext.cs index 740f059c9d..644029ca28 100644 --- a/Terminal.Gui/Input/ICommandContext.cs +++ b/Terminal.Gui/Input/ICommandContext.cs @@ -1,12 +1,14 @@ #nullable enable namespace Terminal.Gui; +#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved /// /// Describes the context in which a is being invoked. inherits from this interface. /// When a is invoked, /// a context object is passed to Command handlers as an reference. /// -/// . +/// . +#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved public interface ICommandContext { /// diff --git a/Terminal.Gui/Input/Keyboard/KeyBinding.cs b/Terminal.Gui/Input/Keyboard/KeyBinding.cs index 872429b9d0..7e05b7b452 100644 --- a/Terminal.Gui/Input/Keyboard/KeyBinding.cs +++ b/Terminal.Gui/Input/Keyboard/KeyBinding.cs @@ -24,7 +24,6 @@ public KeyBinding (Command [] commands, object? context = null) /// Initializes a new instance. /// The commands this key binding will invoke. - /// The scope of the . /// The view the key binding is bound to. /// Arbitrary data that can be associated with this key binding. public KeyBinding (Command [] commands, View? boundView, object? data = null) diff --git a/Terminal.Gui/Input/Keyboard/KeyBindings.cs b/Terminal.Gui/Input/Keyboard/KeyBindings.cs index 5fcaa99bc4..a95073c9e7 100644 --- a/Terminal.Gui/Input/Keyboard/KeyBindings.cs +++ b/Terminal.Gui/Input/Keyboard/KeyBindings.cs @@ -48,17 +48,13 @@ public void Add (Key key, KeyBinding binding) Bindings.Add (new (key), binding); } +#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved /// /// /// Adds a new key combination that will trigger the commands in (if supported by the /// View - see ). /// /// - /// This is a helper function for . If used for a View ( - /// is set), the scope will be set to . - /// Otherwise, it will be set to . - /// - /// /// If the key is already bound to a different array of s it will be rebound /// . /// @@ -74,6 +70,7 @@ public void Add (Key key, KeyBinding binding) /// consumed if any took effect. /// /// If is empty. +#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved public void Add (Key key, params Command [] commands) { Add (key, new KeyBinding (commands)); @@ -168,8 +165,7 @@ public IEnumerable GetKeysFromCommands (params Command [] commands) /// Removes a from the collection. /// - /// Optional View for bindings. - public void Remove (Key key, View? boundViewForAppScope = null) + public void Remove (Key key) { if (!TryGet (key, out KeyBinding _)) { diff --git a/Terminal.Gui/View/View.Keyboard.cs b/Terminal.Gui/View/View.Keyboard.cs index e4bca89b32..9c8917f951 100644 --- a/Terminal.Gui/View/View.Keyboard.cs +++ b/Terminal.Gui/View/View.Keyboard.cs @@ -299,13 +299,13 @@ public bool NewKeyDownEvent (Key key) // During (this is what can be cancelled) // TODO: NewKeyDownEvent returns bool. It should be bool? so state of InvokeCommands can be reflected up stack - if (InvokeCommandsBoundToKey (key) is true || key.Handled) + if (InvokeCommands (key) is true || key.Handled) { return true; } bool? handled = false; - if (InvokeCommandsBoundToHotKeyOnSubviews (key, ref handled)) + if (InvokeCommandsBoundToHotKey (key, ref handled)) { return true; } @@ -516,7 +516,7 @@ bool RaiseKeyUp (Key k) /// Gets the bindings for this view that will be invoked only if this view has focus. public KeyBindings KeyBindings { get; internal set; } = null!; - /// Gets the bindings for this view that will be invoked regardless of whehter this view has focus or not. + /// Gets the bindings for this view that will be invoked regardless of whether this view has focus or not. public KeyBindings HotKeyBindings { get; internal set; } = null!; /// @@ -531,7 +531,7 @@ bool RaiseKeyUp (Key k) /// if at least one command was invoked and handled (or /// cancelled); input processing should stop. /// - internal bool? InvokeCommandsBoundToKey (Key key) + internal bool? InvokeCommands (Key key) { // * If no key binding was found, `InvokeKeyBindings` returns `null`. // Continue passing the event (return `false` from `OnInvokeKeyBindings`). @@ -539,7 +539,7 @@ bool RaiseKeyUp (Key k) // `InvokeKeyBindings` returns `false`. Continue passing the event (return `false` from `OnInvokeKeyBindings`).. // * If key bindings were found, and any handled the key (at least one `Command` returned `true`), // `InvokeKeyBindings` returns `true`. Continue passing the event (return `false` from `OnInvokeKeyBindings`). - bool? handled = InvokeCommandsBoundToFocusedKey (key); + bool? handled = DoInvokeCommands (key); if (handled is true) { @@ -568,7 +568,7 @@ bool RaiseKeyUp (Key k) private static bool InvokeCommandsBoundToKeyOnAdornment (Adornment adornment, Key key, ref bool? handled) { - bool? adornmentHandled = adornment.InvokeCommandsBoundToKey (key); + bool? adornmentHandled = adornment.InvokeCommands (key); if (adornmentHandled is true) { @@ -582,7 +582,7 @@ private static bool InvokeCommandsBoundToKeyOnAdornment (Adornment adornment, Ke foreach (View subview in adornment.Subviews) { - bool? subViewHandled = subview.InvokeCommandsBoundToKey (key); + bool? subViewHandled = subview.InvokeCommands (key); if (subViewHandled is { }) { @@ -598,7 +598,14 @@ private static bool InvokeCommandsBoundToKeyOnAdornment (Adornment adornment, Ke return false; } - internal bool InvokeCommandsBoundToHotKeyOnSubviews (Key key, ref bool? handled, bool invoke = true) + // BUGBUG: This will miss any hotkeys in subviews of Adornments. + /// + /// Invokes any commands bound to on this view and subviews. + /// + /// + /// + /// + internal bool InvokeCommandsBoundToHotKey (Key key, ref bool? handled) { bool? weHandled = InvokeCommandsBoundToHotKey (key); if (weHandled is true) @@ -606,7 +613,7 @@ internal bool InvokeCommandsBoundToHotKeyOnSubviews (Key key, ref bool? handled, return true; } - // Now, process any key bindings in the subviews that are tagged to KeyBindingScope.HotKey. + // Now, process any HotKey bindings in the subviews foreach (View subview in Subviews) { if (subview == Focused) @@ -614,7 +621,7 @@ internal bool InvokeCommandsBoundToHotKeyOnSubviews (Key key, ref bool? handled, continue; } - bool recurse = subview.InvokeCommandsBoundToHotKeyOnSubviews (key, ref handled, invoke); + bool recurse = subview.InvokeCommandsBoundToHotKey (key, ref handled); if (recurse || (handled is { } && (bool)handled)) { @@ -669,7 +676,7 @@ public bool IsHotKeyBound (Key key, out View? boundView) /// if at least one command was invoked and handled (or cancelled); input processing should /// stop. /// - protected bool? InvokeCommandsBoundToFocusedKey (Key key) + protected bool? DoInvokeCommands (Key key) { if (!KeyBindings.TryGet (key, out KeyBinding binding)) { @@ -702,7 +709,6 @@ public bool IsHotKeyBound (Key key, out View? boundView) /// See for an overview of Terminal.Gui keyboard APIs. /// /// The key event passed. - /// The scope. /// /// if no command was invoked; input processing should continue. /// if at least one command was invoked and was not handled (or cancelled); input processing diff --git a/Terminal.Gui/Views/CharMap/CharMap.cs b/Terminal.Gui/Views/CharMap/CharMap.cs index 9f706bd514..b49c8c4e6f 100644 --- a/Terminal.Gui/Views/CharMap/CharMap.cs +++ b/Terminal.Gui/Views/CharMap/CharMap.cs @@ -20,9 +20,12 @@ public class CharMap : View, IDesignable private ContextMenu _contextMenu = new (); + /// /// Initializes a new instance. /// + [RequiresUnreferencedCode ("AOT")] + [RequiresDynamicCode ("AOT")] public CharMap () { base.ColorScheme = Colors.ColorSchemes ["Dialog"]; diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs index 9c2ac63435..369bf88189 100644 --- a/Terminal.Gui/Views/Menu/Menu.cs +++ b/Terminal.Gui/Views/Menu/Menu.cs @@ -251,7 +251,7 @@ protected override bool OnKeyDownNotHandled (Key keyEvent) { // We didn't handle the key, pass it on to host bool? handled = null; - return _host.InvokeCommandsBoundToHotKeyOnSubviews (keyEvent, ref handled, true) == true; + return _host.InvokeCommandsBoundToHotKey (keyEvent, ref handled) == true; } protected override bool OnMouseEvent (MouseEventArgs me) diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs index 56129e0367..f52235da46 100644 --- a/Terminal.Gui/Views/Shortcut.cs +++ b/Terminal.Gui/Views/Shortcut.cs @@ -18,7 +18,7 @@ namespace Terminal.Gui; /// - Pressing the HotKey specified by . /// /// -/// If is , will invoke +/// If is , will invoke /// /// regardless of what View has focus, enabling an application-wide keyboard shortcut. /// diff --git a/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs b/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs index cbbfd24d16..fbc87761f5 100644 --- a/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs +++ b/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs @@ -438,8 +438,6 @@ public void ShouldSwallowUnknownResponses_WhenDelegateSaysSo () [Fact] public void UnknownResponses_ParameterShouldMatch () { - int i = 0; - // Track unknown responses passed to the UnexpectedResponseHandler var unknownResponses = new List (); diff --git a/UnitTests/View/Keyboard/KeyboardEventTests.cs b/UnitTests/View/Keyboard/KeyboardEventTests.cs index 12cffb9a73..fa842d50fc 100644 --- a/UnitTests/View/Keyboard/KeyboardEventTests.cs +++ b/UnitTests/View/Keyboard/KeyboardEventTests.cs @@ -273,12 +273,12 @@ public void NewKeyUpEvent_KeyUp_Handled_True_Stops_Processing () [InlineData (null, null)] [InlineData (true, true)] [InlineData (false, false)] - public void InvokeCommandsBoundToKey_Returns_Nullable_Properly (bool? toReturn, bool? expected) + public void InvokeCommands_Returns_Nullable_Properly (bool? toReturn, bool? expected) { var view = new KeyBindingsTestView (); view.CommandReturns = toReturn; - bool? result = view.InvokeCommandsBoundToKey (Key.A); + bool? result = view.InvokeCommands (Key.A); Assert.Equal (expected, result); } diff --git a/UnitTests/View/ViewCommandTests.cs b/UnitTests/View/ViewCommandTests.cs index 3f4e89e2ed..ff42af6525 100644 --- a/UnitTests/View/ViewCommandTests.cs +++ b/UnitTests/View/ViewCommandTests.cs @@ -1,12 +1,9 @@ -using System.ComponentModel; -using System.Text; -using Xunit.Abstractions; - namespace Terminal.Gui.ViewTests; -public class ViewCommandTests (ITestOutputHelper output) +public class ViewCommandTests { #region OnAccept/Accept tests + [Fact] public void Accept_Command_Raises_NoFocus () { @@ -77,8 +74,8 @@ public void Accept_Command_Invokes_Accept_Event () [Fact] public void Accept_Command_Bubbles_Up_To_SuperView () { - var view = new ViewEventTester () { Id = "view" }; - var subview = new ViewEventTester () { Id = "subview" }; + var view = new ViewEventTester { Id = "view" }; + var subview = new ViewEventTester { Id = "subview" }; view.Add (subview); subview.InvokeCommand (Command.Accept); @@ -97,7 +94,7 @@ public void Accept_Command_Bubbles_Up_To_SuperView () Assert.Equal (1, view.OnAcceptedCount); // Add a super view to test deeper hierarchy - var superView = new ViewEventTester () { Id = "superView" }; + var superView = new ViewEventTester { Id = "superView" }; superView.Add (view); subview.InvokeCommand (Command.Accept); @@ -135,7 +132,7 @@ public void MouseClick_Does_Not_Invoke_Accept_Command () [CombinatorialData] public void Select_Command_Raises_SetsFocus (bool canFocus) { - var view = new ViewEventTester () + var view = new ViewEventTester { CanFocus = canFocus }; @@ -236,30 +233,29 @@ public ViewEventTester () CanFocus = true; Accepting += (s, a) => - { - a.Cancel = HandleAccepted; - AcceptedCount++; - }; + { + a.Cancel = HandleAccepted; + AcceptedCount++; + }; HandlingHotKey += (s, a) => - { - a.Cancel = HandleHandlingHotKey; - HandlingHotKeyCount++; - }; - + { + a.Cancel = HandleHandlingHotKey; + HandlingHotKeyCount++; + }; Selecting += (s, a) => - { - a.Cancel = HandleSelecting; - SelectingCount++; - }; + { + a.Cancel = HandleSelecting; + SelectingCount++; + }; } public int OnAcceptedCount { get; set; } public int AcceptedCount { get; set; } public bool HandleOnAccepted { get; set; } - /// + /// protected override bool OnAccepting (CommandEventArgs args) { OnAcceptedCount++; @@ -273,7 +269,7 @@ protected override bool OnAccepting (CommandEventArgs args) public int HandlingHotKeyCount { get; set; } public bool HandleOnHandlingHotKey { get; set; } - /// + /// protected override bool OnHandlingHotKey (CommandEventArgs args) { OnHandlingHotKeyCount++; @@ -283,12 +279,11 @@ protected override bool OnHandlingHotKey (CommandEventArgs args) public bool HandleHandlingHotKey { get; set; } - public int OnSelectingCount { get; set; } public int SelectingCount { get; set; } public bool HandleOnSelecting { get; set; } - /// + /// protected override bool OnSelecting (CommandEventArgs args) { OnSelectingCount++; @@ -297,6 +292,5 @@ protected override bool OnSelecting (CommandEventArgs args) } public bool HandleSelecting { get; set; } - } }