mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +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>
158 lines
4.8 KiB
C#
158 lines
4.8 KiB
C#
using UnitTests;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace ViewBaseTests.Mouse;
|
|
|
|
[Trait ("Category", "Input")]
|
|
public class MouseTests (ITestOutputHelper output) : TestsAllViews
|
|
{
|
|
[Fact]
|
|
public void Default_MouseBindings ()
|
|
{
|
|
var testView = new View ();
|
|
|
|
Assert.Contains (MouseFlags.Button1Clicked, testView.MouseBindings.GetAllFromCommands (Command.Activate));
|
|
// Assert.Contains (MouseFlags.Button1DoubleClicked, testView.MouseBindings.GetAllFromCommands (Command.Accept));
|
|
|
|
Assert.Equal (5, testView.MouseBindings.GetBindings ().Count ());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (false, false, false)]
|
|
[InlineData (true, false, true)]
|
|
[InlineData (true, true, true)]
|
|
public void MouseClick_SetsFocus_If_CanFocus (bool canFocus, bool setFocus, bool expectedHasFocus)
|
|
{
|
|
var superView = new View { CanFocus = true, Height = 1, Width = 15 };
|
|
var focusedView = new View { CanFocus = true, Width = 1, Height = 1 };
|
|
var testView = new View { CanFocus = canFocus, X = 4, Width = 4, Height = 1 };
|
|
superView.Add (focusedView, testView);
|
|
|
|
focusedView.SetFocus ();
|
|
|
|
Assert.True (superView.HasFocus);
|
|
Assert.True (focusedView.HasFocus);
|
|
Assert.False (testView.HasFocus);
|
|
|
|
if (setFocus)
|
|
{
|
|
testView.SetFocus ();
|
|
}
|
|
|
|
testView.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked });
|
|
Assert.True (superView.HasFocus);
|
|
Assert.Equal (expectedHasFocus, testView.HasFocus);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (false, false, 1)]
|
|
[InlineData (true, false, 1)]
|
|
[InlineData (true, true, 1)]
|
|
public void MouseClick_Raises_Activating (bool canFocus, bool setFocus, int expectedActivatingCount)
|
|
{
|
|
var superView = new View { CanFocus = true, Height = 1, Width = 15 };
|
|
var focusedView = new View { CanFocus = true, Width = 1, Height = 1 };
|
|
var testView = new View { CanFocus = canFocus, X = 4, Width = 4, Height = 1 };
|
|
superView.Add (focusedView, testView);
|
|
|
|
focusedView.SetFocus ();
|
|
|
|
Assert.True (superView.HasFocus);
|
|
Assert.True (focusedView.HasFocus);
|
|
Assert.False (testView.HasFocus);
|
|
|
|
if (setFocus)
|
|
{
|
|
testView.SetFocus ();
|
|
}
|
|
|
|
var activatingCount = 0;
|
|
testView.Activating += (sender, args) => activatingCount++;
|
|
|
|
testView.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked });
|
|
Assert.True (superView.HasFocus);
|
|
Assert.Equal (expectedActivatingCount, activatingCount);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (MouseFlags.WheeledUp | MouseFlags.ButtonCtrl, MouseFlags.WheeledLeft)]
|
|
[InlineData (MouseFlags.WheeledDown | MouseFlags.ButtonCtrl, MouseFlags.WheeledRight)]
|
|
public void WheeledLeft_WheeledRight (MouseFlags mouseFlags, MouseFlags expectedMouseFlagsFromEvent)
|
|
{
|
|
var mouseFlagsFromEvent = MouseFlags.None;
|
|
var view = new View ();
|
|
view.MouseEvent += (s, e) => mouseFlagsFromEvent = e.Flags;
|
|
|
|
view.NewMouseEvent (new () { Flags = mouseFlags });
|
|
Assert.Equal (mouseFlagsFromEvent, expectedMouseFlagsFromEvent);
|
|
}
|
|
|
|
[Fact]
|
|
public void NewMouseEvent_Invokes_MouseEvent_Properly ()
|
|
{
|
|
View view = new ()
|
|
{
|
|
Width = 1,
|
|
Height = 1
|
|
};
|
|
var mouseEventInvoked = false;
|
|
|
|
view.MouseEvent += (s, e) =>
|
|
{
|
|
mouseEventInvoked = true;
|
|
e.Handled = true;
|
|
};
|
|
|
|
MouseEventArgs me = new ();
|
|
view.NewMouseEvent (me);
|
|
Assert.True (mouseEventInvoked);
|
|
Assert.True (me.Handled);
|
|
|
|
view.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData (nameof (AllViewTypes))]
|
|
public void AllViews_NewMouseEvent_Enabled_False_Does_Not_Set_Handled (Type viewType)
|
|
{
|
|
View? view = CreateInstanceIfNotGeneric (viewType);
|
|
|
|
if (view == null)
|
|
{
|
|
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
|
|
|
|
return;
|
|
}
|
|
|
|
view.Enabled = false;
|
|
var me = new MouseEventArgs ();
|
|
view.NewMouseEvent (me);
|
|
Assert.False (me.Handled);
|
|
view.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData (nameof (AllViewTypes))]
|
|
public void AllViews_NewMouseEvent_Clicked_Enabled_False_Does_Not_Set_Handled (Type viewType)
|
|
{
|
|
View? view = CreateInstanceIfNotGeneric (viewType);
|
|
|
|
if (view == null)
|
|
{
|
|
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
|
|
|
|
return;
|
|
}
|
|
|
|
view.Enabled = false;
|
|
|
|
var me = new MouseEventArgs
|
|
{
|
|
Flags = MouseFlags.Button1Clicked
|
|
};
|
|
view.NewMouseEvent (me);
|
|
Assert.False (me.Handled);
|
|
view.Dispose ();
|
|
}
|
|
}
|