mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Initial plan * Add comprehensive MouseClick removal analysis Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix code review feedback on analysis document Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add actual line numbers to analysis document Co-authored-by: tig <585482+tig@users.noreply.github.com> * Final polish on analysis document - clarify TextView Co-authored-by: tig <585482+tig@users.noreply.github.com> * Phase 3: Port 6 simple Views from MouseClick to Selecting/MouseBindings Co-authored-by: tig <585482+tig@users.noreply.github.com> * Phase 2: Port 10 Scenarios from MouseClick to Selecting/remove Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update analysis document - Phases 2 & 3 complete Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix failing tests - Button multi-button support and Label focus handling Co-authored-by: tig <585482+tig@users.noreply.github.com> * Phase 4: Port ScrollBar from OnMouseClick to OnSelecting; remove analysis doc Co-authored-by: tig <585482+tig@users.noreply.github.com> * Phase 5: Update/remove tests that explicitly test MouseClick API Co-authored-by: tig <585482+tig@users.noreply.github.com> * Code cleanup * Remove MouseClick event Consolidated mouse event handling by removing the `MouseClick` event and integrating its functionality into the `MouseEvent` event. Simplified `MouseEventArgs` documentation and added support for invoking commands bound to mouse events. Reorganized code by removing `Mouse Pressed Events` and `Mouse Click Events` regions, introducing a new `WhenGrabbed Handlers` region. Updated tests to replace `MouseClick` with `MouseEvent`, adjusted test logic, and improved variable naming for clarity. Removed redundant assertions and unused code related to `MouseClick`. Improved event propagation logic to ensure proper handling of unhandled events. Performed general code cleanup to enhance readability and maintainability. * Updated deep dives. --------- 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>
This commit is contained in:
@@ -32,9 +32,9 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
};
|
||||
|
||||
Point? receivedPosition = null;
|
||||
var eventReceived = false;
|
||||
bool eventReceived = false;
|
||||
|
||||
view.MouseEvent += (sender, args) =>
|
||||
view.MouseEvent += (_, args) =>
|
||||
{
|
||||
eventReceived = true;
|
||||
receivedPosition = args.Position;
|
||||
@@ -90,9 +90,9 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
};
|
||||
|
||||
Point? receivedPosition = null;
|
||||
var eventReceived = false;
|
||||
bool eventReceived = false;
|
||||
|
||||
view.MouseEvent += (sender, args) =>
|
||||
view.MouseEvent += (_, args) =>
|
||||
{
|
||||
eventReceived = true;
|
||||
receivedPosition = args.Position;
|
||||
@@ -100,7 +100,7 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (viewRelativeX, viewRelativeY),
|
||||
Position = new (viewRelativeX, viewRelativeY),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
@@ -146,9 +146,9 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
superView.Add (subView);
|
||||
|
||||
Point? subViewReceivedPosition = null;
|
||||
var subViewEventReceived = false;
|
||||
bool subViewEventReceived = false;
|
||||
|
||||
subView.MouseEvent += (sender, args) =>
|
||||
subView.MouseEvent += (_, args) =>
|
||||
{
|
||||
subViewEventReceived = true;
|
||||
subViewReceivedPosition = args.Position;
|
||||
@@ -175,7 +175,7 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MouseClick_OnSubView_RaisesMouseClickEvent ()
|
||||
public void MouseClick_OnSubView_RaisesSelectingEvent ()
|
||||
{
|
||||
// Arrange
|
||||
View superView = new ()
|
||||
@@ -194,8 +194,8 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
var clickCount = 0;
|
||||
subView.MouseClick += (sender, args) => clickCount++;
|
||||
int selectingCount = 0;
|
||||
subView.Selecting += (_, _) => selectingCount++;
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
@@ -207,7 +207,7 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
subView.NewMouseEvent (mouseEvent);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (1, clickCount);
|
||||
Assert.Equal (1, selectingCount);
|
||||
|
||||
subView.Dispose ();
|
||||
superView.Dispose ();
|
||||
@@ -222,20 +222,20 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
{
|
||||
// Arrange
|
||||
View view = new () { Width = 10, Height = 10 };
|
||||
var handlerCalled = false;
|
||||
var clickHandlerCalled = false;
|
||||
bool handlerCalled = false;
|
||||
bool clickHandlerCalled = false;
|
||||
|
||||
view.MouseEvent += (sender, args) =>
|
||||
view.MouseEvent += (_, args) =>
|
||||
{
|
||||
handlerCalled = true;
|
||||
args.Handled = true; // Mark as handled
|
||||
};
|
||||
|
||||
view.MouseClick += (sender, args) => { clickHandlerCalled = true; };
|
||||
view.MouseEvent += (_, e) => { clickHandlerCalled = !e.IsSingleDoubleOrTripleClicked; ; };
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
@@ -255,20 +255,17 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
{
|
||||
// Arrange
|
||||
View view = new () { Width = 10, Height = 10 };
|
||||
var eventHandlerCalled = false;
|
||||
var clickHandlerCalled = false;
|
||||
bool eventHandlerCalled = false;
|
||||
|
||||
view.MouseEvent += (sender, args) =>
|
||||
view.MouseEvent += (_, _) =>
|
||||
{
|
||||
eventHandlerCalled = true;
|
||||
// Don't set Handled = true
|
||||
};
|
||||
|
||||
view.MouseClick += (sender, args) => { clickHandlerCalled = true; };
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
@@ -277,7 +274,6 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
|
||||
// Assert
|
||||
Assert.True (eventHandlerCalled);
|
||||
Assert.True (clickHandlerCalled); // Click handler should be called when event is not handled
|
||||
|
||||
view.Dispose ();
|
||||
}
|
||||
@@ -294,11 +290,10 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
{
|
||||
// Arrange
|
||||
View view = new () { Width = 10, Height = 10 };
|
||||
var pressedCount = 0;
|
||||
var releasedCount = 0;
|
||||
var clickedCount = 0;
|
||||
int pressedCount = 0;
|
||||
int releasedCount = 0;
|
||||
|
||||
view.MouseEvent += (sender, args) =>
|
||||
view.MouseEvent += (_, args) =>
|
||||
{
|
||||
if (args.Flags.HasFlag (MouseFlags.Button1Pressed))
|
||||
{
|
||||
@@ -311,11 +306,9 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
}
|
||||
};
|
||||
|
||||
view.MouseClick += (sender, args) => { clickedCount++; };
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = flags
|
||||
};
|
||||
|
||||
@@ -325,7 +318,6 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
// Assert
|
||||
Assert.Equal (expectedPressed, pressedCount);
|
||||
Assert.Equal (expectedReleased, releasedCount);
|
||||
Assert.Equal (expectedClicked, clickedCount);
|
||||
|
||||
view.Dispose ();
|
||||
}
|
||||
@@ -339,13 +331,13 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
{
|
||||
// Arrange
|
||||
View view = new () { Width = 10, Height = 10 };
|
||||
var clickCount = 0;
|
||||
int clickCount = 0;
|
||||
|
||||
view.MouseClick += (sender, args) => clickCount++;
|
||||
view.MouseEvent += (_, a) => clickCount += a.IsSingleDoubleOrTripleClicked ? 1 : 0;
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = clickFlag
|
||||
};
|
||||
|
||||
@@ -373,12 +365,12 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
var eventCalled = false;
|
||||
view.MouseEvent += (sender, args) => { eventCalled = true; };
|
||||
bool eventCalled = false;
|
||||
view.MouseEvent += (_, _) => { eventCalled = true; };
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
@@ -392,7 +384,7 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void View_Disabled_DoesNotRaiseMouseClickEvent ()
|
||||
public void View_Disabled_DoesNotRaiseSelectingEvent ()
|
||||
{
|
||||
// Arrange
|
||||
View view = new ()
|
||||
@@ -402,12 +394,12 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
var clickCalled = false;
|
||||
view.MouseClick += (sender, args) => { clickCalled = true; };
|
||||
bool selectingCalled = false;
|
||||
view.Selecting += (_, _) => { selectingCalled = true; };
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
@@ -415,7 +407,7 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
view.NewMouseEvent (mouseEvent);
|
||||
|
||||
// Assert
|
||||
Assert.False (clickCalled);
|
||||
Assert.False (selectingCalled);
|
||||
|
||||
view.Dispose ();
|
||||
}
|
||||
@@ -445,7 +437,7 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (2, 2),
|
||||
Position = new (2, 2),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
@@ -475,12 +467,12 @@ public class MouseEventRoutingTests (ITestOutputHelper output)
|
||||
|
||||
superView.Add (view);
|
||||
|
||||
var selectingCount = 0;
|
||||
view.Selecting += (sender, args) => selectingCount++;
|
||||
int selectingCount = 0;
|
||||
view.Selecting += (_, _) => selectingCount++;
|
||||
|
||||
MouseEventArgs mouseEvent = new ()
|
||||
{
|
||||
Position = new Point (5, 5),
|
||||
Position = new (5, 5),
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user