Code

Merge branch 'master' of git://repo.or.cz/git-gui
[git.git] / git-gui / lib / class.tcl
index 88b056522a866b3acc9620218ec8dfae042d62a2..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]
+               "
+       }
 }
 
 
@@ -151,4 +169,3 @@ auto_mkindex_parser::command constructor {name args} {
                [format { [list source [file join $dir %s]]} \
                [file split $scriptFile]] "\n"
 }
-