Переглянути джерело

Merge pull request #3613 from BDisp/v2_3350_scenario-refactoring

Fixes #3350. Scenario is complex, confusing, and causes errors.
Tig 1 рік тому
батько
коміт
3e598e7ee0
65 змінених файлів з 494 додано та 429 видалено
  1. 4 80
      UICatalog/Scenario.cs
  2. 1 1
      UICatalog/Scenarios/ASCIICustomButton.cs
  3. 1 1
      UICatalog/Scenarios/Adornments.cs
  4. 1 1
      UICatalog/Scenarios/AllViewsTester.cs
  5. 1 1
      UICatalog/Scenarios/AnimationScenario.cs
  6. 1 1
      UICatalog/Scenarios/Bars.cs
  7. 1 1
      UICatalog/Scenarios/BasicColors.cs
  8. 1 1
      UICatalog/Scenarios/Buttons.cs
  9. 1 1
      UICatalog/Scenarios/ChineseUI.cs
  10. 19 9
      UICatalog/Scenarios/ClassExplorer.cs
  11. 8 12
      UICatalog/Scenarios/Clipping.cs
  12. 13 12
      UICatalog/Scenarios/CollectionNavigatorTester.cs
  13. 1 1
      UICatalog/Scenarios/ColorPicker.cs
  14. 24 24
      UICatalog/Scenarios/CombiningMarks.cs
  15. 13 7
      UICatalog/Scenarios/ComboBoxIteration.cs
  16. 1 1
      UICatalog/Scenarios/ComputedLayout.cs
  17. 1 1
      UICatalog/Scenarios/ContentScrolling.cs
  18. 1 1
      UICatalog/Scenarios/ContextMenus.cs
  19. 1 1
      UICatalog/Scenarios/DatePickers.cs
  20. 1 1
      UICatalog/Scenarios/Dialogs.cs
  21. 1 1
      UICatalog/Scenarios/DimAutoDemo.cs
  22. 1 1
      UICatalog/Scenarios/DynamicMenuBar.cs
  23. 1 1
      UICatalog/Scenarios/DynamicStatusBar.cs
  24. 1 1
      UICatalog/Scenarios/Editor.cs
  25. 36 30
      UICatalog/Scenarios/FileDialogExamples.cs
  26. 1 1
      UICatalog/Scenarios/Generic.cs
  27. 1 1
      UICatalog/Scenarios/HotKeys.cs
  28. 58 52
      UICatalog/Scenarios/Images.cs
  29. 13 4
      UICatalog/Scenarios/InvertColors.cs
  30. 1 1
      UICatalog/Scenarios/KeyBindings.cs
  31. 19 13
      UICatalog/Scenarios/Keys.cs
  32. 1 1
      UICatalog/Scenarios/LineCanvasExperiment.cs
  33. 10 4
      UICatalog/Scenarios/LineDrawing.cs
  34. 7 5
      UICatalog/Scenarios/LineViewExample.cs
  35. 10 9
      UICatalog/Scenarios/ListColumns.cs
  36. 1 1
      UICatalog/Scenarios/ListViewWithSelection.cs
  37. 10 4
      UICatalog/Scenarios/ListsAndCombos.cs
  38. 20 13
      UICatalog/Scenarios/Localization.cs
  39. 1 1
      UICatalog/Scenarios/MenuBarScenario.cs
  40. 1 1
      UICatalog/Scenarios/MessageBoxes.cs
  41. 1 1
      UICatalog/Scenarios/Mouse.cs
  42. 1 1
      UICatalog/Scenarios/MultiColouredTable.cs
  43. 13 5
      UICatalog/Scenarios/ProcessTable.cs
  44. 12 5
      UICatalog/Scenarios/Progress.cs
  45. 1 1
      UICatalog/Scenarios/ProgressBarStyles.cs
  46. 1 1
      UICatalog/Scenarios/Scrolling.cs
  47. 18 12
      UICatalog/Scenarios/SendKeys.cs
  48. 1 1
      UICatalog/Scenarios/ShadowStyles.cs
  49. 1 1
      UICatalog/Scenarios/Shortcuts.cs
  50. 1 1
      UICatalog/Scenarios/Sliders.cs
  51. 8 3
      UICatalog/Scenarios/Snake.cs
  52. 1 1
      UICatalog/Scenarios/SpinnerStyles.cs
  53. 33 27
      UICatalog/Scenarios/Text.cs
  54. 1 1
      UICatalog/Scenarios/TextAlignmentAndDirection.cs
  55. 1 1
      UICatalog/Scenarios/TextFormatterDemo.cs
  56. 13 7
      UICatalog/Scenarios/Threading.cs
  57. 22 12
      UICatalog/Scenarios/TileViewNesting.cs
  58. 19 13
      UICatalog/Scenarios/TimeAndDate.cs
  59. 17 7
      UICatalog/Scenarios/TreeViewFileSystem.cs
  60. 1 1
      UICatalog/Scenarios/TrueColors.cs
  61. 1 1
      UICatalog/Scenarios/Unicode.cs
  62. 1 1
      UICatalog/Scenarios/ViewExperiments.cs
  63. 21 13
      UICatalog/Scenarios/VkeyPacketSimulator.cs
  64. 1 1
      UICatalog/Scenarios/WindowsAndFrameViews.cs
  65. 15 8
      UICatalog/Scenarios/Wizards.cs

+ 4 - 80
UICatalog/Scenario.cs

@@ -93,6 +93,10 @@ public class Scenario : IDisposable
     /// <returns></returns>
     public string GetName () { return ScenarioMetadata.GetName (GetType ()); }
 
+    /// <summary>Helper to get the <see cref="Application.QuitKey"/> and the <see cref="Scenario"/> Name (defined in <see cref="ScenarioMetadata"/>)</summary>
+    /// <returns></returns>
+    public string GetQuitKeyAndName () { return $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"; }
+
     /// <summary>
     ///     Returns a list of all <see cref="Scenario"/> instanaces defined in the project, sorted by
     ///     <see cref="ScenarioMetadata.Name"/>.
@@ -132,90 +136,12 @@ public class Scenario : IDisposable
     /// </remarks>
     public virtual void Main ()
     {
-        Init ();
-        Setup ();
-        Run ();
-    }
-
-    /// <summary>
-    ///     Helper that calls <see cref="Application.Init"/> and creates the default <see cref="Terminal.Gui.Window"/>
-    ///     implementation with a frame and label
-    ///     showing the name of the <see cref="Scenario"/> and logic to exit back to the Scenario picker UI. Override
-    ///     <see cref="Init"/> to provide any <see cref="Terminal.Gui.Toplevel"/> behavior needed.
-    /// </summary>
-    /// <remarks>
-    ///     <para>
-    ///         The base implementation calls <see cref="Application.Init"/> and creates a <see cref="Window"/> for
-    ///         <see cref="Win"/> and adds it to <see cref="Application.Top"/>.
-    ///     </para>
-    ///     <para>
-    ///         Overrides that do not call the base.<see cref="Run"/>, must call <see cref="Application.Init"/> before
-    ///         creating any views or calling other Terminal.Gui APIs.
-    ///     </para>
-    /// </remarks>
-    [ObsoleteAttribute ("This method is obsolete and will be removed in v2. Use Main instead.", false)]
-    public virtual void Init ()
-    {
-        Application.Init ();
-
-        ConfigurationManager.Themes.Theme = Theme;
-        ConfigurationManager.Apply ();
-
-        Top = new ();
-
-        Win = new ()
-        {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
-            X = 0,
-            Y = 0,
-            Width = Dim.Fill (),
-            Height = Dim.Fill (),
-            ColorScheme = Colors.ColorSchemes [TopLevelColorScheme]
-        };
-        Top.Add (Win);
     }
 
-    /// <summary>
-    ///     Runs the <see cref="Scenario"/>. Override to start the <see cref="Scenario"/> using a <see cref="Toplevel"/>
-    ///     different than `Top`.
-    /// </summary>
-    /// <remarks>
-    ///     Overrides that do not call the base.<see cref="Run"/>, must call <see cref="Application.Shutdown"/> before
-    ///     returning.
-    /// </remarks>
-    [ObsoleteAttribute ("This method is obsolete and will be removed in v2. Use Main instead.", false)]
-    public virtual void Run ()
-    {
-        // Must explicitly call Application.Shutdown method to shutdown.
-        Application.Run (Top);
-        Top.Dispose ();
-        Application.Shutdown ();
-    }
-
-    /// <summary>Override this to implement the <see cref="Scenario"/> setup logic (create controls, etc...).</summary>
-    /// <remarks>This is typically the best place to put scenario logic code.</remarks>
-    [ObsoleteAttribute ("This method is obsolete and will be removed in v2. Use Main instead.", false)]
-    public virtual void Setup () { }
-
-    /// <summary>
-    ///     The Toplevel for the <see cref="Scenario"/>. This should be set to <see cref="Terminal.Gui.Application.Top"/>.
-    /// </summary>
-
-    //[ObsoleteAttribute ("This property is obsolete and will be removed in v2. Use Main instead.", false)]
-    public Toplevel Top { get; set; }
-
     /// <summary>Gets the Scenario Name + Description with the Description padded based on the longest known Scenario name.</summary>
     /// <returns></returns>
     public override string ToString () { return $"{GetName ().PadRight (_maxScenarioNameLen)}{GetDescription ()}"; }
 
-    /// <summary>
-    ///     The Window for the <see cref="Scenario"/>. This should be set to <see cref="Terminal.Gui.Application.Top"/> in
-    ///     most cases.
-    /// </summary>
-
-    //[ObsoleteAttribute ("This property is obsolete and will be removed in v2. Use Main instead.", false)]
-    public Window Win { get; set; }
-
     #region IDispose
 
     public void Dispose ()
@@ -231,8 +157,6 @@ public class Scenario : IDisposable
         {
             if (disposing)
             {
-                Top?.Dispose ();
-                Win?.Dispose ();
             }
 
             _disposedValue = true;

+ 1 - 1
UICatalog/Scenarios/ASCIICustomButton.cs

@@ -149,7 +149,7 @@ public class ASCIICustomButtonTest : Scenario
 
         public ScrollViewTestWindow ()
         {
-            Title = "ScrollViewTestWindow";
+            Title = $"{Application.QuitKey} to Quit - Scenario: ScrollViewTestWindow";
 
             Label titleLabel = null;
 

+ 1 - 1
UICatalog/Scenarios/Adornments.cs

@@ -13,7 +13,7 @@ public class Adornments : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var editor = new AdornmentsEditor

+ 1 - 1
UICatalog/Scenarios/AllViewsTester.cs

@@ -53,7 +53,7 @@ public class AllViewsTester : Scenario
 
         var app = new Window
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
             ColorScheme = Colors.ColorSchemes ["TopLevel"]
         };
 

+ 1 - 1
UICatalog/Scenarios/AnimationScenario.cs

@@ -23,7 +23,7 @@ public class AnimationScenario : Scenario
 
         var win = new Window
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
             X = 0,
             Y = 0,
             Width = Dim.Fill (),

+ 1 - 1
UICatalog/Scenarios/Bars.cs

@@ -28,7 +28,7 @@ public class Bars : Scenario
     // QuitKey and it only sticks if changed after init
     private void App_Loaded (object sender, EventArgs e)
     {
-        Application.Top.Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}";
+        Application.Top.Title = GetQuitKeyAndName ();
 
         ObservableCollection<string> eventSource = new ();
         ListView eventLog = new ListView ()

+ 1 - 1
UICatalog/Scenarios/BasicColors.cs

@@ -14,7 +14,7 @@ public class BasicColors : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
         };
 
         var vx = 30;

+ 1 - 1
UICatalog/Scenarios/Buttons.cs

@@ -18,7 +18,7 @@ public class Buttons : Scenario
 
         Window main = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         // Add a label & text field so we can demo IsDefault

+ 1 - 1
UICatalog/Scenarios/ChineseUI.cs

@@ -12,7 +12,7 @@ public class ChineseUI : Scenario
 
         var win = new Window
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
             X = 0,
             Y = 0,
             Width = Dim.Fill (),

+ 19 - 9
UICatalog/Scenarios/ClassExplorer.cs

@@ -17,11 +17,15 @@ public class ClassExplorer : Scenario
     private TextView _textView;
     private TreeView<object> _treeView;
 
-    public override void Setup ()
+    public override void Main ()
     {
-        Win.Title = GetName ();
-        Win.Y = 1; // menu
-        Win.Height = Dim.Fill (1); // status bar
+        Application.Init ();
+        var top = new Toplevel ();
+
+        var win = new Window
+        {
+            Title = GetName ()
+        };
 
         var menu = new MenuBar
         {
@@ -55,15 +59,15 @@ public class ClassExplorer : Scenario
                                 )
             ]
         };
