From 591baa65f065451f2e09150ab9708cf3539ad102 Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 18 Aug 2024 15:45:26 -0600 Subject: [PATCH] GetFocused() -> back to Focused property (get only; computed). --- .../Application/ApplicationNavigation.cs | 2 +- .../Application/ApplicationOverlapped.cs | 2 +- Terminal.Gui/View/View.Keyboard.cs | 6 +- Terminal.Gui/View/View.Navigation.cs | 31 +++++----- Terminal.Gui/View/View.cs | 4 +- Terminal.Gui/Views/Menu/MenuBar.cs | 4 +- Terminal.Gui/Views/TabView.cs | 6 +- Terminal.Gui/Views/Toplevel.cs | 4 +- UnitTests/Application/KeyboardTests.cs | 4 +- UnitTests/View/Navigation/AddRemoveTests.cs | 12 ++-- UnitTests/View/Navigation/CanFocusTests.cs | 2 +- UnitTests/View/Navigation/EnabledTests.cs | 18 +++--- UnitTests/View/Navigation/EnterLeaveTests.cs | 8 +-- UnitTests/View/Navigation/HasFocusTests.cs | 4 +- UnitTests/View/Navigation/NavigationTests.cs | 8 +-- .../View/Navigation/RestoreFocusTests.cs | 28 ++++----- UnitTests/View/Navigation/SetFocusTests.cs | 22 +++---- UnitTests/View/Navigation/VisibleTests.cs | 18 +++--- UnitTests/View/ViewTests.cs | 8 +-- UnitTests/Views/AppendAutocompleteTests.cs | 10 +-- UnitTests/Views/OverlappedTests.cs | 8 +-- UnitTests/Views/TabViewTests.cs | 40 ++++++------ UnitTests/Views/TextFieldTests.cs | 2 +- UnitTests/Views/ToplevelTests.cs | 32 +++++----- UnitTests/Views/WindowTests.cs | 6 +- docfx/docs/migratingfromv1.md | 62 ++++++++++++++++++- 26 files changed, 203 insertions(+), 148 deletions(-) diff --git a/Terminal.Gui/Application/ApplicationNavigation.cs b/Terminal.Gui/Application/ApplicationNavigation.cs index 5a649577a..a7c13bcf8 100644 --- a/Terminal.Gui/Application/ApplicationNavigation.cs +++ b/Terminal.Gui/Application/ApplicationNavigation.cs @@ -117,7 +117,7 @@ public class ApplicationNavigation Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top; top!.AdvanceFocus (NavigationDirection.Backward, TabBehavior.TabGroup); - if (top.GetFocused () is null) + if (top.Focused is null) { top.AdvanceFocus (NavigationDirection.Backward, null); } diff --git a/Terminal.Gui/Application/ApplicationOverlapped.cs b/Terminal.Gui/Application/ApplicationOverlapped.cs index cdbdbe22c..4a8d55d47 100644 --- a/Terminal.Gui/Application/ApplicationOverlapped.cs +++ b/Terminal.Gui/Application/ApplicationOverlapped.cs @@ -151,7 +151,7 @@ public static class ApplicationOverlapped // QUESTION: AdvanceFocus returns false AND sets Focused to null if no view was found to advance to. Should't we only set focusProcessed if it returned true? focusSet = true; - if (Application.Current.SuperView?.GetFocused () != Application.Current) + if (Application.Current.SuperView?.Focused != Application.Current) { return; } diff --git a/Terminal.Gui/View/View.Keyboard.cs b/Terminal.Gui/View/View.Keyboard.cs index 517e4d12b..73625417a 100644 --- a/Terminal.Gui/View/View.Keyboard.cs +++ b/Terminal.Gui/View/View.Keyboard.cs @@ -286,7 +286,7 @@ public partial class View // Keyboard APIs // By default the KeyBindingScope is View - if (GetFocused ()?.NewKeyDownEvent (keyEvent) == true) + if (Focused?.NewKeyDownEvent (keyEvent) == true) { return true; } @@ -446,7 +446,7 @@ public partial class View // Keyboard APIs return false; } - if (GetFocused ()?.NewKeyUpEvent (keyEvent) == true) + if (Focused?.NewKeyUpEvent (keyEvent) == true) { return true; } @@ -611,7 +611,7 @@ public partial class View // Keyboard APIs // Now, process any key bindings in the subviews that are tagged to KeyBindingScope.HotKey. foreach (View subview in Subviews) { - if (subview == GetFocused ()) + if (subview == Focused) { continue; } diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs index bdf964432..0b7f00993 100644 --- a/Terminal.Gui/View/View.Navigation.cs +++ b/Terminal.Gui/View/View.Navigation.cs @@ -133,7 +133,7 @@ public partial class View // Focus and cross-view navigation management (TabStop // If we previously had a subview with focus (`Focused = subview`), we need to make sure that all subviews down the `subview`-hierarchy LeaveFocus. // LeaveFocus will recurse down the subview hierarchy and will also set PreviouslyMostFocused - View focused = GetFocused (); + View focused = Focused; focused?.LeaveFocus (this, true); // We need to ensure all superviews up the superview hierarchy have focus. @@ -155,7 +155,7 @@ public partial class View // Focus and cross-view navigation management (TabStop // - By setting _hasFocus to true we definitively change HasFocus for this view. // Get whatever peer has focus, if any - View focusedPeer = SuperView?.GetFocused (); + View focusedPeer = SuperView?.Focused; _hasFocus = true; @@ -285,7 +285,7 @@ public partial class View // Focus and cross-view navigation management (TabStop Leave?.Invoke (this, args); // Get whatever peer has focus, if any - View focusedPeer = SuperView?.GetFocused (); + View focusedPeer = SuperView?.Focused; _hasFocus = false; if (!traversingDown && CanFocus && Visible && Enabled) @@ -355,7 +355,7 @@ public partial class View // Focus and cross-view navigation management (TabStop return false; } - View focused = GetFocused (); + View focused = Focused; if (focused is {} && focused.AdvanceFocus (direction, behavior)) { @@ -369,7 +369,7 @@ public partial class View // Focus and cross-view navigation management (TabStop return false; } - var focusedIndex = index.IndexOf (GetFocused ()); + var focusedIndex = index.IndexOf (Focused); int next = 0; if (focusedIndex < index.Length - 1) @@ -382,7 +382,7 @@ public partial class View // Focus and cross-view navigation management (TabStop { // Go down the subview-hierarchy and leave // BUGBUG: This doesn't seem right - GetFocused ().HasFocus = false; + Focused.HasFocus = false; // TODO: Should we check the return value of SetHasFocus? @@ -399,7 +399,7 @@ public partial class View // Focus and cross-view navigation management (TabStop } // The subview does not have focus, but at least one other that can. Can this one be focused? - return view.EnterFocus (GetFocused ()); + return view.EnterFocus (Focused); } @@ -411,7 +411,7 @@ public partial class View // Focus and cross-view navigation management (TabStop /// internal bool RestoreFocus (TabBehavior? behavior) { - if (GetFocused () is null && _subviews?.Count > 0) + if (Focused is null && _subviews?.Count > 0) { if (_previouslyMostFocused is { }/* && (behavior is null || _previouslyMostFocused.TabStop == behavior)*/) { @@ -429,19 +429,19 @@ public partial class View // Focus and cross-view navigation management (TabStop /// The most focused Subview, or if no Subview is focused. public View GetMostFocused () { - if (GetFocused () is null) + if (Focused is null) { return null; } - View most = GetFocused ()!.GetMostFocused (); + View most = Focused!.GetMostFocused (); if (most is { }) { return most; } - return GetFocused (); + return Focused; } ///// @@ -595,7 +595,7 @@ public partial class View // Focus and cross-view navigation management (TabStop HasFocus = false; } - if (_canFocus && !HasFocus && Visible && SuperView is { } && SuperView.GetFocused () is null ) + if (_canFocus && !HasFocus && Visible && SuperView is { } && SuperView.Focused is null ) { // If CanFocus is set to true and this view does not have focus, make it enter focus SetFocus (); @@ -611,12 +611,11 @@ public partial class View // Focus and cross-view navigation management (TabStop /// public event EventHandler CanFocusChanged; - /// Returns the currently focused Subview of this view, or if nothing is focused. - /// The currently focused Subview. + /// Gets the currently focused Subview of this view, or if nothing is focused. [CanBeNull] - public View GetFocused () + public View Focused { - return Subviews.FirstOrDefault (v => v.HasFocus); + get { return Subviews.FirstOrDefault (v => v.HasFocus); } } /// diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index fa6e943b0..3807fa1af 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -313,7 +313,7 @@ public partial class View : Responder, ISupportInitializeNotification HasFocus = false; } - if (_enabled && CanFocus && Visible && !HasFocus && SuperView is { } && SuperView ?.GetFocused() is null) + if (_enabled && CanFocus && Visible && !HasFocus && SuperView is { } && SuperView?.Focused is null) { SetFocus (); } @@ -377,7 +377,7 @@ public partial class View : Responder, ISupportInitializeNotification } } - if (_visible && CanFocus && Enabled && !HasFocus && SuperView?.GetFocused () == null) + if (_visible && CanFocus && Enabled && !HasFocus && SuperView?.Focused == null) { SetFocus (); } diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index 35f01bdc7..cb3f5afac 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -391,7 +391,7 @@ public class MenuBar : View, IDesignable _selected = 0; SetNeedsDisplay (); - _previousFocused = SuperView is null ? Application.Current?.GetFocused () : SuperView.GetFocused (); + _previousFocused = SuperView is null ? Application.Current?.Focused : SuperView.Focused; OpenMenu (_selected); if (!SelectEnabledItem ( @@ -452,7 +452,7 @@ public class MenuBar : View, IDesignable if (_openMenu is null) { - _previousFocused = SuperView is null ? Application.Current?.GetFocused () ?? null : SuperView.GetFocused (); + _previousFocused = SuperView is null ? Application.Current?.Focused ?? null : SuperView.Focused; } OpenMenu (idx, sIdx, subMenu); diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index 2835820f6..e6959a491 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -77,7 +77,7 @@ public class TabView : View { _contentView.SetFocus (); - return _contentView.GetFocused () is { }; + return _contentView.Focused is { }; } return false; @@ -94,7 +94,7 @@ public class TabView : View { _contentView.SetFocus (); - return _contentView.GetFocused () is { }; + return _contentView.Focused is { }; } return false; @@ -1300,7 +1300,7 @@ public class TabView : View // if tab is the selected one and focus is inside this control if (toRender.IsSelected && _host.HasFocus) { - if (_host.GetFocused () == this) + if (_host.Focused == this) { // if focus is the tab bar itself then show that they can switch tabs prevAttr = ColorScheme.HotFocus; diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index b74cf8ced..7256b5bfd 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -431,7 +431,7 @@ public partial class Toplevel : View { if (!IsOverlappedContainer) { - if (GetFocused () is null) + if (Focused is null) { RestoreFocus (null); } @@ -441,7 +441,7 @@ public partial class Toplevel : View // This code path only happens when the Toplevel is an Overlapped container - if (GetFocused () is null) + if (Focused is null) { // TODO: this is an Overlapped hack foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!) diff --git a/UnitTests/Application/KeyboardTests.cs b/UnitTests/Application/KeyboardTests.cs index 4208997ca..99a0f6da2 100644 --- a/UnitTests/Application/KeyboardTests.cs +++ b/UnitTests/Application/KeyboardTests.cs @@ -397,7 +397,7 @@ public class KeyboardTests Application.Shutdown (); } - [Fact] + [Fact(Skip = "No longer valid test.")] [AutoInitShutdown] public void EnsuresTopOnFront_CanFocus_False_By_Keyboard () { @@ -457,7 +457,7 @@ public class KeyboardTests top.Dispose (); } - [Fact] + [Fact (Skip = "No longer valid test.")] [AutoInitShutdown] public void EnsuresTopOnFront_CanFocus_True_By_Keyboard () { diff --git a/UnitTests/View/Navigation/AddRemoveTests.cs b/UnitTests/View/Navigation/AddRemoveTests.cs index 873f38e21..ec26e3a2d 100644 --- a/UnitTests/View/Navigation/AddRemoveTests.cs +++ b/UnitTests/View/Navigation/AddRemoveTests.cs @@ -27,7 +27,7 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView top.Add (subView); Assert.True (top.HasFocus); - Assert.Equal (subView, top.GetFocused ()); + Assert.Equal (subView, top.Focused); Assert.True (subView.HasFocus); Assert.Equal (1, nEnter); } @@ -61,7 +61,7 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView top.Add (subView); Assert.True (top.HasFocus); - Assert.Equal (subView, top.GetFocused ()); + Assert.Equal (subView, top.Focused); Assert.True (subView.HasFocus); Assert.True (subSubView.HasFocus); } @@ -88,12 +88,12 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView top.SetFocus (); Assert.True (top.HasFocus); - Assert.Equal (subView, top.GetFocused ()); + Assert.Equal (subView, top.Focused); Assert.True (subView.HasFocus); top.Remove (subView); Assert.True (top.HasFocus); - Assert.Equal (null, top.GetFocused ()); + Assert.Equal (null, top.Focused); Assert.False (subView.HasFocus); Assert.Equal (1, nLeave); } @@ -125,14 +125,14 @@ public class AddRemoveNavigationTests (ITestOutputHelper _output) : TestsAllView top.SetFocus (); Assert.True (top.HasFocus); - Assert.Equal (subView1, top.GetFocused ()); + Assert.Equal (subView1, top.Focused); Assert.True (subView1.HasFocus); Assert.False (subView2.HasFocus); top.Remove (subView1); Assert.True (top.HasFocus); Assert.True (subView2.HasFocus); - Assert.Equal (subView2, top.GetFocused ()); + Assert.Equal (subView2, top.Focused); Assert.False (subView1.HasFocus); Assert.Equal (1, nLeave1); } diff --git a/UnitTests/View/Navigation/CanFocusTests.cs b/UnitTests/View/Navigation/CanFocusTests.cs index 04a8e5ca6..bdc305c15 100644 --- a/UnitTests/View/Navigation/CanFocusTests.cs +++ b/UnitTests/View/Navigation/CanFocusTests.cs @@ -147,7 +147,7 @@ public class CanFocusTests (ITestOutputHelper _output) : TestsAllViews top.SetFocus (); Assert.True (top.HasFocus); - Assert.Equal (subView, top.GetFocused ()); + Assert.Equal (subView, top.Focused); Assert.True (subView.HasFocus); Assert.True (subSubView.HasFocus); diff --git a/UnitTests/View/Navigation/EnabledTests.cs b/UnitTests/View/Navigation/EnabledTests.cs index b6efe45a7..da5fb1170 100644 --- a/UnitTests/View/Navigation/EnabledTests.cs +++ b/UnitTests/View/Navigation/EnabledTests.cs @@ -40,7 +40,7 @@ public class EnabledTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); view.Enabled = false; Assert.False (view.HasFocus); @@ -67,7 +67,7 @@ public class EnabledTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); view.Enabled = false; Assert.False (view.HasFocus); @@ -94,7 +94,7 @@ public class EnabledTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); subView.Enabled = false; Assert.True (view.HasFocus); @@ -139,13 +139,13 @@ public class EnabledTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView2, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView2, subView.Focused); subViewSubView2.Enabled = false; Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView3, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView3, subView.Focused); Assert.True (subViewSubView3.HasFocus); } @@ -246,8 +246,8 @@ public class EnabledTests (ITestOutputHelper _output) : TestsAllViews subView.Enabled = true; Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView2, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView2, subView.Focused); Assert.True (subViewSubView2.HasFocus); } diff --git a/UnitTests/View/Navigation/EnterLeaveTests.cs b/UnitTests/View/Navigation/EnterLeaveTests.cs index 94d2f5750..2be317b8e 100644 --- a/UnitTests/View/Navigation/EnterLeaveTests.cs +++ b/UnitTests/View/Navigation/EnterLeaveTests.cs @@ -330,12 +330,12 @@ public class EnterLeaveTests (ITestOutputHelper _output) : TestsAllViews view.Add (subview1, subview2); view.SetFocus (); - Assert.Equal (subview1, view.GetFocused ()); + Assert.Equal (subview1, view.Focused); Assert.True (subview1.HasFocus); Assert.False (subview2.HasFocus); subview2.SetFocus (); - Assert.Equal (subview2, view.GetFocused ()); + Assert.Equal (subview2, view.Focused); Assert.True (subview2.HasFocus); Assert.False (subview1.HasFocus); } @@ -384,8 +384,8 @@ public class EnterLeaveTests (ITestOutputHelper _output) : TestsAllViews Assert.True (view1.HasFocus); Assert.True (subView1.HasFocus); Assert.True (subView1SubView1.HasFocus); - Assert.Equal (subView1, view1.GetFocused ()); - Assert.Equal (subView1SubView1, subView1.GetFocused ()); + Assert.Equal (subView1, view1.Focused); + Assert.Equal (subView1SubView1, subView1.Focused); view2.SetFocus (); Assert.False (view1.HasFocus); diff --git a/UnitTests/View/Navigation/HasFocusTests.cs b/UnitTests/View/Navigation/HasFocusTests.cs index 6fc845ec7..393a231e2 100644 --- a/UnitTests/View/Navigation/HasFocusTests.cs +++ b/UnitTests/View/Navigation/HasFocusTests.cs @@ -65,10 +65,10 @@ public class HasFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subview.HasFocus); - Assert.Equal (subview, view.GetFocused ()); + Assert.Equal (subview, view.Focused); view.HasFocus = false; - Assert.Null (view.GetFocused ()); + Assert.Null (view.Focused); Assert.False (view.HasFocus); Assert.False (subview.HasFocus); } diff --git a/UnitTests/View/Navigation/NavigationTests.cs b/UnitTests/View/Navigation/NavigationTests.cs index adfb9d656..f96712ba7 100644 --- a/UnitTests/View/Navigation/NavigationTests.cs +++ b/UnitTests/View/Navigation/NavigationTests.cs @@ -385,12 +385,12 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews public void Focused_NoSubviews () { var view = new View (); - Assert.Null (view.GetFocused ()); + Assert.Null (view.Focused); view.CanFocus = true; view.SetFocus (); Assert.True (view.HasFocus); - Assert.Null (view.GetFocused ()); // BUGBUG: Should be view + Assert.Null (view.Focused); // BUGBUG: Should be view } [Fact] @@ -497,7 +497,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews public void GetMostFocused_NoSubviews_Returns_Null () { var view = new View (); - Assert.Null (view.GetFocused ()); + Assert.Null (view.Focused); view.CanFocus = true; Assert.False (view.HasFocus); @@ -675,7 +675,7 @@ public class NavigationTests (ITestOutputHelper _output) : TestsAllViews Application.Init (new FakeDriver ()); var top = new Toplevel (); - top.Ready += (s, e) => { Assert.Null (top.GetFocused ()); }; + top.Ready += (s, e) => { Assert.Null (top.Focused); }; // Keyboard navigation with tab FakeConsole.MockKeyPresses.Push (new ('\t', ConsoleKey.Tab, false, false, false)); diff --git a/UnitTests/View/Navigation/RestoreFocusTests.cs b/UnitTests/View/Navigation/RestoreFocusTests.cs index 0cc70b155..6e7a1fdd7 100644 --- a/UnitTests/View/Navigation/RestoreFocusTests.cs +++ b/UnitTests/View/Navigation/RestoreFocusTests.cs @@ -43,9 +43,9 @@ public class RestoreFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); Assert.True (subViewSubView1.HasFocus); - Assert.Equal (subViewSubView1, subView.GetFocused ()); + Assert.Equal (subViewSubView1, subView.Focused); view.HasFocus = false; Assert.False (view.HasFocus); @@ -57,8 +57,8 @@ public class RestoreFocusTests (ITestOutputHelper _output) : TestsAllViews view.RestoreFocus (view.TabStop); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView1, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView1, subView.Focused); Assert.True (subViewSubView1.HasFocus); Assert.False (subViewSubView2.HasFocus); Assert.False (subViewSubView3.HasFocus); @@ -79,9 +79,9 @@ public class RestoreFocusTests (ITestOutputHelper _output) : TestsAllViews view.RestoreFocus (view.TabStop); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); Assert.True (subViewSubView2.HasFocus); - Assert.Equal (subViewSubView2, subView.GetFocused ()); + Assert.Equal (subViewSubView2, subView.Focused); Assert.False (subViewSubView1.HasFocus); Assert.False (subViewSubView3.HasFocus); } @@ -140,29 +140,29 @@ public class RestoreFocusTests (ITestOutputHelper _output) : TestsAllViews top.SetFocus (); Assert.True (top.HasFocus); - Assert.Equal (tabGroup1, top.GetFocused ()); - Assert.Equal (tabGroup1SubView1, tabGroup1.GetFocused ()); + Assert.Equal (tabGroup1, top.Focused); + Assert.Equal (tabGroup1SubView1, tabGroup1.Focused); top.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup); Assert.True (top.HasFocus); - Assert.Equal (tabGroup2, top.GetFocused ()); - Assert.Equal (tabGroup2SubView1, tabGroup2.GetFocused ()); + Assert.Equal (tabGroup2, top.Focused); + Assert.Equal (tabGroup2SubView1, tabGroup2.Focused); top.HasFocus = false; Assert.False (top.HasFocus); top.RestoreFocus (null); Assert.True (top.HasFocus); - Assert.Equal (tabGroup2, top.GetFocused ()); - Assert.Equal (tabGroup2SubView1, tabGroup2.GetFocused ()); + Assert.Equal (tabGroup2, top.Focused); + Assert.Equal (tabGroup2SubView1, tabGroup2.Focused); top.HasFocus = false; Assert.False (top.HasFocus); top.RestoreFocus (TabBehavior.TabGroup); Assert.True (top.HasFocus); - Assert.Equal (tabGroup2, top.GetFocused ()); - Assert.Equal (tabGroup2SubView1, tabGroup2.GetFocused ()); + Assert.Equal (tabGroup2, top.Focused); + Assert.Equal (tabGroup2SubView1, tabGroup2.Focused); } diff --git a/UnitTests/View/Navigation/SetFocusTests.cs b/UnitTests/View/Navigation/SetFocusTests.cs index 6c78fd273..77cffe72f 100644 --- a/UnitTests/View/Navigation/SetFocusTests.cs +++ b/UnitTests/View/Navigation/SetFocusTests.cs @@ -50,7 +50,7 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); - Assert.Null (view.GetFocused ()); + Assert.Null (view.Focused); } [Fact] @@ -73,7 +73,7 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); - Assert.Equal (subview, view.GetFocused ()); + Assert.Equal (subview, view.Focused); } [Fact] @@ -94,7 +94,7 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (subview.HasFocus); - Assert.Equal (subview, view.GetFocused ()); + Assert.Equal (subview, view.Focused); } [Fact] @@ -135,8 +135,8 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView2, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView2, subView.Focused); } [Fact] @@ -178,9 +178,9 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); Assert.True (subViewSubView1.HasFocus); - Assert.Equal (subViewSubView1, subView.GetFocused ()); + Assert.Equal (subViewSubView1, subView.Focused); subViewSubView2.SetFocus (); Assert.True (view.HasFocus); @@ -213,12 +213,12 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews view.Add (subview1, subview2); view.SetFocus (); - Assert.Equal (subview1, view.GetFocused ()); + Assert.Equal (subview1, view.Focused); Assert.True (subview1.HasFocus); Assert.False (subview2.HasFocus); subview2.SetFocus (); - Assert.Equal (subview2, view.GetFocused ()); + Assert.Equal (subview2, view.Focused); Assert.True (subview2.HasFocus); Assert.False (subview1.HasFocus); } @@ -268,8 +268,8 @@ public class SetFocusTests (ITestOutputHelper _output) : TestsAllViews Assert.True (view1.HasFocus); Assert.True (subView1.HasFocus); Assert.True (subView1SubView1.HasFocus); - Assert.Equal (subView1, view1.GetFocused ()); - Assert.Equal (subView1SubView1, subView1.GetFocused ()); + Assert.Equal (subView1, view1.Focused); + Assert.Equal (subView1SubView1, subView1.Focused); view2.SetFocus (); Assert.False (view1.HasFocus); diff --git a/UnitTests/View/Navigation/VisibleTests.cs b/UnitTests/View/Navigation/VisibleTests.cs index 49358d8d6..fa9d30f72 100644 --- a/UnitTests/View/Navigation/VisibleTests.cs +++ b/UnitTests/View/Navigation/VisibleTests.cs @@ -40,7 +40,7 @@ public class VisibleTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); view.Visible = false; Assert.False (view.HasFocus); @@ -67,7 +67,7 @@ public class VisibleTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); view.Visible = false; Assert.False (view.HasFocus); @@ -94,7 +94,7 @@ public class VisibleTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (view.HasFocus); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); + Assert.Equal (subView, view.Focused); subView.Visible = false; Assert.True (view.HasFocus); @@ -139,13 +139,13 @@ public class VisibleTests (ITestOutputHelper _output) : TestsAllViews view.SetFocus (); Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView2, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView2, subView.Focused); subViewSubView2.Visible = false; Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView3, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView3, subView.Focused); Assert.True (subViewSubView3.HasFocus); } @@ -246,8 +246,8 @@ public class VisibleTests (ITestOutputHelper _output) : TestsAllViews subView.Visible = true; Assert.True (subView.HasFocus); - Assert.Equal (subView, view.GetFocused ()); - Assert.Equal (subViewSubView2, subView.GetFocused ()); + Assert.Equal (subView, view.Focused); + Assert.Equal (subViewSubView2, subView.Focused); Assert.True (subViewSubView2.HasFocus); } } diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index 19dc85fe2..08799d0e2 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -765,7 +765,7 @@ At 0,0 Assert.False (r.HasFocus); Assert.Equal (new (0, 0, 0, 0), r.Viewport); Assert.Equal (new (0, 0, 0, 0), r.Frame); - Assert.Null (r.GetFocused ()); + Assert.Null (r.Focused); Assert.Null (r.ColorScheme); Assert.Equal (0, r.Width); Assert.Equal (0, r.Height); @@ -789,7 +789,7 @@ At 0,0 Assert.False (r.HasFocus); Assert.Equal (new (0, 0, 0, 0), r.Viewport); Assert.Equal (new (0, 0, 0, 0), r.Frame); - Assert.Null (r.GetFocused ()); + Assert.Null (r.Focused); Assert.Null (r.ColorScheme); Assert.Equal (0, r.Width); Assert.Equal (0, r.Height); @@ -813,7 +813,7 @@ At 0,0 Assert.False (r.HasFocus); Assert.Equal (new (0, 0, 3, 4), r.Viewport); Assert.Equal (new (1, 2, 3, 4), r.Frame); - Assert.Null (r.GetFocused ()); + Assert.Null (r.Focused); Assert.Null (r.ColorScheme); Assert.Equal (3, r.Width); Assert.Equal (4, r.Height); @@ -846,7 +846,7 @@ At 0,0 Assert.False (r.HasFocus); Assert.Equal (new (0, 0, 1, 13), r.Viewport); Assert.Equal (new (0, 0, 1, 13), r.Frame); - Assert.Null (r.GetFocused ()); + Assert.Null (r.Focused); Assert.Null (r.ColorScheme); Assert.False (r.IsCurrentTop); #if DEBUG diff --git a/UnitTests/Views/AppendAutocompleteTests.cs b/UnitTests/Views/AppendAutocompleteTests.cs index daed47adb..eaabc43a6 100644 --- a/UnitTests/Views/AppendAutocompleteTests.cs +++ b/UnitTests/Views/AppendAutocompleteTests.cs @@ -26,11 +26,11 @@ public class AppendAutocompleteTests (ITestOutputHelper output) Assert.Equal ("f", tf.Text); // Still has focus though - Assert.Same (tf, Application.Top.GetFocused ()); + Assert.Same (tf, Application.Top.Focused); // But can tab away Application.Driver?.SendKeys ('\t', ConsoleKey.Tab, false, false, false); - Assert.NotSame (tf, Application.Top.GetFocused ()); + Assert.NotSame (tf, Application.Top.Focused); Application.Top.Dispose (); } @@ -201,11 +201,11 @@ public class AppendAutocompleteTests (ITestOutputHelper output) Assert.Equal ("fish", tf.Text); // Tab should autcomplete but not move focus - Assert.Same (tf, Application.Top.GetFocused ()); + Assert.Same (tf, Application.Top.Focused); // Second tab should move focus (nothing to autocomplete) Application.Driver?.SendKeys ('\t', ConsoleKey.Tab, false, false, false); - Assert.NotSame (tf, Application.Top.GetFocused ()); + Assert.NotSame (tf, Application.Top.Focused); Application.Top.Dispose (); } @@ -238,7 +238,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output) Application.Begin (top); - Assert.Same (tf, top.GetFocused ()); + Assert.Same (tf, top.Focused); return tf; } diff --git a/UnitTests/Views/OverlappedTests.cs b/UnitTests/Views/OverlappedTests.cs index 5c82ca100..557106d26 100644 --- a/UnitTests/Views/OverlappedTests.cs +++ b/UnitTests/Views/OverlappedTests.cs @@ -1058,7 +1058,7 @@ public class OverlappedTests win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2); win1.Closing += (s, e) => isRunning = false; - Assert.Null (top.GetFocused ()); + Assert.Null (top.Focused); Assert.Equal (top, Application.Current); Assert.True (top.IsCurrentTop); Assert.Equal (top, ApplicationOverlapped.OverlappedTop); @@ -1071,7 +1071,7 @@ public class OverlappedTests Assert.Equal (win1, Application.Current); Assert.True (win1.IsCurrentTop); Assert.True (ApplicationOverlapped.IsOverlapped(win1)); - Assert.Null (top.GetFocused ()); + Assert.Null (top.Focused); Assert.Null (top.GetMostFocused ()); Assert.Equal (tf1W1, win1.GetMostFocused ()); Assert.True (ApplicationOverlapped.IsOverlapped(win1)); @@ -1085,7 +1085,7 @@ public class OverlappedTests Assert.Equal (win2, Application.Current); Assert.True (win2.IsCurrentTop); Assert.True (ApplicationOverlapped.IsOverlapped(win2)); - Assert.Null (top.GetFocused ()); + Assert.Null (top.Focused); Assert.Null (top.GetMostFocused ()); Assert.Equal (tf1W2, win2.GetMostFocused ()); Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count); @@ -1227,7 +1227,7 @@ public class OverlappedTests Application.Current = current; Assert.True (current.HasFocus); - Assert.Equal (superView.GetFocused (), current); + Assert.Equal (superView.Focused, current); Assert.Equal (superView.GetMostFocused (), current); // Act diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index 630d7ae5c..d84372f95 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -393,9 +393,9 @@ public class TabViewTests (ITestOutputHelper output) // Is the selected tab view hosting focused Assert.Equal (tab1, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); - Assert.Equal (tv.SelectedTab.View, top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); + Assert.Equal (tv.SelectedTab.View, top.Focused.GetMostFocused ()); // Press the cursor up key to focus the selected tab Application.OnKeyDown (Key.CursorUp); @@ -403,8 +403,8 @@ public class TabViewTests (ITestOutputHelper output) // Is the selected tab focused Assert.Equal (tab1, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); Tab oldChanged = null; Tab newChanged = null; @@ -421,8 +421,8 @@ public class TabViewTests (ITestOutputHelper output) Assert.Equal (tab1, oldChanged); Assert.Equal (tab2, newChanged); Assert.Equal (tab2, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); // 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.OnKeyDown (Key.CursorDown); @@ -454,7 +454,7 @@ public class TabViewTests (ITestOutputHelper output) // Press the cursor down key again will focus next view in the toplevel, whic is the TabView Application.OnKeyDown (Key.CursorDown); Assert.Equal (tab2, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); + Assert.Equal (tv, top.Focused); Assert.Equal (tab1, tv.GetMostFocused ()); // Press the cursor down key to focus the selected tab view hosting again @@ -468,8 +468,8 @@ public class TabViewTests (ITestOutputHelper output) // Is the selected tab focused Assert.Equal (tab2, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); // Press the cursor left key to select the previous tab Application.OnKeyDown (Key.CursorLeft); @@ -477,8 +477,8 @@ public class TabViewTests (ITestOutputHelper output) Assert.Equal (tab2, oldChanged); Assert.Equal (tab1, newChanged); Assert.Equal (tab1, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); // Press the end key to select the last tab Application.OnKeyDown (Key.End); @@ -486,8 +486,8 @@ public class TabViewTests (ITestOutputHelper output) Assert.Equal (tab1, oldChanged); Assert.Equal (tab2, newChanged); Assert.Equal (tab2, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); // Press the home key to select the first tab Application.OnKeyDown (Key.Home); @@ -495,8 +495,8 @@ public class TabViewTests (ITestOutputHelper output) Assert.Equal (tab2, oldChanged); Assert.Equal (tab1, newChanged); Assert.Equal (tab1, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); // Press the page down key to select the next set of tabs Application.OnKeyDown (Key.PageDown); @@ -504,8 +504,8 @@ public class TabViewTests (ITestOutputHelper output) Assert.Equal (tab1, oldChanged); Assert.Equal (tab2, newChanged); Assert.Equal (tab2, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); // Press the page up key to select the previous set of tabs Application.OnKeyDown (Key.PageUp); @@ -513,8 +513,8 @@ public class TabViewTests (ITestOutputHelper output) Assert.Equal (tab2, oldChanged); Assert.Equal (tab1, newChanged); Assert.Equal (tab1, tv.SelectedTab); - Assert.Equal (tv, top.GetFocused ()); - Assert.Equal (tv.GetMostFocused (), top.GetFocused ().GetMostFocused ()); + Assert.Equal (tv, top.Focused); + Assert.Equal (tv.GetMostFocused (), top.Focused.GetMostFocused ()); top.Dispose (); } diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index f63f3451d..defee489d 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1948,7 +1948,7 @@ Les Miśerables", Application.Begin (top); - Assert.Same (tf, top.GetFocused ()); + Assert.Same (tf, top.Focused); return tf; } diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 9c630cf19..ba40cd6eb 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -466,7 +466,7 @@ public partial class ToplevelTests (ITestOutputHelper output) Assert.Equal (new (0, 0, 40, 25), win1.Frame); Assert.Equal (new (41, 0, 40, 25), win2.Frame); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.GetMostFocused ()); Assert.True (isRunning); @@ -477,7 +477,7 @@ public partial class ToplevelTests (ITestOutputHelper output) Assert.True (Application.OnKeyDown (Key.F5)); // refresh Assert.True (Application.OnKeyDown (Key.Tab)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.Tab)); Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text); @@ -487,10 +487,10 @@ public partial class ToplevelTests (ITestOutputHelper output) var prevMostFocusedSubview = top.GetMostFocused (); Assert.True (Application.OnKeyDown (Key.F6)); // move to next TabGroup (win2) - Assert.Equal (win2, top.GetFocused ()); + Assert.Equal (win2, top.Focused); Assert.True (Application.OnKeyDown (Key.F6.WithShift)); // move to prev TabGroup (win1) - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.GetMostFocused ()); // BUGBUG: Should be prevMostFocusedSubview - We need to cache the last focused view in the TabGroup somehow prevMostFocusedSubview.SetFocus (); @@ -499,13 +499,13 @@ public partial class ToplevelTests (ITestOutputHelper output) tf2W1.SetFocus (); Assert.True (Application.OnKeyDown (Key.Tab)); // tf2W1 is last subview in win1 - tabbing should take us to first subview of win1 - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.CursorRight)); // move char to right in tf1W1. We're at last char so nav to next view - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.CursorDown)); // move down to next view (tvW1) - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.GetMostFocused ()); #if UNIX_KEY_BINDINGS Assert.True (Application.OnKeyDown (new (Key.I.WithCtrl))); @@ -513,34 +513,34 @@ public partial class ToplevelTests (ITestOutputHelper output) Assert.Equal (tf2W1, top.MostFocused); #endif Assert.True (Application.OnKeyDown (Key.Tab.WithShift)); // Ignored. TextView eats shift-tab by default - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.GetMostFocused ()); tvW1.AllowsTab = false; Assert.True (Application.OnKeyDown (Key.Tab.WithShift)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf1W1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.CursorLeft)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.CursorUp)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.GetMostFocused ()); // nav to win2 Assert.True (Application.OnKeyDown (Key.F6)); - Assert.Equal (win2, top.GetFocused ()); + Assert.Equal (win2, top.Focused); Assert.Equal (tf1W2, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.F6.WithShift)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Application.NextTabGroupKey)); - Assert.Equal (win2, top.GetFocused ()); + Assert.Equal (win2, top.Focused); Assert.Equal (tf1W2, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Application.PrevTabGroupKey)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tf2W1, top.GetMostFocused ()); Assert.True (Application.OnKeyDown (Key.CursorUp)); - Assert.Equal (win1, top.GetFocused ()); + Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.GetMostFocused ()); top.Dispose (); diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs index 8fcfc7dde..539c92431 100644 --- a/UnitTests/Views/WindowTests.cs +++ b/UnitTests/Views/WindowTests.cs @@ -132,7 +132,7 @@ public class WindowTests Assert.False (defaultWindow.HasFocus); Assert.Equal (new Rectangle (0, 0, Application.Screen.Width - 2, Application.Screen.Height - 2), defaultWindow.Viewport); Assert.Equal (new Rectangle (0, 0, Application.Screen.Width, Application.Screen.Height), defaultWindow.Frame); - Assert.Null (defaultWindow.GetFocused ()); + Assert.Null (defaultWindow.Focused); Assert.NotNull (defaultWindow.ColorScheme); Assert.Equal (0, defaultWindow.X); Assert.Equal (0, defaultWindow.Y); @@ -154,7 +154,7 @@ public class WindowTests Assert.False (windowWithFrameRectEmpty.HasFocus); Assert.Equal (Rectangle.Empty, windowWithFrameRectEmpty.Viewport); Assert.Equal (Rectangle.Empty, windowWithFrameRectEmpty.Frame); - Assert.Null (windowWithFrameRectEmpty.GetFocused ()); + Assert.Null (windowWithFrameRectEmpty.Focused); Assert.NotNull (windowWithFrameRectEmpty.ColorScheme); Assert.Equal (0, windowWithFrameRectEmpty.X); Assert.Equal (0, windowWithFrameRectEmpty.Y); @@ -185,7 +185,7 @@ public class WindowTests Assert.False (windowWithFrame1234.HasFocus); Assert.Equal (new (0, 0, 1, 2), windowWithFrame1234.Viewport); Assert.Equal (new (1, 2, 3, 4), windowWithFrame1234.Frame); - Assert.Null (windowWithFrame1234.GetFocused ()); + Assert.Null (windowWithFrame1234.Focused); Assert.NotNull (windowWithFrame1234.ColorScheme); Assert.Equal (1, windowWithFrame1234.X); Assert.Equal (2, windowWithFrame1234.Y); diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index 742521e02..46185982a 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -175,6 +175,7 @@ The API for handling keyboard input is significantly improved. See [Keyboard API * Use [View.Keybindings](~/api/Terminal.Gui.View.Keybindings.yml) to configure key bindings to `Command`s. * It should be very uncommon for v2 code to override `OnKeyPressed` etc... * Anywhere `Ctrl+Q` was hard-coded as the "quit key", replace with `Application.QuitKey`. +* See *Navigation* below for more information on v2's navigation keys. ## Updated Mouse API @@ -193,17 +194,72 @@ The API for mouse input is now internally consistent and easier to use. * Set `View.WantContinousButtonPresses = true` to have the [Command.Accept](~/api/Terminal.Gui.Command.Accept.yml) command be invoked repeatedly as the user holds a mouse button down on the view. * Update any code that assumed mouse events provided coordinates relative to the `Screen`. -## Cursor and Focus +## Navigation - `Cursor`, `Focus`, `TabStop` etc... The cursor and focus system has been redesigned in v2 to be more consistent and easier to use. If you are using custom cursor or focus logic in your application, you may need to update it to use the new system. -### How to Fix +### Cursor + +In v1, whether the cursor (the flashing caret) was visible or not was controlled by `View.CursorVisibility` which was an enum extracted from Ncruses/Terminfo. It only works in some cases on Linux, and only partially with `WindowsDriver`. The position of the cursor was the same as `ConsoleDriver.Row`/`Col` and determined by the last call to `ConsoleDriver.Move`. `View.PositionCursor()` could be overridden by views to cause `Application` to call `ConsoleDriver.Move` on behalf of the app and to manage setting `CursorVisiblity`. This API was confusing and bug-prone. + +In v2, the API is (NOT YET IMPLEMENTED) simplified. A view simply reports the style of cursor it wants and the Viewport-relative location: + +* `public Point? CursorPosition` + - If `null` the cursor is not visible + - If `{}` the cursor is visible at the `Point`. +* `public event EventHandler? CursorPositionChanged` +* `public int? CursorStyle` + - If `null` the default cursor style is used. + - If `{}` specifies the style of cursor. See [cursor.md](cursor.md) for more. +* `Application` now has APIs for querying available cursor styles. +* The details in `ConsoleDriver` are no longer available to applications. + +#### How to Fix (Cursor API) -* Use [Application.MostFocusedView](~/api/Terminal.Gui.Application.MostFocusedView.yml) to get the most focused view in the application. * Use [View.CursorPosition](~/api/Terminal.Gui.View.CursorPosition.yml) to set the cursor position in a view. Set [View.CursorPosition](~/api/Terminal.Gui.View.CursorPosition.yml) to `null` to hide the cursor. * Set [View.CursorVisibility](~/api/Terminal.Gui.View.CursorVisibility.yml) to the cursor style you want to use. + +### Focus + +See [navigation.md](navigation.md) for more details. +See also [Keyboard](keyboard.md) where HotKey is covered more deeply... + +* In v1, calling `super.Add (view)` where `view.CanFocus == true` caused all views up the hierarchy (all SuperViews) to get `CanFocus` set to `true` as well. In v2, developers need to explicitly set `CanFocus` for any view in the view-hierarchy where focus is desired. This simplifies the implementation and removes confusing automatic behavior. +* In v1, if `view.CanFocus == true`, `Add` would automatically set `TabStop`. In v2, the automatic setting of `TabStop` in `Add` is retained because it is not overly complex to do so and is a nice convenience for developers to not have to set both `Tabstop` and `CanFocus`. Note v2 does NOT automatically change `CanFocus` if `TabStop` is changed. +* `view.TabStop` now describes the behavior of a view in the focus-chain. the `TabBehavior` enum includes `NoStop` (the view may be focusable, but not via next/prev keyboard nav), `TabStop` (the view may be focusable, and `NextTabStop`/`PrevTabStop` keyboard nav will stop), `TabGroup` (the view may be focusable, and `NextTabGroup`/`PrevTabGroup` keyboard nav will stop). + +### How to Fix (Focus API) + +* Use [Application.Navigation.GetFocused()](~/api/Terminal.Gui.Application.Navigation.GetFocused.yml) to get the most focused view in the application. * Remove any overrides of `OnEnter` and `OnLeave` that explicitly change the cursor. +### Keyboard Navigation + +In v2, `HotKey`s can be used to navigate across the entire application view-hierarchy. They work independently of `Focus`. This enables a user to navigate across a complex UI of nested subviews if needed (even in overlapped scenarios). An example use-case is the `AllViewsTester` scenario. + +In v2, unlike v1, multiple Views in an application (even within the same SuperView) can have the same `HotKey`. Each press of the `HotKey` will invoke the next `HotKey` across the View hierarchy (NOT IMPLEMENTED YET)* + +In v1, the keys used for navigation were both hard-coded and configurable, but in an inconsistent way. `Tab` and `Shift+Tab` worked consistently for navigating between Subviews, but were not configurable. `Ctrl+Tab` and `Ctrl+Shift+Tab` navigated across `Overlapped` views and had configurable "alternate" versions (`Ctrl+PageDown` and `Ctrl+PageUp`). + +In v2, this is made consistent and configurable: + +- `Application.NextTabStopKey` (`Key.Tab`) - Navigates to the next subview that is a `TabStop` (see below). If there is no next, the first subview that is a `TabStop` will gain focus. +- `Application.PrevTabStopKey` (`Key.Tab.WithShift`) - Opposite of `Application.NextTabStopKey`. +- `Key.CursorRight` - Operates identically to `Application.NextTabStopKey`. +- `Key.CursorDown` - Operates identically to `Application.NextTabStopKey`. +- `Key.CursorLeft` - Operates identically to `Application.PrevTabStopKey`. +- `Key.CursorUp` - Operates identically to `Application.PrevTabStopKey`. +- `Application.NextTabGroupKey` (`Key.F6`) - Navigates to the next view in the view-hierarchy that is a `TabGroup` (see below). If there is no next, the first view that is a `TabGroup` will gain focus. +- `Application.PrevTabGroupKey` (`Key.F6.WithShift`) - Opposite of `Application.NextTabGroupKey`. + +`F6` was chosen to match [Windows](https://learn.microsoft.com/en-us/windows/apps/design/input/keyboard-accelerators#common-keyboard-accelerators) + +These keys are all registered as `KeyBindingScope.Application` key bindings by `Application`. Because application-scoped key bindings have the lowest priority, Views can override the behaviors of these keys (e.g. `TextView` overrides `Key.Tab` by default, enabling the user to enter `\t` into text). The `AllViews_AtLeastOneNavKey_Leaves` unit test ensures all built-in Views have at least one of the above keys that can advance. + +### How to Fix (Keyboard Navigation) + +... + ## Events now use `object sender, EventArgs args` signature Previously events in Terminal.Gui used a mixture of `Action` (no arguments), `Action` (or other raw datatype) and `Action`. Now all events use the `EventHandler` [standard .net design pattern](https://learn.microsoft.com/en-us/dotnet/csharp/event-pattern#event-delegate-signatures).