BDisp преди 1 година
родител
ревизия
f1fcbb91d3
променени са 56 файла, в които са добавени 273 реда и са изтрити 219 реда
  1. 11 2
      UICatalog/Scenario.cs
  2. 5 4
      UICatalog/Scenarios/ASCIICustomButton.cs
  3. 4 3
      UICatalog/Scenarios/AdornmentExperiments.cs
  4. 3 2
      UICatalog/Scenarios/Adornments.cs
  5. 6 5
      UICatalog/Scenarios/AllViewsTester.cs
  6. 4 1
      UICatalog/Scenarios/BackgroundWorkerCollection.cs
  7. 1 1
      UICatalog/Scenarios/Buttons.cs
  8. 8 7
      UICatalog/Scenarios/CharacterMap.cs
  9. 5 2
      UICatalog/Scenarios/ChineseUI.cs
  10. 1 1
      UICatalog/Scenarios/ClassExplorer.cs
  11. 4 3
      UICatalog/Scenarios/Clipping.cs
  12. 8 7
      UICatalog/Scenarios/CollectionNavigatorTester.cs
  13. 3 2
      UICatalog/Scenarios/CombiningMarks.cs
  14. 36 35
      UICatalog/Scenarios/ComputedLayout.cs
  15. 6 5
      UICatalog/Scenarios/ConfigurationEditor.cs
  16. 1 1
      UICatalog/Scenarios/ContextMenus.cs
  17. 2 2
      UICatalog/Scenarios/CsvEditor.cs
  18. 1 1
      UICatalog/Scenarios/Dialogs.cs
  19. 5 3
      UICatalog/Scenarios/DynamicMenuBar.cs
  20. 5 3
      UICatalog/Scenarios/DynamicStatusBar.cs
  21. 6 4
      UICatalog/Scenarios/Editor.cs
  22. 10 5
      UICatalog/Scenarios/FileDialogExamples.cs
  23. 3 2
      UICatalog/Scenarios/Generic.cs
  24. 2 2
      UICatalog/Scenarios/GraphViewExample.cs
  25. 2 2
      UICatalog/Scenarios/HexEditor.cs
  26. 24 23
      UICatalog/Scenarios/HotKeys.cs
  27. 2 2
      UICatalog/Scenarios/InteractiveTree.cs
  28. 7 3
      UICatalog/Scenarios/LineCanvasExperiment.cs
  29. 2 2
      UICatalog/Scenarios/LineViewExample.cs
  30. 2 2
      UICatalog/Scenarios/ListColumns.cs
  31. 1 1
      UICatalog/Scenarios/Localization.cs
  32. 17 16
      UICatalog/Scenarios/MenuBarScenario.cs
  33. 2 2
      UICatalog/Scenarios/MessageBoxes.cs
  34. 2 2
      UICatalog/Scenarios/MultiColouredTable.cs
  35. 6 5
      UICatalog/Scenarios/Notepad.cs
  36. 5 3
      UICatalog/Scenarios/ProgressBarStyles.cs
  37. 6 3
      UICatalog/Scenarios/RunTExample.cs
  38. 4 2
      UICatalog/Scenarios/RuneWidthGreaterThanOne.cs
  39. 4 4
      UICatalog/Scenarios/Scrolling.cs
  40. 8 7
      UICatalog/Scenarios/SingleBackgroundWorker.cs
  41. 1 1
      UICatalog/Scenarios/Sliders.cs
  42. 2 2
      UICatalog/Scenarios/SpinnerStyles.cs
  43. 2 2
      UICatalog/Scenarios/SyntaxHighlighting.cs
  44. 2 2
      UICatalog/Scenarios/TabViewExample.cs
  45. 2 2
      UICatalog/Scenarios/TableEditor.cs
  46. 1 1
      UICatalog/Scenarios/TextFormatterDemo.cs
  47. 2 2
      UICatalog/Scenarios/TextViewAutocompletePopup.cs
  48. 2 2
      UICatalog/Scenarios/Threading.cs
  49. 1 1
      UICatalog/Scenarios/TileViewNesting.cs
  50. 2 2
      UICatalog/Scenarios/TreeUseCases.cs
  51. 1 1
      UICatalog/Scenarios/TreeViewFileSystem.cs
  52. 2 2
      UICatalog/Scenarios/Unicode.cs
  53. 8 7
      UICatalog/Scenarios/ViewExperiments.cs
  54. 5 5
      UICatalog/Scenarios/WindowsAndFrameViews.cs
  55. 4 3
      UICatalog/Scenarios/WizardAsView.cs
  56. 2 2
      UICatalog/Scenarios/Wizards.cs

+ 11 - 2
UICatalog/Scenario.cs

@@ -77,6 +77,11 @@ public class Scenario : IDisposable
     public string TopLevelColorScheme = "Base";
     private bool _disposedValue;
 
+    /// <summary>
+    ///     The Toplevel for the <see cref="Scenario"/>. This should be set to <see cref="Terminal.Gui.Application.Top"/>.
+    /// </summary>
+    public Toplevel Top { get; set; }
+
     /// <summary>
     ///     The Window for the <see cref="Scenario"/>. This should be set to <see cref="Terminal.Gui.Application.Top"/> in
     ///     most cases.
@@ -85,6 +90,8 @@ public class Scenario : IDisposable
 
     public void Dispose ()
     {
+        Top?.Dispose ();
+        Win?.Dispose ();
         // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
         Dispose (true);
         GC.SuppressFinalize (this);
@@ -151,6 +158,8 @@ public class Scenario : IDisposable
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
 
+        Top = new ();
+
         Win = new Window
         {
             Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
@@ -160,7 +169,7 @@ public class Scenario : IDisposable
             Height = Dim.Fill (),
             ColorScheme = Colors.ColorSchemes [TopLevelColorScheme]
         };
-        Application.Top.Add (Win);
+        Top.Add (Win);
     }
 
     /// <summary>Stops the scenario. Override to change shutdown behavior for the <see cref="Scenario"/>.</summary>
@@ -177,7 +186,7 @@ public class Scenario : IDisposable
     public virtual void Run ()
     {
         // Must explicit call Application.Shutdown method to shutdown.
-        Application.Run (Application.Top);
+        Application.Run (Top);
     }
 
     /// <summary>Override this to implement the <see cref="Scenario"/> setup logic (create controls, etc...).</summary>

+ 5 - 4
UICatalog/Scenarios/ASCIICustomButton.cs

@@ -50,8 +50,9 @@ public class ASCIICustomButtonTest : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu, _scrollViewTestWindow);
-        Application.Run ();
+        Top = new ();
+        Top.Add (menu, _scrollViewTestWindow);
+        Application.Run (Top);
     }
 
     public override void Run () { }
@@ -60,9 +61,9 @@ public class ASCIICustomButtonTest : Scenario
     {
         _smallerWindow = (bool)(_miSmallerWindow.Checked = !_miSmallerWindow.Checked);
         _scrollViewTestWindow.Dispose ();
-        Application.Top.Remove (_scrollViewTestWindow);
+        Top.Remove (_scrollViewTestWindow);
         _scrollViewTestWindow = new ScrollViewTestWindow ();
-        Application.Top.Add (_scrollViewTestWindow);
+        Top.Add (_scrollViewTestWindow);
     }
 
     public class ASCIICustomButton : Button

+ 4 - 3
UICatalog/Scenarios/AdornmentExperiments.cs