-        Top.Add (menu);
+        top.Add (menu);
 
         _treeView = new TreeView<object> { X = 0, Y = 1, Width = Dim.Percent (50), Height = Dim.Fill () };
 
         var lblSearch = new Label { Text = "Search" };
         var tfSearch = new TextField { Width = 20, X = Pos.Right (lblSearch) };
 
-        Win.Add (lblSearch);
-        Win.Add (tfSearch);
+        win.Add (lblSearch);
+        win.Add (tfSearch);
 
         TreeViewTextFilter<object> filter = new (_treeView);
         _treeView.Filter = filter;
@@ -83,11 +87,17 @@ public class ClassExplorer : Scenario
         _treeView.TreeBuilder = new DelegateTreeBuilder<object> (ChildGetter, CanExpand);
         _treeView.SelectionChanged += TreeView_SelectionChanged;
 
-        Win.Add (_treeView);
+        win.Add (_treeView);
 
         _textView = new TextView { X = Pos.Right (_treeView), Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
 
-        Win.Add (_textView);
+        win.Add (_textView);
+
+        top.Add (win);
+
+        Application.Run (top);
+        top.Dispose ();
+        Application.Shutdown ();
     }
 
     private bool CanExpand (object arg) { return arg is Assembly || arg is Type || arg is ShowForType; }

+ 8 - 12
UICatalog/Scenarios/Clipping.cs

@@ -8,24 +8,16 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Scrolling")]
 public class Clipping : Scenario
 {
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes ["Base"];
-    }
+        var win = new Window { Title = GetQuitKeyAndName () };
 
-    public override void Setup ()
-    {
-        //Win.X = 1;
-        //Win.Y = 2;
-        //Win.Width = Dim.Fill () - 4;
-        //Win.Height = Dim.Fill () - 2;
         var label = new Label
         {
             X = 0, Y = 0, Text = "ScrollView (new Rectangle (3, 3, 50, 20)) with a 200, 100 GetContentSize ()..."
         };
-        Top.Add (label);
+        win.Add (label);
 
         var scrollView = new ScrollView { X = 3, Y = 3, Width = 50, Height = 20 };
         scrollView.ColorScheme = Colors.ColorSchemes ["Menu"];
@@ -84,6 +76,10 @@ public class Clipping : Scenario
 
         scrollView.Add (embedded1);
 
-        Top.Add (scrollView);
+        win.Add (scrollView);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 13 - 12
UICatalog/Scenarios/CollectionNavigatorTester.cs

@@ -74,19 +74,16 @@ public class CollectionNavigatorTester : Scenario
         "quitter"
     }.ToList ());
 
+    private Toplevel top;
     private ListView _listView;
     private TreeView _treeView;
 
     // Don't create a Window, just return the top-level view
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes ["Base"];
-    }
+        top = new Toplevel { ColorScheme = Colors.ColorSchemes ["Base"] };
 
-    public override void Setup ()
-    {
         var allowMarking = new MenuItem ("Allow _Marking", "", null)
         {
             CheckType = MenuItemCheckStyle.Checked, Checked = false
@@ -128,14 +125,18 @@ public class CollectionNavigatorTester : Scenario
             ]
         };
 
-        Top.Add (menu);
+        top.Add (menu);
 
         _items = new (_items.OrderBy (i => i, StringComparer.OrdinalIgnoreCase));
 
         CreateListView ();
         var vsep = new LineView (Orientation.Vertical) { X = Pos.Right (_listView), Y = 1, Height = Dim.Fill () };
-        Top.Add (vsep);
+        top.Add (vsep);
         CreateTreeView ();
+
+        Application.Run (top);
+        top.Dispose ();
+        Application.Shutdown ();
     }
 
     private void CreateListView ()
@@ -149,7 +150,7 @@ public class CollectionNavigatorTester : Scenario
             Width = Dim.Percent (50),
             Height = 1
         };
-        Top.Add (label);
+        top.Add (label);
 
         _listView = new ListView
         {
@@ -160,7 +161,7 @@ public class CollectionNavigatorTester : Scenario
             AllowsMarking = false,
             AllowsMultipleSelection = false
         };
-        Top.Add (_listView);
+        top.Add (_listView);
 
         _listView.SetSource (_items);
 
@@ -178,14 +179,14 @@ public class CollectionNavigatorTester : Scenario
             Width = Dim.Percent (50),
             Height = 1
         };
-        Top.Add (label);
+        top.Add (label);
 
         _treeView = new TreeView
         {
             X = Pos.Right (_listView) + 1, Y = Pos.Bottom (label), Width = Dim.Fill (), Height = Dim.Fill ()
         };
         _treeView.Style.HighlightModelTextOnly = true;
-        Top.Add (_treeView);
+        top.Add (_treeView);
 
         var root = new TreeNode ("IsLetterOrDigit examples");
 

+ 1 - 1
UICatalog/Scenarios/ColorPicker.cs

@@ -30,7 +30,7 @@ public class ColorPickers : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
         };
 
         // Foreground ColorPicker.

+ 24 - 24
UICatalog/Scenarios/CombiningMarks.cs

@@ -6,33 +6,33 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Text and Formatting")]
 public class CombiningMarks : Scenario
 {
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        ConfigurationManager.Themes.Theme = Theme;
+        ConfigurationManager.Themes!.Theme = Theme;
         ConfigurationManager.Apply ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-    }
+        var top = new Toplevel { ColorScheme = Colors.ColorSchemes [TopLevelColorScheme] };
 
-    public override void Setup ()
-    {
-        Top.DrawContentComplete += (s, e) =>
-                                               {
-                                                   Application.Driver.Move (0, 0);
-                                                   Application.Driver.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");
-                                                   Application.Driver.Move (0, 2);
-                                                   Application.Driver.AddStr ("\u0301\u0301\u0328<- \"\\u301\\u301\\u328]\" using AddStr.");
-                                                   Application.Driver.Move (0, 3);
-                                                   Application.Driver.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u301\\u301\\u328]\" using AddStr.");
-                                                   Application.Driver.Move (0, 4);
-                                                   Application.Driver.AddRune ('[');
-                                                   Application.Driver.AddRune ('a');
-                                                   Application.Driver.AddRune ('\u0301');
-                                                   Application.Driver.AddRune ('\u0301');
-                                                   Application.Driver.AddRune ('\u0328');
-                                                   Application.Driver.AddRune (']');
-                                                   Application.Driver.AddStr ("<- \"[a\\u301\\u301\\u328]\" using AddRune for each.");
-                                               };
+        top.DrawContentComplete += (s, e) =>
+                                   {
+                                       Application.Driver.Move (0, 0);
+                                       Application.Driver.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");
+                                       Application.Driver.Move (0, 2);
+                                       Application.Driver.AddStr ("\u0301\u0301\u0328<- \"\\u301\\u301\\u328]\" using AddStr.");
+                                       Application.Driver.Move (0, 3);
+                                       Application.Driver.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u301\\u301\\u328]\" using AddStr.");
+                                       Application.Driver.Move (0, 4);
+                                       Application.Driver.AddRune ('[');
+                                       Application.Driver.AddRune ('a');
+                                       Application.Driver.AddRune ('\u0301');
+                                       Application.Driver.AddRune ('\u0301');
+                                       Application.Driver.AddRune ('\u0328');
+                                       Application.Driver.AddRune (']');
+                                       Application.Driver.AddStr ("<- \"[a\\u301\\u301\\u328]\" using AddRune for each.");
+                                   };
+
+        Application.Run (top);
+        top.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 13 - 7
UICatalog/Scenarios/ComboBoxIteration.cs

@@ -9,18 +9,20 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("ComboBox")]
 public class ComboBoxIteration : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
         ObservableCollection<string> items = ["one", "two", "three"];
 
+        var win = new Window { Title = GetQuitKeyAndName () };
         var lbListView = new Label { Width = 10, Height = 1 };
-        Win.Add (lbListView);
+        win.Add (lbListView);
 
         var listview = new ListView
         {
             Y = Pos.Bottom (lbListView) + 1, Width = 10, Height = Dim.Fill (2), Source = new ListWrapper<string> (items)
         };
-        Win.Add (listview);
+        win.Add (listview);
 
         var lbComboBox = new Label
         {
@@ -53,8 +55,8 @@ public class ComboBoxIteration : Scenario
                                                 listview.SelectedItem = text.Item;
                                             }
                                         };
