Pārlūkot izejas kodu

Updated CM scenario

Tig 1 gadu atpakaļ
vecāks
revīzija
9c0fb02593

+ 9 - 2
Terminal.Gui/Configuration/SettingsScope.cs

@@ -3,6 +3,7 @@ using System.Diagnostics;
 using System.Reflection;
 using System.Text.Json;
 using System.Text.Json.Serialization;
+using static Terminal.Gui.SpinnerStyle;
 
 namespace Terminal.Gui;
 
@@ -44,7 +45,10 @@ public class SettingsScope : Scope<SettingsScope>
             Update (JsonSerializer.Deserialize<SettingsScope> (stream, _serializerOptions)!);
             OnUpdated ();
             Debug.WriteLine ($"ConfigurationManager: Read configuration from \"{source}\"");
-            Sources.Add (source);
+            if (!Sources.Contains (source))
+            {
+                Sources.Add (source);
+            }
 
             return this;
         }
@@ -70,7 +74,10 @@ public class SettingsScope : Scope<SettingsScope>
         if (!File.Exists (realPath))
         {
             Debug.WriteLine ($"ConfigurationManager: Configuration file \"{realPath}\" does not exist.");
-            Sources.Add (filePath);
+            if (!Sources.Contains (filePath))
+            {
+                Sources.Add (filePath);
+            }
 
             return this;
         }

+ 3 - 5
UICatalog/Scenarios/AdornmentExperiments.cs

@@ -8,6 +8,8 @@ public class AdornmentExperiments : Scenario
 {
     private ViewDiagnosticFlags _diagnosticFlags;
 
+    private View _frameView;
+
     public override void Init ()
     {
         Application.Init ();
@@ -18,17 +20,13 @@ public class AdornmentExperiments : Scenario
 
         _diagnosticFlags = View.Diagnostics;
         //View.Diagnostics = ViewDiagnosticFlags.MouseEnter;
-    }
 
-    private View _frameView;
-    public override void Setup ()
-    {
         _frameView = new View ()
         {
             Title = "Frame View",
             X = 0,
             Y = 0,
-            Width = Dim.Percent(90),
+            Width = Dim.Percent (90),
             Height = Dim.Percent (90),
             CanFocus = true,
         };

+ 0 - 3
UICatalog/Scenarios/AllViewsTester.cs

@@ -48,10 +48,7 @@ public class AllViewsTester : Scenario
         ConfigurationManager.Apply ();
         Top = new ();
         Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-    }
 
-    public override void Setup ()
-    {
         var statusBar = new StatusBar (
                                        new StatusItem []
                                        {

+ 18 - 5
UICatalog/Scenarios/Animation.cs

@@ -17,22 +17,31 @@ public class Animation : Scenario
 {
     private bool _isDisposed;
 
-    public override void Setup ()
+    public override void Main ()
     {
-        base.Setup ();
+        Application.Init();
+
+        var win = new Window
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            X = 0,
+            Y = 0,
+            Width = Dim.Fill (),
+            Height = Dim.Fill (),
+        };
 
         var imageView = new ImageView { Width = Dim.Fill (), Height = Dim.Fill () - 2 };
 
-        Win.Add (imageView);
+        win.Add (imageView);
 
         var lbl = new Label { Y = Pos.AnchorEnd (2), Text = "Image by Wikiscient" };
-        Win.Add (lbl);
+        win.Add (lbl);
 
         var lbl2 = new Label
         {
             Y = Pos.AnchorEnd (1), Text = "https://commons.wikimedia.org/wiki/File:Spinning_globe.gif"
         };
-        Win.Add (lbl2);
+        win.Add (lbl2);
 
         DirectoryInfo dir;
 
@@ -78,6 +87,10 @@ public class Animation : Scenario
                       }
                   }
                  );
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     protected override void Dispose (bool disposing)

+ 18 - 21
UICatalog/Scenarios/ConfigurationEditor.cs

@@ -36,32 +36,17 @@ public class ConfigurationEditor : Scenario
         }
     }
 
-    // Don't create a Window, just return the top-level view
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        ConfigurationManager.Themes.Theme = Theme;
-        ConfigurationManager.Apply ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-    }
-
-    public void Save ()
-    {
-        if (_tileView.MostFocused is ConfigTextView editor)
-        {
-            editor.Save ();
-        }
-    }
 
-    public override void Setup ()
-    {
+        Toplevel top = new ();
         _tileView = new TileView (0)
         {
             Width = Dim.Fill (), Height = Dim.Fill (1), Orientation = Orientation.Vertical, LineStyle = LineStyle.Single
         };
 
-        Top.Add (_tileView);
+        top.Add (_tileView);
 
         _lenStatusItem = new StatusItem (KeyCode.CharMask, "Len: ", null);
 
@@ -79,9 +64,9 @@ public class ConfigurationEditor : Scenario
                                        }
                                       );
 
-        Top.Add (statusBar);
+        top.Add (statusBar);
 
-        Top.Loaded += (s, a) => Open ();
+        top.Loaded += (s, a) => Open ();
 
         _editorColorSchemeChanged += () =>
                                      {
@@ -95,6 +80,18 @@ public class ConfigurationEditor : Scenario
                                      };
 
         _editorColorSchemeChanged.Invoke ();
+
+        Application.Run (top);
+        top.Dispose ();
+
+        Application.Shutdown ();
+    }
+    public void Save ()
+    {
+        if (_tileView.MostFocused is ConfigTextView editor)
+        {
+            editor.Save ();
+        }
     }
 
     private void Open ()
@@ -126,7 +123,7 @@ public class ConfigurationEditor : Scenario
             textView.Enter += (s, e) => { _lenStatusItem.Title = $"Len:{textView.Text.Length}"; };
         }
 
-        Top.LayoutSubviews ();
+        Application.Top.LayoutSubviews ();
     }
 
     private void Quit ()