浏览代码

Fixed Config editor

Tig 11 月之前
父节点
当前提交
cc627781e4

+ 6 - 5
Terminal.Gui/Application/Application.Run.cs

@@ -191,11 +191,12 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         // Try to set initial focus to any TabStop
         if (!toplevel.HasFocus)
         {
-            if (!toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop))
-            {
-                // That didn't work. Try TabGroup.
-                toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup);
-            }
+            toplevel.SetFocus ();
+            //if (!toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop))
+            //{
+            //    // That didn't work. Try TabGroup.
+            //    toplevel.AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabGroup);
+            //}
         }
 
         ApplicationOverlapped.BringOverlappedTopToFront ();

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

@@ -49,6 +49,10 @@ public partial class View // SuperView/SubView hierarchy management (SuperView,
         }
 
         Debug.WriteLineIf (_subviews.Contains (view), $"BUGBUG: {view} has already been added to {this}.");
+
+        // TileView likes to add views that were previously added and have HasFocus = true. No bueno.
+        HasFocus = false;
+
         _subviews.Add (view);
         view._superView = this;
 

+ 7 - 2
Terminal.Gui/Views/TileView.cs

@@ -15,12 +15,15 @@ public class TileView : View
     /// <summary>Creates a new instance of the <see cref="TileView"/> class with 2 tiles (i.e. left and right).</summary>
     public TileView () : this (2)
     {
-        CanFocus = true;
     }
 
     /// <summary>Creates a new instance of the <see cref="TileView"/> class with <paramref name="tiles"/> number of tiles.</summary>
     /// <param name="tiles"></param>
-    public TileView (int tiles) { RebuildForTileCount (tiles); }
+    public TileView (int tiles)
+    {
+        CanFocus = true;
+        RebuildForTileCount (tiles);
+    }
 
     /// <summary>The line style to use when drawing the splitter lines.</summary>
     public LineStyle LineStyle { get; set; } = LineStyle.None;
@@ -119,6 +122,7 @@ public class TileView : View
 
                 // restore old Tile and View
                 _tiles [i] = oldTile;
+                _tiles [i].ContentView.TabStop = TabStop;
                 Add (_tiles [i].ContentView);
             }
             else
@@ -357,6 +361,7 @@ public class TileView : View
 
             var tile = new Tile ();
             _tiles.Add (tile);
+            tile.ContentView.Id = $"Tile.ContentView {i}";
             Add (tile.ContentView);
             tile.TitleChanged += (s, e) => SetNeedsDisplay ();
         }

+ 23 - 6
UICatalog/Scenarios/ConfigurationEditor.cs

@@ -44,7 +44,11 @@ public class ConfigurationEditor : Scenario
 
         _tileView = new TileView (0)
         {
-            Width = Dim.Fill (), Height = Dim.Fill (1), Orientation = Orientation.Vertical, LineStyle = LineStyle.Single
+            Width = Dim.Fill (),
+            Height = Dim.Fill (1),
+            Orientation = Orientation.Vertical,
+            LineStyle = LineStyle.Single,
+            TabStop = TabBehavior.TabGroup
         };
 
         top.Add (_tileView);
@@ -79,7 +83,11 @@ public class ConfigurationEditor : Scenario
 
         top.Add (statusBar);
 
-        top.Loaded += (s, a) => Open ();
+        top.Loaded += (s, a) =>
+                      {
+                          Open ();
+                          //_tileView.AdvanceFocus (NavigationDirection.Forward, null);
+                      };
 
         _editorColorSchemeChanged += () =>
                                      {
@@ -133,9 +141,16 @@ public class ConfigurationEditor : Scenario
 
             textView.Read ();
 
-            textView.HasFocusChanging += (s, e) => { _lenShortcut.Title = $"Len:{textView.Text.Length}"; };
+            textView.HasFocusChanged += (s, e) =>
+                                        {
+                                            if (e.NewValue)
+                                            {
+                                                _lenShortcut.Title = $"Len:{textView.Text.Length}";
+                                            }
+                                        };
         }
 
+        _tileView.Tiles.ToArray () [1].ContentView.SetFocus ();
         Application.Top.LayoutSubviews ();
     }
 
@@ -150,9 +165,9 @@ public class ConfigurationEditor : Scenario
                 int result = MessageBox.Query (
                                                "Save Changes",
                                                $"Save changes to {editor.FileInfo.FullName}",
-                                               "Yes",
-                                               "No",
-                                               "Cancel"
+                                               "_Yes",
+                                               "_No",
+                                               "_Cancel"
                                               );
 
                 if (result == -1 || result == 2)
@@ -196,6 +211,8 @@ public class ConfigurationEditor : Scenario
                                        }
                                    }
                                };
+            TabStop = TabBehavior.TabGroup;
+
         }
 
         internal FileInfo FileInfo { get; set; }