Browse Source

Merged @bdisp latest fixes

Tig 1 year ago
parent
commit
0b90274a15
2 changed files with 16 additions and 15 deletions
  1. 5 0
      Terminal.Gui/Application.cs
  2. 11 15
      UICatalog/Scenarios/BackgroundWorkerCollection.cs

+ 5 - 0
Terminal.Gui/Application.cs

@@ -1066,6 +1066,11 @@ public static partial class Application
         }
         else
         {
+            if (_topLevels.Count > 1 && _topLevels.Peek () == OverlappedTop && OverlappedChildren.Any (t => t.Visible) is { })
+            {
+                OverlappedMoveNext ();
+            }
+
             Current = _topLevels.Peek ();
 
             if (_topLevels.Count == 1 && Current == OverlappedTop)

+ 11 - 15
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -17,22 +17,22 @@ public class BackgroundWorkerCollection : Scenario
     public override void Main ()
     {
         Application.Run<OverlappedMain> ().Dispose ();
-        Application.Top?.Dispose ();
-        Application.Shutdown ();
 
 #if DEBUG_IDISPOSABLE
         if (Application.OverlappedChildren is { })
         {
             Debug.Assert (Application.OverlappedChildren?.Count == 0);
+            Debug.Assert (Application.Top == Application.OverlappedTop);
         }
 #endif
+
+        Application.Shutdown ();
     }
 
     private class OverlappedMain : Toplevel
     {
         private readonly MenuBar _menu;
         private WorkerApp _workerApp;
-        private bool _canOpenWorkerApp;
 
         public OverlappedMain ()
         {
@@ -105,27 +105,22 @@ public class BackgroundWorkerCollection : Scenario
                                           );
             Add (statusBar);
 
+            Ready += OverlappedMain_Ready;
             Activate += OverlappedMain_Activate;
             Deactivate += OverlappedMain_Deactivate;
-
-            Application.Iteration += (s, a) =>
-                                     {
-                                         if (_canOpenWorkerApp && !_workerApp.Running && Application.OverlappedTop.Running)
-                                         {
-                                             Application.Run (_workerApp);
-                                         }
-                                     };
         }
 
-        private void Menu_MenuOpening (object sender, MenuOpeningEventArgs menu)
+        private void OverlappedMain_Ready (object sender, EventArgs e)
         {
-            if (!_canOpenWorkerApp)
+            if (_workerApp?.Running == false)
             {
-                _canOpenWorkerApp = true;
+                Application.Run (_workerApp);
 
                 return;
             }
-
+        }
+        private void Menu_MenuOpening (object sender, MenuOpeningEventArgs menu)
+        {
             if (menu.CurrentMenu.Title == "_Window")
             {
                 menu.NewMenuBarItem = OpenedWindows ();
@@ -527,6 +522,7 @@ public class BackgroundWorkerCollection : Scenario
         {
             WriteLog ($"Report {obj.Staging.StartStaging}.{obj.Staging.StartStaging:fff} closed.");
             _stagingsUi.Remove (obj);
+            obj.Dispose ();
         }
     }
 }