Browse Source

Cleaned up scenarios. Fixed Visible issue.

Tig 11 months ago
parent
commit
492a772abc

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

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

+ 3 - 2
Terminal.Gui/View/View.cs

@@ -392,12 +392,13 @@ public partial class View : Responder, ISupportInitializeNotification
     /// <summary>Event fired when the <see cref="Visible"/> value is being changed.</summary>
     public event EventHandler? VisibleChanged;
 
+    // TODO: This API is a hack. We should make Visible propogate automatically, no? See https://github.com/gui-cs/Terminal.Gui/issues/3703
     /// <summary>
-    /// INTERNAL method for determining if all the specified view and all views up the Superview hierarchy are visible.
+    ///     INTERNAL Indicates whether all views up the Superview hierarchy are visible.
     /// </summary>
     /// <param name="view">The view to test.</param>
     /// <returns> <see langword="false"/> if `view.Visible` is  <see langword="false"/> or any Superview is not visible, <see langword="true"/> otherwise.</returns>
-    private static bool CanBeVisible (View view)
+    internal static bool CanBeVisible (View view)
     {
         if (!view.Visible)
         {

+ 4 - 1
Terminal.Gui/Views/ColorPicker.cs

@@ -89,7 +89,10 @@ public class ColorPicker : View
         CreateTextField ();
         SelectedColor = oldValue;
 
-        LayoutSubviews ();
+        if (IsInitialized)
+        {
+            LayoutSubviews ();
+        }
     }
 
     /// <summary>

+ 4 - 0
Terminal.Gui/Views/Shortcut.cs

@@ -742,6 +742,10 @@ public class Shortcut : View, IOrientation, IDesignable
                 break;
 
             case KeyBindingScope.HotKey:
+                //if (!CanBeVisible(this))
+                //{
+                //    return true;
+                //}
                 cancel = base.OnAccept () == true;
 
                 if (CanFocus)

+ 1 - 1
UICatalog/Scenarios/Adornments.cs

@@ -4,7 +4,7 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Adornments Demo", "Demonstrates Margin, Border, and Padding on Views.")]
 [ScenarioCategory ("Layout")]
-[ScenarioCategory ("Borders")]
+[ScenarioCategory ("Adornments")]
 public class Adornments : Scenario
 {
     public override void Main ()

+ 2 - 1
UICatalog/Scenarios/AllViewsTester.cs

@@ -11,7 +11,8 @@ namespace UICatalog.Scenarios;
 [ScenarioMetadata ("All Views Tester", "Provides a test UI for all classes derived from View.")]
 [ScenarioCategory ("Layout")]
 [ScenarioCategory ("Tests")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Controls")]
+[ScenarioCategory ("Adornments")]
 public class AllViewsTester : Scenario
 {
     private readonly List<string> _dimNames = new () { "Auto", "Percent", "Fill", "Absolute" };

+ 2 - 1
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -10,7 +10,8 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("BackgroundWorker Collection", "A persisting multi Toplevel BackgroundWorker threading")]
 [ScenarioCategory ("Threading")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
+[ScenarioCategory ("Runnable")]
 [ScenarioCategory ("Dialogs")]
 [ScenarioCategory ("Controls")]
 public class BackgroundWorkerCollection : Scenario

+ 1 - 1
UICatalog/Scenarios/ChineseUI.cs

@@ -3,7 +3,7 @@
 namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("ChineseUI", "Chinese UI")]
-[ScenarioCategory ("Unicode")]
+[ScenarioCategory ("Text and Formatting")]
 public class ChineseUI : Scenario
 {
     public override void Main ()

+ 1 - 1
UICatalog/Scenarios/CsvEditor.cs

@@ -16,7 +16,7 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Dialogs")]
 [ScenarioCategory ("Text and Formatting")]
 [ScenarioCategory ("Dialogs")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 [ScenarioCategory ("Files and IO")]
 public class CsvEditor : Scenario
 {

+ 1 - 1
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -9,7 +9,7 @@ using Terminal.Gui;
 namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Dynamic MenuBar", "Demonstrates how to change a MenuBar dynamically.")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 [ScenarioCategory ("Menus")]
 public class DynamicMenuBar : Scenario
 {

+ 1 - 1
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -10,7 +10,7 @@ using Terminal.Gui;
 namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Dynamic StatusBar", "Demonstrates how to add and remove a StatusBar and change items dynamically.")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 public class DynamicStatusBar : Scenario
 {
     public override void Main ()

+ 1 - 1
UICatalog/Scenarios/Editor.cs

@@ -16,7 +16,7 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Controls")]
 [ScenarioCategory ("Dialogs")]
 [ScenarioCategory ("Text and Formatting")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 [ScenarioCategory ("Files and IO")]
 [ScenarioCategory ("TextView")]
 [ScenarioCategory ("Menus")]

+ 1 - 1
UICatalog/Scenarios/HexEditor.cs

@@ -8,7 +8,7 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Controls")]
 [ScenarioCategory ("Dialogs")]
 [ScenarioCategory ("Text and Formatting")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 [ScenarioCategory ("Files and IO")]
 public class HexEditor : Scenario
 {

+ 1 - 1
UICatalog/Scenarios/LineCanvasExperiment.cs

@@ -4,7 +4,7 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("LineCanvas Experiments", "Experiments with LineCanvas")]
 [ScenarioCategory ("Drawing")]
-[ScenarioCategory ("Borders")]
+[ScenarioCategory ("Adornments")]
 [ScenarioCategory ("Proof of Concept")]
 public class LineCanvasExperiment : Scenario
 {

+ 1 - 1
UICatalog/Scenarios/LineViewExample.cs

@@ -6,7 +6,7 @@ namespace UICatalog.Scenarios;
 [ScenarioMetadata ("Line View", "Demonstrates drawing lines using the LineView control.")]
 [ScenarioCategory ("Controls")]
 [ScenarioCategory ("LineView")]
-[ScenarioCategory ("Borders")]
+[ScenarioCategory ("Adornments")]
 public class LineViewExample : Scenario
 {
     public override void Main ()

+ 1 - 1
UICatalog/Scenarios/ListColumns.cs

@@ -11,7 +11,7 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Controls")]
 [ScenarioCategory ("Dialogs")]
 [ScenarioCategory ("Text and Formatting")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 [ScenarioCategory ("Scrolling")]
 public class ListColumns : Scenario
 {

+ 44 - 10
UICatalog/Scenarios/Navigation.cs

@@ -1,5 +1,4 @@
-using System;
-using System.Timers;
+using System.Timers;
 using Terminal.Gui;
 
 namespace UICatalog.Scenarios;
@@ -7,6 +6,7 @@ namespace UICatalog.Scenarios;
 [ScenarioMetadata ("Navigation", "Navigation Tester")]
 [ScenarioCategory ("Mouse and Keyboard")]
 [ScenarioCategory ("Layout")]
+[ScenarioCategory ("Overlapped")]
 public class Navigation : Scenario
 {
     private int _hotkeyCount;
@@ -75,35 +75,68 @@ public class Navigation : Scenario
 
         Timer timer = new (10)
         {
-            AutoReset = true,
+            AutoReset = true
         };
+
         timer.Elapsed += (o, args) =>
                          {
-
                              if (progressBar.Fraction == 1.0)
                              {
                                  progressBar.Fraction = 0;
                              }
+
                              progressBar.Fraction += 0.01f;
 
                              Application.Wakeup ();
 
                              progressBar.SetNeedsDisplay ();
-
                          };
         timer.Start ();
 
-        View overlappedView2 = CreateOverlappedView (3, Pos.Right (overlappedView1) + 2, Pos.Top (overlappedView1) + 1);
+        View overlappedView2 = CreateOverlappedView (3, 8, 10);
 
-        var overlappedInOverlapped1 = CreateOverlappedView (4, 1, 4);
+        View overlappedInOverlapped1 = CreateOverlappedView (4, 1, 4);
         overlappedView2.Add (overlappedInOverlapped1);
 
-        var overlappedInOverlapped2 = CreateOverlappedView (5, 10, 7);
+        View overlappedInOverlapped2 = CreateOverlappedView (5, 10, 7);
         overlappedView2.Add (overlappedInOverlapped2);
 
+        StatusBar statusBar = new ()
+        {
+
+        };
+
+        statusBar.Add (
+                       new Shortcut ()
+                       {
+                           Title = "Close",
+                           Text = "Hotkey",
+                           Key = Key.F4,
+                           Action = () =>
+                                    {
+                                        overlappedView2.Visible = false;
+                                        overlappedView2.Enabled = overlappedView2.Visible;
+                                    }
+                       });
+        statusBar.Add (
+                       new Shortcut ()
+                       {
+                           Title = "Close",
+                           Text = "App",
+                           KeyBindingScope = KeyBindingScope.Application,
+                           Key = Key.F4.WithCtrl,
+                           Action = () =>
+                                    {
+                                        overlappedView2.Visible = !overlappedView2.Visible;
+                                        overlappedView2.Enabled = overlappedView2.Visible;
+
+                                    }
+                       });
+        overlappedView2.Add (statusBar);
+
         ColorPicker colorPicker = new ()
         {
-            Y = Pos.AnchorEnd (),
+            Y = 12,
             Width = Dim.Fill (),
             Id = "colorPicker",
             Style = new ()
@@ -117,6 +150,7 @@ public class Navigation : Scenario
         colorPicker.SelectedColor = testFrame.ColorScheme.Normal.Background;
         colorPicker.ColorChanged += ColorPicker_ColorChanged;
         overlappedView2.Add (colorPicker);
+        overlappedView2.Width = 50;
 
         testFrame.Add (overlappedView1);
         testFrame.Add (overlappedView2);
@@ -151,13 +185,13 @@ public class Navigation : Scenario
         Application.Shutdown ();
 
         return;
+
         void ColorPicker_ColorChanged (object sender, ColorEventArgs e)
         {
             testFrame.ColorScheme = testFrame.ColorScheme with { Normal = new (testFrame.ColorScheme.Normal.Foreground, e.CurrentValue) };
         }
     }
 
-
     private View CreateOverlappedView (int id, Pos x, Pos y)
     {
         var overlapped = new View

+ 2 - 1
UICatalog/Scenarios/RunTExample.cs

@@ -3,7 +3,8 @@
 namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Run<T> Example", "Illustrates using Application.Run<T> to run a custom class")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Runnable")]
+[ScenarioCategory ("Overlapped")]
 public class RunTExample : Scenario
 {
     public override void Main ()

+ 2 - 1
UICatalog/Scenarios/SingleBackgroundWorker.cs

@@ -9,7 +9,8 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Single BackgroundWorker", "A single BackgroundWorker threading opening another Toplevel")]
 [ScenarioCategory ("Threading")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
+[ScenarioCategory ("Runnable")]
 public class SingleBackgroundWorker : Scenario
 {
     public override void Main ()

+ 1 - 1
UICatalog/Scenarios/TableEditor.cs

@@ -14,7 +14,7 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Controls")]
 [ScenarioCategory ("Dialogs")]
 [ScenarioCategory ("Text and Formatting")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 public class TableEditor : Scenario
 {
     private readonly HashSet<FileSystemInfo> _checkedFileSystemInfos = new ();

+ 1 - 1
UICatalog/Scenarios/ViewExperiments.cs

@@ -5,7 +5,7 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("View Experiments", "v2 View Experiments")]
 [ScenarioCategory ("Controls")]
-[ScenarioCategory ("Borders")]
+[ScenarioCategory ("Adornments")]
 [ScenarioCategory ("Layout")]
 [ScenarioCategory ("Proof of Concept")]
 public class ViewExperiments : Scenario

+ 3 - 1
UICatalog/Scenarios/Wizards.cs

@@ -5,8 +5,10 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("Wizards", "Demonstrates the Wizard class")]
 [ScenarioCategory ("Dialogs")]
-[ScenarioCategory ("Top Level Windows")]
+[ScenarioCategory ("Overlapped")]
 [ScenarioCategory ("Wizards")]
+[ScenarioCategory ("Runnable")]
+
 public class Wizards : Scenario
 {
     public override void Main ()

+ 0 - 7
UICatalog/UICatalog.cs

@@ -644,13 +644,6 @@ public class UICatalogApp
             Add (CategoryList);
             Add (ScenarioList);
 
-            Add (MenuBar!);
-
-            if (StatusBar is { })
-            {
-                Add (StatusBar);
-            }
-
             Loaded += LoadedHandler;
             Unloaded += UnloadedHandler;