Code

Merge branch 'master' of git://repo.or.cz/git-gui
[git.git] / git-gui / lib / class.tcl
index 72494c1a1ea51ec004a63f08f2c62db9096c2318..9d298d0dcc7d305eded58911c3c0758e94bb7ab6 100644 (file)
@@ -120,10 +120,21 @@ proc delete_this {{t {}}} {
        if {[namespace exists $t]} {namespace delete $t}
 }
 
-proc make_toplevel {t w} {
-       upvar $t top $w pfx
+proc make_toplevel {t w args} {
+       upvar $t top $w pfx this this
+
+       if {[llength $args] % 2} {
+               error "make_toplevel topvar winvar {options}"
+       }
+       set autodelete 1
+       foreach {name value} $args {
+               switch -exact -- $name {
+               -autodelete {set autodelete $value}
+               default     {error "unsupported option $name"}
+               }
+       }
+
        if {[winfo ismapped .]} {
-               upvar this this
                regsub -all {::} $this {__} w
                set top .$w
                set pfx $top
@@ -132,6 +143,13 @@ proc make_toplevel {t w} {
                set top .
                set pfx {}
        }
+
+       if {$autodelete} {
+               wm protocol $top WM_DELETE_WINDOW "
+                       [list delete_this $this]
+                       [list destroy $top]
+               "
+       }
 }