Ignore:
Timestamp:
Oct 18, 2010, 11:59:55 AM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/gui/scripts/filechoiceentry.tcl

    r1915 r1923  
    2222
    2323    constructor {owner path args} {
    24         # defined below
     24        # defined below
    2525    }
    2626    destructor {
    27         # defined below
     27        # defined below
    2828    }
    2929    public method value {args}
     
    5555itcl::body Rappture::FileChoiceEntry::constructor {owner path args} {
    5656    if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} {
    57         error "bad object \"$owner\": should be Rappture::ControlOwner"
     57        error "bad object \"$owner\": should be Rappture::ControlOwner"
    5858    }
    5959    set _owner $owner
     
    6565    #
    6666    itk_component add choice {
    67         Rappture::Combobox $itk_interior.choice -editable no
     67        Rappture::Combobox $itk_interior.choice -editable no
    6868    }
    6969    pack $itk_component(choice) -expand yes -fill both
     
    7373    # for each template found.
    7474    foreach cname [$_owner xml children -type pattern $_path] {
    75         set glob [string trim [$_owner xml get $_path.$cname]]
    76         # Successively replace each template with its value.
    77         while { [regexp -indices {@@[^@]*@@} $glob range] } {
    78             foreach {first last} $range break
    79             set i1 [expr $first + 2]
    80             set i2 [expr $last  - 2]
    81             set cpath [string range $glob $i1 $i2]
    82             set value [$_owner xml get $cpath.$cname]
    83             set glob [string replace $glob $first $last $value]
    84             $_owner notify add $this $cpath [itcl::code $this _whenidle]
    85         }
     75        set glob [string trim [$_owner xml get $_path.$cname]]
     76        # Successively replace each template with its value.
     77        while { [regexp -indices {@@[^@]*@@} $glob range] } {
     78            foreach {first last} $range break
     79            set i1 [expr $first + 2]
     80            set i2 [expr $last  - 2]
     81            set cpath [string range $glob $i1 $i2]
     82            set value [$_owner xml get $cpath.$cname]
     83            set glob [string replace $glob $first $last $value]
     84            $_owner notify add $this $cpath [itcl::code $this _whenidle]
     85        }
    8686    }
    8787    $_owner notify sync
     
    110110    set i [lsearch -exact $args -check]
    111111    if {$i >= 0} {
    112         set onlycheck 1
    113         set args [lreplace $args $i $i]
     112        set onlycheck 1
     113        set args [lreplace $args $i $i]
    114114    }
    115115
    116116    if {[llength $args] == 1} {
    117         if {$onlycheck} {
    118             # someday we may add validation...
    119             return
    120         }
    121         set newval [lindex $args 0]
    122         if {[info exists _str2val($newval)]} {
    123             # this is a label -- use it directly
    124             $itk_component(choice) value $newval
    125             set newval $_str2val($newval)  ;# report the actual value
    126         } else {
    127             # this is a value -- search for corresponding label
    128             foreach str [array names _str2val] {
    129                 if {$_str2val($str) == $newval} {
    130                     $itk_component(choice) value $str
    131                     break
    132                 }
    133             }
    134         }
    135         return $newval
     117        if {$onlycheck} {
     118            # someday we may add validation...
     119            return
     120        }
     121        set newval [lindex $args 0]
     122        if {[info exists _str2val($newval)]} {
     123            # this is a label -- use it directly
     124            $itk_component(choice) value $newval
     125            set newval $_str2val($newval)  ;# report the actual value
     126        } else {
     127            # this is a value -- search for corresponding label
     128            foreach str [array names _str2val] {
     129                if {$_str2val($str) == $newval} {
     130                    $itk_component(choice) value $str
     131                    break
     132                }
     133            }
     134        }
     135        return $newval
    136136
    137137    } elseif {[llength $args] != 0} {
    138         error "wrong # args: should be \"value ?-check? ?newval?\""
     138        error "wrong # args: should be \"value ?-check? ?newval?\""
    139139    }
    140140
     
    144144    set str [$itk_component(choice) value]
    145145    if {[info exists _str2val($str)]} {
    146         return $_str2val($str)
     146        return $_str2val($str)
    147147    }
    148148    return $str
     
    158158    set label [$_owner xml get $_path.about.label]
    159159    if {"" == $label} {
    160         set label "Choice"
     160        set label "Choice"
    161161    }
    162162    return $label
     
    196196    set allfiles {}
    197197    foreach cname [$_owner xml children -type pattern $_path] {
    198         set glob [string trim [$_owner xml get $_path.$cname]]
    199         # Successively replace each template with its value.
    200         while { [regexp -indices {@@[^@]*@@} $glob range] } {
    201             foreach {first last} $range break
    202             set i1 [expr $first + 2]
    203             set i2 [expr $last  - 2]
    204             set cpath [string range $glob $i1 $i2]
    205             set value [$_owner xml get $cpath.current]
    206             if { $value == "" } {
    207                 set value [$_owner xml get $cpath.default]
    208             }
    209             set glob [string replace $glob $first $last $value]
    210         }
    211         # Replace the template with the substituted value.
    212         set files [glob -nocomplain -type { r f } $glob]
    213         set allfiles [concat $allfiles $files]
     198        set glob [string trim [$_owner xml get $_path.$cname]]
     199        # Successively replace each template with its value.
     200        while { [regexp -indices {@@[^@]*@@} $glob range] } {
     201            foreach {first last} $range break
     202            set i1 [expr $first + 2]
     203            set i2 [expr $last  - 2]
     204            set cpath [string range $glob $i1 $i2]
     205            set value [$_owner xml get $cpath.current]
     206            if { $value == "" } {
     207                set value [$_owner xml get $cpath.default]
     208            }
     209            set glob [string replace $glob $first $last $value]
     210        }
     211        # Replace the template with the substituted value.
     212        set files [glob -nocomplain -type { r f } $glob]
     213        set allfiles [concat $allfiles $files]
    214214    }
    215215    set first ""
    216216    set tail ""
    217217    foreach file $allfiles {
    218         set tail [file tail $file]
    219         if { $first == "" } {
    220             set first $tail
    221         }
    222         set tail [file root $tail]
    223         $itk_component(choice) choices insert end $file $tail
    224         set _str2val($tail) $file
    225         set len [string length $tail]
    226         if {$len > $max} { set max $len }
     218        set tail [file tail $file]
     219        if { $first == "" } {
     220            set first $tail
     221        }
     222        set tail [file root $tail]
     223        $itk_component(choice) choices insert end $file $tail
     224        set _str2val($tail) $file
     225        set len [string length $tail]
     226        if {$len > $max} { set max $len }
    227227    }
    228228    $itk_component(choice) configure -width $max
     
    254254    set desc $path
    255255    if {$path == ""} {
    256         set desc [$_owner xml get $_path.about.description]
     256        set desc [$_owner xml get $_path.about.description]
    257257    }
    258258
    259259    if {[string length $str] > 0 && [string length $desc] > 0} {
    260         append tip "\n\n$str:\n$desc"
     260        append tip "\n\n$str:\n$desc"
    261261    }
    262262    return $tip
     
    269269    set valid {normal disabled}
    270270    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
    271         error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
     271        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
    272272    }
    273273    $itk_component(choice) configure -state $itk_option(-state)
     
    276276itcl::body Rappture::FileChoiceEntry::_whenidle {} {
    277277    if { !$_rebuildPending } {
    278         after 10 [itcl::code $this _rebuild]
    279         set _rebuildPending 1
    280     }
    281 }
     278        after 10 [itcl::code $this _rebuild]
     279        set _rebuildPending 1
     280    }
     281}
Note: See TracChangeset for help on using the changeset viewer.