浏览代码

Made View.Navigation nullable enable.
Changed TabIndex to int?.
Changed TabStop to int?.
Changed TabStop flags.

Tig 1 年之前
父节点
当前提交
d407683d5b

+ 2 - 2
Terminal.Gui/View/Adornment/Margin.cs

@@ -226,12 +226,12 @@ public class Margin : Adornment
             {
                 case ShadowStyle.Transparent:
                     // BUGBUG: This doesn't work right for all Border.Top sizes - Need an API on Border that gives top-right location of line corner.
-                    _rightShadow.Y = Parent.Border.Thickness.Top > 0 ? ScreenToViewport (Parent.Border.GetBorderRectangle ().Location).Y + 1 : 0;
+                    _rightShadow.Y = Parent!.Border.Thickness.Top > 0 ? ScreenToViewport (Parent.Border.GetBorderRectangle ().Location).Y + 1 : 0;
                     break;
 
                 case ShadowStyle.Opaque:
                     // BUGBUG: This doesn't work right for all Border.Top sizes - Need an API on Border that gives top-right location of line corner.
-                    _rightShadow.Y = Parent.Border.Thickness.Top > 0 ? ScreenToViewport (Parent.Border.GetBorderRectangle ().Location).Y + 1 : 0;
+                    _rightShadow.Y = Parent!.Border.Thickness.Top > 0 ? ScreenToViewport (Parent.Border.GetBorderRectangle ().Location).Y + 1 : 0;
                     _bottomShadow.X = Parent.Border.Thickness.Left > 0 ? ScreenToViewport (Parent.Border.GetBorderRectangle ().Location).X + 1 : 0;
                     break;
 

+ 2 - 2
Terminal.Gui/View/Adornment/ShadowView.cs

@@ -113,7 +113,7 @@ internal class ShadowView : View
         {
             Driver.Move (i, screen.Y);
 
-            if (i < Driver.Contents.GetLength (1) && screen.Y < Driver.Contents.GetLength (0))
+            if (i < Driver.Contents!.GetLength (1) && screen.Y < Driver.Contents.GetLength (0))
             {
                 Driver.AddRune (Driver.Contents [screen.Y, i].Rune);
             }
@@ -141,7 +141,7 @@ internal class ShadowView : View
         {
             Driver.Move (screen.X, i);
 
-            if (screen.X < Driver.Contents.GetLength (1) && i < Driver.Contents.GetLength (0))
+            if (Driver.Contents is { } && screen.X < Driver.Contents.GetLength (1) && i < Driver.Contents.GetLength (0))
             {
                 Driver.AddRune (Driver.Contents [i, screen.X].Rune);
             }

+ 4 - 10
Terminal.Gui/View/Navigation/TabStop.cs → Terminal.Gui/View/Navigation/TabBehavior.cs

@@ -1,20 +1,14 @@
 namespace Terminal.Gui;
 
 /// <summary>
-///     Describes a TabStop; a stop-point for keyboard navigation between Views.
+///     Describes how <see cref="View.TabStop"/> behaves. A TabStop is a stop-point for keyboard navigation between Views.
 /// </summary>
-/// <remarks>
-///     <para>
-///         TabStop does not impact whether a view is focusable or not. <see cref="View.CanFocus"/> determines this independently of TabStop.
-///     </para>
-/// </remarks>
-[Flags]
-public enum TabStop
+public enum TabBehavior
 {
     /// <summary>
     ///     The View will not be a stop-poknt for keyboard-based navigation.
     /// </summary>
-    None = 0,
+    NoStop = 0,
 
     /// <summary>
     ///     The View will be a stop-point for keybaord-based navigation across Views (e.g. if the user presses `Tab`).
@@ -22,7 +16,7 @@ public enum TabStop
     TabStop = 1,
 
     /// <summary>
-    ///     The View will be a stop-point for keyboard-based navigation across TabGroups (e.g. if the user preesses <see cref="Application.NextTabGroupKey"/> (`Ctrl-PageDown`).
+    ///     The View will be a stop-point for keyboard-based navigation across groups (e.g. if the user preesses <see cref="Application.NextTabGroupKey"/> (`Ctrl-PageDown`).
     /// </summary>
     TabGroup = 2,
 }

文件差异内容过多而无法显示
+ 382 - 390
Terminal.Gui/View/View.Navigation.cs


+ 0 - 4
Terminal.Gui/View/View.cs

@@ -184,10 +184,6 @@ public partial class View : Responder, ISupportInitializeNotification
 
         //SetupMouse ();
         SetupText ();
-
-        CanFocus = false;
-        //TabIndex = -1;
-        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 = TabStop.None };
+        _listview = new ComboListView (this, HideDropdownListOnClick) { CanFocus = true };
 
         _search.TextChanged += Search_Changed;
         _search.Accept += Search_Accept;
@@ -329,9 +329,9 @@ public class ComboBox : View, IDesignable
             IsShow = false;
             HideList ();
         }
-        else if (_listview.TabStop.HasFlag (TabStop))
+        else if (_listview.TabStop?.HasFlag (TabBehavior.TabStop) ?? false)
         {
-            _listview.TabStop = TabStop.None;
+            _listview.TabStop = TabBehavior.NoStop;
         }
 
         return base.OnLeave (view);
@@ -455,7 +455,7 @@ public class ComboBox : View, IDesignable
     private void FocusSelectedItem ()
     {
         _listview.SelectedItem = SelectedItem > -1 ? SelectedItem : 0;
-        _listview.TabStop = TabStop.TabStop;
+        _listview.TabStop = TabBehavior.TabStop;
         _listview.SetFocus ();
         OnExpanded ();
     }
@@ -491,7 +491,7 @@ public class ComboBox : View, IDesignable
 
         Reset (true);
         _listview.Clear ();
-        _listview.TabStop = TabStop.None;
+        _listview.TabStop = TabBehavior.NoStop;
         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 = TabStop.TabStop;
+                _listview.TabStop = TabBehavior.TabStop;
                 _listview.SetFocus ();
 
                 if (_listview.SelectedItem > -1)
@@ -519,7 +519,7 @@ public class ComboBox : View, IDesignable
             }
             else
             {
-                _listview.TabStop = TabStop.None;
+                _listview.TabStop = TabBehavior.NoStop;
                 SuperView?.AdvanceFocus (NavigationDirection.Forward);
             }
 
