From 684fb199ed4311347ca2391ea336c8919e71ca20 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 24 Nov 2024 12:53:00 +0000 Subject: [PATCH 1/6] Fixes #3847. TabView changes focus to Tab on Layout. --- Terminal.Gui/Views/TabView/TabRowView.cs | 5 ----- Terminal.Gui/Views/TabView/TabView.cs | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/TabView/TabRowView.cs b/Terminal.Gui/Views/TabView/TabRowView.cs index b1ec596ecc..3490615b76 100644 --- a/Terminal.Gui/Views/TabView/TabRowView.cs +++ b/Terminal.Gui/Views/TabView/TabRowView.cs @@ -64,11 +64,6 @@ protected override bool OnMouseEvent (MouseEventArgs me) return false; } - if (!HasFocus && CanFocus) - { - SetFocus (); - } - if (me.IsSingleDoubleOrTripleClicked) { var scrollIndicatorHit = 0; diff --git a/Terminal.Gui/Views/TabView/TabView.cs b/Terminal.Gui/Views/TabView/TabView.cs index 7916911fcd..68264f2a35 100644 --- a/Terminal.Gui/Views/TabView/TabView.cs +++ b/Terminal.Gui/Views/TabView/TabView.cs @@ -518,6 +518,10 @@ internal IEnumerable CalculateViewport (Rectangle bounds) { SelectedTab?.SetFocus (); } + else + { + SelectedTab?.View?.SetFocus (); + } } /// From d4f061d4e8f608fd8139b3fbc3a6dfd6e1b7a5b6 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 24 Nov 2024 14:03:03 +0000 Subject: [PATCH 2/6] Enable wheel to allow focus. --- Terminal.Gui/Views/TabView/TabRowView.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Terminal.Gui/Views/TabView/TabRowView.cs b/Terminal.Gui/Views/TabView/TabRowView.cs index 3490615b76..b3b99ae25c 100644 --- a/Terminal.Gui/Views/TabView/TabRowView.cs +++ b/Terminal.Gui/Views/TabView/TabRowView.cs @@ -59,6 +59,11 @@ protected override bool OnMouseEvent (MouseEventArgs me) } } + if (me.IsWheel && !HasFocus && CanFocus) + { + SetFocus (); + } + if (!me.IsSingleDoubleOrTripleClicked) { return false; From f2ffae152bf1e75f5147d53d39709b24ab31ea06 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 24 Nov 2024 17:50:51 +0000 Subject: [PATCH 3/6] Set TabStop as TabGroup which allow F6 shortcut. --- Terminal.Gui/Views/TabView/TabRowView.cs | 1 + UnitTests/Views/TabViewTests.cs | 71 ++++++++++++++++++------ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/Terminal.Gui/Views/TabView/TabRowView.cs b/Terminal.Gui/Views/TabView/TabRowView.cs index b3b99ae25c..9d9bb85b1a 100644 --- a/Terminal.Gui/Views/TabView/TabRowView.cs +++ b/Terminal.Gui/Views/TabView/TabRowView.cs @@ -13,6 +13,7 @@ public TabRowView (TabView host) Id = "tabRowView"; CanFocus = true; + TabStop = TabBehavior.TabGroup; Width = Dim.Fill (); _rightScrollIndicator = new View diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index 15896267ea..ad02272f33 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -365,10 +365,10 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () } [Fact] - [AutoInitShutdown] - public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () + [SetupFakeDriver] + public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp_F6 () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 7; tv.Height = 5; @@ -393,7 +393,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.SelectedTab.View, top.Focused.MostFocused); // Press the cursor up key to focus the selected tab - Application.RaiseKeyDownEvent (Key.CursorUp); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); Application.LayoutAndDraw (); // Is the selected tab focused @@ -411,7 +411,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () }; // Press the cursor right key to select the next tab - Application.RaiseKeyDownEvent (Key.CursorRight); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorRight)); Application.LayoutAndDraw (); Assert.Equal (tab1, oldChanged); Assert.Equal (tab2, newChanged); @@ -420,7 +420,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the cursor down key. Since the selected tab has no focusable views, the focus should move to the next view in the toplevel - Application.RaiseKeyDownEvent (Key.CursorDown); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown)); Assert.Equal (tab2, tv.SelectedTab); Assert.Equal (btn, top.MostFocused); @@ -436,40 +436,55 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.False (tv.SelectedTab.View.CanFocus); // Press cursor up. Should focus the subview in the selected tab. - Application.RaiseKeyDownEvent (Key.CursorUp); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); Assert.Equal (tab2, tv.SelectedTab); Assert.NotEqual (btnSubView, top.MostFocused); Assert.Equal (tab2, top.MostFocused); tv.SelectedTab.View.CanFocus = true; - Application.RaiseKeyDownEvent (Key.CursorDown); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown)); Assert.Equal (tab2, tv.SelectedTab); Assert.Equal (btnSubView, top.MostFocused); - Application.RaiseKeyDownEvent (Key.CursorUp); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); + // TabRowView now has TabGroup which only F6 is allowed + Assert.NotEqual (tab2, top.MostFocused); + Assert.Equal (btn, top.MostFocused); + + Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); + Assert.Equal (btnSubView, top.MostFocused); + + Assert.True (Application.RaiseKeyDownEvent (Key.F6)); Assert.Equal (tab2, top.MostFocused); // Press the cursor down key twice. - Application.RaiseKeyDownEvent (Key.CursorDown); - Application.RaiseKeyDownEvent (Key.CursorDown); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown)); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown)); Assert.Equal (btn, top.MostFocused); // Press the cursor down key again will focus next view in the toplevel, which is the TabView - Application.RaiseKeyDownEvent (Key.CursorDown); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorDown)); Assert.Equal (tab2, tv.SelectedTab); Assert.Equal (tv, top.Focused); // Due to the RestoreFocus method prioritize the _previouslyFocused, so btnSubView will be focused again Assert.Equal (btnSubView, tv.MostFocused); // Press the cursor up key to focus the selected tab which it's the only way to do that - Application.RaiseKeyDownEvent (Key.CursorUp); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); Assert.Equal (tab2, tv.SelectedTab); + Assert.Equal (btn, top.Focused); + + Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); + Assert.Equal (tv, top.Focused); + Assert.Equal (btnSubView, top.MostFocused); + + Assert.True (Application.RaiseKeyDownEvent (Key.F6)); Assert.Equal (tv, top.Focused); Assert.Equal (tab2, top.Focused.MostFocused); Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the cursor left key to select the previous tab - Application.RaiseKeyDownEvent (Key.CursorLeft); + Assert.True (Application.RaiseKeyDownEvent (Key.CursorLeft)); Application.LayoutAndDraw (); Assert.Equal (tab2, oldChanged); Assert.Equal (tab1, newChanged); @@ -479,7 +494,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tab1, top.Focused.MostFocused); // Press the end key to select the last tab - Application.RaiseKeyDownEvent (Key.End); + Assert.True (Application.RaiseKeyDownEvent (Key.End)); Application.LayoutAndDraw (); Assert.Equal (tab1, oldChanged); Assert.Equal (tab2, newChanged); @@ -488,7 +503,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the home key to select the first tab - Application.RaiseKeyDownEvent (Key.Home); + Assert.True (Application.RaiseKeyDownEvent (Key.Home)); Application.LayoutAndDraw (); Assert.Equal (tab2, oldChanged); Assert.Equal (tab1, newChanged); @@ -497,7 +512,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the page down key to select the next set of tabs - Application.RaiseKeyDownEvent (Key.PageDown); + Assert.True (Application.RaiseKeyDownEvent (Key.PageDown)); Application.LayoutAndDraw (); Assert.Equal (tab1, oldChanged); Assert.Equal (tab2, newChanged); @@ -506,7 +521,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the page up key to select the previous set of tabs - Application.RaiseKeyDownEvent (Key.PageUp); + Assert.True (Application.RaiseKeyDownEvent (Key.PageUp)); Application.LayoutAndDraw (); Assert.Equal (tab2, oldChanged); Assert.Equal (tab1, newChanged); @@ -1455,6 +1470,26 @@ public void Add_Three_TabsOnBottom_ChangesTab () ); } + [Fact] + [SetupFakeDriver] + public void Tab_Get_Focus_By_Press_F6 () + { + TabView tv = GetTabView (out Tab tab1, out Tab tab2); + + tv.Width = 20; + tv.Height = 5; + + Toplevel top = new (); + top.Add (tv); + Application.Begin (top); + + Assert.False (tab1.HasFocus); + + Assert.True (Application.RaiseKeyDownEvent (Key.F6)); + Assert.True (tab1.HasFocus); + top.Dispose (); + } + private TabView GetTabView () { return GetTabView (out _, out _); } private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true) From 2bb057eaaa40bf67a96f8510f5b8184185875dd5 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 24 Nov 2024 18:40:34 +0000 Subject: [PATCH 4/6] Add wheel feature. --- Terminal.Gui/Views/TabView/TabRowView.cs | 8 +++---- UnitTests/Views/TabViewTests.cs | 29 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/TabView/TabRowView.cs b/Terminal.Gui/Views/TabView/TabRowView.cs index 9d9bb85b1a..36ffe303dd 100644 --- a/Terminal.Gui/Views/TabView/TabRowView.cs +++ b/Terminal.Gui/Views/TabView/TabRowView.cs @@ -65,20 +65,20 @@ protected override bool OnMouseEvent (MouseEventArgs me) SetFocus (); } - if (!me.IsSingleDoubleOrTripleClicked) + if (me is { IsSingleDoubleOrTripleClicked: false, IsWheel: false }) { return false; } - if (me.IsSingleDoubleOrTripleClicked) + if (me.IsSingleDoubleOrTripleClicked || me.IsWheel) { var scrollIndicatorHit = 0; - if (me.View is { Id: "rightScrollIndicator" }) + if (me.View is { Id: "rightScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight)) { scrollIndicatorHit = 1; } - else if (me.View is { Id: "leftScrollIndicator" }) + else if (me.View is { Id: "leftScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft)) { scrollIndicatorHit = -1; } diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index ad02272f33..6e6f797322 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -1490,6 +1490,35 @@ public void Tab_Get_Focus_By_Press_F6 () top.Dispose (); } + [Fact] + [SetupFakeDriver] + public void Mouse_Wheel_Changes_Tab () + { + TabView tv = GetTabView (out Tab tab1, out Tab tab2); + + tv.Width = 20; + tv.Height = 5; + + Toplevel top = new (); + top.Add (tv); + Application.Begin (top); + + Assert.False (tab1.HasFocus); + + Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledDown }); + Assert.True (tab2.HasFocus); + + Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledUp }); + Assert.True (tab1.HasFocus); + + Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledRight }); + Assert.True (tab2.HasFocus); + + Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledLeft }); + Assert.True (tab1.HasFocus); + top.Dispose (); + } + private TabView GetTabView () { return GetTabView (out _, out _); } private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true) From 2778482d3b6b9ef70f84b035e920f5513bca13a6 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 24 Nov 2024 18:41:13 +0000 Subject: [PATCH 5/6] Remove InitFakeDriver. --- UnitTests/Views/TabViewTests.cs | 96 ++++++++------------------------- 1 file changed, 23 insertions(+), 73 deletions(-) diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index 6e6f797322..49590a06f5 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -19,16 +19,12 @@ public void AddTab_SameTabMoreThanOnce () tv.AddTab (tab1, false); Assert.Equal (2, tv.Tabs.Count); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] + [SetupFakeDriver] public void AddTwoTabs_SecondIsSelected () { - InitFakeDriver (); - var tv = new TabView (); Tab tab1; Tab tab2; @@ -37,8 +33,6 @@ public void AddTwoTabs_SecondIsSelected () Assert.Equal (2, tv.Tabs.Count); Assert.Equal (tab2, tv.SelectedTab); - - Application.Shutdown (); } [Fact] @@ -57,9 +51,6 @@ public void EnsureSelectedTabVisible_MustScroll () // Asking to show tab2 should automatically move scroll offset accordingly tv.SelectedTab = tab2; Assert.Equal (1, tv.TabScrollOffset); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] @@ -76,8 +67,6 @@ public void EnsureSelectedTabVisible_NullSelect () Assert.Null (tv.SelectedTab); Assert.Equal (0, tv.TabScrollOffset); - - Application.Shutdown (); } [Fact] @@ -98,16 +87,13 @@ public void EnsureValidScrollOffsets_TabScrollOffset () tv.TabScrollOffset = -1; tv.SelectedTab = tab1; Assert.Equal (0, tv.TabScrollOffset); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] [AutoInitShutdown] public void MouseClick_ChangesTab () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 20; tv.Height = 5; @@ -190,7 +176,7 @@ public void MouseClick_ChangesTab () [AutoInitShutdown] public void MouseClick_Right_Left_Arrows_ChangesTab () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 7; tv.Height = 5; @@ -274,7 +260,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab () [AutoInitShutdown] public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 9; tv.Height = 7; @@ -365,7 +351,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () } [Fact] - [SetupFakeDriver] + [AutoInitShutdown] public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp_F6 () { TabView tv = GetTabView (out Tab tab1, out Tab tab2); @@ -541,9 +527,6 @@ public void RemoveAllTabs_ClearsSelection () tv.RemoveTab (tab2); Assert.Null (tv.SelectedTab); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] @@ -555,9 +538,6 @@ public void RemoveTab_ChangesSelection () tv.RemoveTab (tab1); Assert.Equal (tab2, tv.SelectedTab); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] @@ -575,9 +555,6 @@ public void RemoveTab_MultipleCalls_NotAnError () tv.RemoveTab (tab1); Assert.Equal (tab2, tv.SelectedTab); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] @@ -603,16 +580,13 @@ public void SelectedTabChanged_Called () Assert.Equal (1, called); Assert.Equal (tab1, oldTab); Assert.Equal (tab2, newTab); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] [SetupFakeDriver] public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width3 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 3; tv.Height = 5; tv.Style = new () { ShowTopLine = false }; @@ -636,7 +610,7 @@ public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width3 () [SetupFakeDriver] public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width4 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 4; tv.Height = 5; tv.Style = new () { ShowTopLine = false }; @@ -660,7 +634,7 @@ public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width4 () [SetupFakeDriver] public void ShowTopLine_False_TabsOnBottom_False_TestThinTabView_WithLongNames () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 10; tv.Height = 5; tv.Style = new () { ShowTopLine = false }; @@ -759,7 +733,7 @@ public void ShowTopLine_False_TabsOnBottom_False_TestThinTabView_WithLongNames ( [SetupFakeDriver] public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width3 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 3; tv.Height = 5; tv.Style = new () { ShowTopLine = false, TabsOnBottom = true }; @@ -783,7 +757,7 @@ public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width3 () [SetupFakeDriver] public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width4 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 4; tv.Height = 5; tv.Style = new () { ShowTopLine = false, TabsOnBottom = true }; @@ -807,7 +781,7 @@ public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width4 () [SetupFakeDriver] public void ShowTopLine_False_TabsOnBottom_True_TestThinTabView_WithLongNames () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 10; tv.Height = 5; tv.Style = new () { ShowTopLine = false, TabsOnBottom = true }; @@ -908,7 +882,7 @@ public void ShowTopLine_False_TabsOnBottom_True_TestThinTabView_WithLongNames () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width3 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 3; tv.Height = 5; tv.Layout (); @@ -930,7 +904,7 @@ public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width3 () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width4 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 4; tv.Height = 5; tv.Layout (); @@ -953,7 +927,7 @@ public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width4 () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_False_TestThinTabView_WithLongNames () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 10; tv.Height = 5; @@ -1050,7 +1024,7 @@ public void ShowTopLine_True_TabsOnBottom_False_TestThinTabView_WithLongNames () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_False_With_Unicode () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 20; tv.Height = 5; @@ -1092,7 +1066,7 @@ public void ShowTopLine_True_TabsOnBottom_False_With_Unicode () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width3 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 3; tv.Height = 5; tv.Style = new () { TabsOnBottom = true }; @@ -1116,7 +1090,7 @@ public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width3 () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width4 () { - TabView tv = GetTabView (out _, out _, false); + TabView tv = GetTabView (out _, out _); tv.Width = 4; tv.Height = 5; tv.Style = new () { TabsOnBottom = true }; @@ -1140,7 +1114,7 @@ public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width4 () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_True_TestThinTabView_WithLongNames () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 10; tv.Height = 5; tv.Style = new () { TabsOnBottom = true }; @@ -1222,7 +1196,7 @@ public void ShowTopLine_True_TabsOnBottom_True_TestThinTabView_WithLongNames () [SetupFakeDriver] public void ShowTopLine_True_TabsOnBottom_True_With_Unicode () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); tv.Width = 20; tv.Height = 5; tv.Style = new () { TabsOnBottom = true }; @@ -1294,9 +1268,6 @@ public void SwitchTabBy_NormalUsage () // even though we go right 2 indexes the event should only be called once Assert.Equal (1, called); Assert.Equal (tab4, tv.SelectedTab); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] @@ -1312,9 +1283,6 @@ public void SwitchTabBy_OutOfTabsRange () tv.SwitchTabBy (-500); Assert.Equal (tab1, tv.SelectedTab); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] @@ -1333,16 +1301,13 @@ public void RemoveTab_ThatHasFocus () } Assert.Empty (tv.Tabs); - - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); } [Fact] [SetupFakeDriver] public void Add_Three_TabsOnTop_ChangesTab () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); Tab tab3; tv.AddTab ( @@ -1407,7 +1372,7 @@ public void Add_Three_TabsOnTop_ChangesTab () [SetupFakeDriver] public void Add_Three_TabsOnBottom_ChangesTab () { - TabView tv = GetTabView (out Tab tab1, out Tab tab2, false); + TabView tv = GetTabView (out Tab tab1, out Tab tab2); Tab tab3; tv.AddTab ( @@ -1471,7 +1436,7 @@ public void Add_Three_TabsOnBottom_ChangesTab () } [Fact] - [SetupFakeDriver] + [AutoInitShutdown] public void Tab_Get_Focus_By_Press_F6 () { TabView tv = GetTabView (out Tab tab1, out Tab tab2); @@ -1521,13 +1486,8 @@ public void Mouse_Wheel_Changes_Tab () private TabView GetTabView () { return GetTabView (out _, out _); } - private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true) + private TabView GetTabView (out Tab tab1, out Tab tab2) { - if (initFakeDriver) - { - InitFakeDriver (); - } - var tv = new TabView () { Id = "tv " }; tv.BeginInit (); tv.EndInit (); @@ -1541,14 +1501,4 @@ private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = tr return tv; } - - private void InitFakeDriver () - { - ConfigurationManager.Locations = ConfigLocations.Default; - ConfigurationManager.Reset (); - - var driver = new FakeDriver (); - Application.Init (driver); - driver.Init (); - } } From aa2f3f846118c4a153e1cc34df641c5b1c8aeb57 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 25 Nov 2024 13:35:21 +0000 Subject: [PATCH 6/6] Rename to TabRow. --- .../Views/TabView/{TabRowView.cs => TabRow.cs} | 6 +++--- Terminal.Gui/Views/TabView/TabView.cs | 4 ++-- UnitTests/Views/TabViewTests.cs | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) rename Terminal.Gui/Views/TabView/{TabRowView.cs => TabRow.cs} (99%) diff --git a/Terminal.Gui/Views/TabView/TabRowView.cs b/Terminal.Gui/Views/TabView/TabRow.cs similarity index 99% rename from Terminal.Gui/Views/TabView/TabRowView.cs rename to Terminal.Gui/Views/TabView/TabRow.cs index 36ffe303dd..2ca80a69ae 100644 --- a/Terminal.Gui/Views/TabView/TabRowView.cs +++ b/Terminal.Gui/Views/TabView/TabRow.cs @@ -1,16 +1,16 @@ #nullable enable namespace Terminal.Gui; -internal class TabRowView : View +internal class TabRow : View { private readonly TabView _host; private readonly View _leftScrollIndicator; private readonly View _rightScrollIndicator; - public TabRowView (TabView host) + public TabRow (TabView host) { _host = host; - Id = "tabRowView"; + Id = "tabRow"; CanFocus = true; TabStop = TabBehavior.TabGroup; diff --git a/Terminal.Gui/Views/TabView/TabView.cs b/Terminal.Gui/Views/TabView/TabView.cs index 68264f2a35..73f286b564 100644 --- a/Terminal.Gui/Views/TabView/TabView.cs +++ b/Terminal.Gui/Views/TabView/TabView.cs @@ -16,7 +16,7 @@ public class TabView : View private readonly List _tabs = new (); /// This sub view is the 2 or 3 line control that represents the actual tabs themselves. - private readonly TabRowView _tabsBar; + private readonly TabRow _tabsBar; private Tab? _selectedTab; @@ -28,7 +28,7 @@ public TabView () { CanFocus = true; TabStop = TabBehavior.TabStop; // Because TabView has focusable subviews, it must be a TabGroup - _tabsBar = new TabRowView (this); + _tabsBar = new TabRow (this); _containerView = new (); ApplyStyleChanges (); diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index 49590a06f5..ac12a55564 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -101,7 +101,7 @@ public void MouseClick_ChangesTab () tv.Draw (); View tabRow = tv.Subviews [0]; - Assert.Equal ("TabRowView", tabRow.GetType ().Name); + Assert.Equal ("TabRow", tabRow.GetType ().Name); TestHelpers.AssertDriverContentsAre ( @" @@ -184,7 +184,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab () tv.Draw (); View tabRow = tv.Subviews [0]; - Assert.Equal ("TabRowView", tabRow.GetType ().Name); + Assert.Equal ("TabRow", tabRow.GetType ().Name); TestHelpers.AssertDriverContentsAre ( @" @@ -272,7 +272,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () tv.Draw (); View tabRow = tv.Subviews [0]; - Assert.Equal ("TabRowView", tabRow.GetType ().Name); + Assert.Equal ("TabRow", tabRow.GetType ().Name); TestHelpers.AssertDriverContentsAre ( @" @@ -433,7 +433,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp_F6 () Assert.Equal (btnSubView, top.MostFocused); Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp)); - // TabRowView now has TabGroup which only F6 is allowed + // TabRow now has TabGroup which only F6 is allowed Assert.NotEqual (tab2, top.MostFocused); Assert.Equal (btn, top.MostFocused); @@ -660,7 +660,7 @@ public void ShowTopLine_False_TabsOnBottom_False_TestThinTabView_WithLongNames ( ); tv.SelectedTab = tab2; - Assert.Equal (tab2, tv.Subviews.First (v => v.Id.Contains ("tabRowView")).MostFocused); + Assert.Equal (tab2, tv.Subviews.First (v => v.Id.Contains ("tabRow")).MostFocused); tv.Layout (); View.SetClipToScreen (); @@ -806,7 +806,7 @@ public void ShowTopLine_False_TabsOnBottom_True_TestThinTabView_WithLongNames () ); tv.SelectedTab = tab2; - Assert.Equal (tab2, tv.Subviews.First (v => v.Id.Contains ("tabRowView")).MostFocused); + Assert.Equal (tab2, tv.Subviews.First (v => v.Id.Contains ("tabRow")).MostFocused); tv.Layout (); View.SetClipToScreen ();