@@ -13,7 +13,8 @@ public class AdornmentExperiments : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
 
         _diagnosticFlags = View.Diagnostics;
         //View.Diagnostics = ViewDiagnosticFlags.MouseEnter;
@@ -31,10 +32,10 @@ public class AdornmentExperiments : Scenario
             Height = Dim.Percent (90),
             CanFocus = true,
         };
-        Application.Top.Add (_frameView);
+        Top.Add (_frameView);
         _frameView.Initialized += FrameView_Initialized;
 
-        Application.Top.Closed += (s, e) => View.Diagnostics = _diagnosticFlags;
+        Top.Closed += (s, e) => View.Diagnostics = _diagnosticFlags;
     }
 
     private void FrameView_Initialized (object sender, System.EventArgs e)

+ 3 - 2
UICatalog/Scenarios/Adornments.cs

@@ -18,7 +18,8 @@ public class Adornments : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
 
         var view = new Window { Title = "The _Window" };
         var tf1 = new TextField { Width = 10, Text = "TextField" };
@@ -117,7 +118,7 @@ public class Adornments : Scenario
 #endif
                             };
 
-        Application.Top.Closed += (s, e) => View.Diagnostics = _diagnosticFlags;
+        Top.Closed += (s, e) => View.Diagnostics = _diagnosticFlags;
 
         Application.Run (editor);
         editor.Dispose ();

+ 6 - 5
UICatalog/Scenarios/AllViewsTester.cs

@@ -46,7 +46,8 @@ public class AllViewsTester : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
     }
 
     public override void Setup ()
@@ -66,7 +67,7 @@ public class AllViewsTester : Scenario
                                                 {
                                                     View.Diagnostics ^=
                                                         ViewDiagnosticFlags.Ruler;
-                                                    Application.Top.SetNeedsDisplay ();
+                                                    Top.SetNeedsDisplay ();
                                                 }
                                                ),
                                            new (
@@ -76,12 +77,12 @@ public class AllViewsTester : Scenario
                                                 {
                                                     View.Diagnostics ^=
                                                         ViewDiagnosticFlags.Padding;
-                                                    Application.Top.SetNeedsDisplay ();
+                                                    Top.SetNeedsDisplay ();
                                                 }
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         _viewClasses = GetAllViewClassesCollection ()
                        .OrderBy (t => t.Name)
@@ -286,7 +287,7 @@ public class AllViewsTester : Scenario
             ColorScheme = Colors.ColorSchemes ["Dialog"]
         };
 
-        Application.Top.Add (_leftPane, _settingsPane, _hostPane);
+        Top.Add (_leftPane, _settingsPane, _hostPane);
 
         _curView = CreateClass (_viewClasses.First ().Value);
     }

+ 4 - 1
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -13,12 +13,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Controls")]
 public class BackgroundWorkerCollection : Scenario
 {
-    public override void Run ()
+    public override void Init ()
     {
         Application.Run<OverlappedMain> ();
+
         Application.Top.Dispose ();
     }
 
+    public override void Run () { }
+
     private class OverlappedMain : Toplevel
     {
         private readonly MenuBar _menu;

+ 1 - 1
UICatalog/Scenarios/Buttons.cs

@@ -329,6 +329,6 @@ public class Buttons : Scenario
                                               }
                                           };
 
-        Application.Top.Ready += (s, e) => radioGroup.Refresh ();
+        Top.Ready += (s, e) => radioGroup.Refresh ();
     }
 }

+ 8 - 7
UICatalog/Scenarios/CharacterMap.cs

@@ -36,13 +36,14 @@ public class CharacterMap : Scenario
     public override void Init ()
     {
         Application.Init ();
-        Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes ["Base"];
     }
 
     public override void Setup ()
     {
         _charMap = new() { X = 0, Y = 1, Height = Dim.Fill () };
-        Application.Top.Add (_charMap);
+        Top.Add (_charMap);
 
         var jumpLabel = new Label
         {
@@ -51,19 +52,19 @@ public class CharacterMap : Scenario
             HotKeySpecifier = (Rune)'_',
             Text = "_Jump To Code Point:"
         };
-        Application.Top.Add (jumpLabel);
+        Top.Add (jumpLabel);
 
         var jumpEdit = new TextField
         {
             X = Pos.Right (jumpLabel) + 1, Y = Pos.Y (_charMap), Width = 10, Caption = "e.g. 01BE3"
         };
-        Application.Top.Add (jumpEdit);
+        Top.Add (jumpEdit);
 
         _errorLabel = new()
         {
             X = Pos.Right (jumpEdit) + 1, Y = Pos.Y (_charMap), ColorScheme = Colors.ColorSchemes ["error"], Text = "err"
         };
-        Application.Top.Add (_errorLabel);
+        Top.Add (_errorLabel);
 
 #if TEXT_CHANGED_TO_JUMP
         jumpEdit.TextChanged += JumpEdit_TextChanged;
@@ -135,7 +136,7 @@ public class CharacterMap : Scenario
                                                  _charMap.StartCodePoint = table.Data.ToArray () [args.NewRow].Start;
                                              };
 
-        Application.Top.Add (_categoryList);
+        Top.Add (_categoryList);
 
         _charMap.SelectedCodePoint = 0;
         _charMap.SetFocus ();
@@ -164,7 +165,7 @@ public class CharacterMap : Scenario
                     )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
     }
 
     private void _categoryList_Initialized (object sender, EventArgs e) { _charMap.Width = Dim.Fill () - _categoryList.Width; }

+ 5 - 2
UICatalog/Scenarios/ChineseUI.cs

@@ -9,7 +9,8 @@ public class ChineseUI : Scenario
     public override void Init ()
     {
         Application.Init ();
-        Toplevel top = Application.Top;
+
+        Toplevel top = new ();
 
         var win = new Window
         {
@@ -55,7 +56,9 @@ public class ChineseUI : Scenario
                          new Button { X = 22, Y = 1, Text = "呀" } // v1: C
                         );
 
-        Application.Run ();
+        Application.Run (top);
+
+        top.Dispose ();
     }
 
     public override void Run () { }

+ 1 - 1
UICatalog/Scenarios/ClassExplorer.cs

@@ -55,7 +55,7 @@ public class ClassExplorer : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _treeView = new TreeView<object> { X = 0, Y = 1, Width = Dim.Percent (50), Height = Dim.Fill () };
 

+ 4 - 3
UICatalog/Scenarios/Clipping.cs

@@ -9,7 +9,8 @@ public class Clipping : Scenario
     public override void Init ()
     {
         Application.Init ();
-        Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes ["Base"];
     }
 
     public override void Setup ()
@@ -22,7 +23,7 @@ public class Clipping : Scenario
         {
             X = 0, Y = 0, Text = "ScrollView (new Rectangle (3, 3, 50, 20)) with a 200, 100 ContentSize..."
         };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         var scrollView = new ScrollView { X = 3, Y = 3, Width = 50, Height = 20 };
         scrollView.ColorScheme = Colors.ColorSchemes ["Menu"];
@@ -79,6 +80,6 @@ public class Clipping : Scenario
 
         scrollView.Add (embedded1);
 
-        Application.Top.Add (scrollView);
+        Top.Add (scrollView);
     }
 }

+ 8 - 7
UICatalog/Scenarios/CollectionNavigatorTester.cs

@@ -80,7 +80,8 @@ public class CollectionNavigatorTester : Scenario
     public override void Init ()
     {
         Application.Init ();
-        Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes ["Base"];
     }
 
     public override void Setup ()