-        Win.Add (lbComboBox, comboBox);
-        Win.Add (new TextField { X = Pos.Right (listview) + 1, Y = Pos.Top (comboBox) + 3, Height = 1, Width = 20 });
+        win.Add (lbComboBox, comboBox);
+        win.Add (new TextField { X = Pos.Right (listview) + 1, Y = Pos.Top (comboBox) + 3, Height = 1, Width = 20 });
 
         var btnTwo = new Button { X = Pos.Right (comboBox) + 1, Text = "Two" };
 
@@ -65,7 +67,7 @@ public class ComboBoxIteration : Scenario
                               listview.SetSource (items);
                               listview.SelectedItem = 0;
                           };
-        Win.Add (btnTwo);
+        win.Add (btnTwo);
 
         var btnThree = new Button { X = Pos.Right (comboBox) + 1, Y = Pos.Top (comboBox), Text = "Three" };
 
@@ -76,6 +78,10 @@ public class ComboBoxIteration : Scenario
                                 listview.SetSource (items);
                                 listview.SelectedItem = 0;
                             };
-        Win.Add (btnThree);
+        win.Add (btnThree);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 1 - 1
UICatalog/Scenarios/ComputedLayout.cs

@@ -20,7 +20,7 @@ public class ComputedLayout : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
         };
 
         // Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width

+ 1 - 1
UICatalog/Scenarios/ContentScrolling.cs

@@ -104,7 +104,7 @@ public class ContentScrolling : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
 
             // Use a different colorscheme so ViewSettings.ClearContentOnly is obvious
             ColorScheme = Colors.ColorSchemes ["Toplevel"]

+ 1 - 1
UICatalog/Scenarios/ContextMenus.cs

@@ -25,7 +25,7 @@ public class ContextMenus : Scenario
         // Setup - Create a top-level application window and configure it.
         Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var text = "Context Menu";

+ 1 - 1
UICatalog/Scenarios/DatePickers.cs

@@ -13,7 +13,7 @@ public class DatePickers : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var datePicker = new DatePicker { Y = Pos.Center (), X = Pos.Center () };

+ 1 - 1
UICatalog/Scenarios/Dialogs.cs

@@ -17,7 +17,7 @@ public class Dialogs : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var frame = new FrameView

+ 1 - 1
UICatalog/Scenarios/DimAutoDemo.cs

@@ -15,7 +15,7 @@ public class DimAutoDemo : Scenario
         // Setup - Create a top-level application window and configure it.
         Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
         };
 
         // For diagnostics

+ 1 - 1
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -21,7 +21,7 @@ public class DynamicMenuBar : Scenario
         // Setup - Create a top-level application window and configure it.
         DynamicMenuBarSample appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         // Run - Start the application.

