浏览代码

fixed by removing Init calls

Charlie Kindel 2 年之前
父节点
当前提交
87c224297c
共有 2 个文件被更改,包括 9 次插入7 次删除
  1. 7 2
      Terminal.Gui/Core/Application.cs
  2. 2 5
      UICatalog/Scenarios/BackgroundWorkerCollection.cs

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

@@ -816,7 +816,7 @@ namespace Terminal.Gui {
 		{
 			if (toplevel == null) {
 				throw new ArgumentNullException (nameof (toplevel));
-			} else if (toplevel.IsMdiContainer && MdiTop != null) {
+			} else if (toplevel.IsMdiContainer && MdiTop != toplevel && MdiTop != null) {
 				throw new InvalidOperationException ("Only one Mdi Container is allowed.");
 			}
 
@@ -1153,7 +1153,12 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// Runs the application by calling <see cref="Run(Toplevel, Func{Exception, bool})"/> with a new instance of the specified <see cref="Toplevel"/>-derived class
+		/// Runs the application by calling <see cref="Run(Toplevel, Func{Exception, bool})"/> 
+		/// with a new instance of the specified <see cref="Toplevel"/>-derived class.
+		/// <para>
+		/// If <see cref="Init(ConsoleDriver, IMainLoopDriver)"/> has not arleady been called, this function will
+		/// call <see cref="Init(Func{Toplevel}, ConsoleDriver, IMainLoopDriver)"/>.
+		/// </para>
 		/// </summary>
 		public static void Run<T> (Func<Exception, bool> errorHandler = null) where T : Toplevel, new()
 		{

+ 2 - 5
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -14,15 +14,12 @@ namespace UICatalog.Scenarios {
 	public class BackgroundWorkerCollection : Scenario {
 		public override void Init (Toplevel top, ColorScheme colorScheme)
 		{
-			Application.Top.Dispose ();
-
-			Application.Run<MdiMain> ();
-
-			Application.Top.Dispose ();
+			// Do nothing as the call to `Application.Run<MdiMain>` in `Run` implies an `Application.Init()` call.
 		}
 
 		public override void Run ()
 		{
+			Application.Run<MdiMain> ();
 		}
 
 		class MdiMain : Toplevel {