@@ -126,13 +127,13 @@ public class CollectionNavigatorTester : Scenario
             ]
         };
 
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _items.Sort (StringComparer.OrdinalIgnoreCase);
 
         CreateListView ();
         var vsep = new LineView (Orientation.Vertical) { X = Pos.Right (_listView), Y = 1, Height = Dim.Fill () };
-        Application.Top.Add (vsep);
+        Top.Add (vsep);
         CreateTreeView ();
     }
 
@@ -148,7 +149,7 @@ public class CollectionNavigatorTester : Scenario
             Width = Dim.Percent (50),
             Height = 1
         };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         _listView = new ListView
         {
@@ -159,7 +160,7 @@ public class CollectionNavigatorTester : Scenario
             AllowsMarking = false,
             AllowsMultipleSelection = false
         };
-        Application.Top.Add (_listView);
+        Top.Add (_listView);
 
         _listView.SetSource (_items);
 
@@ -178,14 +179,14 @@ public class CollectionNavigatorTester : Scenario
             Width = Dim.Percent (50),
             Height = 1
         };
-        Application.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;
-        Application.Top.Add (_treeView);
+        Top.Add (_treeView);
 
         var root = new TreeNode ("IsLetterOrDigit examples");
 

+ 3 - 2
UICatalog/Scenarios/CombiningMarks.cs

@@ -11,12 +11,13 @@ public class CombiningMarks : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
     }
 
     public override void Setup ()
     {
-        Application.Top.DrawContentComplete += (s, e) =>
+        Top.DrawContentComplete += (s, e) =>
                                                {
                                                    Application.Driver.Move (0, 0);
                                                    Application.Driver.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");

+ 36 - 35
UICatalog/Scenarios/ComputedLayout.cs

@@ -18,7 +18,8 @@ public class ComputedLayout : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
     }
 
     public override void Setup ()
@@ -37,7 +38,7 @@ public class ComputedLayout : Scenario
             Text = rule
         };
 
-        Application.Top.Add (horizontalRuler);
+        Top.Add (horizontalRuler);
 
         // Demonstrate using Dim to create a vertical ruler that always measures the parent window's height
         const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
@@ -53,7 +54,7 @@ public class ComputedLayout : Scenario
             Text = vrule
         };
 
-        Application.Top.LayoutComplete += (s, a) =>
+        Top.LayoutComplete += (s, a) =>
                                           {
                                               horizontalRuler.Text =
                                                   rule.Repeat ((int)Math.Ceiling (horizontalRuler.Bounds.Width / (double)rule.Length)) [
@@ -64,15 +65,15 @@ public class ComputedLayout : Scenario
                                                       [..(verticalRuler.Bounds.Height * 2)];
                                           };
 
-        Application.Top.Add (verticalRuler);
+        Top.Add (verticalRuler);
 
         // Demonstrate At - Using Pos.At to locate a view in an absolute location
         var atButton = new Button { Text = "At(2,1)", X = Pos.At (2), Y = Pos.At (1) };
-        Application.Top.Add (atButton);
+        Top.Add (atButton);
 
         // Throw in a literal absolute - Should function identically to above
         var absoluteButton = new Button { Text = "X = 30, Y = 1", X = 30, Y = 1 };
-        Application.Top.Add (absoluteButton);
+        Top.Add (absoluteButton);
 
         // Demonstrate using Dim to create a window that fills the parent with a margin
         var margin = 10;
@@ -83,7 +84,7 @@ public class ComputedLayout : Scenario
                                   subWin.Title =
                                       $"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}";
                               };
-        Application.Top.Add (subWin);
+        Top.Add (subWin);
 
         var i = 1;
         var txt = "Resize the terminal to see computed layout in action.";
@@ -208,7 +209,7 @@ public class ComputedLayout : Scenario
                        }
                       );
         frameView.Add (labelList.ToArray ());
-        Application.Top.Add (frameView);
+        Top.Add (frameView);
 
         frameView = new FrameView
         {
@@ -222,7 +223,7 @@ public class ComputedLayout : Scenario
                                      fv.Title =
                                          $"{frameView.GetType ().Name} {{X={fv.X},Y={fv.Y},Width={fv.Width},Height={fv.Height}}}";
                                  };
-        Application.Top.Add (frameView);
+        Top.Add (frameView);
 
         // Demonstrate Dim & Pos using percentages - a TextField that is 30% height and 80% wide
         var textView = new TextView
@@ -236,7 +237,7 @@ public class ComputedLayout : Scenario
 
         textView.Text =
             "This TextView should horizontally & vertically centered and \n10% of the screeen height, and 80% of its width.";
-        Application.Top.Add (textView);
+        Top.Add (textView);
 
         var oddballButton = new Button
         {
@@ -244,7 +245,7 @@ public class ComputedLayout : Scenario
             X = Pos.Center (),
             Y = Pos.Bottom (textView) + 1
         };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         #region Issue2358
 
@@ -252,19 +253,19 @@ public class ComputedLayout : Scenario
         // Until https://github.com/gui-cs/Terminal.Gui/issues/2358 is fixed these won't work right
 
         oddballButton = new Button { Text = "Center + 0", X = Pos.Center () + 0, Y = Pos.Bottom (oddballButton) };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         oddballButton = new Button { Text = "Center + 1", X = Pos.Center () + 1, Y = Pos.Bottom (oddballButton) };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         oddballButton = new Button { Text = "0 + Center", X = 0 + Pos.Center (), Y = Pos.Bottom (oddballButton) };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         oddballButton = new Button { Text = "1 + Center", X = 1 + Pos.Center (), Y = Pos.Bottom (oddballButton) };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         oddballButton = new Button { Text = "Center - 1", X = Pos.Center () - 1, Y = Pos.Bottom (oddballButton) };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
         // The `- Pos.Percent(5)` is there so at least something is visible
@@ -274,7 +275,7 @@ public class ComputedLayout : Scenario
             X = Pos.Center () + Pos.Center () - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
         // The `- Pos.Percent(5)` is there so at least something is visible
@@ -284,7 +285,7 @@ public class ComputedLayout : Scenario
             X = Pos.Percent (50) + Pos.Center () - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
         // The `- Pos.Percent(5)` is there so at least something is visible
@@ -294,7 +295,7 @@ public class ComputedLayout : Scenario
             X = Pos.Center () + Pos.Percent (50) - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         #endregion
 
@@ -305,14 +306,14 @@ public class ComputedLayout : Scenario
             X = Pos.Center () + Pos.Center () - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         // This demonstrates combining Percents)
         oddballButton = new Button
         {
             Text = "Percent(40) + Percent(10)", X = Pos.Percent (40) + Pos.Percent (10), Y = Pos.Bottom (oddballButton)
         };
-        Application.Top.Add (oddballButton);
+        Top.Add (oddballButton);
 
         // Demonstrate AnchorEnd - Button is anchored to bottom/right
         var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd () - 1 };
@@ -322,12 +323,12 @@ public class ComputedLayout : Scenario
                                 {
                                     // This demonstrates how to have a dynamically sized button
                                     // Each time the button is clicked the button's text gets longer
-                                    // The call to Application.Top.LayoutSubviews causes the Computed layout to
+                                    // The call to Top.LayoutSubviews causes the Computed layout to
                                     // get updated. 
                                     anchorButton.Text += "!";
-                                    Application.Top.LayoutSubviews ();
+                                    Top.LayoutSubviews ();
                                 };