@@ -721,7 +721,7 @@ public class ComboBox : View, IDesignable
     private void Selected ()
     {
         IsShow = false;
-        _listview.TabStop = TabStop.None;
+        _listview.TabStop = TabBehavior.NoStop;
 
         if (_listview.Source.Count == 0 || (_searchSet?.Count ?? 0) == 0)
         {

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

@@ -464,8 +464,8 @@ public class FileDialog : Dialog
             _btnOk.X = Pos.Right (_btnCancel) + 1;
 
             // Flip tab order too for consistency
-            int p1 = _btnOk.TabIndex;
-            int p2 = _btnCancel.TabIndex;
+            int? p1 = _btnOk.TabIndex;
+            int? p2 = _btnCancel.TabIndex;
 
             _btnOk.TabIndex = p2;
             _btnCancel.TabIndex = p1;
@@ -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 = TabStop.TabStop,
+                TabStop = TabBehavior.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 = TabStop.TabStop;
+            TabStop = TabBehavior.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 = TabStop.TabStop, Text = "TextField (to demo IsDefault):" };
+        var editLabel = new Label { X = 0, Y = 0, 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.Equal (TabStop.TabStop, v2.TabStop);
+        Assert.Equal (TabBehavior.TabStop, v2.TabStop);
 
         v1.CanFocus = true;
         Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
         Assert.Equal (1, v1.TabIndex);
-        Assert.Equal (TabStop.TabStop, v1.TabStop);
+        Assert.Equal (TabBehavior.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.Equal (TabStop.TabStop, v3.TabStop);
+        Assert.Equal (TabBehavior.TabStop, v3.TabStop);
 
         v2.CanFocus = false;
         Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
         Assert.Equal (1, v1.TabIndex);
-        Assert.Equal (TabStop.TabStop, v1.TabStop);
+        Assert.Equal (TabBehavior.TabStop, v1.TabStop);
         Assert.Equal (r.TabIndexes.IndexOf (v2), v2.TabIndex); // TabIndex is not changed
         Assert.NotEqual (-1, v2.TabIndex);
-        Assert.Equal (TabStop.TabStop, v2.TabStop); // TabStop is not changed
+        Assert.Equal (TabBehavior.TabStop, v2.TabStop); // TabStop is not changed
         Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
         Assert.Equal (2, v3.TabIndex);
-        Assert.Equal (TabStop.TabStop, v3.TabStop);
+        Assert.Equal (TabBehavior.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 = TabStop.None };
-        var v2 = new View { CanFocus = true, TabStop = TabStop.None };
-        var v3 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v1 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
+        var v2 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
+        var v3 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
 
         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 = TabStop.TabStop;
+        v1.TabStop = TabBehavior.TabStop;
         r.AdvanceFocus (NavigationDirection.Forward);
         Assert.True (v1.HasFocus);
         Assert.False (v2.HasFocus);
         Assert.False (v3.HasFocus);
-        v2.TabStop = TabStop.TabStop;
+        v2.TabStop = TabBehavior.TabStop;
         r.AdvanceFocus (NavigationDirection.Forward);
         Assert.False (v1.HasFocus);
         Assert.True (v2.HasFocus);
         Assert.False (v3.HasFocus);
-        v3.TabStop = TabStop.TabStop;
+        v3.TabStop = TabBehavior.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 = TabStop.None };
-        var v2 = new View { CanFocus = false, TabStop = TabStop.TabStop };
-        var v3 = new View { CanFocus = false, TabStop = TabStop.None };
+        var v1 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
+        var v2 = new View { CanFocus = false, TabStop = TabBehavior.TabStop };
+        var v3 = new View { CanFocus = false, TabStop = TabBehavior.NoStop };
 
         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 = TabStop.None };
-        var v2 = new View { CanFocus = true, TabStop = TabStop.None };
-        var v3 = new View { CanFocus = true, TabStop = TabStop.None };
+        var v1 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
+        var v2 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
+        var v3 = new View { CanFocus = true, TabStop = TabBehavior.NoStop };
 
         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, TabStop tabStop)
+    public void TabStop_And_CanFocus_Are_Decoupled (bool canFocus, TabBehavior tabStop)
     {
         var view = new View { CanFocus = canFocus, TabStop = tabStop };
 

部分文件因为文件数量过多而无法显示