Browse Source

Fixes #1529. Mdi container will deal with the visibility of their child's.

BDisp 3 years ago
parent
commit
ad9a64c8fb
1 changed files with 22 additions and 7 deletions
  1. 22 7
      Terminal.Gui/Core/Application.cs

+ 22 - 7
Terminal.Gui/Core/Application.cs

@@ -118,9 +118,9 @@ namespace Terminal.Gui {
 				if (Driver == null) {
 					throw new ArgumentNullException ("The driver must be initialized first.");
 				}
-					Driver.HeightAsBuffer = value;
-				}
+				Driver.HeightAsBuffer = value;
 			}
+		}
 
 		/// <summary>
 		/// Used only by <see cref="NetDriver"/> to forcing always moving the cursor position when writing to the screen.
@@ -893,7 +893,7 @@ namespace Terminal.Gui {
 					MainLoop.MainIteration ();
 					Iteration?.Invoke ();
 
-					EnsureModalAlwaysOnTop (state.Toplevel);
+					EnsureModalOrVisibleAlwaysOnTop (state.Toplevel);
 					if ((state.Toplevel != Current && Current?.Modal == true)
 						|| (state.Toplevel != Current && Current?.Modal == false)) {
 						MdiTop?.OnDeactivate (state.Toplevel);
@@ -931,9 +931,9 @@ namespace Terminal.Gui {
 			}
 		}
 
-		static void EnsureModalAlwaysOnTop (Toplevel toplevel)
+		static void EnsureModalOrVisibleAlwaysOnTop (Toplevel toplevel)
 		{
-			if (!toplevel.Running || toplevel == Current || MdiTop == null || toplevels.Peek ().Modal) {
+			if (!toplevel.Running || (toplevel == Current && toplevel.Visible) || MdiTop == null || toplevels.Peek ().Modal) {
 				return;
 			}
 
@@ -943,6 +943,9 @@ namespace Terminal.Gui {
 					return;
 				}
 			}
+			if (!toplevel.Visible && toplevel == Current) {
+				MoveNext ();
+			}
 		}
 
 		static bool MdiChildNeedsDisplay ()
@@ -1191,7 +1194,14 @@ namespace Terminal.Gui {
 			if (MdiTop != null && !Current.Modal) {
 				lock (toplevels) {
 					toplevels.MoveNext ();
+					var isMdi = false;
 					while (toplevels.Peek () == MdiTop || !toplevels.Peek ().Visible) {
+						if (!isMdi && toplevels.Peek () == MdiTop) {
+							isMdi = true;
+						} else if (isMdi && toplevels.Peek () == MdiTop) {
+							MoveCurrent (Top);
+							break;
+						}
 						toplevels.MoveNext ();
 					}
 					Current = toplevels.Peek ();
@@ -1207,10 +1217,15 @@ namespace Terminal.Gui {
 			if (MdiTop != null && !Current.Modal) {
 				lock (toplevels) {
 					toplevels.MovePrevious ();
+					var isMdi = false;
 					while (toplevels.Peek () == MdiTop || !toplevels.Peek ().Visible) {
-						lock (toplevels) {
-							toplevels.MovePrevious ();
+						if (!isMdi && toplevels.Peek () == MdiTop) {
+							isMdi = true;
+						} else if (isMdi && toplevels.Peek () == MdiTop) {
+							MoveCurrent (Top);
+							break;
 						}
+						toplevels.MovePrevious ();
 					}
 					Current = toplevels.Peek ();
 				}