Code

git-gui: Honor rerere.enabled configuration option
[git.git] / lib / class.tcl
index c1291989aa0831af1986c30fff544d9f3678d5c3..9d298d0dcc7d305eded58911c3c0758e94bb7ab6 100644 (file)
@@ -96,7 +96,8 @@ proc method {name params body {deleted {}} {del_body {}}} {
                set n [lindex $n 0]
                if {[regexp -- $n\\M $body]} {
                        if {   [regexp -all -- $n\\M $body] == 1
-                               && [regexp -all -- \\\$$n\\M $body] == 1} {
+                               && [regexp -all -- \\\$$n\\M $body] == 1
+                               && [regexp -all -- \\\$$n\\( $body] == 0} {
                                regsub -all \\\$$n\\M $body "\[set \${this}::$n\]" body
                        } else {
                                append decl { ${this}::} $n { } $n
@@ -119,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
@@ -131,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]
+               "
+       }
 }
 
 
@@ -150,4 +169,3 @@ auto_mkindex_parser::command constructor {name args} {
                [format { [list source [file join $dir %s]]} \
                [file split $scriptFile]] "\n"
 }
-