Browse Source

Fixes #2967. Not all views are removing his subviews upon disposing on both versions. (#2968)

Co-authored-by: Tig <[email protected]>
BDisp 1 year ago
parent
commit
8cb10f8f09
2 changed files with 11 additions and 6 deletions
  1. 3 2
      Terminal.Gui/View/View.cs
  2. 8 4
      Terminal.Gui/Views/Wizard/WizardStep.cs

+ 3 - 2
Terminal.Gui/View/View.cs

@@ -495,7 +495,7 @@ namespace Terminal.Gui {
 		protected override void Dispose (bool disposing)
 		{
 			LineCanvas.Dispose ();
-			
+
 			Margin?.Dispose ();
 			Margin = null;
 			Border?.Dispose ();
@@ -513,8 +513,9 @@ namespace Terminal.Gui {
 				Remove (subview);
 				subview.Dispose ();
 			}
-			
+
 			base.Dispose (disposing);
+			System.Diagnostics.Debug.Assert (InternalSubviews.Count == 0);
 		}
 	}
 }

+ 8 - 4
Terminal.Gui/Views/Wizard/WizardStep.cs

@@ -1,4 +1,4 @@
-namespace Terminal.Gui; 
+namespace Terminal.Gui;
 
 /// <summary>
 /// Represents a basic step that is displayed in a <see cref="Wizard"/>. The <see cref="WizardStep"/> view is divided horizontally in two. On the left is the
@@ -39,7 +39,7 @@ public class WizardStep : FrameView {
 	//private string title = string.Empty;
 
 	// The contentView works like the ContentView in FrameView.
-	private View contentView = new View () { Data = "WizardContentView" };
+	private View contentView = new View () { Id = "WizardContentView" };
 
 	/// <summary>
 	/// Sets or gets help text for the <see cref="WizardStep"/>.If <see cref="WizardStep.HelpText"/> is empty
@@ -185,8 +185,12 @@ public class WizardStep : FrameView {
 		}
 
 		SetNeedsDisplay ();
-		var touched = view.Frame;
-		contentView.Remove (view);
+		var container = view?.SuperView;
+		if (container == this) {
+			base.Remove (view);
+		} else {
+			container?.Remove (view);
+		}
 
 		if (contentView.InternalSubviews.Count < 1) {
 			this.CanFocus = false;