diff --git a/Terminal.Gui/Configuration/SettingsScope.cs b/Terminal.Gui/Configuration/SettingsScope.cs index 87e1b02dc..d77a82b5e 100644 --- a/Terminal.Gui/Configuration/SettingsScope.cs +++ b/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 Update (JsonSerializer.Deserialize (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 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; } diff --git a/UICatalog/Scenarios/AdornmentExperiments.cs b/UICatalog/Scenarios/AdornmentExperiments.cs index b9ed8ea4e..a41c95961 100644 --- a/UICatalog/Scenarios/AdornmentExperiments.cs +++ b/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, }; diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 56dbc8922..22d6d11dc 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/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 [] { diff --git a/UICatalog/Scenarios/Animation.cs b/UICatalog/Scenarios/Animation.cs index b5c875519..e1a739112 100644 --- a/UICatalog/Scenarios/Animation.cs +++ b/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) diff --git a/UICatalog/Scenarios/ConfigurationEditor.cs b/UICatalog/Scenarios/ConfigurationEditor.cs index fb8e95d74..b24e35592 100644 --- a/UICatalog/Scenarios/ConfigurationEditor.cs +++ b/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 ()