Browse Source

Fixes #2987. Set a MdiChild visible to false still processes keystrokes. (#2988)

BDisp 1 year ago
parent
commit
c348cda317
2 changed files with 44 additions and 1 deletions
  1. 1 1
      Terminal.Gui/Core/Application.cs
  2. 43 0
      UnitTests/TopLevels/MdiTests.cs

+ 1 - 1
Terminal.Gui/Core/Application.cs

@@ -531,7 +531,7 @@ namespace Terminal.Gui {
 				return;
 				return;
 			}
 			}
 
 
-			var chain = toplevels.ToList ();
+			var chain = toplevels.Where (t => t.Visible).ToList ();
 			foreach (var topLevel in chain) {
 			foreach (var topLevel in chain) {
 				if (topLevel.ProcessHotKey (ke)) {
 				if (topLevel.ProcessHotKey (ke)) {
 					EnsuresMdiTopOnFrontIfMdiTopMostFocused ();
 					EnsuresMdiTopOnFrontIfMdiTopMostFocused ();

+ 43 - 0
UnitTests/TopLevels/MdiTests.cs

@@ -692,5 +692,48 @@ namespace Terminal.Gui.TopLevelTests {
 
 
 			Assert.Empty (Application.MdiChildes);
 			Assert.Empty (Application.MdiChildes);
 		}
 		}
+
+		[Fact, AutoInitShutdown]
+		public void MdiChild_Set_Visible_False_Does_Not_Process_Keys ()
+		{
+			var count = 0;
+			var mdi = new Mdi ();
+			var button = new Button ();
+			button.Clicked += () => count++;
+			var child = new Window ();
+			child.Add (button);
+			var iterations = -1;
+			Application.Iteration += () => {
+				iterations++;
+				if (iterations == 0) {
+					Application.Run (child);
+				} else if (iterations == 1) {
+					Assert.Equal (child, Application.Current);
+					ReflectionTools.InvokePrivate (
+						typeof (Application),
+						"ProcessKeyEvent",
+						new KeyEvent (Key.Enter, new KeyModifiers ()));
+				} else if (iterations == 2) {
+					Assert.Equal (child, Application.Current);
+					Assert.True (child.Visible);
+					child.Visible = false;
+				} else if (iterations == 3) {
+					Assert.Equal (mdi, Application.Current);
+					ReflectionTools.InvokePrivate (
+						typeof (Application),
+						"ProcessKeyEvent",
+						new KeyEvent (Key.Enter, new KeyModifiers ()));
+				} else if (iterations == 4) {
+					ReflectionTools.InvokePrivate (
+						typeof (Application),
+						"ProcessKeyEvent",
+						new KeyEvent (Application.QuitKey, new KeyModifiers ()));
+				}
+			};
+			Application.Run (mdi);
+			Assert.Equal (4, iterations);
+			Assert.Equal (1, count);
+		}
+
 	}
 	}
 }
 }