From a03e30537c13f7f71db045e18539c3954631aee3 Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 18 Aug 2024 16:00:35 -0600 Subject: [PATCH] reordered params for consistency --- Terminal.Gui/View/View.Navigation.cs | 18 +++++++++--------- UICatalog/Scenarios/Editor.cs | 6 +++--- UICatalog/Scenarios/Sliders.cs | 2 +- UnitTests/View/Navigation/EnabledTests.cs | 2 +- UnitTests/Views/ComboBoxTests.cs | 6 +++--- UnitTests/Views/TableViewTests.cs | 4 ++-- docfx/docs/migratingfromv1.md | 6 +++++- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Terminal.Gui/View/View.Navigation.cs b/Terminal.Gui/View/View.Navigation.cs index 0b7f00993..c4744081b 100644 --- a/Terminal.Gui/View/View.Navigation.cs +++ b/Terminal.Gui/View/View.Navigation.cs @@ -362,7 +362,7 @@ public partial class View // Focus and cross-view navigation management (TabStop return true; } - View[] index = GetScopedTabIndexes (behavior, direction); + View[] index = GetScopedTabIndexes (direction, behavior); if (index.Length == 0) { @@ -622,12 +622,12 @@ public partial class View // Focus and cross-view navigation management (TabStop /// Focuses the deepest focusable view in if one exists. If there are no views in /// then the focus is set to the view itself. /// - /// /// + /// /// if a subview other than this was focused. - public bool FocusDeepest (TabBehavior? behavior, NavigationDirection direction) + public bool FocusDeepest (NavigationDirection direction, TabBehavior? behavior) { - View deepest = FindDeepestFocusableView (behavior, direction); + View deepest = FindDeepestFocusableView (direction, behavior); if (deepest is { }) { @@ -638,9 +638,9 @@ public partial class View // Focus and cross-view navigation management (TabStop } [CanBeNull] - private View FindDeepestFocusableView (TabBehavior? behavior, NavigationDirection direction) + private View FindDeepestFocusableView (NavigationDirection direction, TabBehavior? behavior) { - var indicies = GetScopedTabIndexes (behavior, direction); + var indicies = GetScopedTabIndexes (direction, behavior); foreach (View v in indicies) { @@ -649,7 +649,7 @@ public partial class View // Focus and cross-view navigation management (TabStop return v; } - return v.FindDeepestFocusableView (behavior, direction); + return v.FindDeepestFocusableView (direction, behavior); } return null; @@ -680,10 +680,10 @@ public partial class View // Focus and cross-view navigation management (TabStop /// /// Gets TabIndexes that are scoped to the specified behavior and direction. If behavior is null, all TabIndexes are returned. /// - /// /// + /// /// GetScopedTabIndexes - private View [] GetScopedTabIndexes (TabBehavior? behavior, NavigationDirection direction) + private View [] GetScopedTabIndexes (NavigationDirection direction, TabBehavior? behavior) { IEnumerable? indicies; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index c0dcaab3e..73b0773ca 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -722,7 +722,7 @@ public class Editor : Scenario } else { - FocusDeepest (null, NavigationDirection.Forward); + FocusDeepest (NavigationDirection.Forward, null); } } @@ -739,7 +739,7 @@ public class Editor : Scenario _findReplaceWindow.SuperView.BringSubviewToFront (_findReplaceWindow); _tabView.SetFocus (); _tabView.SelectedTab = isFind ? _tabView.Tabs.ToArray () [0] : _tabView.Tabs.ToArray () [1]; - _tabView.SelectedTab.View.FocusDeepest (null, NavigationDirection.Forward); + _tabView.SelectedTab.View.FocusDeepest (NavigationDirection.Forward, null); } private void CreateFindReplace () @@ -753,7 +753,7 @@ public class Editor : Scenario _tabView.AddTab (new () { DisplayText = "Find", View = CreateFindTab () }, true); _tabView.AddTab (new () { DisplayText = "Replace", View = CreateReplaceTab () }, false); - _tabView.SelectedTabChanged += (s, e) => _tabView.SelectedTab.View.FocusDeepest (null, NavigationDirection.Forward); + _tabView.SelectedTabChanged += (s, e) => _tabView.SelectedTab.View.FocusDeepest (NavigationDirection.Forward, null); _findReplaceWindow.Add (_tabView); // _tabView.SelectedTab.View.FocusLast (null); // Hack to get the first tab to be focused diff --git a/UICatalog/Scenarios/Sliders.cs b/UICatalog/Scenarios/Sliders.cs index ad97078f9..f697ebdab 100644 --- a/UICatalog/Scenarios/Sliders.cs +++ b/UICatalog/Scenarios/Sliders.cs @@ -609,7 +609,7 @@ public class Sliders : Scenario }; } - app.FocusDeepest (null, NavigationDirection.Forward); + app.FocusDeepest (NavigationDirection.Forward, null); Application.Run (app); app.Dispose (); diff --git a/UnitTests/View/Navigation/EnabledTests.cs b/UnitTests/View/Navigation/EnabledTests.cs index da5fb1170..f909fe924 100644 --- a/UnitTests/View/Navigation/EnabledTests.cs +++ b/UnitTests/View/Navigation/EnabledTests.cs @@ -302,7 +302,7 @@ public class EnabledTests (ITestOutputHelper _output) : TestsAllViews Assert.False (win.HasFocus); win.Enabled = true; - win.FocusDeepest (null, NavigationDirection.Forward); + win.FocusDeepest (NavigationDirection.Forward, null); Assert.True (button.HasFocus); Assert.True (win.HasFocus); diff --git a/UnitTests/Views/ComboBoxTests.cs b/UnitTests/Views/ComboBoxTests.cs index 5ed4c72e2..d6206d216 100644 --- a/UnitTests/Views/ComboBoxTests.cs +++ b/UnitTests/Views/ComboBoxTests.cs @@ -852,7 +852,7 @@ Three ", Assert.True (Application.OnKeyDown (Key.CursorDown)); // losing focus Assert.False (cb.IsShow); Assert.False (cb.HasFocus); - top.FocusDeepest (null, NavigationDirection.Forward); // Gets focus again + top.FocusDeepest (NavigationDirection.Forward, null); // Gets focus again Assert.False (cb.IsShow); Assert.True (cb.HasFocus); cb.Expand (); @@ -960,7 +960,7 @@ Three Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("One", cb.Text); - top.FocusDeepest (null, NavigationDirection.Forward); // Gets focus again + top.FocusDeepest (NavigationDirection.Forward, null); // Gets focus again Assert.True (cb.HasFocus); Assert.False (cb.IsShow); Assert.Equal (-1, cb.SelectedItem); @@ -980,7 +980,7 @@ Three var cb = new ComboBox (); var top = new Toplevel (); top.Add (cb); - top.FocusDeepest (null, NavigationDirection.Forward); + top.FocusDeepest (NavigationDirection.Forward, null); Assert.Null (cb.Source); Assert.Equal (-1, cb.SelectedItem); ObservableCollection source = []; diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index b93174f40..6db72eef7 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -616,7 +616,7 @@ public class TableViewTests (ITestOutputHelper output) top.Add (tableView); Application.Begin (top); - top.FocusDeepest (null, NavigationDirection.Forward); + top.FocusDeepest (NavigationDirection.Forward, null); Assert.True (tableView.HasFocus); Assert.Equal (0, tableView.RowOffset); @@ -1606,7 +1606,7 @@ public class TableViewTests (ITestOutputHelper output) top.Add (tv); Application.Begin (top); - top.FocusDeepest (null, NavigationDirection.Forward); + top.FocusDeepest (NavigationDirection.Forward, null); Assert.True (tv.HasFocus); // already on fish diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index 46185982a..8f3551a40 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -218,6 +218,7 @@ In v2, the API is (NOT YET IMPLEMENTED) simplified. A view simply reports the st * 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. +* Remove any overrides of `OnEnter` and `OnLeave` that explicitly change the cursor. ### Focus @@ -227,11 +228,14 @@ 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). +* In v1, the `View.Focused` property was a cache of which view in `SubViews/TabIndexes` had `HasFocus == true`. There was a lot of logic for keeping this property in sync. In v2, `View.Focused` is a get-only, computed property. +* In v1, the `View.OnEnter/Enter` and `View.OnLeave/Leave` virtual methods/events could be used to notify that a view had gained or lost focus, but had confusing semantics around what it mean to override (requiring calling `base`) and bug-ridden behavior on what the return values signified. The "Enter" and "Leave" terminology was confusing. In v2, the terminology is "Focus" and "Blur", matching modern web frameworks and the `View.OnFocus/Focus` and `View.OnBlur/Blur` virtual methods/events follow standard dotnet event patterns. The `OnFocus/Focus` event supports being cancelled. +* In v1, the concept of `Mdi` views included a large amount of complex code (in `Toplevel` and `Application`) for dealing with navigation across overlapped Views. This has all been radically simplified in v2. Any View can work in an "overlapped" or "tiled" way. See [navigation.md](navigation.md) for more details. ### 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