From 0d6ad5b1129428f82b5f03534111e974b70603ff Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 19 Aug 2024 12:07:10 -0600 Subject: [PATCH] Fixed treeviewTests --- Terminal.Gui/View/View.Navigation.cs | 5 +- Terminal.Gui/Views/ComboBox.cs | 4 +- Terminal.Gui/Views/DatePicker.cs | 1 + Terminal.Gui/Views/Menu/MenuBar.cs | 1 + Terminal.Gui/Views/TileView.cs | 5 +- Terminal.Gui/Views/TreeView/TreeView.cs | 3 + UnitTests/Views/ComboBoxTests.cs | 2 +- UnitTests/Views/DatePickerTests.cs | 4 +- UnitTests/Views/TableViewTests.cs | 153 +++++++++++------------- UnitTests/Views/ToplevelTests.cs | 2 +- UnitTests/Views/TreeTableSourceTests.cs | 2 +- UnitTests/Views/TreeViewTests.cs | 15 ++- 12 files changed, 98 insertions(+), 99 deletions(-) diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs index 6ba3ed1e6..8328cf5f3 100644 --- a/Terminal.Gui/View/View.Navigation.cs +++ b/Terminal.Gui/View/View.Navigation.cs @@ -45,7 +45,8 @@ public partial class View // Focus and cross-view navigation management (TabStop { if (value) { - if (FocusChanging (Application.Navigation!.GetFocused ())) + // NOTE: If Application.Navigation is null, we pass null to FocusChanging. For unit tests. + if (FocusChanging (Application.Navigation?.GetFocused ())) { // The change happened // HasFocus is now true @@ -388,7 +389,7 @@ public partial class View // Focus and cross-view navigation management (TabStop if (view.HasFocus) { // We could not advance - return false; + return true; } // The subview does not have focus, but at least one other that can. Can this one be focused? diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 22f62c238..7be720522 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -28,6 +28,7 @@ public class ComboBox : View, IDesignable /// Public constructor public ComboBox () { + CanFocus = true; _search = new TextField () { CanFocus = true, TabStop = TabBehavior.NoStop }; _listview = new ComboListView (this, HideDropdownListOnClick) { CanFocus = true, TabStop = TabBehavior.NoStop}; @@ -824,6 +825,7 @@ public class ComboBox : View, IDesignable set => _hideDropdownListOnClick = WantContinuousButtonPressed = value; } + // BUGBUG: OnMouseEvent is internal! protected internal override bool OnMouseEvent (MouseEvent me) { var res = false; @@ -960,8 +962,6 @@ public class ComboBox : View, IDesignable _highlighted = _container.SelectedItem; Application.UngrabMouse (); } - - return; } public override bool OnSelectedChanged () diff --git a/Terminal.Gui/Views/DatePicker.cs b/Terminal.Gui/Views/DatePicker.cs index d93f80e03..b4546c28d 100644 --- a/Terminal.Gui/Views/DatePicker.cs +++ b/Terminal.Gui/Views/DatePicker.cs @@ -187,6 +187,7 @@ public class DatePicker : View BorderStyle = LineStyle.Single; Date = date; _dateLabel = new Label { X = 0, Y = 0, Text = "Date: " }; + CanFocus = true; TabStop = TabBehavior.TabGroup; _calendar = new TableView diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index 570bf7847..e1a5f2d18 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -68,6 +68,7 @@ public class MenuBar : View, IDesignable { MenuItem._menuBar = this; + CanFocus = true; TabStop = TabBehavior.NoStop; X = 0; Y = 0; diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index cc27c00b3..05ae7399f 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -13,7 +13,10 @@ public class TileView : View private TileView parentTileView; /// Creates a new instance of the class with 2 tiles (i.e. left and right). - public TileView () : this (2) { } + public TileView () : this (2) + { + CanFocus = true; + } /// Creates a new instance of the class with number of tiles. /// diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index c6cca5991..9b8da2bae 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -34,6 +34,8 @@ public class TreeView : TreeView /// public TreeView () { + CanFocus = true; + TreeBuilder = new TreeNodeBuilder (); AspectGetter = o => o is null ? "Null" : o.Text ?? o?.ToString () ?? "Unnamed Node"; } @@ -975,6 +977,7 @@ public class TreeView : View, ITreeView where T : class /// public bool IsSelected (T model) { return Equals (SelectedObject, model) || (MultiSelect && multiSelectedRegions.Any (s => s.Contains (model))); } + // BUGBUG: OnMouseEvent is internal. TreeView should not be overriding. /// protected internal override bool OnMouseEvent (MouseEvent me) { diff --git a/UnitTests/Views/ComboBoxTests.cs b/UnitTests/Views/ComboBoxTests.cs index d6206d216..fa8bee57c 100644 --- a/UnitTests/Views/ComboBoxTests.cs +++ b/UnitTests/Views/ComboBoxTests.cs @@ -806,7 +806,7 @@ Three ", top.Dispose (); } - [Fact (Skip = "BUGBUG: New focus stuff broke. Fix later.")] + [Fact] [AutoInitShutdown] public void KeyBindings_Command () { diff --git a/UnitTests/Views/DatePickerTests.cs b/UnitTests/Views/DatePickerTests.cs index 60cf574b6..00dc4bd13 100644 --- a/UnitTests/Views/DatePickerTests.cs +++ b/UnitTests/Views/DatePickerTests.cs @@ -59,11 +59,11 @@ public class DatePickerTests datePicker.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop); // Change month to December - Assert.True (datePicker.NewKeyDownEvent (Key.Enter)); + Assert.True (Application.OnKeyDown (Key.Enter)); Assert.Equal (12, datePicker.Date.Month); // Date should not change as next month button is disabled - Assert.False (datePicker.NewKeyDownEvent (Key.Enter)); + Assert.False (Application.OnKeyDown (Key.Enter)); Assert.Equal (12, datePicker.Date.Month); top.Dispose (); } diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 0850689f6..21d1e6c18 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -671,7 +671,7 @@ public class TableViewTests (ITestOutputHelper output) tableView.SelectedRow = 3; // row is 0 indexed so this is the 4th visible row // Scroll down - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorDown }); // Scrolled off the page by 1 row so it should only have moved down 1 line of RowOffset Assert.Equal (4, tableView.SelectedRow); @@ -723,7 +723,7 @@ public class TableViewTests (ITestOutputHelper output) TestHelpers.AssertDriverContentsAre (expected, output); // Scroll right - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); // since A is now pushed off screen we get indicator showing // that user can scroll left to see first column @@ -738,8 +738,8 @@ public class TableViewTests (ITestOutputHelper output) TestHelpers.AssertDriverContentsAre (expected, output); // Scroll right twice more (to end of columns) - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); tableView.Draw (); @@ -798,7 +798,7 @@ public class TableViewTests (ITestOutputHelper output) TestHelpers.AssertDriverContentsAre (expected, output); // Scroll right - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); tableView.Draw (); @@ -858,7 +858,7 @@ public class TableViewTests (ITestOutputHelper output) TestHelpers.AssertDriverContentsAre (expected, output); // Scroll right - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); tableView.Draw (); @@ -1034,13 +1034,14 @@ public class TableViewTests (ITestOutputHelper output) top.Dispose (); } - [Theory (Skip = "#2491 - Uses private SetHasFocus. Refactor to not.")] + [Theory] [SetupFakeDriver] [InlineData (false)] [InlineData (true)] public void TableView_ColorsTest_ColorGetter (bool focused) { TableView tv = SetUpMiniTable (out DataTable dt); + tv.LayoutSubviews (); // width exactly matches the max col widths @@ -1062,12 +1063,8 @@ public class TableViewTests (ITestOutputHelper output) bStyle.ColorGetter = a => Convert.ToInt32 (a.CellValue) == 2 ? cellHighlight : null; - // private method for forcing the view to be focused/not focused - MethodInfo setFocusMethod = - typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic); - - // when the view is/isn't focused - setFocusMethod.Invoke (tv, new object [] { focused, tv, true }); + tv.HasFocus = focused; + Assert.Equal(focused, tv.HasFocus); tv.Draw (); @@ -1128,7 +1125,7 @@ public class TableViewTests (ITestOutputHelper output) ); } - [Theory (Skip = "#2491 - Uses private SetHasFocus. Refactor to not.")] + [Theory] [SetupFakeDriver] [InlineData (false)] [InlineData (true)] @@ -1153,12 +1150,8 @@ public class TableViewTests (ITestOutputHelper output) // when B is 2 use the custom highlight color for the row tv.Style.RowColorGetter += e => Convert.ToInt32 (e.Table [e.RowIndex, 1]) == 2 ? rowHighlight : null; - // private method for forcing the view to be focused/not focused - MethodInfo setFocusMethod = - typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic); - - // when the view is/isn't focused - setFocusMethod.Invoke (tv, new object [] { focused, tv, true }); + tv.HasFocus = focused; + Assert.Equal (focused, tv.HasFocus); tv.Draw (); @@ -1219,7 +1212,7 @@ public class TableViewTests (ITestOutputHelper output) ); } - [Theory (Skip = "#2491 - Uses private SetHasFocus. Refactor to not.")] + [Theory] [SetupFakeDriver] [InlineData (false)] [InlineData (true)] @@ -1231,12 +1224,8 @@ public class TableViewTests (ITestOutputHelper output) // width exactly matches the max col widths tv.Viewport = new (0, 0, 5, 4); - // private method for forcing the view to be focused/not focused - MethodInfo setFocusMethod = - typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic); - - // when the view is/isn't focused - setFocusMethod.Invoke (tv, new object [] { focused, tv, true }); + tv.HasFocus = focused; + Assert.Equal (focused, tv.HasFocus); tv.Draw (); @@ -1264,7 +1253,7 @@ public class TableViewTests (ITestOutputHelper output) } - [Theory (Skip = "#2491 - Uses private SetHasFocus. Refactor to not.")] + [Theory] [SetupFakeDriver] [InlineData (false)] [InlineData (true)] @@ -1277,12 +1266,8 @@ public class TableViewTests (ITestOutputHelper output) // width exactly matches the max col widths tv.Viewport = new (0, 0, 5, 4); - // private method for forcing the view to be focused/not focused - MethodInfo setFocusMethod = - typeof (View).GetMethod ("SetHasFocus", BindingFlags.Instance | BindingFlags.NonPublic); - - // when the view is/isn't focused - setFocusMethod.Invoke (tv, new object [] { focused, tv, true }); + tv.HasFocus = focused; + Assert.Equal (focused, tv.HasFocus); tv.Draw (); @@ -1569,7 +1554,7 @@ public class TableViewTests (ITestOutputHelper output) tv.Table = new EnumerableTableSource ( new [] { "fish", "troll", "trap", "zoo" }, - new() { { "Name", t => t }, { "EndsWith", t => t.Last () } } + new () { { "Name", t => t }, { "EndsWith", t => t.Last () } } ); tv.LayoutSubviews (); @@ -1594,11 +1579,11 @@ public class TableViewTests (ITestOutputHelper output) Assert.False (tv.HasFocus); // already on fish - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.F }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.F }); Assert.Equal (0, tv.SelectedRow); // not focused - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.Z }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.Z }); Assert.Equal (0, tv.SelectedRow); // ensure that TableView has the input focus @@ -1610,38 +1595,38 @@ public class TableViewTests (ITestOutputHelper output) Assert.True (tv.HasFocus); // already on fish - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.F }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.F }); Assert.Equal (0, tv.SelectedRow); // move to zoo - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.Z }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.Z }); Assert.Equal (3, tv.SelectedRow); // move to troll - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.T }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.T }); Assert.Equal (1, tv.SelectedRow); // move to trap - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.T }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.T }); Assert.Equal (2, tv.SelectedRow); // change columns to navigate by column 2 Assert.Equal (0, tv.SelectedColumn); Assert.Equal (2, tv.SelectedRow); - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); Assert.Equal (1, tv.SelectedColumn); Assert.Equal (2, tv.SelectedRow); // nothing ends with t so stay where you are - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.T }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.T }); Assert.Equal (2, tv.SelectedRow); //jump to fish which ends in h - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.H }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.H }); Assert.Equal (0, tv.SelectedRow); // jump to zoo which ends in o - tv.NewKeyDownEvent (new() { KeyCode = KeyCode.O }); + tv.NewKeyDownEvent (new () { KeyCode = KeyCode.O }); Assert.Equal (3, tv.SelectedRow); top.Dispose (); } @@ -1884,7 +1869,7 @@ public class TableViewTests (ITestOutputHelper output) Assert.Equal (1, tableView.SelectedColumn); tableView.NewKeyDownEvent ( - new() { KeyCode = useHome ? KeyCode.Home : KeyCode.CursorLeft } + new () { KeyCode = useHome ? KeyCode.Home : KeyCode.CursorLeft } ); // Expect the cursor to stay at 1 @@ -1935,7 +1920,7 @@ public class TableViewTests (ITestOutputHelper output) Assert.Equal (2, tableView.SelectedColumn); tableView.NewKeyDownEvent ( - new() { KeyCode = useEnd ? KeyCode.End : KeyCode.CursorRight } + new () { KeyCode = useEnd ? KeyCode.End : KeyCode.CursorRight } ); // Expect the cursor to stay at 2 @@ -2032,12 +2017,12 @@ public class TableViewTests (ITestOutputHelper output) tableView.Style.GetOrCreateColumnStyle (1).Visible = false; tableView.SelectedColumn = 0; - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); // Expect the cursor navigation to skip over the invisible column(s) Assert.Equal (2, tableView.SelectedColumn); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorLeft }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorLeft }); // Expect the cursor navigation backwards to skip over invisible column too Assert.Equal (0, tableView.SelectedColumn); @@ -2170,7 +2155,7 @@ public class TableViewTests (ITestOutputHelper output) // Clicking in bottom row tv.NewMouseEvent ( - new() { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } + new () { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } ); // should select that row @@ -2178,7 +2163,7 @@ public class TableViewTests (ITestOutputHelper output) // shift clicking top row tv.NewMouseEvent ( - new() { Position = new (1, 2), Flags = MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl } + new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl } ); // should extend the selection @@ -2196,14 +2181,14 @@ public class TableViewTests (ITestOutputHelper output) [SetupFakeDriver] public void TestEnumerableDataSource_BasicTypes () { - ((FakeDriver)Application.Driver!).SetBufferSize(100,100); + ((FakeDriver)Application.Driver!).SetBufferSize (100, 100); var tv = new TableView (); tv.ColorScheme = Colors.ColorSchemes ["TopLevel"]; tv.Viewport = new (0, 0, 50, 6); tv.Table = new EnumerableTableSource ( new [] { typeof (string), typeof (int), typeof (float) }, - new() + new () { { "Name", t => t.Name }, { "Namespace", t => t.Namespace }, { "BaseType", t => t.BaseType } @@ -2243,7 +2228,7 @@ public class TableViewTests (ITestOutputHelper output) // Clicking in bottom row tv.NewMouseEvent ( - new() { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } + new () { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } ); // should select that row @@ -2298,7 +2283,7 @@ public class TableViewTests (ITestOutputHelper output) // Clicking in bottom row tv.NewMouseEvent ( - new() { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } + new () { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } ); // should select that row @@ -2351,7 +2336,7 @@ A B C // Clicking in bottom row tv.NewMouseEvent ( - new() { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } + new () { Position = new (1, 4), Flags = MouseFlags.Button1Clicked } ); // should select that row @@ -2407,7 +2392,7 @@ A B C tv.ColorScheme = Colors.ColorSchemes ["TopLevel"]; tv.Viewport = new (0, 0, 25, 4); - tv.Style = new() + tv.Style = new () { ShowHeaders = false, ShowHorizontalHeaderOverline = false, ShowHorizontalHeaderUnderline = false }; @@ -2532,7 +2517,7 @@ A B C // Clicking in bottom row tv.NewMouseEvent ( - new() { Position = new (1, 3), Flags = MouseFlags.Button1Clicked } + new () { Position = new (1, 3), Flags = MouseFlags.Button1Clicked } ); // should select that row @@ -2540,7 +2525,7 @@ A B C // shift clicking top row tv.NewMouseEvent ( - new() { Position = new (1, 2), Flags = MouseFlags.Button1Clicked | MouseFlags.ButtonShift } + new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked | MouseFlags.ButtonShift } ); // should extend the selection @@ -3048,14 +3033,14 @@ A B C Assert.Equal (1, s2.Y); // Go back to the toggled cell - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorUp }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorUp }); // Toggle off - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.Space }); // Go Left - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorLeft }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorLeft }); selectedCell = tableView.GetAllSelectedCells ().Single (); Assert.Equal (0, selectedCell.X); @@ -3074,10 +3059,10 @@ A B C tableView.KeyBindings.ReplaceCommands (Key.Space, Command.Select); // Toggle Select Cell 0,0 - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.Space }); // Go Down - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorDown }); TableSelection m = tableView.MultiSelectedRegions.Single (); Assert.True (m.IsToggled); @@ -3087,13 +3072,13 @@ A B C //First row toggled and Second row active = 12 selected cells Assert.Equal (12, tableView.GetAllSelectedCells ().Count ()); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorUp }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorUp }); Assert.Single (tableView.MultiSelectedRegions.Where (r => r.IsToggled)); // Can untoggle at 1,0 even though 0,0 was initial toggle because FullRowSelect is on - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.Space }); #pragma warning disable xUnit2029 Assert.Empty (tableView.MultiSelectedRegions.Where (r => r.IsToggled)); @@ -3112,16 +3097,16 @@ A B C tableView.KeyBindings.ReplaceCommands (Key.Space, Command.Select); // Make a square selection - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.ShiftMask | KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.ShiftMask | KeyCode.CursorRight }); Assert.Equal (4, tableView.GetAllSelectedCells ().Count ()); // Toggle the square selected region on - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.Space }); // Go Right - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight }); //Toggled on square + the active cell (x=2,y=1) Assert.Equal (5, tableView.GetAllSelectedCells ().Count ()); @@ -3130,11 +3115,11 @@ A B C // Untoggle the rectangular region by hitting toggle in // any cell in that rect - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorUp }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorLeft }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorUp }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorLeft }); Assert.Equal (4, tableView.GetAllSelectedCells ().Count ()); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.Space }); Assert.Single (tableView.GetAllSelectedCells ()); } @@ -3153,17 +3138,17 @@ A B C tableView.KeyBindings.ReplaceCommands (Key.Space, Command.Select); // Make first square selection (0,0 to 1,1) - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.ShiftMask | KeyCode.CursorRight }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.Space }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.ShiftMask | KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.Space }); Assert.Equal (4, tableView.GetAllSelectedCells ().Count ()); // Make second square selection leaving 1 unselected line between them - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorLeft }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorDown }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.CursorDown }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); - tableView.NewKeyDownEvent (new() { KeyCode = KeyCode.ShiftMask | KeyCode.CursorRight }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorLeft }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.ShiftMask | KeyCode.CursorDown }); + tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.ShiftMask | KeyCode.CursorRight }); // 2 square selections Assert.Equal (8, tableView.GetAllSelectedCells ().Count ()); @@ -3213,7 +3198,7 @@ A B C tv.Table = source = new ( pets, - new() + new () { { "Name", p => p.Name }, { "Kind", p => p.Kind } } diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 19b63c0a6..75b4ea67c 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -1078,7 +1078,7 @@ public partial class ToplevelTests (ITestOutputHelper output) public void PositionCursor_SetCursorVisibility_To_Invisible_If_Focused_Is_Null () { var tf = new TextField { Width = 5, Text = "test" }; - var view = new View { Width = 10, Height = 10 }; + var view = new View { Width = 10, Height = 10, CanFocus = true }; view.Add (tf); var top = new Toplevel (); top.Add (view); diff --git a/UnitTests/Views/TreeTableSourceTests.cs b/UnitTests/Views/TreeTableSourceTests.cs index 4e4ba260e..5f17475cc 100644 --- a/UnitTests/Views/TreeTableSourceTests.cs +++ b/UnitTests/Views/TreeTableSourceTests.cs @@ -289,7 +289,7 @@ public class TreeTableSourceTests : IDisposable var top = new Toplevel (); top.Add (tableView); - top.RestoreFocus (null); + top.SetFocus (); Assert.Equal (tableView, top.MostFocused); return tableView; diff --git a/UnitTests/Views/TreeViewTests.cs b/UnitTests/Views/TreeViewTests.cs index a770d1d9d..240c18a26 100644 --- a/UnitTests/Views/TreeViewTests.cs +++ b/UnitTests/Views/TreeViewTests.cs @@ -483,7 +483,11 @@ public class TreeViewTests public void ObjectActivationButton_SetToNull () { TreeView tree = CreateTree (out Factory f, out Car car1, out _); + Assert.Null (tree.SelectedObject); + Assert.True (tree.SetFocus ()); + tree.SelectedObject = null; + Assert.Null (tree.SelectedObject); // disable activation tree.ObjectActivationButton = null; @@ -500,6 +504,7 @@ public class TreeViewTests Assert.False (called); + // double click does nothing because we changed button to null tree.NewMouseEvent (new MouseEvent { Flags = MouseFlags.Button1DoubleClicked }); @@ -1338,13 +1343,13 @@ oot two var treeView = new TreeView (); var accepted = false; -treeView.Accept += OnAccept; -treeView.InvokeCommand (Command.HotKey); + treeView.Accept += OnAccept; + treeView.InvokeCommand (Command.HotKey); -Assert.False (accepted); + Assert.False (accepted); -return; -void OnAccept (object sender, HandledEventArgs e) { accepted = true; } + return; + void OnAccept (object sender, HandledEventArgs e) { accepted = true; } }