From bb7e4282a428e81417243c60cfacc8b48820552a Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 7 Oct 2024 08:37:46 -0400 Subject: [PATCH] HotKeyHandled->HandlingHotKey --- Terminal.Gui/Input/Command.cs | 2 +- Terminal.Gui/View/View.Command.cs | 24 ++++++++++++------------ Terminal.Gui/Views/Label.cs | 2 +- Terminal.Gui/Views/RadioGroup.cs | 2 +- UnitTests/View/HotKeyTests.cs | 2 +- UnitTests/View/ViewCommandTests.cs | 20 ++++++++++---------- UnitTests/Views/AllViewsTests.cs | 4 ++-- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Terminal.Gui/Input/Command.cs b/Terminal.Gui/Input/Command.cs index 8b169c718..270d7a3f4 100644 --- a/Terminal.Gui/Input/Command.cs +++ b/Terminal.Gui/Input/Command.cs @@ -26,7 +26,7 @@ public enum Command /// Performs a hot key action (e.g. setting focus, accepting, and/or moving focus to the next View). /// /// The default implementation in calls and then - /// . + /// . /// /// HotKey, diff --git a/Terminal.Gui/View/View.Command.cs b/Terminal.Gui/View/View.Command.cs index 4d0c3a9af..dbd689216 100644 --- a/Terminal.Gui/View/View.Command.cs +++ b/Terminal.Gui/View/View.Command.cs @@ -15,11 +15,11 @@ public partial class View // Command APIs // Enter - Raise Accepted AddCommand (Command.Accept, RaiseAccepted); - // HotKey - SetFocus and raise HotKeyHandled + // HotKey - SetFocus and raise HandlingHotKey AddCommand (Command.HotKey, () => { - if (RaiseHotKeyHandled () is true) + if (RaiseHandlingHotKey () is true) { return true; } @@ -157,44 +157,44 @@ public partial class View // Command APIs // TODO: What does this event really do? "Called when the user has pressed the View's hot key or otherwise invoked the View's hot key command.???" /// - /// Called when the View has handled the user pressing the View's . Calls which can be cancelled; if not cancelled raises . + /// Called when the View is handlingthe user pressing the View's s. Calls which can be cancelled; if not cancelled raises . /// event. The default handler calls this method. /// /// /// If the event was handled. If the event was raised but not handled. /// If no event was raised. /// - protected bool? RaiseHotKeyHandled () + protected bool? RaiseHandlingHotKey () { - HandledEventArgs args = new (); + CommandEventArgs args = new (); // Best practice is to invoke the virtual method first. // This allows derived classes to handle the event and potentially cancel it. - if (OnHotKeyHandled (args) || args.Handled) + if (OnHandlingHotKey (args) || args.Cancel) { return true; } // If the event is not canceled by the virtual method, raise the event to notify any external subscribers. - HotKeyHandled?.Invoke (this, args); + HandlingHotKey?.Invoke (this, args); - return HotKeyHandled is null ? null : args.Handled; + return HandlingHotKey is null ? null : args.Cancel; } /// - /// Called when the View has handled the user pressing the View's . Set to + /// Called when the View has handled the user pressing the View's . Set to /// to stop processing. /// /// /// to stop processing. - protected virtual bool OnHotKeyHandled (HandledEventArgs args) { return false; } + protected virtual bool OnHandlingHotKey (CommandEventArgs args) { return false; } /// /// Cancelable event raised when the command is invoked. Set - /// + /// /// to cancel the event. /// - public event EventHandler? HotKeyHandled; + public event EventHandler? HandlingHotKey; #endregion Default Implementation diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 7ec7f8c87..3a76a8a71 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -62,7 +62,7 @@ public class Label : View, IDesignable private bool? InvokeHotKeyOnNext (CommandContext context) { - if (RaiseHotKeyHandled () == true) + if (RaiseHandlingHotKey () == true) { return true; } diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 121a4024a..f01dd2ead 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -100,7 +100,7 @@ public class RadioGroup : View, IDesignable, IOrientation return false; } - if (RaiseHotKeyHandled () == true) + if (RaiseHandlingHotKey () == true) { return true; }; diff --git a/UnitTests/View/HotKeyTests.cs b/UnitTests/View/HotKeyTests.cs index 3335276d4..778078399 100644 --- a/UnitTests/View/HotKeyTests.cs +++ b/UnitTests/View/HotKeyTests.cs @@ -357,7 +357,7 @@ public class HotKeyTests Title = "_Test" }; Application.Top.Add (view); - view.HotKeyHandled += (s, e) => hotKeyRaised = true; + view.HandlingHotKey += (s, e) => hotKeyRaised = true; view.Accepted += (s, e) => acceptRaised = true; view.Selecting += (s, e) => selectRaised = true; diff --git a/UnitTests/View/ViewCommandTests.cs b/UnitTests/View/ViewCommandTests.cs index e1176b097..49dd62f93 100644 --- a/UnitTests/View/ViewCommandTests.cs +++ b/UnitTests/View/ViewCommandTests.cs @@ -241,10 +241,10 @@ public class ViewCommandTests (ITestOutputHelper output) AcceptedCount++; }; - HotKeyHandled += (s, a) => + HandlingHotKey += (s, a) => { - a.Handled = HandleHotKeyHandled; - HotKeyHandledCount++; + a.Cancel = HandleHandlingHotKey; + HandlingHotKeyCount++; }; @@ -269,19 +269,19 @@ public class ViewCommandTests (ITestOutputHelper output) public bool HandleAccepted { get; set; } - public int OnHotKeyHandledCount { get; set; } - public int HotKeyHandledCount { get; set; } - public bool HandleOnHotKeyHandled { get; set; } + public int OnHandlingHotKeyCount { get; set; } + public int HandlingHotKeyCount { get; set; } + public bool HandleOnHandlingHotKey { get; set; } /// - protected override bool OnHotKeyHandled (HandledEventArgs args) + protected override bool OnHandlingHotKey (CommandEventArgs args) { - OnHotKeyHandledCount++; + OnHandlingHotKeyCount++; - return HandleOnHotKeyHandled; + return HandleOnHandlingHotKey; } - public bool HandleHotKeyHandled { get; set; } + public bool HandleHandlingHotKey { get; set; } public int OnSelectingCount { get; set; } diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index f568d2b0d..639c74f28 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -168,7 +168,7 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews [Theory] [MemberData (nameof (AllViewTypes))] - public void AllViews_Command_HotKey_Raises_HotKeyHandled (Type viewType) + public void AllViews_Command_HotKey_Raises_HandlingHotKey (Type viewType) { var view = (View)CreateInstanceIfNotGeneric (viewType); @@ -198,7 +198,7 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews }; var hotkeyHandledCount = 0; - view.HotKeyHandled += (s, e) => + view.HandlingHotKey += (s, e) => { hotkeyHandledCount++; };