reordered params for consistency

This commit is contained in:
Tig
2024-08-18 16:00:35 -06:00
parent 591baa65f0
commit a03e30537c
7 changed files with 24 additions and 20 deletions

View File

@@ -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 <see cref="View.TabIndexes"/> if one exists. If there are no views in
/// <see cref="View.TabIndexes"/> then the focus is set to the view itself.
/// </summary>
/// <param name="behavior"></param>
/// <param name="direction"></param>
/// <param name="behavior"></param>
/// <returns><see langword="true"/> if a subview other than this was focused.</returns>
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
/// <summary>
/// Gets TabIndexes that are scoped to the specified behavior and direction. If behavior is null, all TabIndexes are returned.
/// </summary>
/// <param name="behavior"></param>
/// <param name="direction"></param>
/// <param name="behavior"></param>
/// <returns></returns>GetScopedTabIndexes
private View [] GetScopedTabIndexes (TabBehavior? behavior, NavigationDirection direction)
private View [] GetScopedTabIndexes (NavigationDirection direction, TabBehavior? behavior)
{
IEnumerable<View>? indicies;

View File

@@ -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

View File

@@ -609,7 +609,7 @@ public class Sliders : Scenario
};
}
app.FocusDeepest (null, NavigationDirection.Forward);
app.FocusDeepest (NavigationDirection.Forward, null);
Application.Run (app);
app.Dispose ();

View File

@@ -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);

View File

@@ -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<string> source = [];

View File

@@ -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

View File

@@ -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