New branch to correct merge problem

This commit is contained in:
Tig
2024-06-07 18:41:31 -06:00
parent e09f394155
commit 7213588973
14 changed files with 1721 additions and 397 deletions

View File

@@ -4,8 +4,15 @@ namespace Terminal.Gui;
public partial class View
{
private void AddCommands ()
/// <summary>
/// Helper to configure all things keyboard related for a View. Called from the View constructor.
/// </summary>
private void SetupKeyboard ()
{
KeyBindings = new (this);
HotKeySpecifier = (Rune)'_';
TitleTextFormatter.HotKeyChanged += TitleTextFormatter_HotKeyChanged;
// By default, the HotKey command sets the focus
AddCommand (Command.HotKey, OnHotKey);
@@ -13,6 +20,15 @@ public partial class View
AddCommand (Command.Accept, OnAccept);
}
/// <summary>
/// Helper to dispose all things keyboard related for a View. Called from the View Dispose method.
/// </summary>
private void DisposeKeyboard ()
{
TitleTextFormatter.HotKeyChanged -= TitleTextFormatter_HotKeyChanged;
KeyBindings.Clear ();
}
#region HotKey Support
/// <summary>
@@ -601,7 +617,7 @@ public partial class View
#region Key Bindings
/// <summary>Gets the key bindings for this view.</summary>
public KeyBindings KeyBindings { get; } = new ();
public KeyBindings KeyBindings { get; internal set; }
private Dictionary<Command, Func<bool?>> CommandImplementations { get; } = new ();
@@ -704,6 +720,30 @@ public partial class View
return false;
}
// Function to search the subview hierarchy for the first view that has a KeyBindingScope.Application binding for the key.
// Called from Application.OnKeyDown
// TODO: Unwind recursion
// QUESTION: Should this return a list of views? As is, it will only return the first view that has the binding.
internal static View FindViewWithApplicationKeyBinding (View start, Key keyEvent)
{
if (start.KeyBindings.TryGet (keyEvent, KeyBindingScope.Application, out KeyBinding binding))
{
return start;
}
foreach (View subview in start.Subviews)
{
View found = FindViewWithApplicationKeyBinding (subview, keyEvent);
if (found is { })
{
return found;
}
}
return null;
}
/// <summary>
/// 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.