-        Application.Top.Add (anchorButton);
+        Top.Add (anchorButton);
 
         // Demonstrate AnchorEnd(n) 
         // This is intentionally convoluted to illustrate potential bugs.
@@ -341,7 +342,7 @@ public class ComputedLayout : Scenario
             X = 5,
             Y = Pos.AnchorEnd (2)
         };
-        Application.Top.Add (anchorEndLabel1);
+        Top.Add (anchorEndLabel1);
 
         // Demonstrate DimCombine (via AnchorEnd(n) - 1)
         // This is intentionally convoluted to illustrate potential bugs.
@@ -356,7 +357,7 @@ public class ComputedLayout : Scenario
             X = 5,
             Y = Pos.AnchorEnd (2) - 1 // Pos.Combine
         };
-        Application.Top.Add (anchorEndLabel2);
+        Top.Add (anchorEndLabel2);
 
         // Show positioning vertically using Pos.AnchorEnd via Pos.Combine
         var leftButton = new Button
@@ -368,10 +369,10 @@ public class ComputedLayout : Scenario
                               {
                                   // This demonstrates how to have a dynamically sized button
                                   // Each time the button is clicked the button's text gets longer
-                                  // The call to Application.Top.LayoutSubviews causes the Computed layout to
+                                  // The call to Top.LayoutSubviews causes the Computed layout to
                                   // get updated. 
                                   leftButton.Text += "!";
-                                  Application.Top.LayoutSubviews ();
+                                  Top.LayoutSubviews ();
                               };
 
         // show positioning vertically using Pos.AnchorEnd
@@ -384,10 +385,10 @@ public class ComputedLayout : Scenario
                                 {
                                     // This demonstrates how to have a dynamically sized button
                                     // Each time the button is clicked the button's text gets longer
-                                    // The call to Application.Top.LayoutSubviews causes the Computed layout to
+                                    // The call to Top.LayoutSubviews causes the Computed layout to
                                     // get updated. 
                                     centerButton.Text += "!";
-                                    Application.Top.LayoutSubviews ();
+                                    Top.LayoutSubviews ();
                                 };
 
         // show positioning vertically using another window and Pos.Bottom
@@ -397,18 +398,18 @@ public class ComputedLayout : Scenario
                                {
                                    // This demonstrates how to have a dynamically sized button
                                    // Each time the button is clicked the button's text gets longer
-                                   // The call to Application.Top.LayoutSubviews causes the Computed layout to
+                                   // The call to Top.LayoutSubviews causes the Computed layout to
                                    // get updated. 
                                    rightButton.Text += "!";
-                                   Application.Top.LayoutSubviews ();
+                                   Top.LayoutSubviews ();
                                };
 
         // Center three buttons with 5 spaces between them
         leftButton.X = Pos.Left (centerButton) - (Pos.Right (leftButton) - Pos.Left (leftButton)) - 5;
         rightButton.X = Pos.Right (centerButton) + 5;
 
-        Application.Top.Add (leftButton);
-        Application.Top.Add (centerButton);
-        Application.Top.Add (rightButton);
+        Top.Add (leftButton);
+        Top.Add (centerButton);
+        Top.Add (rightButton);
     }
 }

+ 6 - 5
UICatalog/Scenarios/ConfigurationEditor.cs

@@ -42,7 +42,8 @@ public class ConfigurationEditor : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
     }
 
     public void Save ()
@@ -60,7 +61,7 @@ public class ConfigurationEditor : Scenario
             Width = Dim.Fill (), Height = Dim.Fill (1), Orientation = Orientation.Vertical, LineStyle = LineStyle.Single
         };
 
-        Application.Top.Add (_tileView);
+        Top.Add (_tileView);
 
         _lenStatusItem = new StatusItem (KeyCode.CharMask, "Len: ", null);
 
@@ -78,9 +79,9 @@ public class ConfigurationEditor : Scenario
                                        }
                                       );
 
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
-        Application.Top.Loaded += (s, a) => Open ();
+        Top.Loaded += (s, a) => Open ();
 
         _editorColorSchemeChanged += () =>
                                      {
@@ -125,7 +126,7 @@ public class ConfigurationEditor : Scenario
             textView.Enter += (s, e) => { _lenStatusItem.Title = $"Len:{textView.Text.Length}"; };
         }
 
-        Application.Top.LayoutSubviews ();
+        Top.LayoutSubviews ();
     }
 
     private void Quit ()

+ 1 - 1
UICatalog/Scenarios/ContextMenus.cs

@@ -78,7 +78,7 @@ public class ContextMenus : Scenario
 
         Win.WantMousePositionReports = true;
 
-        Application.Top.Closed += (s, e) =>
+        Top.Closed += (s, e) =>
                                   {
                                       Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
                                       Application.MouseEvent -= ApplicationMouseEvent;

+ 2 - 2
UICatalog/Scenarios/CsvEditor.cs

@@ -101,7 +101,7 @@ public class CsvEditor : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new StatusItem []
@@ -123,7 +123,7 @@ public class CsvEditor : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         Win.Add (_tableView);
 

+ 1 - 1
UICatalog/Scenarios/Dialogs.cs

@@ -155,7 +155,7 @@ public class Dialogs : Scenario
                 + frame.GetAdornmentsThickness ().Vertical;
         }
 
-        Application.Top.LayoutComplete += Top_LayoutComplete;
+        Top.LayoutComplete += Top_LayoutComplete;
 
         Win.Add (frame);
 

+ 5 - 3
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -18,9 +18,11 @@ public class DynamicMenuBar : Scenario
     {
         Application.Init ();
 
-        Application.Top.Add (
-                             new DynamicMenuBarSample { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" }
-                            );
+        Top = new ();
+
+        Top.Add (
+                 new DynamicMenuBarSample { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" }
+                );
     }
 
     public class Binding

+ 5 - 3
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -17,9 +17,11 @@ public class DynamicStatusBar : Scenario
     {
         Application.Init ();
 
-        Application.Top.Add (
-                             new DynamicStatusBarSample { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" }
-                            );
+        Top = new ();
+
+        Top.Add (
+                 new DynamicStatusBarSample { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" }
+                );
     }
 
     public class Binding

+ 6 - 4
UICatalog/Scenarios/Editor.cs

@@ -42,6 +42,8 @@ public class Editor : Scenario
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
 
+        Top = new ();
+
         Win = new Window
         {
             Title = _fileName ?? "Untitled",
@@ -51,7 +53,7 @@ public class Editor : Scenario
             Height = Dim.Fill (),
             ColorScheme = Colors.ColorSchemes [TopLevelColorScheme]
         };
-        Application.Top.Add (Win);
+        Top.Add (Win);
 
         _textView = new TextView
         {
@@ -238,7 +240,7 @@ public class Editor : Scenario
             ]
         };
 
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var siCursorPosition = new StatusItem (KeyCode.Null, "", null);
 
@@ -268,7 +270,7 @@ public class Editor : Scenario
                                                  statusBar.SetNeedsDisplay ();
                                              };
 
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         _scrollBar = new ScrollBarView (_textView, true);
 
@@ -374,7 +376,7 @@ public class Editor : Scenario
                            }
                        };
 
-        Application.Top.Closed += (s, e) => Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
+        Top.Closed += (s, e) => Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
     }
 
     public override void Setup () { }

+ 10 - 5
UICatalog/Scenarios/FileDialogExamples.cs

