This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch to get rid of error when closing last window


Hi all.

Here is a patch that fixes a problem in Source-Navigator related to closing
of the last main window. The bug was caused by a problem in Itk where
a component in an Itk megawidget would not get destroyed if it was not a
child of the hull. The attached patch fixes the problem and adds test cases
to Itk for the areas that were changed.

This patch has already been submitted to the Itk maintainers at SF. Michael
McLennan's comment on the patch is as follows:

This patch looks good. If you want to apply it to CVS, you have my blessing
and my thanks.

cheers
Mo DeJong

2002-02-19  Mo DeJong  <supermo@bayarea.net>

	* itk/library/Toplevel.itk (destructor):
	* itk/library/Widget.itk (destructor): Remove the
	hull component after destroying the hull.
	Destroy any component that still exists after
	destroying the hull since it must have been
	created outside the hull.
	* itk/tests/toplevel.test:
	* itk/tests/widget.test: Test that a component
	outside the hull is destroyed when the mega-widget
	is destroyed.

Index: itk/library/Toplevel.itk
===================================================================
RCS file: /cvs/src/src/itcl/itk/library/Toplevel.itk,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 Toplevel.itk
--- Toplevel.itk	2001/09/09 19:49:05	1.1.1.2
+++ Toplevel.itk	2002/02/19 23:05:11
@@ -63,6 +63,12 @@
             }
             destroy $itk_hull
         }
+        itk_component delete hull
+
+        # Any remaining components must be outside the hull
+        foreach component [component] {
+            destroy [component $component]
+        }
     }
 
     itk_option define -title title Title "" {
Index: itk/library/Widget.itk
===================================================================
RCS file: /cvs/src/src/itcl/itk/library/Widget.itk,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 Widget.itk
--- Widget.itk	2001/09/09 19:49:05	1.1.1.2
+++ Widget.itk	2002/02/19 23:05:11
@@ -64,6 +64,12 @@
             }
             destroy $itk_hull
         }
+        itk_component delete hull
+
+        # Any remaining components must be outside the hull
+        foreach component [component] {
+            destroy [component $component]
+        }
     }
 
     private variable itk_hull ""
Index: itk/tests/toplevel.test
===================================================================
RCS file: /cvs/src/src/itcl/itk/tests/toplevel.test,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 toplevel.test
--- toplevel.test	2001/09/09 19:49:06	1.1.1.2
+++ toplevel.test	2002/02/19 23:05:11
@@ -79,6 +79,45 @@
     itcl::find objects .testToplevel*
 } {}
 
+test toplevel-1.7 {when an mega-widget object is deleted, its window and any
+        components are destroyed } {
+    TestToplevel .delme
+    set label [.delme component test1]
+    itcl::delete object .delme
+    list [winfo exists .delme] [winfo exists $label]
+} {0 0}
+
+test toplevel-1.8 {when a mega-widget object is deleted, its window and any
+        components are destroyed (even if in another window) } {
+    itcl::class ButtonTop {
+        inherit itk::Toplevel
+
+        constructor {args} {
+            eval itk_initialize $args
+
+	    itk_component add button {
+                button $itk_option(-container).b -text Button
+	    } {}
+            pack $itk_component(button)
+        }
+
+        itk_option define -container container Container {}
+    }
+
+    toplevel .t1
+    ButtonTop .t2 -container .t1
+
+    set button [.t2 component button]
+
+    itcl::delete object .t2
+
+    set result [list $button [winfo exists $button]]
+
+    itcl::delete class ButtonTop
+
+    set result
+} {.t1.b 0}
+
 # ----------------------------------------------------------------------
 #  Clean up
 # ----------------------------------------------------------------------
Index: itk/tests/widget.test
===================================================================
RCS file: /cvs/src/src/itcl/itk/tests/widget.test,v
retrieving revision 1.1.1.2
diff -u -1 -r1.1.1.2 widget.test
--- widget.test	2001/09/09 19:49:06	1.1.1.2
+++ widget.test	2002/02/19 23:06:23
@@ -267,2 +267,38 @@
 
+test widget-1.27 {when a mega-widget object is deleted, its window and any
+        components are destroyed (even if in another window) } {
+    itcl::class ButtonWidget {
+        inherit itk::Widget
+
+        constructor {args} {
+            eval itk_initialize $args
+
+	    itk_component add button {
+                button $itk_option(-container).b -text Button
+	    } {}
+            pack $itk_component(button)
+        }
+
+        itk_option define -container container Container {}
+    }
+
+    toplevel .t1
+    frame .t1.f
+    ButtonWidget .t1.bw -container .t1.f
+
+    pack .t1.f
+    pack .t1.bw
+
+    set button [.t1.bw component button]
+
+    itcl::delete object .t1.bw
+
+    set result [list $button [winfo exists $button]]
+
+    itcl::delete class ButtonWidget
+
+    set result
+} {.t1.f.b 0}
+
+
 # ----------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]