+ 1 - 1
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -317,7 +317,7 @@ public class DynamicStatusBar : Scenario
         {
             DataContext = new DynamicStatusItemModel ();
 
-            Title = $"{Application.QuitKey} to Quit";
+            Title = $"{Application.QuitKey} to Quit - Scenario: Dynamic StatusBar";
 
             var _frmStatusBar = new FrameView
             {

+ 1 - 1
UICatalog/Scenarios/Editor.cs

@@ -46,7 +46,7 @@ public class Editor : Scenario
         // Setup - Create a top-level application window and configure it.
         _appWindow = new ()
         {
-            //Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            //Title = GetQuitKeyAndName (),
             Title = _fileName ?? "Untitled",
             BorderStyle = LineStyle.None
         };

+ 36 - 30
UICatalog/Scenarios/FileDialogExamples.cs

@@ -26,104 +26,110 @@ public class FileDialogExamples : Scenario
     private TextField _tbCancelButton;
     private TextField _tbOkButton;
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
         var y = 0;
         var x = 1;
+        var win = new Window { Title = GetQuitKeyAndName () };
 
         _cbMustExist = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Must Exist" };
-        Win.Add (_cbMustExist);
+        win.Add (_cbMustExist);
 
         _cbUseColors = new CheckBox { State = FileDialogStyle.DefaultUseColors ? CheckState.Checked : CheckState.UnChecked, Y = y++, X = x, Text = "Use Colors" };
-        Win.Add (_cbUseColors);
+        win.Add (_cbUseColors);
 
         _cbCaseSensitive = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Case Sensitive Search" };
-        Win.Add (_cbCaseSensitive);
+        win.Add (_cbCaseSensitive);
 
         _cbAllowMultipleSelection = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Multiple" };
-        Win.Add (_cbAllowMultipleSelection);
+        win.Add (_cbAllowMultipleSelection);
 
         _cbShowTreeBranchLines = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Tree Branch Lines" };
-        Win.Add (_cbShowTreeBranchLines);
+        win.Add (_cbShowTreeBranchLines);
 
         _cbAlwaysTableShowHeaders = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Always Show Headers" };
-        Win.Add (_cbAlwaysTableShowHeaders);
+        win.Add (_cbAlwaysTableShowHeaders);
 
         _cbDrivesOnlyInTree = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Only Show Drives" };
-        Win.Add (_cbDrivesOnlyInTree);
+        win.Add (_cbDrivesOnlyInTree);
 
         y = 0;
         x = 24;
 
-        Win.Add (
+        win.Add (
                  new LineView (Orientation.Vertical) { X = x++, Y = 1, Height = 4 }
                 );
-        Win.Add (new Label { X = x++, Y = y++, Text = "Caption" });
+        win.Add (new Label { X = x++, Y = y++, Text = "Caption" });
 
         _rgCaption = new RadioGroup { X = x, Y = y };
         _rgCaption.RadioLabels = new [] { "Ok", "Open", "Save" };
-        Win.Add (_rgCaption);
+        win.Add (_rgCaption);
 
         y = 0;
         x = 34;
 
-        Win.Add (
+        win.Add (
                  new LineView (Orientation.Vertical) { X = x++, Y = 1, Height = 4 }
                 );
-        Win.Add (new Label { X = x++, Y = y++, Text = "OpenMode" });
+        win.Add (new Label { X = x++, Y = y++, Text = "OpenMode" });
 
         _rgOpenMode = new RadioGroup { X = x, Y = y };
         _rgOpenMode.RadioLabels = new [] { "File", "Directory", "Mixed" };
-        Win.Add (_rgOpenMode);
+        win.Add (_rgOpenMode);
 
         y = 0;
         x = 48;
 
-        Win.Add (
+        win.Add (
                  new LineView (Orientation.Vertical) { X = x++, Y = 1, Height = 4 }
                 );
-        Win.Add (new Label { X = x++, Y = y++, Text = "Icons" });
+        win.Add (new Label { X = x++, Y = y++, Text = "Icons" });
 
         _rgIcons = new RadioGroup { X = x, Y = y };
         _rgIcons.RadioLabels = new [] { "None", "Unicode", "Nerd*" };
-        Win.Add (_rgIcons);
+        win.Add (_rgIcons);
 
-        Win.Add (new Label { Y = Pos.AnchorEnd (2), Text = "* Requires installing Nerd fonts" });
-        Win.Add (new Label { Y = Pos.AnchorEnd (1), Text = "  (see: https://github.com/devblackops/Terminal-Icons)" });
+        win.Add (new Label { Y = Pos.AnchorEnd (2), Text = "* Requires installing Nerd fonts" });
+        win.Add (new Label { Y = Pos.AnchorEnd (1), Text = "  (see: https://github.com/devblackops/Terminal-Icons)" });
 
         y = 5;
         x = 24;
 
-        Win.Add (
+        win.Add (
                  new LineView (Orientation.Vertical) { X = x++, Y = y + 1, Height = 4 }
                 );
-        Win.Add (new Label { X = x++, Y = y++, Text = "Allowed" });
+        win.Add (new Label { X = x++, Y = y++, Text = "Allowed" });
 
         _rgAllowedTypes = new RadioGroup { X = x, Y = y };
         _rgAllowedTypes.RadioLabels = new [] { "Any", "Csv (Recommended)", "Csv (Strict)" };
-        Win.Add (_rgAllowedTypes);
+        win.Add (_rgAllowedTypes);
 
         y = 5;
         x = 45;
 
-        Win.Add (
+        win.Add (
                  new LineView (Orientation.Vertical) { X = x++, Y = y + 1, Height = 4 }
                 );
-        Win.Add (new Label { X = x++, Y = y++, Text = "Buttons" });
+        win.Add (new Label { X = x++, Y = y++, Text = "Buttons" });
 
-        Win.Add (new Label { X = x, Y = y++, Text = "Ok Text:" });
+        win.Add (new Label { X = x, Y = y++, Text = "Ok Text:" });
         _tbOkButton = new TextField { X = x, Y = y++, Width = 12 };
-        Win.Add (_tbOkButton);
-        Win.Add (new Label { X = x, Y = y++, Text = "Cancel Text:" });
+        win.Add (_tbOkButton);
+        win.Add (new Label { X = x, Y = y++, Text = "Cancel Text:" });
         _tbCancelButton = new TextField { X = x, Y = y++, Width = 12 };
-        Win.Add (_tbCancelButton);
+        win.Add (_tbCancelButton);
         _cbFlipButtonOrder = new CheckBox { X = x, Y = y++, Text = "Flip Order" };
-        Win.Add (_cbFlipButtonOrder);
+        win.Add (_cbFlipButtonOrder);
 
         var btn = new Button { X = 1, Y = 9, Text = "Run Dialog" };
 
         SetupHandler (btn);
-        Win.Add (btn);
+        win.Add (btn);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private void ConfirmOverwrite (object sender, FilesSelectedEventArgs e)

+ 1 - 1
UICatalog/Scenarios/Generic.cs

@@ -14,7 +14,7 @@ public sealed class MyScenario : Scenario
         // Setup - Create a top-level application window and configure it.
         Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
         };
 
         var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };

+ 1 - 1
UICatalog/Scenarios/HotKeys.cs

@@ -13,7 +13,7 @@ public class HotKeys : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var textViewLabel = new Label { Text = "_TextView:", X = 0, Y = 0 };

+ 58 - 52
UICatalog/Scenarios/Images.cs

@@ -15,14 +15,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Drawing")]
 public class Images : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
-        base.Setup ();
+        Application.Init ();
+        var win = new Window { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName()}" };
 
         bool canTrueColor = Application.Driver.SupportsTrueColor;
 
         var lblDriverName = new Label { X = 0, Y = 0, Text = $"Driver is {Application.Driver.GetType ().Name}" };
-        Win.Add (lblDriverName);
+        win.Add (lblDriverName);
 
         var cbSupportsTrueColor = new CheckBox
         {
@@ -32,7 +33,7 @@ public class Images : Scenario
             CanFocus = false,
             Text = "supports true color "
         };
-        Win.Add (cbSupportsTrueColor);
+        win.Add (cbSupportsTrueColor);
 
         var cbUseTrueColor = new CheckBox
         {
@@ -43,63 +44,68 @@ public class Images : Scenario
             Text = "Use true color"
         };
         cbUseTrueColor.Toggle += (_, evt) => Application.Force16Colors = evt.NewValue == CheckState.UnChecked;
-        Win.Add (cbUseTrueColor);
+        win.Add (cbUseTrueColor);
 
         var btnOpenImage = new Button { X = Pos.Right (cbUseTrueColor) + 2, Y = 0, Text = "Open Image" };
-        Win.Add (btnOpenImage);
+        win.Add (btnOpenImage);
 
         var imageView = new ImageView
         {
             X = 0, Y = Pos.Bottom (lblDriverName), Width = Dim.Fill (), Height = Dim.Fill ()
         };
-        Win.Add (imageView);
+        win.Add (imageView);
 
         btnOpenImage.Accept += (_, _) =>
-                                {
-                                    var ofd = new OpenDialog { Title = "Open Image", AllowsMultipleSelection = false };
-                                    Application.Run (ofd);
-
-                                    if (ofd.Path is { })
-                                    {
-                                        Directory.SetCurrentDirectory (Path.GetFullPath (Path.GetDirectoryName (ofd.Path)!));
-                                    }
-
-                                    if (ofd.Canceled)
-                                    {
-                                        ofd.Dispose ();
-                                        return;
-                                    }
-
-                                    string path = ofd.FilePaths [0];
-
-                                    ofd.Dispose ();
-
-                                    if (string.IsNullOrWhiteSpace (path))
-                                    {
-                                        return;
-                                    }
-
-                                    if (!File.Exists (path))
-                                    {
-                                        return;
-                                    }
-
-                                    Image<Rgba32> img;
-
-                                    try
-                                    {
-                                        img = Image.Load<Rgba32> (File.ReadAllBytes (path));
-                                    }
-                                    catch (Exception ex)
-                                    {
-                                        MessageBox.ErrorQuery ("Could not open file", ex.Message, "Ok");
-
-                                        return;
-                                    }
-
-                                    imageView.SetImage (img);
-                                    Application.Refresh ();
-                                };
+                               {
+                                   var ofd = new OpenDialog { Title = "Open Image", AllowsMultipleSelection = false };
+                                   Application.Run (ofd);
+
+                                   if (ofd.Path is { })
+                                   {
+                                       Directory.SetCurrentDirectory (Path.GetFullPath (Path.GetDirectoryName (ofd.Path)!));
+                                   }
+
+                                   if (ofd.Canceled)
+                                   {
+                                       ofd.Dispose ();
+
+                                       return;
+                                   }
+
+                                   string path = ofd.FilePaths [0];
+
+                                   ofd.Dispose ();
+
+                                   if (string.IsNullOrWhiteSpace (path))
+                                   {
+                                       return;
+                                   }
+
+                                   if (!File.Exists (path))
+                                   {
+                                       return;
+                                   }
+
+                                   Image<Rgba32> img;
+
+                                   try
+                                   {
+                                       img = Image.Load<Rgba32> (File.ReadAllBytes (path));
+                                   }
+                                   catch (Exception ex)
+                                   {
+                                       MessageBox.ErrorQuery ("Could not open file", ex.Message, "Ok");
+
+                                       return;
+                                   }
+
+                                   imageView.SetImage (img);
+                                   Application.Refresh ();
+                               };
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private class ImageView : View

+ 13 - 4
UICatalog/Scenarios/InvertColors.cs

@@ -10,9 +10,14 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Text and Formatting")]
 public class InvertColors : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
-        Win.ColorScheme = Colors.ColorSchemes ["TopLevel"];
+        Application.Init ();
+        var win = new Window
+        {
+            Title = GetQuitKeyAndName (),
+            ColorScheme = Colors.ColorSchemes ["TopLevel"]
+        };
 
         List<Label> labels = new ();
         ColorName [] foreColors = Enum.GetValues (typeof (ColorName)).Cast<ColorName> ().ToArray ();
@@ -25,7 +30,7 @@ public class InvertColors : Scenario
 
             var label = new Label { ColorScheme = new ColorScheme (), Y = y, Text = $"{fore} on {back}" };
             label.ColorScheme = new ColorScheme (label.ColorScheme) { Normal = color };
-            Win.Add (label);
+            win.Add (label);
             labels.Add (label);
         }
 
@@ -43,6 +48,10 @@ public class InvertColors : Scenario
                                   label.SetNeedsDisplay ();
                               }
                           };
-        Win.Add (button);
+        win.Add (button);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 1 - 1
UICatalog/Scenarios/KeyBindings.cs

@@ -22,7 +22,7 @@ public sealed class KeyBindings : Scenario
         // Setup - Create a top-level application window and configure it.
         Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
             SuperViewRendersLineCanvas = true,
         };
 

+ 19 - 13
UICatalog/Scenarios/Keys.cs

@@ -7,16 +7,18 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Mouse and Keyboard")]
 public class Keys : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
         ObservableCollection<string> keyPressedList = [];
         ObservableCollection<string> invokingKeyBindingsList = new ();
 
+        var win = new Window { Title = GetQuitKeyAndName () };
         var editLabel = new Label { X = 0, Y = 0, Text = "Type text here:" };
-        Win.Add (editLabel);
+        win.Add (editLabel);
 
         var edit = new TextField { X = Pos.Right (editLabel) + 1, Y = Pos.Top (editLabel), Width = Dim.Fill (2) };
-        Win.Add (edit);
+        win.Add (edit);
 
         edit.KeyDown += (s, a) => { keyPressedList.Add (a.ToString ()); };
 
@@ -33,9 +35,9 @@ public class Keys : Scenario
         {
             X = Pos.Left (editLabel), Y = Pos.Top (editLabel) + 1, Text = "Last TextView.KeyPressed:"
         };
-        Win.Add (keyPressedLabel);
+        win.Add (keyPressedLabel);
         var labelTextViewKeypress = new Label { X = Pos.Right (keyPressedLabel) + 1, Y = Pos.Top (keyPressedLabel) };
-        Win.Add (labelTextViewKeypress);
+        win.Add (labelTextViewKeypress);
 
         edit.KeyDown += (s, e) => labelTextViewKeypress.Text = e.ToString ();
 
@@ -43,9 +45,9 @@ public class Keys : Scenario
         {
             X = Pos.Left (keyPressedLabel), Y = Pos.Bottom (keyPressedLabel), Text = "Last Application.KeyDown:"
         };
-        Win.Add (keyPressedLabel);
+        win.Add (keyPressedLabel);
         var labelAppKeypress = new Label { X = Pos.Right (keyPressedLabel) + 1, Y = Pos.Top (keyPressedLabel) };
-        Win.Add (labelAppKeypress);
+        win.Add (labelAppKeypress);
 
         Application.KeyDown += (s, e) => labelAppKeypress.Text = e.ToString ();
 
@@ -54,7 +56,7 @@ public class Keys : Scenario
         {
             X = Pos.Left (editLabel), Y = Pos.Top (editLabel) + 4, Text = "Application Key Events:"
         };
-        Win.Add (keyLogLabel);
+        win.Add (keyLogLabel);
         int maxKeyString = Key.CursorRight.WithAlt.WithCtrl.WithShift.ToString ().Length;
         var yOffset = 1;
         ObservableCollection<string> keyEventlist = new ();
@@ -68,14 +70,14 @@ public class Keys : Scenario
             Source = new ListWrapper<string> (keyEventlist)
         };
         keyEventListView.ColorScheme = Colors.ColorSchemes ["TopLevel"];
-        Win.Add (keyEventListView);
+        win.Add (keyEventListView);
 
         // OnKeyPressed
         var onKeyPressedLabel = new Label
         {
             X = Pos.Right (keyEventListView) + 1, Y = Pos.Top (editLabel) + 4, Text = "TextView KeyDown:"
         };
-        Win.Add (onKeyPressedLabel);
+        win.Add (onKeyPressedLabel);
 
         yOffset = 1;
 
@@ -88,7 +90,7 @@ public class Keys : Scenario
             Source = new ListWrapper<string> (keyPressedList)
         };
         onKeyPressedListView.ColorScheme = Colors.ColorSchemes ["TopLevel"];
-        Win.Add (onKeyPressedListView);
+        win.Add (onKeyPressedListView);
 
         // OnInvokeKeyBindings
         var onInvokingKeyBindingsLabel = new Label
@@ -97,7 +99,7 @@ public class Keys : Scenario
             Y = Pos.Top (editLabel) + 4,
             Text = "TextView InvokingKeyBindings:"
         };
-        Win.Add (onInvokingKeyBindingsLabel);
+        win.Add (onInvokingKeyBindingsLabel);
 
         var onInvokingKeyBindingsListView = new ListView
         {
@@ -108,7 +110,7 @@ public class Keys : Scenario
             Source = new ListWrapper<string> (invokingKeyBindingsList)
         };
         onInvokingKeyBindingsListView.ColorScheme = Colors.ColorSchemes ["TopLevel"];
-        Win.Add (onInvokingKeyBindingsListView);
+        win.Add (onInvokingKeyBindingsListView);
 
         //Application.KeyDown += (s, a) => KeyDownPressUp (a, "Down");
         Application.KeyDown += (s, a) => KeyDownPressUp (a, "Down");
@@ -123,5 +125,9 @@ public class Keys : Scenario
             onKeyPressedListView.MoveDown ();
             onInvokingKeyBindingsListView.MoveDown ();
         }
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 1 - 1
UICatalog/Scenarios/LineCanvasExperiment.cs

@@ -14,7 +14,7 @@ public class LineCanvasExperiment : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var frame1 = new FrameView

+ 10 - 4
UICatalog/Scenarios/LineDrawing.cs