@@ -204,7 +204,14 @@ public class FileDialogExamples : Scenario
 
         Application.Run (fd);
 
-        if (fd.Canceled)
+        var canceled = fd.Canceled;
+        var multiSelected = fd.MultiSelected;
+        var path = fd.Path;
+
+        // This needs to be disposed before opening other toplevel
+        fd.Dispose ();
+
+        if (canceled)
         {
             MessageBox.Query (
                               "Canceled",
@@ -216,7 +223,7 @@ public class FileDialogExamples : Scenario
         {
             MessageBox.Query (
                               "Chosen!",
-                              "You chose:" + Environment.NewLine + string.Join (Environment.NewLine, fd.MultiSelected.Select (m => m)),
+                              "You chose:" + Environment.NewLine + string.Join (Environment.NewLine, multiSelected.Select (m => m)),
                               "Ok"
                              );
         }
@@ -224,12 +231,10 @@ public class FileDialogExamples : Scenario
         {
             MessageBox.Query (
                               "Chosen!",
-                              "You chose:" + Environment.NewLine + fd.Path,
+                              "You chose:" + Environment.NewLine + path,
                               "Ok"
                              );
         }
-
-        fd.Dispose ();
     }
 
     private void SetupHandler (Button btn)

+ 3 - 2
UICatalog/Scenarios/Generic.cs

@@ -23,7 +23,8 @@ public class MyScenario : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new Toplevel ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
     }
 
     public override void Setup ()
@@ -34,6 +35,6 @@ public class MyScenario : Scenario
         // `Scenario.Run` which calls `Application.Run`. Example:
 
         var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };
-        Application.Top.Add (button);
+        Top.Add (button);
     }
 }

+ 2 - 2
UICatalog/Scenarios/GraphViewExample.cs

@@ -133,7 +133,7 @@ public class GraphViewExample : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _graphView = new GraphView
         {
@@ -179,7 +179,7 @@ public class GraphViewExample : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
     }
 
     private void EnableDiagnostics ()

+ 2 - 2
UICatalog/Scenarios/HexEditor.cs

@@ -74,7 +74,7 @@ public class HexEditor : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _statusBar = new StatusBar (
                                     new []
@@ -101,7 +101,7 @@ public class HexEditor : Scenario
                                                                             )
                                     }
                                    );
-        Application.Top.Add (_statusBar);
+        Top.Add (_statusBar);
     }
 
     private void _hexView_Edited (object sender, HexViewEditEventArgs e) { _saved = false; }

+ 24 - 23
UICatalog/Scenarios/HotKeys.cs

