|
@@ -1,11 +1,64 @@
|
|
#nullable enable
|
|
#nullable enable
|
|
using System.Text.Json.Serialization;
|
|
using System.Text.Json.Serialization;
|
|
-using static System.Formats.Asn1.AsnWriter;
|
|
|
|
|
|
|
|
namespace Terminal.Gui;
|
|
namespace Terminal.Gui;
|
|
|
|
|
|
public static partial class Application // Keyboard handling
|
|
public static partial class Application // Keyboard handling
|
|
{
|
|
{
|
|
|
|
+ private static Key _nextTabKey = Key.Empty; // Defined in config.json
|
|
|
|
+
|
|
|
|
+ /// <summary>Alternative key to navigate forwards through views. Ctrl+Tab is the primary key.</summary>
|
|
|
|
+ [SerializableConfigurationProperty (Scope = typeof (SettingsScope))]
|
|
|
|
+ [JsonConverter (typeof (KeyJsonConverter))]
|
|
|
|
+ public static Key NextTabKey
|
|
|
|
+ {
|
|
|
|
+ get => _nextTabKey;
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ if (_nextTabKey != value)
|
|
|
|
+ {
|
|
|
|
+ Key oldKey = _nextTabKey;
|
|
|
|
+ _nextTabKey = value;
|
|
|
|
+
|
|
|
|
+ if (_nextTabKey == Key.Empty)
|
|
|
|
+ {
|
|
|
|
+ KeyBindings.Remove (_nextTabKey);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ KeyBindings.ReplaceKey (oldKey, _nextTabKey);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static Key _prevTabKey = Key.Empty; // Defined in config.json
|
|
|
|
+
|
|
|
|
+ /// <summary>Alternative key to navigate backwards through views. Shift+Ctrl+Tab is the primary key.</summary>
|
|
|
|
+ [SerializableConfigurationProperty (Scope = typeof (SettingsScope))]
|
|
|
|
+ [JsonConverter (typeof (KeyJsonConverter))]
|
|
|
|
+ public static Key PrevTabKey
|
|
|
|
+ {
|
|
|
|
+ get => _prevTabKey;
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ if (_prevTabKey != value)
|
|
|
|
+ {
|
|
|
|
+ Key oldKey = _prevTabKey;
|
|
|
|
+ _prevTabKey = value;
|
|
|
|
+
|
|
|
|
+ if (_prevTabKey == Key.Empty)
|
|
|
|
+ {
|
|
|
|
+ KeyBindings.Remove (_prevTabKey);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ KeyBindings.ReplaceKey (oldKey, _prevTabKey);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private static Key _nextTabGroupKey = Key.Empty; // Defined in config.json
|
|
private static Key _nextTabGroupKey = Key.Empty; // Defined in config.json
|
|
|
|
|
|
/// <summary>Alternative key to navigate forwards through views. Ctrl+Tab is the primary key.</summary>
|
|
/// <summary>Alternative key to navigate forwards through views. Ctrl+Tab is the primary key.</summary>
|
|
@@ -74,6 +127,7 @@ public static partial class Application // Keyboard handling
|
|
{
|
|
{
|
|
Key oldKey = _quitKey;
|
|
Key oldKey = _quitKey;
|
|
_quitKey = value;
|
|
_quitKey = value;
|
|
|
|
+
|
|
if (_quitKey == Key.Empty)
|
|
if (_quitKey == Key.Empty)
|
|
{
|
|
{
|
|
KeyBindings.Remove (_quitKey);
|
|
KeyBindings.Remove (_quitKey);
|
|
@@ -139,7 +193,7 @@ public static partial class Application // Keyboard handling
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (Application.Current.NewKeyDownEvent (keyEvent))
|
|
|
|
|
|
+ if (Current.NewKeyDownEvent (keyEvent))
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -147,7 +201,7 @@ public static partial class Application // Keyboard handling
|
|
|
|
|
|
// Invoke any Application-scoped KeyBindings.
|
|
// Invoke any Application-scoped KeyBindings.
|
|
// The first view that handles the key will stop the loop.
|
|
// The first view that handles the key will stop the loop.
|
|
- foreach (var binding in KeyBindings.Bindings.Where (b => b.Key == keyEvent.KeyCode))
|
|
|
|
|
|
+ foreach (KeyValuePair<Key, KeyBinding> binding in KeyBindings.Bindings.Where (b => b.Key == keyEvent.KeyCode))
|
|
{
|
|
{
|
|
if (binding.Value.BoundView is { })
|
|
if (binding.Value.BoundView is { })
|
|
{
|
|
{
|
|
@@ -193,7 +247,6 @@ public static partial class Application // Keyboard handling
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -252,13 +305,13 @@ public static partial class Application // Keyboard handling
|
|
public static KeyBindings KeyBindings { get; internal set; } = new ();
|
|
public static KeyBindings KeyBindings { get; internal set; } = new ();
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Commands for Application.
|
|
|
|
|
|
+ /// Commands for Application.
|
|
/// </summary>
|
|
/// </summary>
|
|
private static Dictionary<Command, Func<CommandContext, bool?>> CommandImplementations { get; set; }
|
|
private static Dictionary<Command, Func<CommandContext, bool?>> CommandImplementations { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// <para>
|
|
/// <para>
|
|
- /// Sets the function that will be invoked for a <see cref="Command"/>.
|
|
|
|
|
|
+ /// Sets the function that will be invoked for a <see cref="Command"/>.
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
/// If AddCommand has already been called for <paramref name="command"/> <paramref name="f"/> will
|
|
/// If AddCommand has already been called for <paramref name="command"/> <paramref name="f"/> will
|
|
@@ -266,28 +319,23 @@ public static partial class Application // Keyboard handling
|
|
/// </para>
|
|
/// </para>
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <remarks>
|
|
- /// <para>
|
|
|
|
- /// This version of AddCommand is for commands that do not require a <see cref="CommandContext"/>.
|
|
|
|
- /// </para>
|
|
|
|
|
|
+ /// <para>
|
|
|
|
+ /// This version of AddCommand is for commands that do not require a <see cref="CommandContext"/>.
|
|
|
|
+ /// </para>
|
|
/// </remarks>
|
|
/// </remarks>
|
|
/// <param name="command">The command.</param>
|
|
/// <param name="command">The command.</param>
|
|
/// <param name="f">The function.</param>
|
|
/// <param name="f">The function.</param>
|
|
- private static void AddCommand (Command command, Func<bool?> f)
|
|
|
|
- {
|
|
|
|
- CommandImplementations [command] = ctx => f ();
|
|
|
|
- }
|
|
|
|
|
|
+ private static void AddCommand (Command command, Func<bool?> f) { CommandImplementations [command] = ctx => f (); }
|
|
|
|
|
|
- static Application ()
|
|
|
|
- {
|
|
|
|
- AddApplicationKeyBindings();
|
|
|
|
- }
|
|
|
|
|
|
+ static Application () { AddApplicationKeyBindings (); }
|
|
|
|
|
|
internal static void AddApplicationKeyBindings ()
|
|
internal static void AddApplicationKeyBindings ()
|
|
{
|
|
{
|
|
- CommandImplementations = new Dictionary<Command, Func<CommandContext, bool?>> ();
|
|
|
|
|
|
+ CommandImplementations = new ();
|
|
|
|
+
|
|
// Things this view knows how to do
|
|
// Things this view knows how to do
|
|
AddCommand (
|
|
AddCommand (
|
|
- Command.QuitToplevel, // TODO: IRunnable: Rename to Command.Quit to make more generic.
|
|
|
|
|
|
+ Command.QuitToplevel, // TODO: IRunnable: Rename to Command.Quit to make more generic.
|
|
() =>
|
|
() =>
|
|
{
|
|
{
|
|
if (ApplicationOverlapped.OverlappedTop is { })
|
|
if (ApplicationOverlapped.OverlappedTop is { })
|
|
@@ -296,7 +344,7 @@ public static partial class Application // Keyboard handling
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- Application.RequestStop ();
|
|
|
|
|
|
+ RequestStop ();
|
|
}
|
|
}
|
|
|
|
|
|
return true;
|
|
return true;
|
|
@@ -363,24 +411,24 @@ public static partial class Application // Keyboard handling
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
-
|
|
|
|
KeyBindings.Clear ();
|
|
KeyBindings.Clear ();
|
|
|
|
|
|
- KeyBindings.Add (Application.QuitKey, KeyBindingScope.Application, Command.QuitToplevel);
|
|
|
|
|
|
+ KeyBindings.Add (QuitKey, KeyBindingScope.Application, Command.QuitToplevel);
|
|
|
|
|
|
KeyBindings.Add (Key.CursorRight, KeyBindingScope.Application, Command.NextView);
|
|
KeyBindings.Add (Key.CursorRight, KeyBindingScope.Application, Command.NextView);
|
|
KeyBindings.Add (Key.CursorDown, KeyBindingScope.Application, Command.NextView);
|
|
KeyBindings.Add (Key.CursorDown, KeyBindingScope.Application, Command.NextView);
|
|
KeyBindings.Add (Key.CursorLeft, KeyBindingScope.Application, Command.PreviousView);
|
|
KeyBindings.Add (Key.CursorLeft, KeyBindingScope.Application, Command.PreviousView);
|
|
KeyBindings.Add (Key.CursorUp, KeyBindingScope.Application, Command.PreviousView);
|
|
KeyBindings.Add (Key.CursorUp, KeyBindingScope.Application, Command.PreviousView);
|
|
- KeyBindings.Add (Key.Tab, KeyBindingScope.Application, Command.NextView);
|
|
|
|
- KeyBindings.Add (Key.Tab.WithShift, KeyBindingScope.Application, Command.PreviousView);
|
|
|
|
|
|
+ KeyBindings.Add (NextTabKey, KeyBindingScope.Application, Command.NextView);
|
|
|
|
+ KeyBindings.Add (PrevTabKey, KeyBindingScope.Application, Command.PreviousView);
|
|
|
|
|
|
- KeyBindings.Add (Application.NextTabGroupKey, KeyBindingScope.Application, Command.NextViewOrTop); // Needed on Unix
|
|
|
|
- KeyBindings.Add (Application.PrevTabGroupKey, KeyBindingScope.Application, Command.PreviousViewOrTop); // Needed on Unix
|
|
|
|
|
|
+ KeyBindings.Add (NextTabGroupKey, KeyBindingScope.Application, Command.NextViewOrTop); // Needed on Unix
|
|
|
|
+ KeyBindings.Add (PrevTabGroupKey, KeyBindingScope.Application, Command.PreviousViewOrTop); // Needed on Unix
|
|
|
|
|
|
// TODO: Refresh Key should be configurable
|
|
// TODO: Refresh Key should be configurable
|
|
KeyBindings.Add (Key.F5, KeyBindingScope.Application, Command.Refresh);
|
|
KeyBindings.Add (Key.F5, KeyBindingScope.Application, Command.Refresh);
|
|
|
|
|
|
|
|
+ // TODO: Suspend Key should be configurable
|
|
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
|
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
|
{
|
|
{
|
|
KeyBindings.Add (Key.Z.WithCtrl, KeyBindingScope.Application, Command.Suspend);
|
|
KeyBindings.Add (Key.Z.WithCtrl, KeyBindingScope.Application, Command.Suspend);
|
|
@@ -431,10 +479,10 @@ public static partial class Application // Keyboard handling
|
|
/// <param name="view">The view that is bound to the key.</param>
|
|
/// <param name="view">The view that is bound to the key.</param>
|
|
internal static void RemoveKeyBindings (View view)
|
|
internal static void RemoveKeyBindings (View view)
|
|
{
|
|
{
|
|
- var list = KeyBindings.Bindings
|
|
|
|
- .Where (kv => kv.Value.Scope != KeyBindingScope.Application)
|
|
|
|
- .Select (kv => kv.Value)
|
|
|
|
- .Distinct ()
|
|
|
|
- .ToList ();
|
|
|
|
|
|
+ List<KeyBinding> list = KeyBindings.Bindings
|
|
|
|
+ .Where (kv => kv.Value.Scope != KeyBindingScope.Application)
|
|
|
|
+ .Select (kv => kv.Value)
|
|
|
|
+ .Distinct ()
|
|
|
|
+ .ToList ();
|
|
}
|
|
}
|
|
}
|
|
}
|