Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop

This commit is contained in:
Tig
2025-03-09 09:57:43 -06:00
3 changed files with 24 additions and 27 deletions

View File

@@ -89,7 +89,11 @@ public static partial class Application // Run (Begin, Run, End, Stop)
//#endif //#endif
// Ensure the mouse is ungrabbed. // Ensure the mouse is ungrabbed.
MouseGrabView = null; if (MouseGrabView is { })
{
UngrabMouse ();
MouseGrabView = null;
}
var rs = new RunState (toplevel); var rs = new RunState (toplevel);

View File

@@ -17,6 +17,7 @@ internal sealed class Menu : View
} }
Application.MouseEvent += Application_RootMouseEvent; Application.MouseEvent += Application_RootMouseEvent;
Application.UnGrabbedMouse += Application_UnGrabbedMouse;
// Things this view knows how to do // Things this view knows how to do
AddCommand (Command.Up, () => MoveUp ()); AddCommand (Command.Up, () => MoveUp ());
@@ -235,6 +236,7 @@ internal sealed class Menu : View
} }
Application.MouseEvent -= Application_RootMouseEvent; Application.MouseEvent -= Application_RootMouseEvent;
Application.UnGrabbedMouse -= Application_UnGrabbedMouse;
base.Dispose (disposing); base.Dispose (disposing);
} }
@@ -522,6 +524,14 @@ internal sealed class Menu : View
} }
} }
private void Application_UnGrabbedMouse (object? sender, ViewEventArgs a)
{
if (_host.IsMenuOpen)
{
_host.CloseAllMenus ();
}
}
private void CloseAllMenus () private void CloseAllMenus ()
{ {
Application.UngrabMouse (); Application.UngrabMouse ();

View File

@@ -2562,47 +2562,30 @@ Edit
Assert.Equal ("_Edit", miCurrent.Parent.Title); Assert.Equal ("_Edit", miCurrent.Parent.Title);
Assert.Equal ("_Paste", miCurrent.Title); Assert.Equal ("_Paste", miCurrent.Title);
for (var i = 2; i >= -1; i--) for (var i = 4; i >= -1; i--)
{ {
if (i == -1) Application.RaiseMouseEvent (
{ new () { ScreenPosition = new (10, i), Flags = MouseFlags.ReportMousePosition }
// Edit menu is open. Click on the menu at Y = -1, which is outside the menu. );
Assert.False (
mCurrent.NewMouseEvent (
new () { Position = new (10, i), Flags = MouseFlags.ReportMousePosition, View = menu }
)
);
}
else
{
// Edit menu is open. Click on the menu at Y = i.
Assert.True (
mCurrent.NewMouseEvent (
new () { Position = new (10, i), Flags = MouseFlags.ReportMousePosition, View = mCurrent }
)
);
}
Assert.True (menu.IsMenuOpen); Assert.True (menu.IsMenuOpen);
Assert.Equal (menu, Application.MouseGrabView);
Assert.Equal ("_Edit", miCurrent.Parent.Title);
if (i == 2) if (i == 4)
{ {
Assert.Equal ("_Edit", miCurrent.Parent.Title);
Assert.Equal ("_Paste", miCurrent.Title); Assert.Equal ("_Paste", miCurrent.Title);
} }
else if (i == 1) else if (i == 3)
{ {
Assert.Equal ("_Edit", miCurrent.Parent.Title);
Assert.Equal ("C_ut", miCurrent.Title); Assert.Equal ("C_ut", miCurrent.Title);
} }
else if (i == 0) else if (i == 2)
{ {
Assert.Equal ("_Edit", miCurrent.Parent.Title);
Assert.Equal ("_Copy", miCurrent.Title); Assert.Equal ("_Copy", miCurrent.Title);
} }
else else
{ {
Assert.Equal ("_Edit", miCurrent.Parent.Title);
Assert.Equal ("_Copy", miCurrent.Title); Assert.Equal ("_Copy", miCurrent.Title);
} }
} }