@@ -10,8 +10,10 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Drawing")]
 public class LineDrawing : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
         var canvas = new DrawingArea { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
 
         var tools = new ToolsView { Title = "Tools", X = Pos.Right (canvas) - 20, Y = 2 };
@@ -20,10 +22,14 @@ public class LineDrawing : Scenario
         tools.SetStyle += b => canvas.LineStyle = b;
         tools.AddLayer += () => canvas.AddLayer ();
 
-        Win.Add (canvas);
-        Win.Add (tools);
+        win.Add (canvas);
+        win.Add (tools);
 
-        Win.KeyDown += (s, e) => { e.Handled = canvas.OnKeyDown (e); };
+        win.KeyDown += (s, e) => { e.Handled = canvas.OnKeyDown (e); };
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private class DrawingArea : View

+ 7 - 5
UICatalog/Scenarios/LineViewExample.cs

@@ -13,7 +13,7 @@ public class LineViewExample : Scenario
     {
         Application.Init ();
         // Setup - Create a top-level application window and configure it.
-        Toplevel appWindow = new ();
+        Toplevel top = new ();
 
         var menu = new MenuBar
         {
@@ -22,8 +22,9 @@ public class LineViewExample : Scenario
                 new ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
             ]
         };
-        appWindow.Add (menu);
+        top.Add (menu);
 
+        var appWindow = new Window ();
         appWindow.Add (new Label { Y = 1, Text = "Regular Line" });
 
         // creates a horizontal line
@@ -78,11 +79,12 @@ public class LineViewExample : Scenario
                                            new (Application.QuitKey, "Quit", Quit)
                                        }
                                       );
-        appWindow.Add (statusBar);
+        top.Add (statusBar);
+        top.Add (appWindow);
 
         // Run - Start the application.
-        Application.Run (appWindow);
-        appWindow.Dispose ();
+        Application.Run (top);
+        top.Dispose ();
 
         // Shutdown - Calling Application.Shutdown is required.
         Application.Shutdown ();

+ 10 - 9
UICatalog/Scenarios/ListColumns.cs

@@ -53,17 +53,16 @@ public class ListColumns : Scenario
         Application.Init ();
 
         // Setup - Create a top-level application window and configure it.
-        Toplevel appWindow = new ()
+        Toplevel top = new ();
+        Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         _listColView = new ()
         {
-            X = 0,
-            Y = 1,
             Width = Dim.Fill (),
-            Height = Dim.Fill (1),
+            Height = Dim.Fill (),
             Style = new ()
             {
                 ShowHeaders = false,
@@ -212,7 +211,7 @@ public class ListColumns : Scenario
             ]
         };
 
-        appWindow.Add (menu);
+        top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new Shortcut []
@@ -223,7 +222,7 @@ public class ListColumns : Scenario
                                            new (Application.QuitKey, "Quit", Quit)
                                        }
                                       );
-        appWindow.Add (statusBar);
+        top.Add (statusBar);
 
         appWindow.Add (_listColView);
 
@@ -257,9 +256,11 @@ public class ListColumns : Scenario
 
         _listColView.KeyBindings.Add (Key.Space, Command.Accept);
 
+        top.Add (appWindow);
+
         // Run - Start the application.
-        Application.Run (appWindow);
-        appWindow.Dispose ();
+        Application.Run (top);
+        top.Dispose ();
 
         // Shutdown - Calling Application.Shutdown is required.
         Application.Shutdown ();

+ 1 - 1
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -27,7 +27,7 @@ public class ListViewWithSelection : Scenario
 
         _appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
         };
 
         _scenarios = GetScenarios ();

+ 10 - 4
UICatalog/Scenarios/ListsAndCombos.cs

@@ -12,8 +12,9 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("ComboBox")]
 public class ListsAndCombos : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
         //TODO: Duplicated code in Demo.cs Consider moving to shared assembly
         ObservableCollection<string> items = [];
 
@@ -31,6 +32,7 @@ public class ListsAndCombos : Scenario
             }
         }
 
+        var win = new Window { Title = GetQuitKeyAndName () };
         // ListView
         var lbListView = new Label
         {
@@ -50,7 +52,7 @@ public class ListsAndCombos : Scenario
             Source = new ListWrapper<string> (items)
         };
         listview.SelectedItemChanged += (s, e) => lbListView.Text = items [listview.SelectedItem];
-        Win.Add (lbListView, listview);
+        win.Add (lbListView, listview);
 
         var scrollBar = new ScrollBarView (listview, true);
 
@@ -107,7 +109,7 @@ public class ListsAndCombos : Scenario
         comboBox.SetSource (items);
 
         comboBox.SelectedItemChanged += (s, text) => lbComboBox.Text = text.Value.ToString ();
-        Win.Add (lbComboBox, comboBox);
+        win.Add (lbComboBox, comboBox);
 
         var scrollBarCbx = new ScrollBarView (comboBox.Subviews [1], true);
 
@@ -153,6 +155,10 @@ public class ListsAndCombos : Scenario
         };
         btnMoveDown.Accept += (s, e) => { listview.MoveDown (); };
 
-        Win.Add (btnMoveUp, btnMoveDown);
+        win.Add (btnMoveUp, btnMoveDown);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 20 - 13
UICatalog/Scenarios/Localization.cs

@@ -41,9 +41,11 @@ public class Localization : Scenario
         Application.Refresh ();
     }
 
-    public override void Setup ()
+    public override void Main ()
     {
-        base.Setup ();
+        Application.Init ();
+        var top = new Toplevel ();
+        var win = new Window { Title = GetQuitKeyAndName () };
         _cultureInfoSource = Application.SupportedCultures.Append (CultureInfo.InvariantCulture).ToArray ();
 
         _cultureInfoNameSource = Application.SupportedCultures.Select (c => $"{c.NativeName} ({c.Name})")
@@ -93,7 +95,7 @@ public class Localization : Scenario
                     )
             ]
         };
-        Top.Add (menu);
+        top.Add (menu);
 
         var selectLanguageLabel = new Label
         {
@@ -103,7 +105,7 @@ public class Localization : Scenario
             Width = Dim.Fill (2),
             Text = "Please select a language."
         };
-        Win.Add (selectLanguageLabel);
+        win.Add (selectLanguageLabel);
 
         _languageComboBox = new()
         {
@@ -117,7 +119,7 @@ public class Localization : Scenario
         };
         _languageComboBox.SetSource<string> (new (_cultureInfoNameSource));
         _languageComboBox.SelectedItemChanged += LanguageComboBox_SelectChanged;
-        Win.Add (_languageComboBox);
+        win.Add (_languageComboBox);
 
         var textAndFileDialogLabel = new Label
         {
@@ -129,13 +131,13 @@ public class Localization : Scenario
             Text =
                 "Right click on the text field to open a context menu, click the button to open a file dialog.\r\nOpen mode will loop through 'File', 'Directory' and 'Mixed' as 'Open' or 'Save' button clicked."
         };
-        Win.Add (textAndFileDialogLabel);
+        win.Add (textAndFileDialogLabel);
 
         var textField = new TextView
         {
             X = 2, Y = Pos.Bottom (textAndFileDialogLabel) + 1, Width = Dim.Fill (32), Height = 1
         };
-        Win.Add (textField);
+        win.Add (textField);
 
         _allowAnyCheckBox = new()
         {
@@ -144,21 +146,21 @@ public class Localization : Scenario
             State = CheckState.UnChecked,
             Text = "Allow any"
         };
-        Win.Add (_allowAnyCheckBox);
+        win.Add (_allowAnyCheckBox);
 
         var openDialogButton = new Button
         {
             X = Pos.Right (_allowAnyCheckBox) + 1, Y = Pos.Bottom (textAndFileDialogLabel) + 1, Text = "Open"
         };
         openDialogButton.Accept += (sender, e) => ShowFileDialog (false);
-        Win.Add (openDialogButton);
+        win.Add (openDialogButton);
 
         var saveDialogButton = new Button
         {
             X = Pos.Right (openDialogButton) + 1, Y = Pos.Bottom (textAndFileDialogLabel) + 1, Text = "Save"
         };
         saveDialogButton.Accept += (sender, e) => ShowFileDialog (true);
-        Win.Add (saveDialogButton);
+        win.Add (saveDialogButton);
 
         var wizardLabel = new Label
         {
@@ -168,13 +170,18 @@ public class Localization : Scenario
             Width = Dim.Fill (2),
             Text = "Click the button to open a wizard."
         };
-        Win.Add (wizardLabel);
+        win.Add (wizardLabel);
 
         var wizardButton = new Button { X = 2, Y = Pos.Bottom (wizardLabel) + 1, Text = "Open _wizard" };
         wizardButton.Accept += (sender, e) => ShowWizard ();
-        Win.Add (wizardButton);
+        win.Add (wizardButton);
 
-        Win.Unloaded += (sender, e) => Quit ();
+        win.Unloaded += (sender, e) => Quit ();
+        top.Add (win);
+
+        Application.Run (top);
+        top.Dispose ();
+        Application.Shutdown ();
     }
 
     public void ShowFileDialog (bool isSaveFile)

+ 1 - 1
UICatalog/Scenarios/MenuBarScenario.cs

@@ -22,7 +22,7 @@ public class MenuBarScenario : Scenario
         // Setup - Create a top-level application window and configure it.
         Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
             BorderStyle = LineStyle.None
         };
 

+ 1 - 1
UICatalog/Scenarios/MessageBoxes.cs

@@ -15,7 +15,7 @@ public class MessageBoxes : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var frame = new FrameView

+ 1 - 1
UICatalog/Scenarios/Mouse.cs

@@ -15,7 +15,7 @@ public class Mouse : Scenario
 
         Window win = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         Slider<MouseFlags> filterSlider = new ()

+ 1 - 1
UICatalog/Scenarios/MultiColouredTable.cs

@@ -22,7 +22,7 @@ public class MultiColouredTable : Scenario
         // Setup - Create a top-level application window and configure it.
         Toplevel appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         _tableView = new () { X = 0, Y = 1, Width = Dim.Fill (), Height = Dim.Fill (1) };

+ 13 - 5
UICatalog/Scenarios/ProcessTable.cs

@@ -11,11 +11,15 @@ public class ProcessTable : Scenario
 {
     private TableView tableView;
 
-    public override void Setup ()
+    public override void Main ()
     {
-        Win.Title = GetName ();
-        Win.Y = 1; // menu
-        Win.Height = Dim.Fill (1); // status bar
+        Application.Init ();
+        var win = new Window
+        {
+            Title = GetName (),
+            Y = 1, // menu
+            Height = Dim.Fill (1) // status bar
+        };
 
         tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) };
 
@@ -33,7 +37,11 @@ public class ProcessTable : Scenario
                                 }
                                );
 
-        Win.Add (tableView);
+        win.Add (tableView);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private void CreateProcessTable ()

+ 12 - 5
UICatalog/Scenarios/Progress.cs

