mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Initial plan
* Rename Command.Select to Command.Activate and Selecting to Activating
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Add Activating event propagation to SuperView
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Update all comments and docs referencing Select to Activate
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Fix event log messages in examples to use Activating/Activate
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Revert automatic Activating event propagation that broke tests
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Update docfx documentation to use Activate/Activating terminology
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* renames
* Revert "Add Activating event propagation to SuperView"
This reverts commit 6d82bee9ad.
* added command diagrams
* mermaid
* updated level 3
* again
* Select->Activate in MouseTests.cs
* Update Terminal.Gui/Views/Selectors/FlagSelector.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Refactor: Rename Selecting to Activating in View APIs
Renamed the `Selecting` event and `OnSelecting` method to
`Activating` and `OnActivating` to better reflect their purpose.
Updated all related comments, test method names, variables,
and assertions in `View` and `ViewCommandTests` to align with
the new terminology.
Improved code clarity by using `_` for unused parameters in
lambda expressions. Renamed properties like `HandleSelecting`
to `HandleActivating` and adjusted naming conventions for
consistency (e.g., `OnactivatingCount` to `OnActivatingCount`).
These changes enhance readability, maintainability, and
terminology consistency across the codebase.
* Update Terminal.Gui/Views/Selectors/OptionSelector.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Typos
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
428 lines
13 KiB
C#
428 lines
13 KiB
C#
using JetBrains.Annotations;
|
|
using UnitTests;
|
|
|
|
namespace UnitTests.ViewsTests;
|
|
|
|
[TestSubject (typeof (Shortcut))]
|
|
public class ShortcutTests
|
|
{
|
|
[Theory]
|
|
|
|
// 0123456789
|
|
// " C 0 A "
|
|
[InlineData (-1, 0)]
|
|
[InlineData (0, 1)]
|
|
[InlineData (1, 1)]
|
|
[InlineData (2, 1)]
|
|
[InlineData (3, 1)]
|
|
[InlineData (4, 1)]
|
|
[InlineData (5, 1)]
|
|
[InlineData (6, 1)]
|
|
[InlineData (7, 1)]
|
|
[InlineData (8, 1)]
|
|
[InlineData (9, 0)]
|
|
public void MouseClick_Raises_Accepted (int x, int expectedAccepted)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Key = Key.A,
|
|
Text = "0",
|
|
Title = "C"
|
|
};
|
|
Application.TopRunnableView.Add (shortcut);
|
|
Application.TopRunnableView.Layout ();
|
|
|
|
var accepted = 0;
|
|
shortcut.Accepting += (s, e) => accepted++;
|
|
|
|
Application.RaiseMouseEvent (
|
|
new ()
|
|
{
|
|
ScreenPosition = new (x, 0),
|
|
Flags = MouseFlags.Button1Clicked
|
|
});
|
|
|
|
Assert.Equal (expectedAccepted, accepted);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
[Theory]
|
|
|
|
// 0123456789
|
|
// " C 0 A "
|
|
[InlineData (-1, 0, 0, 0, 0)]
|
|
[InlineData (0, 0, 1, 1, 1)] // mouseX = 0 is on the CommandView.Margin, so Shortcut will get MouseEvent for click
|
|
[InlineData (1, 0, 1, 1, 1)] // mouseX = 1 is on the CommandView, so CommandView will get MouseEvent for click
|
|
[InlineData (2, 0, 1, 1, 1)] // mouseX = 2 is on the CommandView.Margin, so Shortcut will get MouseEvent for click
|
|
[InlineData (3, 0, 1, 1, 1)]
|
|
[InlineData (4, 0, 1, 1, 1)]
|
|
[InlineData (5, 0, 1, 1, 1)]
|
|
[InlineData (6, 0, 1, 1, 1)]
|
|
[InlineData (7, 0, 1, 1, 1)]
|
|
[InlineData (8, 0, 1, 1, 1)]
|
|
[InlineData (9, 0, 0, 0, 0)]
|
|
|
|
public void MouseClick_Default_CommandView_Raises_Accepted_Selected_Correctly (
|
|
int mouseX,
|
|
int expectedCommandViewAccepted,
|
|
int expectedCommandViewActivated,
|
|
int expectedShortcutAccepted,
|
|
int expectedShortcutActivated
|
|
)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Title = "C",
|
|
Key = Key.A,
|
|
HelpText = "0"
|
|
};
|
|
|
|
var commandViewAcceptCount = 0;
|
|
shortcut.CommandView.Accepting += (s, e) => { commandViewAcceptCount++; };
|
|
var commandViewActivatingCount = 0;
|
|
shortcut.CommandView.Activating += (s, e) => { commandViewActivatingCount++; };
|
|
|
|
var shortcutAcceptCount = 0;
|
|
shortcut.Accepting += (s, e) => { shortcutAcceptCount++; };
|
|
var shortcutSelectCount = 0;
|
|
shortcut.Activating += (s, e) => { shortcutSelectCount++; };
|
|
|
|
Application.TopRunnableView.Add (shortcut);
|
|
Application.TopRunnableView.SetRelativeLayout (new (100, 100));
|
|
Application.TopRunnableView.LayoutSubViews ();
|
|
|
|
Application.RaiseMouseEvent (
|
|
new ()
|
|
{
|
|
ScreenPosition = new (mouseX, 0),
|
|
Flags = MouseFlags.Button1Clicked
|
|
});
|
|
|
|
Assert.Equal (expectedShortcutAccepted, shortcutAcceptCount);
|
|
Assert.Equal (expectedShortcutActivated, shortcutSelectCount);
|
|
Assert.Equal (expectedCommandViewAccepted, commandViewAcceptCount);
|
|
Assert.Equal (expectedCommandViewActivated, commandViewActivatingCount);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
[Theory]
|
|
|
|
// 0123456789
|
|
// " C 0 A "
|
|
[InlineData (-1, 0, 0)]
|
|
[InlineData (0, 1, 0)]
|
|
[InlineData (1, 1, 0)]
|
|
[InlineData (2, 1, 0)]
|
|
[InlineData (3, 1, 0)]
|
|
[InlineData (4, 1, 0)]
|
|
[InlineData (5, 1, 0)]
|
|
[InlineData (6, 1, 0)]
|
|
[InlineData (7, 1, 0)]
|
|
[InlineData (8, 1, 0)]
|
|
[InlineData (9, 0, 0)]
|
|
public void MouseClick_Button_CommandView_Raises_Shortcut_Accepted (int mouseX, int expectedAccept, int expectedButtonAccept)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Key = Key.A,
|
|
Text = "0"
|
|
};
|
|
|
|
shortcut.CommandView = new Button
|
|
{
|
|
Title = "C",
|
|
NoDecorations = true,
|
|
NoPadding = true,
|
|
CanFocus = false
|
|
};
|
|
var buttonAccepted = 0;
|
|
shortcut.CommandView.Accepting += (s, e) => { buttonAccepted++; };
|
|
Application.TopRunnableView.Add (shortcut);
|
|
Application.TopRunnableView.SetRelativeLayout (new (100, 100));
|
|
Application.TopRunnableView.LayoutSubViews ();
|
|
|
|
var accepted = 0;
|
|
shortcut.Accepting += (s, e) => { accepted++; };
|
|
|
|
Application.RaiseMouseEvent (
|
|
new ()
|
|
{
|
|
ScreenPosition = new (mouseX, 0),
|
|
Flags = MouseFlags.Button1Clicked
|
|
});
|
|
|
|
Assert.Equal (expectedAccept, accepted);
|
|
Assert.Equal (expectedButtonAccept, buttonAccepted);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
[Theory]
|
|
|
|
// 01234567890
|
|
// " ☑C 0 A "
|
|
[InlineData (-1, 0, 0)]
|
|
[InlineData (0, 1, 0)]
|
|
[InlineData (1, 1, 0)]
|
|
[InlineData (2, 1, 0)]
|
|
[InlineData (3, 1, 0)]
|
|
[InlineData (4, 1, 0)]
|
|
[InlineData (5, 1, 0)]
|
|
[InlineData (6, 1, 0)]
|
|
[InlineData (7, 1, 0)]
|
|
[InlineData (8, 1, 0)]
|
|
[InlineData (9, 1, 0)]
|
|
[InlineData (10, 1, 0)]
|
|
public void MouseClick_CheckBox_CommandView_Raises_Shortcut_Accepted_Selected_Correctly (int mouseX, int expectedAccepted, int expectedCheckboxAccepted)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Key = Key.A,
|
|
Text = "0"
|
|
};
|
|
|
|
shortcut.CommandView = new CheckBox
|
|
{
|
|
Title = "C",
|
|
CanFocus = false
|
|
};
|
|
var checkboxAccepted = 0;
|
|
shortcut.CommandView.Accepting += (s, e) => { checkboxAccepted++; };
|
|
|
|
var checkboxActivated = 0;
|
|
shortcut.CommandView.Activating += (s, e) =>
|
|
{
|
|
if (e.Handled)
|
|
{
|
|
return;
|
|
}
|
|
checkboxActivated++;
|
|
};
|
|
|
|
Application.TopRunnableView.Add (shortcut);
|
|
Application.TopRunnableView.SetRelativeLayout (new (100, 100));
|
|
Application.TopRunnableView.LayoutSubViews ();
|
|
|
|
var activatingCount = 0;
|
|
shortcut.Activating += (s, e) =>
|
|
{
|
|
activatingCount++;
|
|
};
|
|
|
|
var accepted = 0;
|
|
shortcut.Accepting += (s, e) =>
|
|
{
|
|
accepted++;
|
|
e.Handled = true;
|
|
};
|
|
|
|
Application.RaiseMouseEvent (
|
|
new ()
|
|
{
|
|
ScreenPosition = new (mouseX, 0),
|
|
Flags = MouseFlags.Button1Clicked
|
|
});
|
|
|
|
Assert.Equal (expectedAccepted, accepted);
|
|
Assert.Equal (expectedAccepted, activatingCount);
|
|
Assert.Equal (expectedCheckboxAccepted, checkboxAccepted);
|
|
Assert.Equal (expectedCheckboxAccepted, checkboxActivated);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (true, KeyCode.A, 1, 1)]
|
|
[InlineData (true, KeyCode.C, 1, 1)]
|
|
[InlineData (true, KeyCode.C | KeyCode.AltMask, 1, 1)]
|
|
[InlineData (true, KeyCode.Enter, 1, 1)]
|
|
[InlineData (true, KeyCode.Space, 1, 1)]
|
|
[InlineData (true, KeyCode.F1, 0, 0)]
|
|
[InlineData (false, KeyCode.A, 1, 1)]
|
|
[InlineData (false, KeyCode.C, 1, 1)]
|
|
[InlineData (false, KeyCode.C | KeyCode.AltMask, 1, 1)]
|
|
[InlineData (false, KeyCode.Enter, 0, 0)]
|
|
[InlineData (false, KeyCode.Space, 0, 0)]
|
|
[InlineData (false, KeyCode.F1, 0, 0)]
|
|
public void KeyDown_Raises_Accepted_Selected (bool canFocus, KeyCode key, int expectedAccept, int expectedSelect)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Key = Key.A,
|
|
Text = "0",
|
|
Title = "_C",
|
|
CanFocus = canFocus
|
|
};
|
|
Application.TopRunnableView.Add (shortcut);
|
|
shortcut.SetFocus ();
|
|
|
|
Assert.Equal (canFocus, shortcut.HasFocus);
|
|
|
|
var accepted = 0;
|
|
shortcut.Accepting += (s, e) => accepted++;
|
|
|
|
var selected = 0;
|
|
shortcut.Activating += (s, e) => selected++;
|
|
|
|
Application.RaiseKeyDownEvent (key);
|
|
|
|
Assert.Equal (expectedAccept, accepted);
|
|
Assert.Equal (expectedSelect, selected);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (KeyCode.A, 1)]
|
|
[InlineData (KeyCode.C, 1)]
|
|
[InlineData (KeyCode.C | KeyCode.AltMask, 1)]
|
|
[InlineData (KeyCode.Enter, 1)]
|
|
[InlineData (KeyCode.Space, 1)]
|
|
[InlineData (KeyCode.F1, 0)]
|
|
public void KeyDown_App_Scope_Invokes_Accept (KeyCode key, int expectedAccept)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Key = Key.A,
|
|
Text = "0",
|
|
Title = "_C"
|
|
};
|
|
Application.TopRunnableView.Add (shortcut);
|
|
shortcut.BindKeyToApplication = true;
|
|
Application.TopRunnableView.SetFocus ();
|
|
|
|
var accepted = 0;
|
|
shortcut.Accepting += (s, e) => accepted++;
|
|
|
|
Application.RaiseKeyDownEvent (key);
|
|
|
|
Assert.Equal (expectedAccept, accepted);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (true, KeyCode.A, 1)]
|
|
[InlineData (true, KeyCode.C, 1)]
|
|
[InlineData (true, KeyCode.C | KeyCode.AltMask, 1)]
|
|
[InlineData (true, KeyCode.Enter, 1)]
|
|
[InlineData (true, KeyCode.Space, 1)]
|
|
[InlineData (true, KeyCode.F1, 0)]
|
|
[InlineData (false, KeyCode.A, 1)]
|
|
[InlineData (false, KeyCode.C, 1)]
|
|
[InlineData (false, KeyCode.C | KeyCode.AltMask, 1)]
|
|
[InlineData (false, KeyCode.Enter, 0)]
|
|
[InlineData (false, KeyCode.Space, 0)]
|
|
[InlineData (false, KeyCode.F1, 0)]
|
|
[AutoInitShutdown]
|
|
public void KeyDown_Invokes_Action (bool canFocus, KeyCode key, int expectedAction)
|
|
{
|
|
var current = new Runnable ();
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
Key = Key.A,
|
|
Text = "0",
|
|
Title = "_C",
|
|
CanFocus = canFocus
|
|
};
|
|
current.Add (shortcut);
|
|
|
|
Application.Begin (current);
|
|
Assert.Equal (canFocus, shortcut.HasFocus);
|
|
|
|
var action = 0;
|
|
shortcut.Action += () => action++;
|
|
|
|
Application.RaiseKeyDownEvent (key);
|
|
|
|
Assert.Equal (expectedAction, action);
|
|
|
|
current.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (true, KeyCode.A, 1)]
|
|
[InlineData (true, KeyCode.C, 1)]
|
|
[InlineData (true, KeyCode.C | KeyCode.AltMask, 1)]
|
|
[InlineData (true, KeyCode.Enter, 1)]
|
|
[InlineData (true, KeyCode.Space, 1)]
|
|
[InlineData (true, KeyCode.F1, 0)]
|
|
[InlineData (false, KeyCode.A, 1)]
|
|
[InlineData (false, KeyCode.C, 1)]
|
|
[InlineData (false, KeyCode.C | KeyCode.AltMask, 1)]
|
|
[InlineData (false, KeyCode.Enter, 0)]
|
|
[InlineData (false, KeyCode.Space, 0)]
|
|
[InlineData (false, KeyCode.F1, 0)]
|
|
public void KeyDown_App_Scope_Invokes_Action (bool canFocus, KeyCode key, int expectedAction)
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut
|
|
{
|
|
App = ApplicationImpl.Instance, // HACK: Move to Parallel and get rid of this
|
|
BindKeyToApplication = true,
|
|
Key = Key.A,
|
|
Text = "0",
|
|
Title = "_C",
|
|
CanFocus = canFocus,
|
|
};
|
|
|
|
Application.TopRunnableView.Add (shortcut);
|
|
|
|
Application.TopRunnableView.SetFocus ();
|
|
|
|
var action = 0;
|
|
shortcut.Action += () => action++;
|
|
|
|
Application.RaiseKeyDownEvent (key);
|
|
|
|
Assert.Equal (expectedAction, action);
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState (true);
|
|
}
|
|
|
|
// https://github.com/gui-cs/Terminal.Gui/issues/3664
|
|
[Fact]
|
|
public void Scheme_SetScheme_Does_Not_Fault_3664 ()
|
|
{
|
|
Application.Begin (new Runnable<bool> ());
|
|
|
|
var shortcut = new Shortcut ();
|
|
|
|
Application.TopRunnableView.SetScheme (null);
|
|
|
|
Assert.False (shortcut.HasScheme);
|
|
Assert.NotNull (shortcut.GetScheme ());
|
|
|
|
shortcut.HasFocus = true;
|
|
|
|
Assert.False (shortcut.HasScheme);
|
|
Assert.NotNull (shortcut.GetScheme ());
|
|
|
|
Application.TopRunnableView.Dispose ();
|
|
Application.ResetState ();
|
|
}
|
|
}
|