@@ -12,21 +12,22 @@ public class HotKeys : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-        Application.Top.BorderStyle = LineStyle.RoundedDotted;
-        Application.Top.Title = $"{Application.QuitKey} to _Quit - Scenario: {GetName ()}";
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top.BorderStyle = LineStyle.RoundedDotted;
+        Top.Title = $"{Application.QuitKey} to _Quit - Scenario: {GetName ()}";
     }
 
     public override void Run ()
     {
         var textViewLabel = new Label { Text = "_TextView:", X = 0, Y = 0 };
-        Application.Top.Add (textViewLabel);
+        Top.Add (textViewLabel);
         
         var textField = new TextField (){ X = Pos.Right (textViewLabel) + 1, Y = 0, Width = 10 };
-        Application.Top.Add (textField);
+        Top.Add (textField);
 
         var viewLabel = new Label { Text = "_View:", X = 0, Y = Pos.Bottom (textField) + 1 };
-        Application.Top.Add (viewLabel);
+        Top.Add (viewLabel);
 
         var view = new View () { 
             Title = "View (_focusable)", 
@@ -35,10 +36,10 @@ public class HotKeys : Scenario
             X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (view);
+        Top.Add (view);
 
         viewLabel = new Label { Text = "Vi_ew:", X = 0, Y = Pos.Bottom (view) + 1 };
-        Application.Top.Add (viewLabel);
+        Top.Add (viewLabel);
 
         view = new View ()
         {
@@ -47,10 +48,10 @@ public class HotKeys : Scenario
             X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (view);
+        Top.Add (view);
 
         var labelWithFrameLabel = new Label { Text = "_Label with Frame:", X = 0, Y = Pos.Bottom (view) + 1 };
-        Application.Top.Add (labelWithFrameLabel);
+        Top.Add (labelWithFrameLabel);
 
         var labelWithFrameFocusable = new Label ()
         {
@@ -60,10 +61,10 @@ public class HotKeys : Scenario
             X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (labelWithFrameFocusable);
+        Top.Add (labelWithFrameFocusable);
 
         labelWithFrameLabel = new Label { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 };
-        Application.Top.Add (labelWithFrameLabel);
+        Top.Add (labelWithFrameLabel);
 
         var labelWithFrame = new Label ()
         {
@@ -72,11 +73,11 @@ public class HotKeys : Scenario
             X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (labelWithFrame);
+        Top.Add (labelWithFrame);
 
         
         var buttonWithFrameLabel = new Label { Text = "_Button with Frame:", X = 0, Y = Pos.Bottom (labelWithFrame) + 1 };
-        Application.Top.Add (buttonWithFrameLabel);
+        Top.Add (buttonWithFrameLabel);
 
         var buttonWithFrameFocusable = new Button ()
         {
@@ -86,10 +87,10 @@ public class HotKeys : Scenario
             X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (buttonWithFrameFocusable);
+        Top.Add (buttonWithFrameFocusable);
 
         buttonWithFrameLabel = new Label { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 };
-        Application.Top.Add (buttonWithFrameLabel);
+        Top.Add (buttonWithFrameLabel);
 
         var buttonWithFrame = new Button ()
         {
@@ -99,12 +100,12 @@ public class HotKeys : Scenario
             CanFocus = false,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (buttonWithFrame);
+        Top.Add (buttonWithFrame);
 
 
 
         var checkboxWithFrameLabel = new Label { Text = "_Checkbox with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrame) + 1 };
-        Application.Top.Add (checkboxWithFrameLabel);
+        Top.Add (checkboxWithFrameLabel);
 
         var checkboxWithFrameFocusable = new CheckBox
         {
@@ -114,10 +115,10 @@ public class HotKeys : Scenario
             X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (checkboxWithFrameFocusable);
+        Top.Add (checkboxWithFrameFocusable);
 
         checkboxWithFrameLabel = new Label { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 };
-        Application.Top.Add (checkboxWithFrameLabel);
+        Top.Add (checkboxWithFrameLabel);
 
         var checkboxWithFrame = new CheckBox
         {
@@ -127,12 +128,12 @@ public class HotKeys : Scenario
             CanFocus = false,
             BorderStyle = LineStyle.Dashed,
         };
-        Application.Top.Add (checkboxWithFrame);
+        Top.Add (checkboxWithFrame);
 
 
         var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (1), Text = "_Press me!" };
-        Application.Top.Add (button);
+        Top.Add (button);
 
-        Application.Run (Application.Top);
+        Application.Run (Top);
     }
 }

+ 2 - 2
UICatalog/Scenarios/InteractiveTree.cs

@@ -23,7 +23,7 @@ public class InteractiveTree : Scenario
                 new MenuBarItem ("_File", new MenuItem [] { new ("_Quit", "", Quit) })
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _treeView = new TreeView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) };
         _treeView.KeyDown += TreeView_KeyPress;
@@ -55,7 +55,7 @@ public class InteractiveTree : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
     }
 
     private void AddChildNode ()

+ 7 - 3
UICatalog/Scenarios/LineCanvasExperiment.cs

@@ -8,7 +8,11 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Proof of Concept")]
 public class LineCanvasExperiment : Scenario
 {
-    public override void Init () { Application.Init (); }
+    public override void Init ()
+    {
+        Application.Init ();
+        Top = new ();
+    }
 
     /// <summary>Setup the scenario.</summary>
     public override void Setup ()
@@ -18,7 +22,7 @@ public class LineCanvasExperiment : Scenario
         //	new MenuItem ("_Quit", "", () => Application.RequestStop()),
         //}) });
 
-        //Application.Top.Add (menu);
+        //Top.Add (menu);
 
         var frame1 = new FrameView
         {
@@ -33,7 +37,7 @@ public class LineCanvasExperiment : Scenario
 
         //View.Diagnostics ^= DiagnosticFlags.FrameRuler;
 
-        Application.Top.Add (frame1);
+        Top.Add (frame1);
 
         var win1 = new Window
         {

+ 2 - 2
UICatalog/Scenarios/LineViewExample.cs

@@ -22,7 +22,7 @@ public class LineViewExample : Scenario
                 new MenuBarItem ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         Win.Add (new Label { Y = 0, Text = "Regular Line" });
 
@@ -82,7 +82,7 @@ public class LineViewExample : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
     }
 
     private void Quit () { Application.RequestStop (); }

+ 2 - 2
UICatalog/Scenarios/ListColumns.cs

@@ -208,7 +208,7 @@ public class ListColumns : Scenario
             ]
         };
 
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new StatusItem []
@@ -235,7 +235,7 @@ public class ListColumns : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         Win.Add (_listColView);
 

+ 1 - 1
UICatalog/Scenarios/Localization.cs

@@ -93,7 +93,7 @@ public class Localization : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var selectLanguageLabel = new Label
         {

+ 17 - 16
UICatalog/Scenarios/MenuBarScenario.cs

@@ -199,7 +199,8 @@ public class MenuBarScenario : Scenario
     public override void Init ()
     {
         Application.Init ();
-        Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes ["Base"];
     }
 
     public override void Setup ()
@@ -208,34 +209,34 @@ public class MenuBarScenario : Scenario
         MenuItem miCurrent = null;
 
         var label = new Label { X = 0, Y = 10, Text = "Last Key: " };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         _lastKey = new Label { X = Pos.Right (label), Y = Pos.Top (label), Text = "" };
 
-        Application.Top.Add (_lastKey);
+        Top.Add (_lastKey);
         label = new Label { X = 0, Y = Pos.Bottom (label), Text = "Current MenuBarItem: " };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         _currentMenuBarItem = new Label { X = Pos.Right (label), Y = Pos.Top (label), Text = "" };
-        Application.Top.Add (_currentMenuBarItem);
+        Top.Add (_currentMenuBarItem);
 
         label = new Label { X = 0, Y = Pos.Bottom (label), Text = "Current MenuItem: " };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         _currentMenuItem = new Label { X = Pos.Right (label), Y = Pos.Top (label), Text = "" };
-        Application.Top.Add (_currentMenuItem);
+        Top.Add (_currentMenuItem);
 
         label = new Label { X = 0, Y = Pos.Bottom (label), Text = "Last Action: " };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         _lastAction = new Label { X = Pos.Right (label), Y = Pos.Top (label), Text = "" };
-        Application.Top.Add (_lastAction);
+        Top.Add (_lastAction);
 
         label = new Label { X = 0, Y = Pos.Bottom (label), Text = "Focused View: " };
-        Application.Top.Add (label);
+        Top.Add (label);
 
         _focusedView = new Label { X = Pos.Right (label), Y = Pos.Top (label), Text = "" };
-        Application.Top.Add (_focusedView);
+        Top.Add (_focusedView);
 
         MenuBar menuBar = CreateTestMenu (
                                           s =>
@@ -276,21 +277,21 @@ public class MenuBarScenario : Scenario
                                };
 
         // There's no focus change event, so this is a bit of a hack.
-        menuBar.LayoutComplete += (s, e) => { _focusedView.Text = Application.Top.MostFocused?.ToString () ?? "None"; };
+        menuBar.LayoutComplete += (s, e) => { _focusedView.Text = Top.MostFocused?.ToString () ?? "None"; };
 
         var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefault = true };
         openBtn.Accept += (s, e) => { menuBar.OpenMenu (); };
-        Application.Top.Add (openBtn);
+        Top.Add (openBtn);
 
         var hideBtn = new Button { X = Pos.Center (), Y = Pos.Bottom (openBtn), Text = "Toggle Menu._Visible" };
         hideBtn.Accept += (s, e) => { menuBar.Visible = !menuBar.Visible; };
-        Application.Top.Add (hideBtn);
+        Top.Add (hideBtn);
 
         var enableBtn = new Button { X = Pos.Center (), Y = Pos.Bottom (hideBtn), Text = "_Toggle Menu.Enable" };
         enableBtn.Accept += (s, e) => { menuBar.Enabled = !menuBar.Enabled; };
-        Application.Top.Add (enableBtn);
+        Top.Add (enableBtn);
 
-        Application.Top.Add (menuBar);
+        Top.Add (menuBar);
     }
 
     private void SetCurrentMenuBarItem (MenuItem mbi) { _currentMenuBarItem.Text = mbi != null ? mbi.Title : "Closed"; }

+ 2 - 2
UICatalog/Scenarios/MessageBoxes.cs

@@ -188,10 +188,10 @@ public class MessageBoxes : Scenario
                 + styleRadioGroup.Frame.Height
                 + ckbWrapMessage.Frame.Height
                 + frame.GetAdornmentsThickness ().Vertical;
-            Application.Top.Loaded -= Top_LayoutComplete;
+            Top.Loaded -= Top_LayoutComplete;
         }
 
-        Application.Top.LayoutComplete += Top_LayoutComplete;
+        Top.LayoutComplete += Top_LayoutComplete;
 
         label = new Label
         {

+ 2 - 2
UICatalog/Scenarios/MultiColouredTable.cs

@@ -29,7 +29,7 @@ public class MultiColouredTable : Scenario
                 new MenuBarItem ("_File", new MenuItem [] { new ("_Quit", "", () => Quit ()) })
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new StatusItem []
@@ -41,7 +41,7 @@ public class MultiColouredTable : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         Win.Add (_tableView);
 

+ 6 - 5
UICatalog/Scenarios/Notepad.cs

@@ -19,7 +19,8 @@ public class Notepad : Scenario
     public override void Init ()
     {
         Application.Init ();
-        Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes ["Base"];
     }
 
     public void Save () { Save (_focusedTabView, _focusedTabView.SelectedTab); }
@@ -108,7 +109,7 @@ public class Notepad : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _tabView = CreateNewTabView ();
 
@@ -120,7 +121,7 @@ public class Notepad : Scenario
         split.Tiles.ElementAt (0).ContentView.Add (_tabView);
         split.LineStyle = LineStyle.None;
 
-        Application.Top.Add (split);
+        Top.Add (split);
 
         _lenStatusItem = new StatusItem (KeyCode.CharMask, "Len: ", null);
 
@@ -146,8 +147,8 @@ public class Notepad : Scenario
         _tabView.SelectedTabChanged += TabView_SelectedTabChanged;
         _tabView.Enter += (s, e) => _focusedTabView = _tabView;
 
-        Application.Top.Add (statusBar);
-        Application.Top.Ready += (s, e) => New ();
+        Top.Add (statusBar);
+        Top.Ready += (s, e) => New ();
     }
 
     private void Close () { Close (_focusedTabView, _focusedTabView.SelectedTab); }

+ 5 - 3
UICatalog/Scenarios/ProgressBarStyles.cs

@@ -27,6 +27,8 @@ public class ProgressBarStyles : Scenario
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
 
+        Top = new ();
+
         var editor = new AdornmentsEditor
         {
             Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}", BorderStyle = LineStyle.Single
@@ -72,7 +74,7 @@ public class ProgressBarStyles : Scenario
 
                                          dialog.Bounds = new Rectangle (0, 0, colorPicker.Frame.Width, colorPicker.Frame.Height);
 
-                                         Application.Top.LayoutSubviews ();
+                                         Top.LayoutSubviews ();
                                      };
 
             dialog.Add (colorPicker);