@@ -15,13 +15,16 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Progress")]
 public class Progress : Scenario
 {
+    private Window win;
     private uint _mainLooopTimeoutTick = 100; // ms
     private object _mainLoopTimeout;
     private Timer _systemTimer;
     private uint _systemTimerTick = 100; // ms
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        win = new Window { Title = GetQuitKeyAndName () };
         // Demo #1 - Use System.Timer (and threading)
         var systemTimerDemo = new ProgressDemo
         {
@@ -78,7 +81,7 @@ public class Progress : Scenario
                                                      Debug.WriteLine ("bad entry");
                                                  }
                                              };
-        Win.Add (systemTimerDemo);
+        win.Add (systemTimerDemo);
 
         // Demo #2 - Use Application.AddTimeout (no threads)
         var mainLoopTimeoutDemo = new ProgressDemo
@@ -135,7 +138,7 @@ public class Progress : Scenario
                                                          }
                                                      }
                                                  };
-        Win.Add (mainLoopTimeoutDemo);
+        win.Add (mainLoopTimeoutDemo);
 
         var startBoth = new Button { X = Pos.Center (), Y = Pos.Bottom (mainLoopTimeoutDemo) + 1, Text = "Start Both" };
 
@@ -144,12 +147,16 @@ public class Progress : Scenario
                                  systemTimerDemo.Start ();
                                  mainLoopTimeoutDemo.Start ();
                              };
-        Win.Add (startBoth);
+        win.Add (startBoth);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     protected override void Dispose (bool disposing)
     {
-        foreach (ProgressDemo v in Win.Subviews.OfType<ProgressDemo> ())
+        foreach (ProgressDemo v in win.Subviews.OfType<ProgressDemo> ())
         {
             v?.StopBtnClick ();
         }

+ 1 - 1
UICatalog/Scenarios/ProgressBarStyles.cs

@@ -30,7 +30,7 @@ public class ProgressBarStyles : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}", BorderStyle = LineStyle.Single,
+            Title = GetQuitKeyAndName (), BorderStyle = LineStyle.Single,
         };
 
         var editor = new AdornmentsEditor ()

+ 1 - 1
UICatalog/Scenarios/Scrolling.cs

@@ -19,7 +19,7 @@ public class Scrolling : Scenario
 
         var app = new Window
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+            Title = GetQuitKeyAndName (),
 
             // Offset to stress clipping
             X = 3,

+ 18 - 12
UICatalog/Scenarios/SendKeys.cs

@@ -7,28 +7,30 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Mouse and Keyboard")]
 public class SendKeys : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
         var label = new Label { X = Pos.Center (), Y = Pos.Center () - 6, Text = "Insert the text to send:" };
-        Win.Add (label);
+        win.Add (label);
 
         var txtInput = new TextField { X = Pos.Center (), Y = Pos.Center () - 5, Width = 20, Text = "MockKeyPresses" };
-        Win.Add (txtInput);
+        win.Add (txtInput);
 
         var ckbShift = new CheckBox { X = Pos.Center (), Y = Pos.Center () - 4, Text = "Shift" };
-        Win.Add (ckbShift);
+        win.Add (ckbShift);
 
         var ckbAlt = new CheckBox { X = Pos.Center (), Y = Pos.Center () - 3, Text = "Alt" };
-        Win.Add (ckbAlt);
+        win.Add (ckbAlt);
 
         var ckbControl = new CheckBox { X = Pos.Center (), Y = Pos.Center () - 2, Text = "Control" };
-        Win.Add (ckbControl);
+        win.Add (ckbControl);
 
         label = new Label { X = Pos.Center (), Y = Pos.Center () + 1, Text = "Result keys:" };
-        Win.Add (label);
+        win.Add (label);
 
         var txtResult = new TextField { X = Pos.Center (), Y = Pos.Center () + 2, Width = 20 };
-        Win.Add (txtResult);
+        win.Add (txtResult);
 
         var rKeys = "";
         var rControlKeys = "";
@@ -60,13 +62,13 @@ public class SendKeys : Scenario
                              };
 
         var lblShippedKeys = new Label { X = Pos.Center (), Y = Pos.Center () + 3 };
-        Win.Add (lblShippedKeys);
+        win.Add (lblShippedKeys);
 
         var lblShippedControlKeys = new Label { X = Pos.Center (), Y = Pos.Center () + 5 };
-        Win.Add (lblShippedControlKeys);
+        win.Add (lblShippedControlKeys);
 
         var button = new Button { X = Pos.Center (), Y = Pos.Center () + 7, IsDefault = true, Text = "Process keys" };
-        Win.Add (button);
+        win.Add (button);
 
         void ProcessInput ()
         {
@@ -100,7 +102,7 @@ public class SendKeys : Scenario
 
         button.Accept += (s, e) => ProcessInput ();
 
-        Win.KeyDown += (s, e) =>
+        win.KeyDown += (s, e) =>
                        {
                            if (e.KeyCode == KeyCode.Enter)
                            {
@@ -108,5 +110,9 @@ public class SendKeys : Scenario
                                e.Handled = true;
                            }
                        };
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 1 - 1
UICatalog/Scenarios/ShadowStyles.cs

@@ -17,7 +17,7 @@ public class ShadowStyles : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
 

+ 1 - 1
UICatalog/Scenarios/Shortcuts.cs

@@ -31,7 +31,7 @@ public class Shortcuts : Scenario
     private void App_Loaded (object sender, EventArgs e)
     {
         Application.QuitKey = Key.Z.WithCtrl;
-        Application.Top.Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}";
+        Application.Top.Title = GetQuitKeyAndName ();
 
         ObservableCollection<string> eventSource = new ();
 

+ 1 - 1
UICatalog/Scenarios/Sliders.cs

@@ -129,7 +129,7 @@ public class Sliders : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         MakeSliders (

+ 8 - 3
UICatalog/Scenarios/Snake.cs

@@ -15,9 +15,10 @@ public class Snake : Scenario
 {
     private bool isDisposed;
 
-    public override void Setup ()
+    public override void Main ()
     {
-        base.Setup ();
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
 
         var state = new SnakeState ();
 
@@ -25,7 +26,7 @@ public class Snake : Scenario
 
         var snakeView = new SnakeView (state) { Width = state.Width, Height = state.Height };
 
-        Win.Add (snakeView);
+        win.Add (snakeView);
 
         var sw = new Stopwatch ();
 
@@ -51,6 +52,10 @@ public class Snake : Scenario
                       }
                   }
                  );
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     protected override void Dispose (bool disposing)

+ 1 - 1
UICatalog/Scenarios/SpinnerStyles.cs

@@ -18,7 +18,7 @@ public class SpinnerViewStyles : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         const int DEFAULT_DELAY = 130;

+ 33 - 27
UICatalog/Scenarios/Text.cs

@@ -17,11 +17,13 @@ public class Text : Scenario
     private Label _labelMirroringTimeField;
     private TimeField _timeField;
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
         // TextField is a simple, single-line text input control
         var label = new Label { Text = "_TextField:" };
-        Win.Add (label);
+        win.Add (label);
 
         var textField = new TextField
         {
@@ -43,7 +45,7 @@ public class Text : Scenario
                                                       .ToList ();
         }
 
-        Win.Add (textField);
+        win.Add (textField);
 
         var labelMirroringTextField = new Label
         {
@@ -54,12 +56,12 @@ public class Text : Scenario
             Height = 1,
             Text = textField.Text
         };
-        Win.Add (labelMirroringTextField);
+        win.Add (labelMirroringTextField);
         textField.TextChanged += (s, prev) => { labelMirroringTextField.Text = textField.Text; };
 
         // TextView is a rich (as in functionality, not formatting) text editing control
         label = new() { Text = "T_extView:", Y = Pos.Bottom (label) + 1 };
-        Win.Add (label);
+        win.Add (label);
 
         var textView = new TextView
         {
@@ -80,7 +82,7 @@ public class Text : Scenario
                                                       .ToList ();
         }
 
-        Win.Add (textView);
+        win.Add (textView);
 
         var labelMirroringTextView = new Label
         {
@@ -90,7 +92,7 @@ public class Text : Scenario
             Width = Dim.Fill (1) - 1,
             Height = Dim.Height (textView) - 1
         };
-        Win.Add (labelMirroringTextView);
+        win.Add (labelMirroringTextView);
 
         // Use ContentChanged to detect if the user has typed something in a TextView.
         // The TextChanged property is only fired if the TextView.Text property is
@@ -107,7 +109,7 @@ public class Text : Scenario
         {
             X = Pos.Left (textView), Y = Pos.Bottom (textView), State = textView.Multiline ? CheckState.Checked : CheckState.UnChecked, Text = "_Multiline"
         };
-        Win.Add (chxMultiline);
+        win.Add (chxMultiline);
 
         var chxWordWrap = new CheckBox
         {
@@ -117,7 +119,7 @@ public class Text : Scenario
             Text = "_Word Wrap"
         };
         chxWordWrap.Toggle += (s, e) => textView.WordWrap = e.NewValue == CheckState.Checked;
-        Win.Add (chxWordWrap);
+        win.Add (chxWordWrap);
 
         // TextView captures Tabs (so users can enter /t into text) by default;
         // This means using Tab to navigate doesn't work by default. This shows
@@ -163,11 +165,11 @@ public class Text : Scenario
 
                                       textView.AllowsTab = e.NewValue == CheckState.Checked;
                                   };
-        Win.Add (chxCaptureTabs);
+        win.Add (chxCaptureTabs);
 
         // Hex editor
         label = new() { Text = "_HexView:", Y = Pos.Bottom (chxMultiline) + 1 };
