diff --git a/Terminal.Gui/Input/InputBindings.cs b/Terminal.Gui/Input/InputBindings.cs index ec970a4df..3812cdfd4 100644 --- a/Terminal.Gui/Input/InputBindings.cs +++ b/Terminal.Gui/Input/InputBindings.cs @@ -2,7 +2,7 @@ namespace Terminal.Gui; /// -/// Abstract base class for and . +/// Abstract class for and . /// /// The type of the event (e.g. or ). /// The binding type (e.g. ). @@ -136,7 +136,7 @@ public abstract class InputBindings where TBinding : IInputBin public bool TryGet (TEvent eventArgs, out TBinding? binding) { return _bindings.TryGetValue (eventArgs, out binding); } /// Gets the array of s bound to if it exists. - /// The key to check. + /// The to check. /// /// The array of s if is bound. An empty array /// if not. diff --git a/Terminal.Gui/View/View.Keyboard.cs b/Terminal.Gui/View/View.Keyboard.cs index 700729509..cc21f6203 100644 --- a/Terminal.Gui/View/View.Keyboard.cs +++ b/Terminal.Gui/View/View.Keyboard.cs @@ -1,7 +1,4 @@ #nullable enable -using System.Diagnostics; -using System.Reflection.Metadata; - namespace Terminal.Gui; public partial class View // Keyboard APIs @@ -188,7 +185,7 @@ public partial class View // Keyboard APIs { Commands = [Command.HotKey], Key = newKey, - Data = context, + Data = context }; // Add the base and Alt key @@ -263,7 +260,8 @@ public partial class View // Keyboard APIs /// /// If a more focused subview does not handle the key press, this method raises / /// to allow the - /// view to pre-process the key press. If / is not handled any commands bound to the key will be invoked. + /// view to pre-process the key press. If / is not handled any commands + /// bound to the key will be invoked. /// Then, only if no key bindings are /// handled, / will be raised allowing the view to /// process the key press. @@ -305,6 +303,7 @@ public partial class View // Keyboard APIs } bool? handled = false; + if (InvokeCommandsBoundToHotKey (key, ref handled)) { return true; @@ -588,17 +587,20 @@ public partial class View // Keyboard APIs // BUGBUG: This will miss any hotkeys in subviews of Adornments. /// - /// Invokes any commands bound to on this view and subviews. + /// Invokes any commands bound to on this view and subviews. /// - /// + /// /// /// - internal bool InvokeCommandsBoundToHotKey (Key key, ref bool? handled) + internal bool InvokeCommandsBoundToHotKey (Key hotKey, ref bool? handled) { - bool? weHandled = InvokeCommandsBoundToHotKey (key); - if (weHandled is true) + // Process this View + if (HotKeyBindings.TryGet (hotKey, out KeyBinding binding)) { - return true; + if (InvokeCommands (binding.Commands, binding) is true) + { + return true; + } } // Now, process any HotKey bindings in the subviews @@ -609,7 +611,7 @@ public partial class View // Keyboard APIs continue; } - bool recurse = subview.InvokeCommandsBoundToHotKey (key, ref handled); + bool recurse = subview.InvokeCommandsBoundToHotKey (hotKey, ref handled); if (recurse || (handled is { } && (bool)handled)) { @@ -620,38 +622,6 @@ public partial class View // Keyboard APIs return false; } - // TODO: This is a "prototype" debug check. It may be too annoying vs. useful. - // TODO: A better approach would be to have Application hold a list of bound Hotkeys, similar to - // TODO: how Application holds a list of Application Scoped key bindings and then check that list. - /// - /// Returns true if Key is bound in this view hierarchy. For debugging - /// - /// The key to test. - /// Returns the view the key is bound to. - /// - public bool IsHotKeyBound (Key key, out View? boundView) - { - // recurse through the subviews to find the views that has the key bound - boundView = null; - - foreach (View subview in Subviews) - { - if (subview.HotKeyBindings.TryGet (key, out _)) - { - boundView = subview; - - return true; - } - - if (subview.IsHotKeyBound (key, out boundView)) - { - return true; - } - } - - return false; - } - /// /// Invokes the Commands bound to . /// See for an overview of Terminal.Gui keyboard APIs. @@ -671,27 +641,9 @@ public partial class View // Keyboard APIs return null; } -#if DEBUG - - //if (Application.KeyBindings.TryGet (key, out KeyBinding b)) - //{ - // Debug.WriteLine ( - // $"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command."); - //} - - // TODO: This is a "prototype" debug check. It may be too annoying vs. useful. - // Scour the bindings up our View hierarchy - // to ensure that the key is not already bound to a different set of commands. - if (SuperView?.IsHotKeyBound (key, out View? previouslyBoundView) ?? false) - { - Debug.WriteLine ($"WARNING: InvokeKeyBindings ({key}) - A subview or peer has bound this Key and will not see it: {previouslyBoundView}."); - } - -#endif - return InvokeCommands (binding.Commands, binding); + return InvokeCommands (binding.Commands, binding); } - /// /// Invokes the Commands bound to . /// See for an overview of Terminal.Gui keyboard APIs. @@ -711,24 +663,7 @@ public partial class View // Keyboard APIs return null; } -//#if DEBUG - -// //if (Application.KeyBindings.TryGet (key, out KeyBinding b)) -// //{ -// // Debug.WriteLine ( -// // $"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command."); -// //} - -// // TODO: This is a "prototype" debug check. It may be too annoying vs. useful. -// // Scour the bindings up our View hierarchy -// // to ensure that the key is not already bound to a different set of commands. -// if (SuperView?.IsHotKeyBound (hotKey, out View? previouslyBoundView) ?? false) -// { -// Debug.WriteLine ($"WARNING: InvokeKeyBindings ({hotKey}) - A subview or peer has bound this Key and will not see it: {previouslyBoundView}."); -// } - -//#endif - return InvokeCommands (binding.Commands, binding); + return InvokeCommands (binding.Commands, binding); } #endregion Key Bindings diff --git a/Terminal.Gui/View/View.Mouse.cs b/Terminal.Gui/View/View.Mouse.cs index 03cb167c4..41f68a320 100644 --- a/Terminal.Gui/View/View.Mouse.cs +++ b/Terminal.Gui/View/View.Mouse.cs @@ -1,6 +1,5 @@ #nullable enable using System.ComponentModel; -using System.Diagnostics; namespace Terminal.Gui; @@ -21,7 +20,6 @@ public partial class View // Mouse APIs MouseBindings.Add (MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl, Command.Select); } - /// /// Invokes the Commands bound to the MouseFlags specified by . /// See for an overview of Terminal.Gui mouse APIs. @@ -43,7 +41,7 @@ public partial class View // Mouse APIs binding.MouseEventArgs = mouseEventArgs; - return InvokeCommands (binding.Commands, binding); + return InvokeCommands (binding.Commands, binding); } #region MouseEnterLeave @@ -52,7 +50,8 @@ public partial class View // Mouse APIs private ColorScheme? _savedNonHoverColorScheme; /// - /// INTERNAL Called by when the mouse moves over the View's . + /// INTERNAL Called by when the mouse moves over the View's + /// . /// will /// be raised when the mouse is no longer over the . If another View occludes this View, the /// that View will also receive MouseEnter/Leave events. @@ -167,7 +166,8 @@ public partial class View // Mouse APIs public event EventHandler? MouseEnter; /// - /// INTERNAL Called by when the mouse leaves , or is occluded + /// INTERNAL Called by when the mouse leaves , or is + /// occluded /// by another non-SubView. /// /// @@ -245,7 +245,8 @@ public partial class View // Mouse APIs public bool WantMousePositionReports { get; set; } /// - /// Processes a new . This method is called by when a mouse + /// Processes a new . This method is called by when a + /// mouse /// event occurs. /// /// @@ -260,8 +261,10 @@ public partial class View // Mouse APIs /// See for more information. /// /// - /// If is , the / event - /// will be raised on any new mouse event where indicates a button is pressed. + /// If is , the / + /// event + /// will be raised on any new mouse event where indicates a button + /// is pressed. /// /// /// @@ -332,7 +335,7 @@ public partial class View // Mouse APIs /// , if the event was handled, otherwise. public bool RaiseMouseEvent (MouseEventArgs mouseEvent) { - if (OnMouseEvent (mouseEvent) || mouseEvent.Handled == true) + if (OnMouseEvent (mouseEvent) || mouseEvent.Handled) { return true; } @@ -350,10 +353,7 @@ public partial class View // Mouse APIs /// /// /// , if the event was handled, otherwise. - protected virtual bool OnMouseEvent (MouseEventArgs mouseEvent) - { - return false; - } + protected virtual bool OnMouseEvent (MouseEventArgs mouseEvent) { return false; } /// Raised when a mouse event occurs. /// @@ -368,7 +368,8 @@ public partial class View // Mouse APIs #region Mouse Pressed Events /// - /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically + /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the released event + /// (typically /// when or are set). /// /// @@ -394,7 +395,8 @@ public partial class View // Mouse APIs } /// - /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically + /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the released event + /// (typically /// when or are set). /// /// @@ -463,7 +465,8 @@ public partial class View // Mouse APIs /// Called when the mouse is either clicked or double-clicked. /// /// - /// If is , will be invoked on every mouse event where + /// If is , will be invoked on every mouse event + /// where /// the mouse button is pressed. /// /// @@ -507,7 +510,8 @@ public partial class View // Mouse APIs /// Called when the mouse is either clicked or double-clicked. /// /// - /// If is , will be called on every mouse event where + /// If is , will be called on every mouse event + /// where /// the mouse button is pressed. /// /// @@ -521,14 +525,16 @@ public partial class View // Mouse APIs /// Raised when the mouse is either clicked or double-clicked. /// /// - /// If is , will be raised on every mouse event where + /// If is , will be raised on every mouse event + /// where /// the mouse button is pressed. /// /// public event EventHandler? MouseClick; /// - /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically + /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the click event + /// (typically /// when or are set). /// /// @@ -562,10 +568,8 @@ public partial class View // Mouse APIs return false; } - #endregion Mouse Clicked Events - #region Mouse Wheel Events /// Raises the / event. @@ -601,7 +605,8 @@ public partial class View // Mouse APIs } /// - /// Called when a mouse wheel event occurs. Check to see which wheel was moved was clicked. + /// Called when a mouse wheel event occurs. Check to see which wheel was moved was + /// clicked. /// /// /// @@ -828,8 +833,5 @@ public partial class View // Mouse APIs return viewsUnderMouse; } - private void DisposeMouse () - { - - } + private void DisposeMouse () { } }