mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
HotKeyHandled->HandlingHotKey
This commit is contained in:
@@ -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).
|
||||
/// <para>
|
||||
/// The default implementation in <see cref="View"/> calls <see cref="View.SetFocus"/> and then
|
||||
/// <see cref="View.RaiseHotKeyHandled"/>.
|
||||
/// <see cref="View.RaiseHandlingHotKey"/>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
HotKey,
|
||||
|
||||
@@ -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.???"
|
||||
/// <summary>
|
||||
/// Called when the View has handled the user pressing the View's <see cref="HotKey"/>. Calls <see cref="OnHotKeyHandled"/> which can be cancelled; if not cancelled raises <see cref="Accepted"/>.
|
||||
/// Called when the View is handlingthe user pressing the View's <see cref="HotKey"/>s. Calls <see cref="OnHandlingHotKey"/> which can be cancelled; if not cancelled raises <see cref="Accepted"/>.
|
||||
/// event. The default <see cref="Command.HotKey"/> handler calls this method.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// If <see langword="true"/> the event was handled. If <see langword="false"/> the event was raised but not handled.
|
||||
/// If <see langword="null"/> no event was raised.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the View has handled the user pressing the View's <see cref="HotKey"/>. Set <see cref="HandledEventArgs.Handled"/> to
|
||||
/// Called when the View has handled the user pressing the View's <see cref="HotKey"/>. Set <see cref="CommandEventArgs.Cancel"/> to
|
||||
/// <see langword="true"/> to stop processing.
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns><see langword="true"/> to stop processing.</returns>
|
||||
protected virtual bool OnHotKeyHandled (HandledEventArgs args) { return false; }
|
||||
protected virtual bool OnHandlingHotKey (CommandEventArgs args) { return false; }
|
||||
|
||||
/// <summary>
|
||||
/// Cancelable event raised when the <see cref="Command.HotKey"/> command is invoked. Set
|
||||
/// <see cref="HandledEventArgs.Handled"/>
|
||||
/// <see cref="CommandEventArgs.Cancel"/>
|
||||
/// to cancel the event.
|
||||
/// </summary>
|
||||
public event EventHandler<HandledEventArgs>? HotKeyHandled;
|
||||
public event EventHandler<CommandEventArgs>? HandlingHotKey;
|
||||
|
||||
#endregion Default Implementation
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Label : View, IDesignable
|
||||
|
||||
private bool? InvokeHotKeyOnNext (CommandContext context)
|
||||
{
|
||||
if (RaiseHotKeyHandled () == true)
|
||||
if (RaiseHandlingHotKey () == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class RadioGroup : View, IDesignable, IOrientation
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RaiseHotKeyHandled () == true)
|
||||
if (RaiseHandlingHotKey () == true)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
/// <inheritdoc />
|
||||
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; }
|
||||
|
||||
@@ -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++;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user