@@ -275,7 +277,7 @@ public class ProgressBarStyles : Scenario
                                  300
                                 );
 
-        Application.Top.Unloaded += Top_Unloaded;
+        Top.Unloaded += Top_Unloaded;
 
         void Top_Unloaded (object sender, EventArgs args)
         {
@@ -291,7 +293,7 @@ public class ProgressBarStyles : Scenario
                 _pulseTimer = null;
             }
 
-            Application.Top.Unloaded -= Top_Unloaded;
+            Top.Unloaded -= Top_Unloaded;
         }
 
         Application.Run (editor);

+ 6 - 3
UICatalog/Scenarios/RunTExample.cs

@@ -6,13 +6,16 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Top Level Windows")]
 public class RunTExample : Scenario
 {
-    public override void Run () { Application.Run<ExampleWindow> (); }
-
-    public override void Setup ()
+    public override void Init ()
     {
         // No need to call Init if Application.Run<T> is used
+        Application.Run<ExampleWindow> ();
+
+        Application.Top.Dispose ();
     }
 
+    public override void Run () { }
+
     public class ExampleWindow : Window
     {
         private readonly TextField _usernameText;

+ 4 - 2
UICatalog/Scenarios/RuneWidthGreaterThanOne.cs

@@ -21,6 +21,8 @@ public class RuneWidthGreaterThanOne : Scenario
     {
         Application.Init ();
 
+        Top = new ();
+
         var menu = new MenuBar
         {
             Menus =
@@ -85,13 +87,13 @@ public class RuneWidthGreaterThanOne : Scenario
         };
         _win = new Window { X = 5, Y = 5, Width = Dim.Fill (22), Height = Dim.Fill (5) };
         _win.Add (_label, _text, _button, _labelR, _labelV);
-        Application.Top.Add (menu, _win);
+        Top.Add (menu, _win);
 
         WideRunes ();
 
         //NarrowRunes ();
         //MixedRunes ();
-        Application.Run ();
+        Application.Run (Top);
     }
 
     public override void Run () { }

+ 4 - 4
UICatalog/Scenarios/Scrolling.cs

@@ -78,10 +78,10 @@ public class Scrolling : Scenario
             verticalRuler.Text =
                 vrule.Repeat ((int)Math.Ceiling (verticalRuler.Bounds.Height * 2 / (double)rule.Length))
                     [..(verticalRuler.Bounds.Height * 2)];
-            Application.Top.Loaded -= Top_Loaded;
+            Top.Loaded -= Top_Loaded;
         }
 
-        Application.Top.Loaded += Top_Loaded;
+        Top.Loaded += Top_Loaded;
 
         var pressMeButton = new Button { X = 3, Y = 3, Text = "Press me!" };
         pressMeButton.Accept += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
@@ -270,9 +270,9 @@ public class Scrolling : Scenario
         void Top_Unloaded (object sender, EventArgs args)
         {
             pulsing = false;
-            Application.Top.Unloaded -= Top_Unloaded;
+            Top.Unloaded -= Top_Unloaded;
         }
 
-        Application.Top.Unloaded += Top_Unloaded;
+        Top.Unloaded += Top_Unloaded;
     }
 }

+ 8 - 7
UICatalog/Scenarios/SingleBackgroundWorker.cs

@@ -12,15 +12,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Top Level Windows")]
 public class SingleBackgroundWorker : Scenario
 {
-    public override void Run ()
+    public override void Init ()
     {
-        Application.Top.Dispose ();
-
         Application.Run<MainApp> ();
 
         Application.Top.Dispose ();
     }
 
+    public override void Run () { }
+
     public class MainApp : Toplevel
     {
         private readonly ListView _listLog;
@@ -195,9 +195,12 @@ public class SingleBackgroundWorker : Scenario
 
                                                   var builderUI =
                                                       new StagingUIController (_startStaging, e.Result as List<string>);
+                                                  var top = Application.Top;
+                                                  top.Visible = false;
+                                                  Application.Current.Visible = false;
                                                   builderUI.Load ();
                                                   builderUI.Dispose ();
-
+                                                  top.Visible = true;
                                               }
 
                                               _worker = null;
@@ -214,11 +217,9 @@ public class SingleBackgroundWorker : Scenario
 
         public StagingUIController (DateTime? start, List<string> list)
         {
-            Rectangle frame = Application.Top.Frame;
             _top = new Toplevel
             {
-                Title = "_top", 
-                X = frame.X, Y = frame.Y, Width = frame.Width, Height = frame.Height
+                Title = "_top", Width = Dim.Fill (), Height = Dim.Fill ()
             };
 
             _top.KeyDown += (s, e) =>

+ 1 - 1
UICatalog/Scenarios/Sliders.cs

@@ -477,6 +477,6 @@ public class Sliders : Scenario
         #endregion Config Slider
 
         Win.FocusFirst ();
-        Application.Top.Initialized += (s, e) => Application.Top.LayoutSubviews ();
+        Top.Initialized += (s, e) => Top.LayoutSubviews ();
     }
 }

+ 2 - 2
UICatalog/Scenarios/SpinnerStyles.cs

@@ -159,7 +159,7 @@ public class SpinnerViewStyles : Scenario
 
         ckbBounce.Toggled += (s, e) => { spinner.SpinBounce = (bool)!e.OldValue; };
 
-        Application.Top.Unloaded += Top_Unloaded;
+        Top.Unloaded += Top_Unloaded;
 
         void SetCustom ()
         {
@@ -200,7 +200,7 @@ public class SpinnerViewStyles : Scenario
                 spinner = null;
             }
 
-            Application.Top.Unloaded -= Top_Unloaded;
+            Top.Unloaded -= Top_Unloaded;
         }
     }
 

+ 2 - 2
UICatalog/Scenarios/SyntaxHighlighting.cs

@@ -164,7 +164,7 @@ public class SyntaxHighlighting : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _textView = new TextView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
 
@@ -183,7 +183,7 @@ public class SyntaxHighlighting : Scenario
                                        }
                                       );
 
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
     }
 
     /// <summary>

+ 2 - 2
UICatalog/Scenarios/TabViewExample.cs

@@ -67,7 +67,7 @@ public class TabViewExample : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _tabView = new TabView
         {
@@ -181,7 +181,7 @@ public class TabViewExample : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
     }
 
     private void AddBlankTab () { _tabView.AddTab (new Tab (), false); }

+ 2 - 2
UICatalog/Scenarios/TableEditor.cs

