Tig 11 miesięcy temu
rodzic
commit
6931326686

+ 15 - 1
Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs

@@ -42,8 +42,22 @@ public abstract partial class PopupAutocomplete : AutocompleteBase
         get => _hostControl;
         set
         {
-            Debug.Assert (_hostControl is null);
+            if (value == _hostControl)
+            {
+                return;
+            }
+
             _hostControl = value;
+
+            if (_hostControl is null)
+            {
+                RemovePopupFromTop();
+                _top.Removed -= _top_Removed;
+                _top = null;
+
+                return;
+            }
+
             _top = _hostControl.SuperView;
 
             if (_top is { })

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

@@ -64,7 +64,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
                 return false;
             }
 
-            // - If we are TabGrup and our SuperView has at least one other TabGroup subview, move to the SuperView's chain
+            // - If we are TabGroup and our SuperView has at least one other TabGroup subview, move to the SuperView's chain
             if (TabStop == TabBehavior.TabGroup && SuperView is { TabStop: TabBehavior.TabGroup })
             {
                 if (behavior == TabBehavior.TabGroup)

+ 17 - 44
Terminal.Gui/Views/TabView.cs

@@ -1,3 +1,5 @@
+using System.Diagnostics;
+
 namespace Terminal.Gui;
 
 /// <summary>Control that hosts multiple sub views, presenting a single one at once.</summary>
@@ -25,13 +27,12 @@ public class TabView : View
     public TabView ()
     {
         CanFocus = true;
-        TabStop = TabBehavior.TabGroup; // Because TabView has focusable subviews, it must be a TabGroup
+        TabStop = TabBehavior.TabStop; // Because TabView has focusable subviews, it must be a TabGroup
         _tabsBar = new TabRowView (this);
         _contentView = new View ()
         {
-            Id = "TabView._contentView"
+            //Id = "TabView._contentView",
         };
-
         ApplyStyleChanges ();
 
         base.Add (_tabsBar);
@@ -64,42 +65,6 @@ public class TabView : View
                     }
                    );
 
-        AddCommand (
-                    Command.NextView,
-                    () =>
-                    {
-                        if (Style.TabsOnBottom)
-                        {
-                            return false;
-                        }
-
-                        if (_contentView is { HasFocus: false })
-                        {
-                            _contentView.SetFocus ();
-
-                            return _contentView.Focused is { };
-                        }
-
-                        return false;
-                    }
-                   );
-
-        AddCommand (Command.PreviousView, () =>
-                                          {
-                                              if (!Style.TabsOnBottom)
-                                              {
-                                                  return false;
-                                              }
-                                              if (_contentView is { HasFocus: false })
-                                              {
-                                                  _contentView.SetFocus ();
-
-                                                  return _contentView.Focused is { };
-                                              }
-
-                                              return false;
-                                          });
-
         AddCommand (
                     Command.PageDown,
                     () =>
@@ -127,8 +92,6 @@ public class TabView : View
         KeyBindings.Add (Key.CursorRight, Command.Right);
         KeyBindings.Add (Key.Home, Command.LeftHome);
         KeyBindings.Add (Key.End, Command.RightEnd);
-        KeyBindings.Add (Key.CursorDown, Command.NextView);
-        KeyBindings.Add (Key.CursorUp, Command.PreviousView);
         KeyBindings.Add (Key.PageDown, Command.PageDown);
         KeyBindings.Add (Key.PageUp, Command.PageUp);
     }
@@ -167,9 +130,12 @@ public class TabView : View
                 if (_selectedTab.View is { })
                 {
                     _contentView.Add (_selectedTab.View);
+                   // _contentView.Id = $"_contentView for {_selectedTab.DisplayText}";
                 }
             }
 
+            _contentView.CanFocus = _contentView.Subviews.Count (v => v.CanFocus) > 0;
+
             EnsureSelectedTabIsVisible ();
 
             if (old != value)
@@ -267,7 +233,7 @@ public class TabView : View
             int tabHeight = GetTabHeight (true);
 
             //move content down to make space for tabs
-            _contentView.Y = Pos.Bottom (_tabsBar);
+            _contentView.Y = Pos.Bottom (_tabsBar) ;
 
             // Fill client area leaving space at bottom for border
             _contentView.Height = Dim.Fill ();
@@ -439,7 +405,10 @@ public class TabView : View
     }
 
     /// <summary>Raises the <see cref="SelectedTabChanged"/> event.</summary>
