Forráskód Böngészése

TabStop -> now of type TabStop.
Updated unit tests.

Tig 1 éve
szülő
commit
4ede0648f4

+ 16 - 7
Terminal.Gui/View/View.Navigation.cs

@@ -169,7 +169,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
     ///         <see cref="SuperView"/> must also have <see cref="CanFocus"/> set to <see langword="true"/>.
     ///     </para>
     ///     <para>
-    ///         When set to <see langword="false"/>, if this view is focused, the focus will be set to the next focusable view.
+    ///         When set to <see langword="false"/>, if an attempt is made to make this view focused, the focus will be set to the next focusable view.
     ///     </para>
     ///     <para>
     ///         When set to <see langword="false"/>, the <see cref="TabIndex"/> will be set to -1.
@@ -179,6 +179,10 @@ public partial class View // Focus and cross-view navigation management (TabStop
     ///         subviews will be cached so that when <see cref="CanFocus"/> is set back to <see langword="true"/>, the subviews
     ///         will be restored to their previous values.
     ///     </para>
+    ///     <para>
+    ///         Changing this peroperty to <see langword="true"/> will cause <see cref="TabStop"/> to be set to <see cref="TabStop.TabStop"/>
+    ///         as a convenience. Changing this peroperty to <see langword="false"/> will have no effect on <see cref="TabStop"/>.
+    ///     </para>
     /// </remarks>
     public bool CanFocus
     {
@@ -200,6 +204,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
             switch (_canFocus)
             {
                 case false when _tabIndex > -1:
+                    // BUGBUG: This is a poor API design. Automatic behavior like this is non-obvious and should be avoided. Callers should adjust TabIndex explicitly.
                     TabIndex = -1;
 
                     break;
@@ -212,10 +217,14 @@ public partial class View // Focus and cross-view navigation management (TabStop
 
             if (_canFocus && _tabIndex == -1)
             {
+                // BUGBUG: This is a poor API design. Automatic behavior like this is non-obvious and should be avoided. Callers should adjust TabIndex explicitly.
                 TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
             }
 
-            TabStop = _canFocus;
+            if (TabStop == TabStop.None && _canFocus)
+            {
+                TabStop = TabStop.TabStop;
+            }
 
             if (!_canFocus && SuperView?.Focused == this)
             {
@@ -469,7 +478,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
 
         foreach (View view in _tabIndexes.Where (v => !overlappedOnly || v.Arrangement.HasFlag (ViewArrangement.Overlapped)))
         {
-            if (view.CanFocus && view.TabStop && view.Visible && view.Enabled)
+            if (view.CanFocus && view.TabStop.HasFlag (TabStop.TabStop) && view.Visible && view.Enabled)
             {
                 SetFocus (view);
 
@@ -503,7 +512,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
 
         foreach (View view in _tabIndexes.Where (v => !overlappedOnly || v.Arrangement.HasFlag (ViewArrangement.Overlapped)).Reverse ())
         {
-            if (view.CanFocus && view.TabStop && view.Visible && view.Enabled)
+            if (view.CanFocus && view.TabStop.HasFlag (TabStop.TabStop) && view.Visible && view.Enabled)
             {
                 SetFocus (view);
 
@@ -601,7 +610,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?
-            if (focusedFound && w.CanFocus && w.TabStop && w.Visible && w.Enabled)
+            if (focusedFound && w.CanFocus && w.TabStop.HasFlag (TabStop.TabStop) && w.Visible && w.Enabled)
             {
                 // Make Focused Leave
                 Focused.SetHasFocus (false, w);
@@ -769,14 +778,14 @@ public partial class View // Focus and cross-view navigation management (TabStop
     /// <remarks>
     /// <para>
     ///     TabStop is independent of <see cref="CanFocus"/>. If <see cref="CanFocus"/> is <see langword="false"/>, the view will not gain
-    ///     focus even if this property is <see langword="true"/> and vice-versa.
+    ///     focus even if this property is set and vice-versa.
     /// </para>
     /// <para>
     ///     The default keyboard navigation keys are <c>Key.Tab</c> and <c>Key>Tab.WithShift</c>. These can be changed by
     ///     modifying the key bindings (see <see cref="KeyBindings.Add(Key, Command[])"/>) of the SuperView.
     /// </para>
     /// </remarks>
-    public bool TabStop { get; set; } = true;
+    public TabStop TabStop { get; set; } = TabStop.None;
 
     #endregion Tab/Focus Handling
 }

+ 1 - 1
Terminal.Gui/View/View.cs

@@ -187,7 +187,7 @@ public partial class View : Responder, ISupportInitializeNotification
 
         CanFocus = false;
         TabIndex = -1;
-        TabStop = false;
+        TabStop = TabStop.None;
     }
 
     /// <summary>

+ 8 - 8
Terminal.Gui/Views/ComboBox.cs

@@ -29,7 +29,7 @@ public class ComboBox : View, IDesignable
     public ComboBox ()
     {
         _search = new TextField ();
-        _listview = new ComboListView (this, HideDropdownListOnClick) { CanFocus = true, TabStop = false };
+        _listview = new ComboListView (this, HideDropdownListOnClick) { CanFocus = true, TabStop = TabStop.None };
 
         _search.TextChanged += Search_Changed;
         _search.Accept += Search_Accept;
@@ -329,9 +329,9 @@ public class ComboBox : View, IDesignable
             IsShow = false;
             HideList ();
         }
-        else if (_listview.TabStop)
+        else if (_listview.TabStop.HasFlag (TabStop))
         {
-            _listview.TabStop = false;
+            _listview.TabStop = TabStop.None;
         }
 
         return base.OnLeave (view);
@@ -455,7 +455,7 @@ public class ComboBox : View, IDesignable
     private void FocusSelectedItem ()
     {
         _listview.SelectedItem = SelectedItem > -1 ? SelectedItem : 0;
-        _listview.TabStop = true;
+        _listview.TabStop = TabStop.TabStop;
         _listview.SetFocus ();
         OnExpanded ();
     }
@@ -491,7 +491,7 @@ public class ComboBox : View, IDesignable
 
         Reset (true);
         _listview.Clear ();
-        _listview.TabStop = false;
+        _listview.TabStop = TabStop.None;
         SuperView?.SendSubviewToBack (this);
         Rectangle rect = _listview.ViewportToScreen (_listview.IsInitialized ? _listview.Viewport : Rectangle.Empty);
         SuperView?.SetNeedsDisplay (rect);
@@ -505,7 +505,7 @@ public class ComboBox : View, IDesignable
             // jump to list
             if (_searchSet?.Count > 0)
             {
-                _listview.TabStop = true;
+                _listview.TabStop = TabStop.TabStop;
                 _listview.SetFocus ();
 
                 if (_listview.SelectedItem > -1)
@@ -519,7 +519,7 @@ public class ComboBox : View, IDesignable
             }
             else
             {
-                _listview.TabStop = false;
+                _listview.TabStop = TabStop.None;
                 SuperView?.AdvanceFocus (NavigationDirection.Forward);
             }
 
@@ -721,7 +721,7 @@ public class ComboBox : View, IDesignable
     private void Selected ()
     {
         IsShow = false;
-        _listview.TabStop = false;
+        _listview.TabStop = TabStop.None;
 
         if (_listview.Source.Count == 0 || (_searchSet?.Count ?? 0) == 0)
         {

+ 1 - 1
Terminal.Gui/Views/FileDialog.cs

@@ -513,7 +513,7 @@ public class FileDialog : Dialog
                 // TODO: Does not work, if this worked then we could tab to it instead
                 // of having to hit F9
                 CanFocus = true,
-                TabStop = true,
+                TabStop = TabStop.TabStop,
                 Menus = [_allowedTypeMenu]
             };
             AllowedTypeMenuClicked (0);

+ 1 - 1
Terminal.Gui/Views/TileView.cs

@@ -871,7 +871,7 @@ public class TileView : View
         public TileViewLineView (TileView parent, int idx)
         {
             CanFocus = false;
-            TabStop = true;
+            TabStop = TabStop.TabStop;
 
             Parent = parent;
             Idx = idx;

+ 1 - 1
UICatalog/Scenarios/Buttons.cs

@@ -22,7 +22,7 @@ public class Buttons : Scenario
         };
 
         // Add a label & text field so we can demo IsDefault
-        var editLabel = new Label { X = 0, Y = 0, TabStop = true, Text = "TextField (to demo IsDefault):" };
+        var editLabel = new Label { X = 0, Y = 0, TabStop = TabStop.TabStop, Text = "TextField (to demo IsDefault):" };
         main.Add (editLabel);
 
         // Add a TextField using Absolute layout. 

+ 19 - 19
UnitTests/View/NavigationTests.cs

@@ -253,12 +253,12 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
         v2.CanFocus = true;
         Assert.Equal (r.TabIndexes.IndexOf (v2), v2.TabIndex);
         Assert.Equal (0, v2.TabIndex);
-        Assert.True (v2.TabStop);
+        Assert.Equal (TabStop.TabStop, v2.TabStop);
 
         v1.CanFocus = true;
         Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
         Assert.Equal (1, v1.TabIndex);
-        Assert.True (v1.TabStop);
+        Assert.Equal (TabStop.TabStop, v1.TabStop);
 
         v1.TabIndex = 2;
         Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
@@ -268,18 +268,18 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
         Assert.Equal (1, v1.TabIndex);
         Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
         Assert.Equal (2, v3.TabIndex);
-        Assert.True (v3.TabStop);
+        Assert.Equal (TabStop.TabStop, v3.TabStop);
 
         v2.CanFocus = false;
         Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
         Assert.Equal (1, v1.TabIndex);
-        Assert.True (v1.TabStop);
+        Assert.Equal (TabStop.TabStop, v1.TabStop);
         Assert.NotEqual (r.TabIndexes.IndexOf (v2), v2.TabIndex);
         Assert.Equal (-1, v2.TabIndex);
-        Assert.False (v2.TabStop);
+        Assert.Equal (TabStop.TabStop, v2.TabStop); // TabStop is not changed
         Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
         Assert.Equal (2, v3.TabIndex);
-        Assert.True (v3.TabStop);
+        Assert.Equal (TabStop.TabStop, v3.TabStop);
         r.Dispose ();
     }
 
@@ -1373,9 +1373,9 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
     public void TabStop_All_False_And_All_True_And_Changing_TabStop_Later ()
     {
         var r = new View ();
-        var v1 = new View { CanFocus = true, TabStop = false };
-        var v2 = new View { CanFocus = true, TabStop = false };
-        var v3 = new View { CanFocus = true, TabStop = false };
+        var v1 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v2 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v3 = new View { CanFocus = true, TabStop = TabStop.None };
 
         r.Add (v1, v2, v3);
 
@@ -1384,17 +1384,17 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
         Assert.False (v2.HasFocus);
         Assert.False (v3.HasFocus);
 
-        v1.TabStop = true;
+        v1.TabStop = TabStop.TabStop;
         r.AdvanceFocus (NavigationDirection.Forward);
         Assert.True (v1.HasFocus);
         Assert.False (v2.HasFocus);
         Assert.False (v3.HasFocus);
-        v2.TabStop = true;
+        v2.TabStop = TabStop.TabStop;
         r.AdvanceFocus (NavigationDirection.Forward);
         Assert.False (v1.HasFocus);
         Assert.True (v2.HasFocus);
         Assert.False (v3.HasFocus);
-        v3.TabStop = true;
+        v3.TabStop = TabStop.TabStop;
         r.AdvanceFocus (NavigationDirection.Forward);
         Assert.False (v1.HasFocus);
         Assert.False (v2.HasFocus);
@@ -1464,9 +1464,9 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
     public void TabStop_And_CanFocus_Mixed_And_BothFalse ()
     {
         var r = new View ();
-        var v1 = new View { CanFocus = true, TabStop = false };
-        var v2 = new View { CanFocus = false, TabStop = true };
-        var v3 = new View { CanFocus = false, TabStop = false };
+        var v1 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v2 = new View { CanFocus = false, TabStop = TabStop.TabStop };
+        var v3 = new View { CanFocus = false, TabStop = TabStop.None };
 
         r.Add (v1, v2, v3);
 
@@ -1489,9 +1489,9 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
     public void TabStop_Are_All_False_And_CanFocus_Are_All_True ()
     {
         var r = new View ();
-        var v1 = new View { CanFocus = true, TabStop = false };
-        var v2 = new View { CanFocus = true, TabStop = false };
-        var v3 = new View { CanFocus = true, TabStop = false };
+        var v1 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v2 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v3 = new View { CanFocus = true, TabStop = TabStop.None };
 
         r.Add (v1, v2, v3);
 
@@ -1537,7 +1537,7 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
 
     [Theory]
     [CombinatorialData]
-    public void TabStop_And_CanFocus_Are_Decoupled (bool canFocus, bool tabStop)
+    public void TabStop_And_CanFocus_Are_Decoupled (bool canFocus, TabStop tabStop)
     {
         var view = new View { CanFocus = canFocus, TabStop = tabStop };