mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Fixes #1825. Parent MenuItem stay focused if child MenuItem is empty.
This commit is contained in:
@@ -1296,5 +1296,193 @@ Edit
|
||||
Assert.False (menu.UseKeysUpDownAsKeysLeftRight);
|
||||
Assert.True (menu.UseSubMenusSingleFrame);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Parent_MenuItem_Stay_Focused_If_Child_MenuItem_Is_Empty_By_Mouse ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("File", new MenuItem [] {
|
||||
new MenuItem ("New", "", null)
|
||||
}),
|
||||
new MenuBarItem ("Edit", new MenuItem [] {
|
||||
}),
|
||||
new MenuBarItem ("Format", new MenuItem [] {
|
||||
new MenuItem ("Wrap", "", null)
|
||||
})
|
||||
});
|
||||
var tf = new TextField () { Y = 2, Width = 10 };
|
||||
Application.Top.Add (menu, tf);
|
||||
|
||||
Application.Begin (Application.Top);
|
||||
Assert.True (tf.HasFocus);
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () { X = 1, Y = 0, Flags = MouseFlags.Button1Pressed, View = menu }));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
File Edit Format
|
||||
┌──────┐
|
||||
│ New │
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 4), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () { X = 8, Y = 0, Flags = MouseFlags.ReportMousePosition, View = menu }));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 1), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () { X = 15, Y = 0, Flags = MouseFlags.ReportMousePosition, View = menu }));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
┌───────┐
|
||||
│ Wrap │
|
||||
└───────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 23, 4), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () { X = 8, Y = 0, Flags = MouseFlags.ReportMousePosition, View = menu }));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 1), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () { X = 1, Y = 0, Flags = MouseFlags.ReportMousePosition, View = menu }));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
┌──────┐
|
||||
│ New │
|
||||
└──────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 4), pos);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent () { X = 8, Y = 0, Flags = MouseFlags.Button1Pressed, View = menu }));
|
||||
Assert.False (menu.IsMenuOpen);
|
||||
Assert.True (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 1), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Parent_MenuItem_Stay_Focused_If_Child_MenuItem_Is_Empty_By_Keyboard ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("File", new MenuItem [] {
|
||||
new MenuItem ("New", "", null)
|
||||
}),
|
||||
new MenuBarItem ("Edit", new MenuItem [] {
|
||||
}),
|
||||
new MenuBarItem ("Format", new MenuItem [] {
|
||||
new MenuItem ("Wrap", "", null)
|
||||
})
|
||||
});
|
||||
var tf = new TextField () { Y = 2, Width = 10 };
|
||||
Application.Top.Add (menu, tf);
|
||||
|
||||
Application.Begin (Application.Top);
|
||||
Assert.True (tf.HasFocus);
|
||||
Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, new KeyModifiers ())));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
var expected = @"
|
||||
File Edit Format
|
||||
┌──────┐
|
||||
│ New │
|
||||
└──────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 4), pos);
|
||||
|
||||
Assert.True (menu.openMenu.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 1), pos);
|
||||
|
||||
Assert.True (menu.openMenu.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
┌───────┐
|
||||
│ Wrap │
|
||||
└───────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 23, 4), pos);
|
||||
|
||||
Assert.True (menu.openMenu.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 1), pos);
|
||||
|
||||
Assert.True (menu.openMenu.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
|
||||
Assert.True (menu.IsMenuOpen);
|
||||
Assert.False (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
┌──────┐
|
||||
│ New │
|
||||
└──────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 4), pos);
|
||||
|
||||
Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, new KeyModifiers ())));
|
||||
Assert.False (menu.IsMenuOpen);
|
||||
Assert.True (tf.HasFocus);
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
expected = @"
|
||||
File Edit Format
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (2, 0, 22, 1), pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user