Sfoglia il codice sorgente

Some fixes for the WebConsole support. (#1865)

* Invoking NotifyStopRunState for all situations.

* Added Clicked property to support web console.

* Changing to MoveDown to stay always visible.
BDisp 3 anni fa
parent
commit
250d4af44b

+ 13 - 2
Terminal.Gui/Core/Application.cs

@@ -893,6 +893,8 @@ namespace Terminal.Gui {
 			RootMouseEvent = null;
 			RootKeyEvent = null;
 			Resized = null;
+			NotifyNewRunState = null;
+			NotifyStopRunState = null;
 			_initialized = false;
 			mouseGrabView = null;
 
@@ -1202,7 +1204,9 @@ namespace Terminal.Gui {
 					return;
 				}
 				Current.Running = false;
+				OnNotifyStopRunState (Current);
 				top.Running = false;
+				OnNotifyStopRunState (top);
 			} else if ((MdiTop != null && top != MdiTop && top != Current && Current?.Modal == false
 				&& Current?.Running == true && !top.Running)
 				|| (MdiTop != null && top != MdiTop && top != Current && Current?.Modal == false
@@ -1213,11 +1217,13 @@ namespace Terminal.Gui {
 				&& Current?.Modal == true && top.Modal) {
 				// The Current and the top are both modal so needed to set the Current.Running to false too.
 				Current.Running = false;
+				OnNotifyStopRunState (Current);
 			} else if (MdiTop != null && Current == top && MdiTop?.Running == true && Current?.Running == true && top.Running
 				&& Current?.Modal == true && top.Modal) {
 				// The MdiTop was requested to stop inside a modal toplevel which is the Current and top,
 				// both are the same, so needed to set the Current.Running to false too.
 				Current.Running = false;
+				OnNotifyStopRunState (Current);
 			} else {
 				Toplevel currentTop;
 				if (top == Current || (Current?.Modal == true && !top.Modal)) {
@@ -1234,11 +1240,16 @@ namespace Terminal.Gui {
 					return;
 				}
 				currentTop.Running = false;
-				if (ExitRunLoopAfterFirstIteration)
-					NotifyStopRunState?.Invoke (currentTop);
+				OnNotifyStopRunState (currentTop);
 			}
 		}
 
+		static void OnNotifyStopRunState (Toplevel top)
+		{
+			if (ExitRunLoopAfterFirstIteration)
+				NotifyStopRunState?.Invoke (top);
+		}
+
 		/// <summary>
 		/// Event arguments for the <see cref="Application.Resized"/> event.
 		/// </summary>

+ 9 - 3
Terminal.Gui/Windows/MessageBox.cs

@@ -292,12 +292,12 @@ namespace Terminal.Gui {
 			d.Width = msgboxWidth;
 
 			// Setup actions
-			int clicked = -1;
+			Clicked = -1;
 			for (int n = 0; n < buttonList.Count; n++) {
 				int buttonId = n;
 				var b = buttonList [n];
 				b.Clicked += () => {
-					clicked = buttonId;
+					Clicked = buttonId;
 					Application.RequestStop ();
 				};
 				if (b.IsDefault) {
@@ -307,7 +307,13 @@ namespace Terminal.Gui {
 
 			// Run the modal; do not shutdown the mainloop driver when done
 			Application.Run (d);
-			return clicked;
+			return Clicked;
 		}
+
+		/// <summary>
+		/// The index of the selected button, or -1 if the user pressed ESC to close the dialog.
+		/// This is useful for web based console where by default there is no SynchronizationContext or TaskScheduler.
+		/// </summary>
+		public static int Clicked { get; private set; } = -1;
 	}
 }

+ 1 - 1
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -286,7 +286,7 @@ namespace UICatalog.Scenarios {
 			public void WriteLog (string msg)
 			{
 				log.Add (msg);
-				listLog.MoveEnd ();
+				listLog.MoveDown ();
 			}
 		}