mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
Merge branch 'v2_alt-key-on-window-with-menubar-fix_2776' into v2_alt-key-on-toplevel-with-menubar-fix_2810
This commit is contained in:
@@ -383,7 +383,7 @@ namespace Terminal.Gui {
|
||||
SuperView?.EnsureFocus ();
|
||||
if (SuperView != null && SuperView.Focused == null) {
|
||||
SuperView.FocusNext ();
|
||||
if (SuperView.Focused == null) {
|
||||
if (SuperView.Focused == null && Application.Current != null) {
|
||||
Application.Current.FocusNext ();
|
||||
}
|
||||
Application.BringOverlappedTopToFront ();
|
||||
|
||||
@@ -56,29 +56,5 @@ namespace Terminal.Gui {
|
||||
ColorScheme = Colors.Base; // TODO: make this a theme property
|
||||
BorderStyle = DefaultBorderStyle;
|
||||
}
|
||||
|
||||
// TODO: Are these overrides really needed?
|
||||
/// <inheritdoc/>
|
||||
public override void Add (View view)
|
||||
{
|
||||
base.Add (view);
|
||||
if (view.CanFocus) {
|
||||
CanFocus = true;
|
||||
}
|
||||
AddMenuStatusBar (view);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Remove (View view)
|
||||
{
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetNeedsDisplay ();
|
||||
base.Remove (view);
|
||||
RemoveMenuStatusBar (view);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,11 +764,25 @@ namespace Terminal.Gui.ViewTests {
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
view1.CanFocus = false;
|
||||
Assert.False (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
Assert.Equal (win2, Application.Current.Focused);
|
||||
Assert.Equal (view2, Application.Current.MostFocused);
|
||||
}
|
||||
@@ -790,11 +804,26 @@ namespace Terminal.Gui.ViewTests {
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
view1.CanFocus = false;
|
||||
Assert.False (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus);
|
||||
Assert.Equal (win1, Application.Current.Focused);
|
||||
Assert.Equal (view12, Application.Current.MostFocused);
|
||||
}
|
||||
@@ -815,13 +844,27 @@ namespace Terminal.Gui.ViewTests {
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
|
||||
Assert.True (Application.Top.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.True (view1.CanFocus);
|
||||
Assert.True (view1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
||||
|
||||
win1.CanFocus = false;
|
||||
Assert.False (view1.CanFocus);
|
||||
Assert.False (view1.HasFocus);
|
||||
Assert.False (win1.CanFocus);
|
||||
Assert.False (win1.HasFocus);
|
||||
Assert.True (view2.CanFocus);
|
||||
Assert.True (view2.HasFocus);
|
||||
Assert.Equal (win2, Application.Current.Focused);
|
||||
Assert.Equal (view2, Application.Current.MostFocused);
|
||||
}
|
||||
|
||||
@@ -193,5 +193,22 @@ namespace Terminal.Gui.ViewsTests {
|
||||
Assert.False (win2.HasFocus);
|
||||
Assert.False (view2.HasFocus);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Activating_MenuBar_By_Alt_Key_Does_Not_Throw ()
|
||||
{
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("Child", new MenuItem [] {
|
||||
new MenuItem ("_Create Child", "", null)
|
||||
})
|
||||
});
|
||||
var win = new Window ();
|
||||
win.Add (menu);
|
||||
Application.Top.Add (win);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
var exception = Record.Exception (() => win.ProcessHotKey (new KeyEvent (Key.AltMask, new KeyModifiers { Alt = true })));
|
||||
Assert.Null (exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user