Browse Source

minor tweaks. ready to go?

Charlie Kindel 5 years ago
parent
commit
773c353df8
3 changed files with 25 additions and 7 deletions
  1. 8 2
      Terminal.Gui/Core/Toplevel.cs
  2. 1 1
      Terminal.Gui/Views/Menu.cs
  3. 16 4
      UICatalog/UICatalog.cs

+ 8 - 2
Terminal.Gui/Core/Toplevel.cs

@@ -229,10 +229,14 @@ namespace Terminal.Gui {
 		public override void Remove (View view)
 		public override void Remove (View view)
 		{
 		{
 			if (this == Application.Top) {
 			if (this == Application.Top) {
-				if (view is MenuBar)
+				if (view is MenuBar) {
+					MenuBar?.Dispose ();
 					MenuBar = null;
 					MenuBar = null;
-				if (view is StatusBar)
+				}
+				if (view is StatusBar) {
 					StatusBar = null;
 					StatusBar = null;
+					StatusBar = null;
+				}
 			}
 			}
 			base.Remove (view);
 			base.Remove (view);
 		}
 		}
@@ -241,7 +245,9 @@ namespace Terminal.Gui {
 		public override void RemoveAll ()
 		public override void RemoveAll ()
 		{
 		{
 			if (this == Application.Top) {
 			if (this == Application.Top) {
+				MenuBar?.Dispose ();
 				MenuBar = null;
 				MenuBar = null;
+				StatusBar?.Dispose ();
 				StatusBar = null;
 				StatusBar = null;
 			}
 			}
 			base.RemoveAll ();
 			base.RemoveAll ();

+ 1 - 1
Terminal.Gui/Views/Menu.cs

@@ -877,7 +877,7 @@ namespace Terminal.Gui {
 				SetNeedsDisplay ();
 				SetNeedsDisplay ();
 				if (previousFocused != null && openMenu != null && previousFocused.ToString () != openCurrentMenu.ToString ())
 				if (previousFocused != null && openMenu != null && previousFocused.ToString () != openCurrentMenu.ToString ())
 					previousFocused?.SuperView?.SetFocus (previousFocused);
 					previousFocused?.SuperView?.SetFocus (previousFocused);
-				openMenu.Dispose ();
+				openMenu?.Dispose ();
 				openMenu = null;
 				openMenu = null;
 				if (lastFocused is Menu) {
 				if (lastFocused is Menu) {
 					lastFocused = null;
 					lastFocused = null;

+ 16 - 4
UICatalog/UICatalog.cs

@@ -78,8 +78,18 @@ namespace UICatalog {
 				return;
 				return;
 			}
 			}
 
 
-			Scenario scenario = GetScenarioToRun ();
-			while (scenario != null) {
+			Scenario scenario;
+			while ((scenario = GetScenarioToRun ()) != null) {
+#if DEBUG_IDISPOSABLE
+				// Validate there are no outstanding Responder-based instances 
+				// after a sceanario was selected to run. This proves the main UI Catalog
+				// 'app' closed cleanly.
+				foreach (var inst in Responder.Instances) {
+					Debug.Assert (inst.WasDisposed);
+				}
+				Responder.Instances.Clear ();
+#endif
+
 				Application.UseSystemConsole = _useSystemConsole;
 				Application.UseSystemConsole = _useSystemConsole;
 				Application.Init ();
 				Application.Init ();
 				scenario.Init (Application.Top, _baseColorScheme);
 				scenario.Init (Application.Top, _baseColorScheme);
@@ -87,16 +97,18 @@ namespace UICatalog {
 				scenario.Run ();
 				scenario.Run ();
 
 
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
+				// After the scenario runs, validate all Responder-based instances
+				// were disposed. This proves the scenario 'app' closed cleanly.
 				foreach (var inst in Responder.Instances) {
 				foreach (var inst in Responder.Instances) {
 					Debug.Assert (inst.WasDisposed);
 					Debug.Assert (inst.WasDisposed);
 				}
 				}
 				Responder.Instances.Clear();
 				Responder.Instances.Clear();
 #endif
 #endif
-
-				scenario = GetScenarioToRun ();
 			}
 			}
 
 
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
+			// This proves that when the user exited the UI Catalog app
+			// it cleaned up properly.
 			foreach (var inst in Responder.Instances) {
 			foreach (var inst in Responder.Instances) {
 				Debug.Assert (inst.WasDisposed);
 				Debug.Assert (inst.WasDisposed);
 			}
 			}