|
@@ -1,4 +1,5 @@
|
|
-using System.ComponentModel;
|
|
|
|
|
|
+#nullable enable
|
|
|
|
+using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
|
|
|
|
namespace Terminal.Gui;
|
|
namespace Terminal.Gui;
|
|
@@ -50,7 +51,7 @@ public partial class View // Keyboard APIs
|
|
public event EventHandler<KeyChangedEventArgs> HotKeyChanged;
|
|
public event EventHandler<KeyChangedEventArgs> HotKeyChanged;
|
|
|
|
|
|
private Key _hotKey = new ();
|
|
private Key _hotKey = new ();
|
|
- private void TitleTextFormatter_HotKeyChanged (object sender, KeyChangedEventArgs e) { HotKeyChanged?.Invoke (this, e); }
|
|
|
|
|
|
+ private void TitleTextFormatter_HotKeyChanged (object? sender, KeyChangedEventArgs e) { HotKeyChanged?.Invoke (this, e); }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets the hot key defined for this view. Pressing the hot key on the keyboard while this view has focus will
|
|
/// Gets or sets the hot key defined for this view. Pressing the hot key on the keyboard while this view has focus will
|
|
@@ -131,7 +132,7 @@ public partial class View // Keyboard APIs
|
|
/// <param name="context">Arbitrary context that can be associated with this key binding.</param>
|
|
/// <param name="context">Arbitrary context that can be associated with this key binding.</param>
|
|
/// <returns><see langword="true"/> if the HotKey bindings were added.</returns>
|
|
/// <returns><see langword="true"/> if the HotKey bindings were added.</returns>
|
|
/// <exception cref="ArgumentException"></exception>
|
|
/// <exception cref="ArgumentException"></exception>
|
|
- public virtual bool AddKeyBindingsForHotKey (Key prevHotKey, Key hotKey, [CanBeNull] object context = null)
|
|
|
|
|
|
+ public virtual bool AddKeyBindingsForHotKey (Key prevHotKey, Key hotKey, object? context = null)
|
|
{
|
|
{
|
|
if (_hotKey == hotKey)
|
|
if (_hotKey == hotKey)
|
|
{
|
|
{
|
|
@@ -657,7 +658,7 @@ public partial class View // Keyboard APIs
|
|
/// <param name="key">The key to test.</param>
|
|
/// <param name="key">The key to test.</param>
|
|
/// <param name="boundView">Returns the view the key is bound to.</param>
|
|
/// <param name="boundView">Returns the view the key is bound to.</param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public bool IsHotKeyKeyBound (Key key, out View boundView)
|
|
|
|
|
|
+ public bool IsHotKeyKeyBound (Key key, out View? boundView)
|
|
{
|
|
{
|
|
// recurse through the subviews to find the views that has the key bound
|
|
// recurse through the subviews to find the views that has the key bound
|
|
boundView = null;
|
|
boundView = null;
|
|
@@ -683,7 +684,7 @@ public partial class View // Keyboard APIs
|
|
/// Invoked when a key is pressed that may be mapped to a key binding. Set <see cref="Key.Handled"/> to true to
|
|
/// Invoked when a key is pressed that may be mapped to a key binding. Set <see cref="Key.Handled"/> to true to
|
|
/// stop the key from being processed by other views.
|
|
/// stop the key from being processed by other views.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public event EventHandler<Key> InvokingKeyBindings;
|
|
|
|
|
|
+ public event EventHandler<Key>? InvokingKeyBindings;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Invokes any binding that is registered on this <see cref="View"/> and matches the <paramref name="key"/>
|
|
/// Invokes any binding that is registered on this <see cref="View"/> and matches the <paramref name="key"/>
|
|
@@ -719,7 +720,7 @@ public partial class View // Keyboard APIs
|
|
// TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
|
|
// TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
|
|
// Scour the bindings up our View hierarchy
|
|
// Scour the bindings up our View hierarchy
|
|
// to ensure that the key is not already bound to a different set of commands.
|
|
// to ensure that the key is not already bound to a different set of commands.
|
|
- if (SuperView?.IsHotKeyKeyBound (key, out View previouslyBoundView) ?? false)
|
|
|
|
|
|
+ if (SuperView?.IsHotKeyKeyBound (key, out View? previouslyBoundView) ?? false)
|
|
{
|
|
{
|
|
Debug.WriteLine ($"WARNING: InvokeKeyBindings ({key}) - A subview or peer has bound this Key and will not see it: {previouslyBoundView}.");
|
|
Debug.WriteLine ($"WARNING: InvokeKeyBindings ({key}) - A subview or peer has bound this Key and will not see it: {previouslyBoundView}.");
|
|
}
|
|
}
|
|
@@ -763,7 +764,7 @@ public partial class View // Keyboard APIs
|
|
/// <see langword="true"/> if the command was invoked the command was handled.
|
|
/// <see langword="true"/> if the command was invoked the command was handled.
|
|
/// <see langword="false"/> if the command was invoked and the command was not handled.
|
|
/// <see langword="false"/> if the command was invoked and the command was not handled.
|
|
/// </returns>
|
|
/// </returns>
|
|
- public bool? InvokeCommands (Command [] commands, [CanBeNull] Key key = null, [CanBeNull] KeyBinding? keyBinding = null)
|
|
|
|
|
|
+ public bool? InvokeCommands (Command [] commands, Key? key = null, KeyBinding? keyBinding = null)
|
|
{
|
|
{
|
|
bool? toReturn = null;
|
|
bool? toReturn = null;
|
|
|
|
|
|
@@ -798,9 +799,9 @@ public partial class View // Keyboard APIs
|
|
/// <see langword="null"/> if no command was found. <see langword="true"/> if the command was invoked, and it
|
|
/// <see langword="null"/> if no command was found. <see langword="true"/> if the command was invoked, and it
|
|
/// handled the command. <see langword="false"/> if the command was invoked, and it did not handle the command.
|
|
/// handled the command. <see langword="false"/> if the command was invoked, and it did not handle the command.
|
|
/// </returns>
|
|
/// </returns>
|
|
- public bool? InvokeCommand (Command command, [CanBeNull] Key key = null, [CanBeNull] KeyBinding? keyBinding = null)
|
|
|
|
|
|
+ public bool? InvokeCommand (Command command, Key? key = null, KeyBinding? keyBinding = null)
|
|
{
|
|
{
|
|
- if (CommandImplementations.TryGetValue (command, out Func<CommandContext, bool?> implementation))
|
|
|
|
|
|
+ if (CommandImplementations.TryGetValue (command, out Func<CommandContext, bool?>? implementation))
|
|
{
|
|
{
|
|
var context = new CommandContext (command, key, keyBinding); // Create the context here
|
|
var context = new CommandContext (command, key, keyBinding); // Create the context here
|
|
return implementation (context);
|
|
return implementation (context);
|