Moved Toplevel keybindings out of Toplevel to Application.

Still need to move navigation code out of Toplevel
This commit is contained in:
Tig
2024-07-24 12:28:30 -06:00
parent feaf5c0f6c
commit c03dd32031
36 changed files with 1035 additions and 870 deletions

View File

@@ -1030,28 +1030,30 @@ public class OverlappedTests
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
var lblTf1W1 = new Label { Text = "Enter text in TextField on Win1:" };
var tf1W1 = new TextField { X = Pos.Right (lblTf1W1) + 1, Width = Dim.Fill (), Text = "Text1 on Win1" };
var tf1W1 = new TextField { Id="tf1W1", X = Pos.Right (lblTf1W1) + 1, Width = Dim.Fill (), Text = "Text1 on Win1" };
var lblTvW1 = new Label { Y = Pos.Bottom (lblTf1W1) + 1, Text = "Enter text in TextView on Win1:" };
var tvW1 = new TextView
{
Id = "tvW1",
X = Pos.Left (tf1W1), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win1"
};
var lblTf2W1 = new Label { Y = Pos.Bottom (lblTvW1) + 1, Text = "Enter text in TextField on Win1:" };
var tf2W1 = new TextField { X = Pos.Left (tf1W1), Width = Dim.Fill (), Text = "Text2 on Win1" };
var tf2W1 = new TextField { Id = "tf2W1", X = Pos.Left (tf1W1), Width = Dim.Fill (), Text = "Text2 on Win1" };
win1.Add (lblTf1W1, tf1W1, lblTvW1, tvW1, lblTf2W1, tf2W1);
var win2 = new Window { Id = "win2", Width = Dim.Percent (50), Height = Dim.Fill () };
var lblTf1W2 = new Label { Text = "Enter text in TextField on Win2:" };
var tf1W2 = new TextField { X = Pos.Right (lblTf1W2) + 1, Width = Dim.Fill (), Text = "Text1 on Win2" };
var tf1W2 = new TextField { Id = "tf1W2", X = Pos.Right (lblTf1W2) + 1, Width = Dim.Fill (), Text = "Text1 on Win2" };
var lblTvW2 = new Label { Y = Pos.Bottom (lblTf1W2) + 1, Text = "Enter text in TextView on Win2:" };
var tvW2 = new TextView
{
Id = "tvW2",
X = Pos.Left (tf1W2), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win2"
};
var lblTf2W2 = new Label { Y = Pos.Bottom (lblTvW2) + 1, Text = "Enter text in TextField on Win2:" };
var tf2W2 = new TextField { X = Pos.Left (tf1W2), Width = Dim.Fill (), Text = "Text2 on Win2" };
var tf2W2 = new TextField { Id = "tf2W2", X = Pos.Left (tf1W2), Width = Dim.Fill (), Text = "Text2 on Win2" };
win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2);
win1.Closing += (s, e) => isRunning = false;
@@ -1104,72 +1106,69 @@ public class OverlappedTests
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
Assert.True (
Application.OnKeyDown (Key.Tab.WithShift)
);
Assert.True (Application.OnKeyDown (Key.Tab.WithShift));
Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
Assert.True (
Application.OnKeyDown (Key.Tab.WithCtrl)
);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // move to win2
Assert.Equal (win2, Application.OverlappedChildren [0]);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift)); // move back to win1
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorRight));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));
Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab)); // text view eats tab
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
tvW1.AllowsTab = false;
Assert.True (Application.OnKeyDown (Key.Tab)); // text view eats tab
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorRight));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.I.WithCtrl)));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
#endif
Assert.True (
Application.OverlappedChildren [0]
.NewKeyDownEvent (Key.Tab.WithShift)
);
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorLeft));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorUp));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorLeft)); // The view to the left of tvW1 is tf2W1, but tvW1 is still focused and eats cursor keys
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorUp));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.Tab));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (
Application.OverlappedChildren [0]
.NewKeyDownEvent (Key.Tab.WithCtrl)
);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // Move to win2
Assert.Equal (win2, Application.OverlappedChildren [0]);
Assert.Equal (tf1W2, win2.MostFocused);
tf2W2.SetFocus ();
Assert.True (tf2W2.HasFocus);
Assert.True (
Application.OverlappedChildren [0]
.NewKeyDownEvent (Key.Tab.WithCtrl.WithShift)
);
Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Application.AlternateForwardKey));
Assert.Equal (win2, Application.OverlappedChildren [0]);
Assert.Equal (tf2W2, win2.MostFocused);
Assert.True (Application.OnKeyDown (Application.AlternateBackwardKey));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.True (Application.OnKeyDown (Key.CursorDown));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
Assert.Equal (tf1W1, win1.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.B.WithCtrl)));
Assert.True (Application.OnKeyDown (new (Key.B.WithCtrl)));
#else
Assert.True (Application.OnKeyDown (Key.CursorLeft));
#endif
@@ -1180,20 +1179,17 @@ public class OverlappedTests
Assert.Equal (tvW1, win1.MostFocused);
Assert.Equal (Point.Empty, tvW1.CursorPosition);
Assert.True (
Application.OverlappedChildren [0]
.NewKeyDownEvent (Key.End.WithCtrl)
);
Assert.True (Application.OnKeyDown (Key.End.WithCtrl));
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tvW1, win1.MostFocused);
Assert.Equal (new (16, 1), tvW1.CursorPosition);
#if UNIX_KEY_BINDINGS
Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.F.WithCtrl)));
Assert.True (Application.OnKeyDown (new (Key.F.WithCtrl)));
#else
Assert.True (Application.OnKeyDown (Key.CursorRight));
#endif
Assert.Equal (win1, Application.OverlappedChildren [0]);
Assert.Equal (tf2W1, win1.MostFocused);
Assert.Equal (tvW1, win1.MostFocused);
#if UNIX_KEY_BINDINGS
Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.L.WithCtrl)));