-        Win.Add (label);
+        win.Add (label);
 
         var hexEditor =
             new HexView (
@@ -176,7 +178,7 @@ public class Text : Scenario
             {
                 X = Pos.Right (label) + 1, Y = Pos.Bottom (chxMultiline) + 1, Width = Dim.Percent (50) - 1, Height = Dim.Percent (30)
             };
-        Win.Add (hexEditor);
+        win.Add (hexEditor);
 
         var labelMirroringHexEditor = new Label
         {
@@ -195,14 +197,14 @@ public class Text : Scenario
                                 byte [] array = ((MemoryStream)hexEditor.Source).ToArray ();
                                 labelMirroringHexEditor.Text = Encoding.UTF8.GetString (array, 0, array.Length);
                             };
-        Win.Add (labelMirroringHexEditor);
+        win.Add (labelMirroringHexEditor);
 
         // DateField
         label = new() { Text = "_DateField:", Y = Pos.Bottom (hexEditor) + 1 };
-        Win.Add (label);
+        win.Add (label);
 
         var dateField = new DateField (DateTime.Now) { X = Pos.Right (label) + 1, Y = Pos.Bottom (hexEditor) + 1, Width = 20 };
-        Win.Add (dateField);
+        win.Add (dateField);
 
         var labelMirroringDateField = new Label
         {
@@ -213,13 +215,13 @@ public class Text : Scenario
             Height = Dim.Height (dateField),
             Text = dateField.Text
         };
-        Win.Add (labelMirroringDateField);
+        win.Add (labelMirroringDateField);
 
         dateField.TextChanged += (s, prev) => { labelMirroringDateField.Text = dateField.Text; };
 
         // TimeField
         label = new() { Text = "T_imeField:", Y = Pos.Top (dateField), X = Pos.Right (labelMirroringDateField) + 5 };
-        Win.Add (label);
+        win.Add (label);
 
         _timeField = new()
         {
@@ -229,7 +231,7 @@ public class Text : Scenario
             IsShortFormat = false,
             Time = DateTime.Now.TimeOfDay
         };
-        Win.Add (_timeField);
+        win.Add (_timeField);
 
         _labelMirroringTimeField = new()
         {
@@ -240,7 +242,7 @@ public class Text : Scenario
             Height = Dim.Height (_timeField),
             Text = _timeField.Text
         };
-        Win.Add (_labelMirroringTimeField);
+        win.Add (_labelMirroringTimeField);
 
         _timeField.TimeChanged += TimeChanged;
 
@@ -251,7 +253,7 @@ public class Text : Scenario
             Y = Pos.Bottom (dateField) + 1,
             Text = "_NetMaskedTextProvider [ 999 000 LLL >LLL |AAA aaa ]:"
         };
-        Win.Add (netProviderLabel);
+        win.Add (netProviderLabel);
 
         var netProvider = new NetMaskedTextProvider ("999 000 LLL >LLL |AAA aaa");
 
@@ -259,7 +261,7 @@ public class Text : Scenario
         {
             X = Pos.Right (netProviderLabel) + 1, Y = Pos.Y (netProviderLabel), Provider = netProvider
         };
-        Win.Add (netProviderField);
+        win.Add (netProviderField);
 
         var labelMirroringNetProviderField = new Label
         {
@@ -270,7 +272,7 @@ public class Text : Scenario
             Height = Dim.Height (netProviderField),
             Text = netProviderField.Text
         };
-        Win.Add (labelMirroringNetProviderField);
+        win.Add (labelMirroringNetProviderField);
 
         netProviderField.Provider.TextChanged += (s, prev) => { labelMirroringNetProviderField.Text = netProviderField.Text; };
 
@@ -281,7 +283,7 @@ public class Text : Scenario
             Y = Pos.Bottom (netProviderLabel) + 1,
             Text = "Text_RegexProvider [ ^([0-9]?[0-9]?[0-9]|1000)$ ]:"
         };
-        Win.Add (regexProvider);
+        win.Add (regexProvider);
 
         var provider2 = new TextRegexProvider ("^([0-9]?[0-9]?[0-9]|1000)$") { ValidateOnInput = false };
 
@@ -293,7 +295,7 @@ public class Text : Scenario
             TextAlignment = Alignment.Center,
             Provider = provider2
         };
-        Win.Add (regexProviderField);
+        win.Add (regexProviderField);
 
         var labelMirroringRegexProviderField = new Label
         {
@@ -304,7 +306,7 @@ public class Text : Scenario
             Height = Dim.Height (regexProviderField),
             Text = regexProviderField.Text
         };
-        Win.Add (labelMirroringRegexProviderField);
+        win.Add (labelMirroringRegexProviderField);
 
         regexProviderField.Provider.TextChanged += (s, prev) => { labelMirroringRegexProviderField.Text = regexProviderField.Text; };
 
@@ -428,8 +430,12 @@ public class Text : Scenario
             }
         };
 
-        Win.Add (labelAppendAutocomplete);
-        Win.Add (appendAutocompleteTextField);
+        win.Add (labelAppendAutocomplete);
+        win.Add (appendAutocompleteTextField);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private void TimeChanged (object sender, DateTimeEventArgs<TimeSpan> e) { _labelMirroringTimeField.Text = _timeField.Text; }

+ 1 - 1
UICatalog/Scenarios/TextAlignmentAndDirection.cs

@@ -16,7 +16,7 @@ public class TextAlignmentAndDirection : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var txt = $"Hello World{Environment.NewLine}HELLO WORLD{Environment.NewLine}世界 您好";

+ 1 - 1
UICatalog/Scenarios/TextFormatterDemo.cs

@@ -16,7 +16,7 @@ public class TextFormatterDemo : Scenario
 
         var app = new Window
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         // Make Win smaller so sizing the window horizontally will make the

+ 13 - 7
UICatalog/Scenarios/Threading.cs

@@ -20,8 +20,10 @@ public class Threading : Scenario
     private ListView _logJob;
     private Action _sync;
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
         _action = LoadData;
 
         _lambda = async () =>
@@ -56,7 +58,7 @@ public class Threading : Scenario
         _btnActionCancel = new Button { X = 1, Y = 1, Text = "Cancelable Load Items" };
         _btnActionCancel.Accept += (s, e) => Application.Invoke (CallLoadItemsAsync);
 
-        Win.Add (new Label { X = Pos.X (_btnActionCancel), Y = Pos.Y (_btnActionCancel) + 4, Text = "Data Items:" });
+        win.Add (new Label { X = Pos.X (_btnActionCancel), Y = Pos.Y (_btnActionCancel) + 4, Text = "Data Items:" });
 
         _itemsList = new ListView
         {
@@ -67,7 +69,7 @@ public class Threading : Scenario
             ColorScheme = Colors.ColorSchemes ["TopLevel"]
         };
 
-        Win.Add (new Label { X = Pos.Right (_itemsList) + 10, Y = Pos.Y (_btnActionCancel) + 4, Text = "Task Logs:" });
+        win.Add (new Label { X = Pos.Right (_itemsList) + 10, Y = Pos.Y (_btnActionCancel) + 4, Text = "Task Logs:" });
 
         _logJob = new ListView
         {
@@ -101,7 +103,7 @@ public class Threading : Scenario
         var btnQuit = new Button { X = 80, Y = 22, Text = "Quit" };
         btnQuit.Accept += (s, e) => Application.RequestStop ();
 
-        Win.Add (
+        win.Add (
                  _itemsList,
                  _btnActionCancel,
                  _logJob,
@@ -115,13 +117,17 @@ public class Threading : Scenario
                  btnQuit
                 );
 
-        void Top_Loaded (object sender, EventArgs args)
+        void Win_Loaded (object sender, EventArgs args)
         {
             _btnActionCancel.SetFocus ();
-            Top.Loaded -= Top_Loaded;
+            win.Loaded -= Win_Loaded;
         }
 
-        Top.Loaded += Top_Loaded;
+        win.Loaded += Win_Loaded;
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private async void CallLoadItemsAsync ()

+ 22 - 12
UICatalog/Scenarios/TileViewNesting.cs

@@ -19,11 +19,15 @@ public class TileViewNesting : Scenario
     private View _workArea;
 
     /// <summary>Setup the scenario.</summary>
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
         // Scenario Windows.
-        Win.Title = GetName ();
-        Win.Y = 1;
+        var win = new Window
+        {
+            Title = GetName (),
+            Y = 1
+        };
 
         var lblViews = new Label { Text = "Number Of Views:" };
         _textField = new() { X = Pos.Right (lblViews), Width = 10, Text = "2" };
@@ -52,19 +56,25 @@ public class TileViewNesting : Scenario
             ]
         };
 
-        Win.Add (lblViews);
-        Win.Add (_textField);
-        Win.Add (_cbHorizontal);
-        Win.Add (_cbBorder);
-        Win.Add (_cbTitles);
-        Win.Add (_cbUseLabels);
-        Win.Add (_workArea);
+        win.Add (lblViews);
+        win.Add (_textField);
+        win.Add (_cbHorizontal);
+        win.Add (_cbBorder);
+        win.Add (_cbTitles);
+        win.Add (_cbUseLabels);
+        win.Add (_workArea);
 
         SetupTileView ();
 
-        Top.Add (menu);
+        var top = new Toplevel ();
+        top.Add (menu);
+        top.Add (win);
+
+        top.Loaded += (s, e) => _loaded = true;
 
-        Win.Loaded += (s, e) => _loaded = true;
+        Application.Run (top);
+        top.Dispose ();
+        Application.Shutdown ();
     }
 
     private void AddMoreViews (TileView to)

+ 19 - 13
UICatalog/Scenarios/TimeAndDate.cs

@@ -15,8 +15,10 @@ public class TimeAndDate : Scenario
     private Label _lblOldTime;
     private Label _lblTimeFmt;
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
         var longTime = new TimeField
         {
             X = Pos.Center (),
@@ -26,7 +28,7 @@ public class TimeAndDate : Scenario
             Time = DateTime.Now.TimeOfDay
         };
         longTime.TimeChanged += TimeChanged;
-        Win.Add (longTime);
+        win.Add (longTime);
 
         var shortTime = new TimeField
         {
@@ -37,21 +39,21 @@ public class TimeAndDate : Scenario
             Time = DateTime.Now.TimeOfDay
         };
         shortTime.TimeChanged += TimeChanged;
-        Win.Add (shortTime);
+        win.Add (shortTime);
 
         var shortDate = new DateField (DateTime.Now)
         {
             X = Pos.Center (), Y = Pos.Bottom (shortTime) + 1, ReadOnly = true
         };
         shortDate.DateChanged += DateChanged;
-        Win.Add (shortDate);
+        win.Add (shortDate);
 
         var longDate = new DateField (DateTime.Now)
         {
             X = Pos.Center (), Y = Pos.Bottom (shortDate) + 1, ReadOnly = false
         };
         longDate.DateChanged += DateChanged;
-        Win.Add (longDate);
+        win.Add (longDate);
 
         _lblOldTime = new()
         {
@@ -62,7 +64,7 @@ public class TimeAndDate : Scenario
             Width = Dim.Fill (),
             Text = "Old Time: "
         };
-        Win.Add (_lblOldTime);
+        win.Add (_lblOldTime);
 
         _lblNewTime = new()
         {
@@ -73,7 +75,7 @@ public class TimeAndDate : Scenario
             Width = Dim.Fill (),
             Text = "New Time: "
         };