@@ -669,7 +669,7 @@ public class TableEditor : Scenario
             ]
         };
 
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new StatusItem []
@@ -696,7 +696,7 @@ public class TableEditor : Scenario
                                                )
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         Win.Add (_tableView);
 

+ 1 - 1
UICatalog/Scenarios/TextFormatterDemo.cs

@@ -57,7 +57,7 @@ public class TextFormatterDemo : Scenario
             X = 0,
             Y = Pos.Bottom (blockText) + 1,
             Text = "Unicode",
-            Checked = Application.Top.HotKeySpecifier == (Rune)' '
+            Checked = Top.HotKeySpecifier == (Rune)' '
         };
 
         Win.Add (unicodeCheckBox);

+ 2 - 2
UICatalog/Scenarios/TextViewAutocompletePopup.cs

@@ -51,7 +51,7 @@ public class TextViewAutocompletePopup : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         _textViewTopLeft = new TextView { Width = width, Height = _height, Text = text };
         _textViewTopLeft.DrawContent += TextViewTopLeft_DrawContent;
@@ -105,7 +105,7 @@ public class TextViewAutocompletePopup : Scenario
                                            _siWrap = new StatusItem (KeyCode.Null, "", null)
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         Win.LayoutStarted += Win_LayoutStarted;
     }

+ 2 - 2
UICatalog/Scenarios/Threading.cs

@@ -118,10 +118,10 @@ public class Threading : Scenario
         void Top_Loaded (object sender, EventArgs args)
         {
             _btnActionCancel.SetFocus ();
-            Application.Top.Loaded -= Top_Loaded;
+            Top.Loaded -= Top_Loaded;
         }
 
-        Application.Top.Loaded += Top_Loaded;
+        Top.Loaded += Top_Loaded;
     }
 
     private async void CallLoadItemsAsync ()

+ 1 - 1
UICatalog/Scenarios/TileViewNesting.cs

@@ -62,7 +62,7 @@ public class TileViewNesting : Scenario
 
         SetupTileView ();
 
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         Win.Loaded += (s, e) => _loaded = true;
     }

+ 2 - 2
UICatalog/Scenarios/TreeUseCases.cs

@@ -47,7 +47,7 @@ public class TreeUseCases : Scenario
             ]
         };
 
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new StatusItem []
@@ -60,7 +60,7 @@ public class TreeUseCases : Scenario
                                        }
                                       );
 
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         // Start with the most basic use case
         LoadSimpleNodes ();

+ 1 - 1
UICatalog/Scenarios/TreeViewFileSystem.cs

@@ -172,7 +172,7 @@ public class TreeViewFileSystem : Scenario
                                 )
             ]
         };
-        Application.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;

+ 2 - 2
UICatalog/Scenarios/Unicode.cs

@@ -60,7 +60,7 @@ public class UnicodeInMenu : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top.Add (menu);
 
         var statusBar = new StatusBar (
                                        new StatusItem []
@@ -74,7 +74,7 @@ public class UnicodeInMenu : Scenario
                                            new (KeyCode.Null, "~F3~ Со_хранить", null)
                                        }
                                       );
-        Application.Top.Add (statusBar);
+        Top.Add (statusBar);
 
         var label = new Label { X = 0, Y = 1, Text = "Label:" };
         Win.Add (label);

+ 8 - 7
UICatalog/Scenarios/ViewExperiments.cs

@@ -14,7 +14,8 @@ public class ViewExperiments : Scenario
         Application.Init ();
         ConfigurationManager.Themes.Theme = Theme;
         ConfigurationManager.Apply ();
-        Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
+        Top = new ();
+        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
     }
 
     public override void Setup ()
@@ -27,7 +28,7 @@ public class ViewExperiments : Scenario
             Width = Dim.Fill (),
             Height = 3
         };
-        Application.Top.Add (containerLabel);
+        Top.Add (containerLabel);
 
         var view = new View
         {
@@ -40,7 +41,7 @@ public class ViewExperiments : Scenario
             Id = "DaView"
         };
 
-        //Application.Top.Add (view);
+        //Top.Add (view);
 
         view.Margin.Thickness = new Thickness (2, 2, 2, 2);
         view.Margin.ColorScheme = Colors.ColorSchemes ["Toplevel"];
@@ -216,9 +217,9 @@ public class ViewExperiments : Scenario
                                {
                                    containerLabel.Text =
                                        $"Container.Frame: {
-                                           Application.Top.Frame
+                                           Top.Frame
                                        } .Bounds: {
-                                           Application.Top.Bounds
+                                           Top.Bounds
                                        }\nView.Frame: {
                                            view.Frame
                                        } .Bounds: {
@@ -243,11 +244,11 @@ public class ViewExperiments : Scenario
             ViewToEdit = view
         };
 
-        Application.Top.Add (editor);
+        Top.Add (editor);
         view.X = 36;
         view.Y = 4;
         view.Width = Dim.Fill ();
         view.Height = Dim.Fill ();
-        Application.Top.Add (view);
+        Top.Add (view);
     }
 }

+ 5 - 5
UICatalog/Scenarios/WindowsAndFrameViews.cs

@@ -27,7 +27,7 @@ public class WindowsAndFrameViews : Scenario
         List<View> listWin = new ();
 
         //Ignore the Win that UI Catalog created and create a new one
-        Application.Top.Remove (Win);
+        Top.Remove (Win);
         Win?.Dispose ();
 
         Win = new Window
@@ -61,7 +61,7 @@ public class WindowsAndFrameViews : Scenario
                      Text = "Press ME! (Y = Pos.AnchorEnd(1))"
                  }
                 );
-        Application.Top.Add (Win);
+        Top.Add (Win);
 
         // add it to our list
         listWin.Add (Win);
@@ -130,7 +130,7 @@ public class WindowsAndFrameViews : Scenario
                           );
             win.Add (frameView);
 
-            Application.Top.Add (win);
+            Top.Add (win);
             listWin.Add (win);
         }
 
@@ -212,9 +212,9 @@ public class WindowsAndFrameViews : Scenario
 
         frame.Add (subFrameViewofFV);
 
-        Application.Top.Add (frame);
+        Top.Add (frame);
         listWin.Add (frame);
 
-        Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        Top.ColorScheme = Colors.ColorSchemes ["Base"];
     }
 }

+ 4 - 3
UICatalog/Scenarios/WizardAsView.cs

@@ -52,7 +52,8 @@ public class WizardAsView : Scenario
                                 )
             ]
         };
-        Application.Top.Add (menu);
+        Top = new ();
+        Top.Add (menu);
 
         // No need for a Title because the border is disabled
         var wizard = new Wizard { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
@@ -138,8 +139,8 @@ public class WizardAsView : Scenario
         lastStep.HelpText =
             "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing Esc will cancel.";
 
-        Application.Top.Add (wizard);
-        Application.Run (Application.Top);
+        Top.Add (wizard);
+        Application.Run (Top);
     }
 
     public override void Run ()

+ 2 - 2
UICatalog/Scenarios/Wizards.cs

@@ -81,10 +81,10 @@ public class Wizards : Scenario
         void Top_Loaded (object sender, EventArgs args)
         {
             frame.Height = widthEdit.Frame.Height + heightEdit.Frame.Height + titleEdit.Frame.Height + 2;
-            Application.Top.Loaded -= Top_Loaded;
+            Top.Loaded -= Top_Loaded;
         }
 
-        Application.Top.Loaded += Top_Loaded;
+        Top.Loaded += Top_Loaded;
 
         label = new Label
         {