Skip to content

Commit 5590c28

Browse files
authored
Merge branch 'v2_develop' into v2_3029-MouseEvents
2 parents e6fd635 + 23eb14c commit 5590c28

File tree

10 files changed

+43
-219
lines changed

10 files changed

+43
-219
lines changed

Terminal.Gui/Application/Application.Keyboard.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ public static partial class Application // Keyboard handling
55
{
66
/// <summary>
77
/// Called when the user presses a key (by the <see cref="ConsoleDriver"/>). Raises the cancelable
8-
/// <see cref="KeyDown"/> event
9-
/// then calls <see cref="View.NewKeyDownEvent"/> on all top level views. Called before <see cref="RaiseKeyUpEvent"/>.
8+
/// <see cref="KeyDown"/> event, then calls <see cref="View.NewKeyDownEvent"/> on all top level views, and finally
9+
/// if the key was not handled, invokes any Application-scoped <see cref="KeyBindings"/>.
1010
/// </summary>
1111
/// <remarks>Can be used to simulate key press events.</remarks>
12-
/// <param name="keyEvent"></param>
12+
/// <param name="key"></param>
1313
/// <returns><see langword="true"/> if the key was handled.</returns>
14-
public static bool RaiseKeyDownEvent (Key keyEvent)
14+
public static bool RaiseKeyDownEvent (Key key)
1515
{
16-
KeyDown?.Invoke (null, keyEvent);
16+
KeyDown?.Invoke (null, key);
1717

18-
if (keyEvent.Handled)
18+
if (key.Handled)
1919
{
2020
return true;
2121
}
@@ -24,7 +24,7 @@ public static bool RaiseKeyDownEvent (Key keyEvent)
2424
{
2525
foreach (Toplevel topLevel in TopLevels.ToList ())
2626
{
27-
if (topLevel.NewKeyDownEvent (keyEvent))
27+
if (topLevel.NewKeyDownEvent (key))
2828
{
2929
return true;
3030
}
@@ -37,15 +37,15 @@ public static bool RaiseKeyDownEvent (Key keyEvent)
3737
}
3838
else
3939
{
40-
if (Top.NewKeyDownEvent (keyEvent))
40+
if (Top.NewKeyDownEvent (key))
4141
{
4242
return true;
4343
}
4444
}
4545

4646
// Invoke any Application-scoped KeyBindings.
4747
// The first view that handles the key will stop the loop.
48-
foreach (KeyValuePair<Key, KeyBinding> binding in KeyBindings.Bindings.Where (b => b.Key == keyEvent.KeyCode))
48+
foreach (KeyValuePair<Key, KeyBinding> binding in KeyBindings.Bindings.Where (b => b.Key == key.KeyCode))
4949
{
5050
if (binding.Value.BoundView is { })
5151
{
@@ -58,7 +58,7 @@ public static bool RaiseKeyDownEvent (Key keyEvent)
5858
}
5959
else
6060
{
61-
if (!KeyBindings.TryGet (keyEvent, KeyBindingScope.Application, out KeyBinding appBinding))
61+
if (!KeyBindings.TryGet (key, KeyBindingScope.Application, out KeyBinding appBinding))
6262
{
6363
continue;
6464
}
@@ -67,7 +67,7 @@ public static bool RaiseKeyDownEvent (Key keyEvent)
6767

6868
foreach (Command command in appBinding.Commands)
6969
{
70-
toReturn = InvokeCommand (command, keyEvent, appBinding);
70+
toReturn = InvokeCommand (command, key, appBinding);
7171
}
7272

7373
return toReturn ?? true;
@@ -76,18 +76,18 @@ public static bool RaiseKeyDownEvent (Key keyEvent)
7676

7777
return false;
7878

79-
static bool? InvokeCommand (Command command, Key keyEvent, KeyBinding appBinding)
79+
static bool? InvokeCommand (Command command, Key key, KeyBinding appBinding)
8080
{
8181
if (!CommandImplementations!.ContainsKey (command))
8282
{
8383
throw new NotSupportedException (
84-
@$"A KeyBinding was set up for the command {command} ({keyEvent}) but that command is not supported by Application."
84+
@$"A KeyBinding was set up for the command {command} ({key}) but that command is not supported by Application."
8585
);
8686
}
8787

8888
if (CommandImplementations.TryGetValue (command, out View.CommandImplementation? implementation))
8989
{
90-
var context = new CommandContext (command, keyEvent, appBinding); // Create the context here
90+
var context = new CommandContext (command, key, appBinding); // Create the context here
9191

9292
return implementation (context);
9393
}
@@ -116,25 +116,25 @@ public static bool RaiseKeyDownEvent (Key keyEvent)
116116
/// then calls <see cref="View.NewKeyUpEvent"/> on all top level views. Called after <see cref="RaiseKeyDownEvent"/>.
117117
/// </summary>
118118
/// <remarks>Can be used to simulate key release events.</remarks>
119-
/// <param name="a"></param>
119+
/// <param name="key"></param>
120120
/// <returns><see langword="true"/> if the key was handled.</returns>
121-
public static bool RaiseKeyUpEvent (Key a)
121+
public static bool RaiseKeyUpEvent (Key key)
122122
{
123123
if (!IsInitialized)
124124
{
125125
return true;
126126
}
127127

128-
KeyUp?.Invoke (null, a);
128+
KeyUp?.Invoke (null, key);
129129

130-
if (a.Handled)
130+
if (key.Handled)
131131
{
132132
return true;
133133
}
134134

135135
foreach (Toplevel topLevel in TopLevels.ToList ())
136136
{
137-
if (topLevel.NewKeyUpEvent (a))
137+
if (topLevel.NewKeyUpEvent (key))
138138
{
139139
return true;
140140
}

Terminal.Gui/Input/ShortcutHelper.cs

Lines changed: 0 additions & 173 deletions
This file was deleted.

Terminal.Gui/View/View.Keyboard.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ public bool NewKeyDownEvent (Key key)
297297
}
298298

299299
// After
300-
// TODO: Is ProcessKeyDown really the right name?
301300
if (RaiseKeyDownNotHandled (key) || key.Handled)
302301
{
303302
return true;
@@ -426,7 +425,7 @@ bool RaiseKeyDownNotHandled (Key k)
426425
/// <para>
427426
/// If the focused sub view does not handle the key press, this method raises <see cref="OnKeyUp"/>/
428427
/// <see cref="KeyUp"/> to allow the
429-
/// view to pre-process the key press. If <see cref="OnKeyUp"/>/<see cref="KeyUp"/>.
428+
/// view to pre-process the key press.
430429
/// </para>
431430
/// <para>See <see href="../docs/keyboard.md">for an overview of Terminal.Gui keyboard APIs.</see></para>
432431
/// </remarks>

Terminal.Gui/Views/FileDialog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,11 @@ private void Accept (bool allowMulti)
670670
FinishAccept ();
671671
}
672672

673-
private void AcceptIf (Key keyEvent, KeyCode isKey)
673+
private void AcceptIf (Key key, KeyCode isKey)
674674
{
675-
if (!keyEvent.Handled && keyEvent.KeyCode == isKey)
675+
if (!key.Handled && key.KeyCode == isKey)
676676
{
677-
keyEvent.Handled = true;
677+
key.Handled = true;
678678

679679
// User hit Enter in text box so probably wants the
680680
// contents of the text box as their selection not

Terminal.Gui/Views/ListView.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ protected override void OnHasFocusChanged (bool newHasFocus, [CanBeNull] View cu
817817
}
818818
}
819819

820-
// TODO: This should be cancelable
821820
/// <summary>Invokes the <see cref="OpenSelectedItem"/> event if it is defined.</summary>
822821
/// <returns><see langword="true"/> if the <see cref="OpenSelectedItem"/> event was fired.</returns>
823822
public bool OnOpenSelectedItem ()

Terminal.Gui/Views/TableView/TableView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ private TableSelection CreateTableSelection (int pt1X, int pt1Y, int pt2X, int p
15631563
/// <returns></returns>
15641564
private TableSelection CreateTableSelection (int x, int y) { return CreateTableSelection (x, y, x, y); }
15651565

1566-
private bool CycleToNextTableEntryBeginningWith (Key keyEvent)
1566+
private bool CycleToNextTableEntryBeginningWith (Key key)
15671567
{
15681568
int row = SelectedRow;
15691569

@@ -1573,7 +1573,7 @@ private bool CycleToNextTableEntryBeginningWith (Key keyEvent)
15731573
return false;
15741574
}
15751575

1576-
int match = CollectionNavigator.GetNextMatchingItem (row, (char)keyEvent);
1576+
int match = CollectionNavigator.GetNextMatchingItem (row, (char)key);
15771577

15781578
if (match != -1)
15791579
{

Terminal.Gui/Views/TileView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ public override void OnDrawContent (Rectangle viewport)
286286

287287
//// BUGBUG: Why is this not handled by a key binding???
288288
/// <inheritdoc/>
289-
protected override bool OnKeyDownNotHandled (Key keyEvent)
289+
protected override bool OnKeyDownNotHandled (Key key)
290290
{
291291
var focusMoved = false;
292292

293-
if (keyEvent.KeyCode == ToggleResizable)
293+
if (key.KeyCode == ToggleResizable)
294294
{
295295
foreach (TileViewLineView l in _splitterLines)
296296
{

Terminal.Gui/Views/TreeView/TreeView.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,23 +1182,23 @@ protected override void OnHasFocusChanged (bool newHasFocus, [CanBeNull] View cu
11821182
}
11831183

11841184
/// <inheritdoc/>
1185-
protected override bool OnKeyDown (Key keyEvent)
1185+
protected override bool OnKeyDown (Key key)
11861186
{
11871187
if (!Enabled)
11881188
{
11891189
return false;
11901190
}
11911191

11921192
// If not a keybinding, is the key a searchable key press?
1193-
if (CollectionNavigatorBase.IsCompatibleKey (keyEvent) && AllowLetterBasedNavigation)
1193+
if (CollectionNavigatorBase.IsCompatibleKey (key) && AllowLetterBasedNavigation)
11941194
{
11951195
// If there has been a call to InvalidateMap since the last time
11961196
// we need a new one to reflect the new exposed tree state
11971197
IReadOnlyCollection<Branch<T>> map = BuildLineMap ();
11981198

11991199
// Find the current selected object within the tree
12001200
int current = map.IndexOf (b => b.Model == SelectedObject);
1201-
int? newIndex = KeystrokeNavigator?.GetNextMatchingItem (current, (char)keyEvent);
1201+
int? newIndex = KeystrokeNavigator?.GetNextMatchingItem (current, (char)key);
12021202

12031203
if (newIndex is int && newIndex != -1)
12041204
{

0 commit comments

Comments
 (0)