mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
New branch to correct merge problem
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user