-    protected virtual void OnSelectedTabChanged (Tab oldTab, Tab newTab) { SelectedTabChanged?.Invoke (this, new TabChangedEventArgs (oldTab, newTab)); }
+    protected virtual void OnSelectedTabChanged (Tab oldTab, Tab newTab)
+    {
+        SelectedTabChanged?.Invoke (this, new TabChangedEventArgs (oldTab, newTab));
+    }
 
     /// <summary>Returns which tabs to render at each x location.</summary>
     /// <returns></returns>
@@ -539,7 +508,10 @@ public class TabView : View
         return Style.ShowTopLine ? 3 : 2;
     }
 
-    private void Tab_MouseClick (object sender, MouseEventEventArgs e) { e.Handled = _tabsBar.NewMouseEvent (e.MouseEvent) == true; }
+    private void Tab_MouseClick (object sender, MouseEventEventArgs e)
+    {
+        e.Handled = _tabsBar.NewMouseEvent (e.MouseEvent) == true;
+    }
 
     private void UnSetCurrentTabs ()
     {
@@ -568,6 +540,7 @@ public class TabView : View
         public TabRowView (TabView host)
         {
             _host = host;
+            Id = "tabRowView";
 
             CanFocus = true;
             Height = 1; // BUGBUG: Views should avoid setting Height as doing so implies Frame.Size == GetContentSize ().

+ 7 - 0
Terminal.Gui/Views/TextField.cs

@@ -48,6 +48,8 @@ public class TextField : View
 
         Added += TextField_Added;
 
+        Removed += TextField_Removed;
+
         // Things this view knows how to do
         AddCommand (
                     Command.DeleteCharRight,
@@ -1870,6 +1872,11 @@ public class TextField : View
         }
     }
 
+    private void TextField_Removed (object sender, SuperViewChangedEventArgs e)
+    {
+        Autocomplete.HostControl = null;
+    }
+
     private void TextField_Initialized (object sender, EventArgs e)
     {
         _cursorPosition = Text.GetRuneCount ();

+ 15 - 8
UICatalog/Scenarios/TabViewExample.cs

@@ -73,6 +73,7 @@ public class TabViewExample : Scenario
 
         _tabView = new()
         {
+            Title = "_Tab View",
             X = 0,
             Y = 1,
             Width = 60,
@@ -80,9 +81,9 @@ public class TabViewExample : Scenario
             BorderStyle = LineStyle.Single
         };
 
-        _tabView.AddTab (new() { DisplayText = "Tab1", View = new Label { Text = "hodor!" } }, false);
-        _tabView.AddTab (new() { DisplayText = "Tab2", View = new TextField { Text = "durdur" } }, false);
-        _tabView.AddTab (new() { DisplayText = "Interactive Tab", View = GetInteractiveTab () }, false);
+        _tabView.AddTab (new() { DisplayText = "Tab_1", View = new Label { Text = "hodor!" } }, false);
+        _tabView.AddTab (new() { DisplayText = "Tab_2", View = new TextField { Text = "durdur", Width = 10 } }, false);
+        _tabView.AddTab (new() { DisplayText = "_Interactive Tab", View = GetInteractiveTab () }, false);
         _tabView.AddTab (new() { DisplayText = "Big Text", View = GetBigTextFileTab () }, false);
 
         _tabView.AddTab (
@@ -138,9 +139,10 @@ public class TabViewExample : Scenario
             Y = 1,
             Width = Dim.Fill (),
             Height = Dim.Fill (1),
-            Title = "About",
+            Title = "_About",
             BorderStyle = LineStyle.Single,
-            TabStop = TabBehavior.TabStop
+            TabStop = TabBehavior.TabStop,
+            CanFocus = true
         };
 
         frameRight.Add (
@@ -161,9 +163,10 @@ public class TabViewExample : Scenario
             Y = Pos.Bottom (_tabView),
             Width = _tabView.Width,
             Height = Dim.Fill (1),
-            Title = "Bottom Frame",
+            Title = "B_ottom Frame",
             BorderStyle = LineStyle.Single,
-            TabStop = TabBehavior.TabStop
+            TabStop = TabBehavior.TabStop,
+            CanFocus = true
 
         };
 
@@ -216,7 +219,11 @@ public class TabViewExample : Scenario
 
     private View GetInteractiveTab ()
     {
-        var interactiveTab = new View { Width = Dim.Fill (), Height = Dim.Fill () };
+        var interactiveTab = new View
+        {
+            Width = Dim.Fill (), Height = Dim.Fill (),
+            CanFocus = true
+        };
         var lblName = new Label { Text = "Name:" };
         interactiveTab.Add (lblName);