-        Win.Add (_lblNewTime);
+        win.Add (_lblNewTime);
 
         _lblTimeFmt = new()
         {
@@ -84,7 +86,7 @@ public class TimeAndDate : Scenario
             Width = Dim.Fill (),
             Text = "Time Format: "
         };
-        Win.Add (_lblTimeFmt);
+        win.Add (_lblTimeFmt);
 
         _lblOldDate = new()
         {
@@ -95,7 +97,7 @@ public class TimeAndDate : Scenario
             Width = Dim.Fill (),
             Text = "Old Date: "
         };
-        Win.Add (_lblOldDate);
+        win.Add (_lblOldDate);
 
         _lblNewDate = new()
         {
@@ -106,7 +108,7 @@ public class TimeAndDate : Scenario
             Width = Dim.Fill (),
             Text = "New Date: "
         };
-        Win.Add (_lblNewDate);
+        win.Add (_lblNewDate);
 
         _lblDateFmt = new()
         {
@@ -117,11 +119,11 @@ public class TimeAndDate : Scenario
             Width = Dim.Fill (),
             Text = "Date Format: "
         };
-        Win.Add (_lblDateFmt);
+        win.Add (_lblDateFmt);
 
         var swapButton = new Button
         {
-            X = Pos.Center (), Y = Pos.Bottom (Win) - 5, Text = "Swap Long/Short & Read/Read Only"
+            X = Pos.Center (), Y = Pos.Bottom (win) - 5, Text = "Swap Long/Short & Read/Read Only"
         };
 
         swapButton.Accept += (s, e) =>
@@ -135,7 +137,11 @@ public class TimeAndDate : Scenario
                                  longDate.ReadOnly = !longDate.ReadOnly;
                                  shortDate.ReadOnly = !shortDate.ReadOnly;
                              };
-        Win.Add (swapButton);
+        win.Add (swapButton);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 
     private void DateChanged (object sender, DateTimeEventArgs<DateTime> e)

+ 17 - 7
UICatalog/Scenarios/TreeViewFileSystem.cs

@@ -34,11 +34,16 @@ public class TreeViewFileSystem : Scenario
     /// <summary>A tree view where nodes are files and folders</summary>
     private TreeView<IFileSystemInfo> _treeViewFiles;
 
-    public override void Setup ()
+    public override void Main ()
     {
-        Win.Title = GetName ();
-        Win.Y = 1; // menu
-        Win.Height = Dim.Fill ();
+        Application.Init ();
+        var win = new Window
+        {
+            Title = GetName (),
+            Y = 1, // menu
+            Height = Dim.Fill ()
+        };
+        var top = new Toplevel ();
 
         var menu = new MenuBar
         {
@@ -172,7 +177,7 @@ public class TreeViewFileSystem : Scenario
                                 )
             ]
         };
-        Top.Add (menu);
+        top.Add (menu);
 
         _treeViewFiles = new TreeView<IFileSystemInfo> { X = 0, Y = 0, Width = Dim.Percent (50), Height = Dim.Fill () };
         _treeViewFiles.DrawLine += TreeViewFiles_DrawLine;
@@ -182,14 +187,15 @@ public class TreeViewFileSystem : Scenario
             X = Pos.Right (_treeViewFiles), Y = 0, Width = Dim.Fill (), Height = Dim.Fill ()
         };
 
-        Win.Add (_detailsFrame);
+        win.Add (_detailsFrame);
         _treeViewFiles.MouseClick += TreeViewFiles_MouseClick;
         _treeViewFiles.KeyDown += TreeViewFiles_KeyPress;
         _treeViewFiles.SelectionChanged += TreeViewFiles_SelectionChanged;
 
         SetupFileTree ();
 
-        Win.Add (_treeViewFiles);
+        win.Add (_treeViewFiles);
+        top.Add (win);
         _treeViewFiles.GoToFirst ();
         _treeViewFiles.Expand ();
 
@@ -198,6 +204,10 @@ public class TreeViewFileSystem : Scenario
         _treeViewFiles.SetFocus ();
 
         UpdateIconCheckedness ();
+
+        Application.Run (top);
+        top.Dispose ();
+        Application.Shutdown ();
     }
 
     private string AspectGetter (IFileSystemInfo f) { return (_iconProvider.GetIconWithOptionalSpace (f) + f.Name).Trim (); }

+ 1 - 1
UICatalog/Scenarios/TrueColors.cs

@@ -13,7 +13,7 @@ public class TrueColors : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var x = 2;

+ 1 - 1
UICatalog/Scenarios/Unicode.cs

@@ -34,7 +34,7 @@ public class UnicodeInMenu : Scenario
         // Setup - Create a top-level application window and configure it.
         Window appWindow = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var menu = new MenuBar

+ 1 - 1
UICatalog/Scenarios/ViewExperiments.cs

@@ -15,7 +15,7 @@ public class ViewExperiments : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         var containerLabel = new Label

+ 21 - 13
UICatalog/Scenarios/VkeyPacketSimulator.cs

@@ -16,13 +16,16 @@ public class VkeyPacketSimulator : Scenario
     private bool _outputStarted;
     private bool _wasUnknown;
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
+
         var label = new Label { X = Pos.Center (), Text = "Input" };
-        Win.Add (label);
+        win.Add (label);
 
         var btnInput = new Button { X = Pos.AnchorEnd (16), Text = "Select Input" };
-        Win.Add (btnInput);
+        win.Add (btnInput);
 
         const string ruler = "|123456789";
 
@@ -30,17 +33,18 @@ public class VkeyPacketSimulator : Scenario
         {
             Y = Pos.Bottom (btnInput), Width = Dim.Fill (), ColorScheme = Colors.ColorSchemes ["Error"]
         };
-        Win.Add (inputHorizontalRuler);
+        win.Add (inputHorizontalRuler);
 
         var inputVerticalRuler = new Label
         {
             Y = Pos.Bottom (btnInput),
 
             Width = 1,
+            Height = Dim.Percent (50),
             ColorScheme = Colors.ColorSchemes ["Error"],
             TextDirection = TextDirection.TopBottom_LeftRight
         };
-        Win.Add (inputVerticalRuler);
+        win.Add (inputVerticalRuler);
 
         var tvInput = new TextView
         {
@@ -50,13 +54,13 @@ public class VkeyPacketSimulator : Scenario
             Width = Dim.Fill (),
             Height = Dim.Percent (50) - 1
         };
-        Win.Add (tvInput);
+        win.Add (tvInput);
 
         label = new() { X = Pos.Center (), Y = Pos.Bottom (tvInput), Text = "Output" };
-        Win.Add (label);
+        win.Add (label);
 
         var btnOutput = new Button { X = Pos.AnchorEnd (17), Y = Pos.Top (label), Text = "Select Output" };
-        Win.Add (btnOutput);
+        win.Add (btnOutput);
 
         var outputHorizontalRuler = new Label
         {
@@ -65,18 +69,18 @@ public class VkeyPacketSimulator : Scenario
             Width = Dim.Fill (),
             ColorScheme = Colors.ColorSchemes ["Error"]
         };
-        Win.Add (outputHorizontalRuler);
+        win.Add (outputHorizontalRuler);
 
         var outputVerticalRuler = new Label
         {
-            Y = Pos.Bottom (btnOutput),
+            Y = Pos.Bottom(btnOutput),
 
             Width = 1,
             Height = Dim.Fill (),
             ColorScheme = Colors.ColorSchemes ["Error"],
             TextDirection = TextDirection.TopBottom_LeftRight
         };
-        Win.Add (outputVerticalRuler);
+        win.Add (outputVerticalRuler);
 
         var tvOutput = new TextView
         {
@@ -128,7 +132,7 @@ public class VkeyPacketSimulator : Scenario
                                 _stopOutput.Set ();
                             };
 
-        Win.Add (tvOutput);
+        win.Add (tvOutput);
 
         tvInput.KeyDown += (s, e) =>
                            {
@@ -283,6 +287,10 @@ public class VkeyPacketSimulator : Scenario
                      ..outputVerticalRuler.Viewport.Height];
         }
 
-        Win.LayoutComplete += Win_LayoutComplete;
+        win.LayoutComplete += Win_LayoutComplete;
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 1 - 1
UICatalog/Scenarios/WindowsAndFrameViews.cs

@@ -14,7 +14,7 @@ public class WindowsAndFrameViews : Scenario
 
         Window app = new ()
         {
-            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+            Title = GetQuitKeyAndName ()
         };
 
         static int About ()

+ 15 - 8
UICatalog/Scenarios/Wizards.cs

@@ -9,8 +9,11 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Wizards")]
 public class Wizards : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+        var win = new Window { Title = GetQuitKeyAndName () };
+
         var frame = new FrameView
         {
             X = Pos.Center (),
@@ -19,7 +22,7 @@ public class Wizards : Scenario
             ColorScheme = Colors.ColorSchemes ["Base"],
             Title = "Wizard Options"
         };
-        Win.Add (frame);
+        win.Add (frame);
 
         var label = new Label { X = 0, Y = 0, TextAlignment = Alignment.End, Text = "Width:" };
         frame.Add (label);
@@ -78,25 +81,25 @@ public class Wizards : Scenario
         };
         frame.Add (titleEdit);
 
-        void Top_Loaded (object sender, EventArgs args)
+        void Win_Loaded (object sender, EventArgs args)
         {
             frame.Height = widthEdit.Frame.Height + heightEdit.Frame.Height + titleEdit.Frame.Height + 2;
-            Top.Loaded -= Top_Loaded;
+            win.Loaded -= Win_Loaded;
         }
 
-        Top.Loaded += Top_Loaded;
+        win.Loaded += Win_Loaded;
 
         label = new()
         {
             X = Pos.Center (), Y = Pos.AnchorEnd (1), TextAlignment = Alignment.End, Text = "Action:"
         };
-        Win.Add (label);
+        win.Add (label);
 
         var actionLabel = new Label
         {
             X = Pos.Right (label), Y = Pos.AnchorEnd (1), ColorScheme = Colors.ColorSchemes ["Error"]
         };
-        Win.Add (actionLabel);
+        win.Add (actionLabel);
 
         var showWizardButton = new Button
         {
@@ -344,6 +347,10 @@ public class Wizards : Scenario
                                            actionLabel.Text = "Invalid Options";
                                        }
                                    };
-        Win.Add (showWizardButton);
+        win.Add (showWizardButton);
+
+        Application.Run (win);
+        win.Dispose ();
+        Application.Shutdown ();
     }
 }