| |
| |
| |
| |
| |
| |
|
|
| |
| namespace eval ::tk::dialog {} |
| namespace eval ::tk::dialog::file {} |
|
|
| |
| namespace eval ::tk::dialog::file::chooseDir { |
| namespace import -force ::tk::msgcat::* |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| proc ::tk::dialog::file::chooseDir:: {args} { |
| variable ::tk::Priv |
| set dataName __tk_choosedir |
| upvar ::tk::dialog::file::$dataName data |
| Config $dataName $args |
|
|
| if {$data(-parent) eq "."} { |
| set w .$dataName |
| } else { |
| set w $data(-parent).$dataName |
| } |
|
|
| |
| |
| if {![winfo exists $w]} { |
| ::tk::dialog::file::Create $w TkChooseDir |
| } elseif {[winfo class $w] ne "TkChooseDir"} { |
| destroy $w |
| ::tk::dialog::file::Create $w TkChooseDir |
| } else { |
| set data(dirMenuBtn) $w.contents.f1.menu |
| set data(dirMenu) $w.contents.f1.menu.menu |
| set data(upBtn) $w.contents.f1.up |
| set data(icons) $w.contents.icons |
| set data(ent) $w.contents.f2.ent |
| set data(okBtn) $w.contents.f2.ok |
| set data(cancelBtn) $w.contents.f2.cancel |
| set data(hiddenBtn) $w.contents.f2.hidden |
| } |
| if {$::tk::dialog::file::showHiddenBtn} { |
| $data(hiddenBtn) configure -state normal |
| grid $data(hiddenBtn) |
| } else { |
| $data(hiddenBtn) configure -state disabled |
| grid remove $data(hiddenBtn) |
| } |
|
|
| |
| $data(okBtn) configure -state normal |
| if {$data(-mustexist)} { |
| $data(ent) configure -validate key \ |
| -validatecommand [list ::tk::dialog::file::chooseDir::IsOK? $w %P] |
| } else { |
| $data(ent) configure -validate none |
| } |
|
|
| |
| |
| |
| |
| |
| |
|
|
| if {[winfo viewable [winfo toplevel $data(-parent)]] } { |
| wm transient $w $data(-parent) |
| } |
|
|
| trace add variable data(selectPath) write \ |
| [list ::tk::dialog::file::SetPath $w] |
| $data(dirMenuBtn) configure \ |
| -textvariable ::tk::dialog::file::${dataName}(selectPath) |
|
|
| set data(filter) "*" |
| set data(previousEntryText) "" |
| ::tk::dialog::file::UpdateWhenIdle $w |
|
|
| |
| |
| |
|
|
| ::tk::PlaceWindow $w widget $data(-parent) |
| wm title $w $data(-title) |
|
|
| |
|
|
| ::tk::SetFocusGrab $w $data(ent) |
| $data(ent) delete 0 end |
| $data(ent) insert 0 $data(selectPath) |
| $data(ent) selection range 0 end |
| $data(ent) icursor end |
|
|
| |
| |
| |
| |
| |
|
|
| vwait ::tk::Priv(selectFilePath) |
|
|
| ::tk::RestoreFocusGrab $w $data(ent) withdraw |
|
|
| |
| |
|
|
| foreach trace [trace info variable data(selectPath)] { |
| trace remove variable data(selectPath) [lindex $trace 0] [lindex $trace 1] |
| } |
| $data(dirMenuBtn) configure -textvariable {} |
|
|
| |
| |
|
|
| return $Priv(selectFilePath) |
| } |
|
|
| |
| |
| |
| |
| proc ::tk::dialog::file::chooseDir::Config {dataName argList} { |
| upvar ::tk::dialog::file::$dataName data |
|
|
| |
| |
| |
| |
| foreach trace [trace info variable data(selectPath)] { |
| trace remove variable data(selectPath) [lindex $trace 0] [lindex $trace 1] |
| } |
|
|
| |
| |
| set specs { |
| {-mustexist "" "" 0} |
| {-initialdir "" "" ""} |
| {-parent "" "" "."} |
| {-title "" "" ""} |
| } |
|
|
| |
| |
| if {![info exists data(selectPath)]} { |
| |
| set data(selectPath) [pwd] |
| } |
|
|
| |
| |
| tclParseConfigSpec ::tk::dialog::file::$dataName $specs "" $argList |
|
|
| if {$data(-title) eq ""} { |
| set data(-title) "[mc "Choose Directory"]" |
| } |
|
|
| |
| |
| |
| set data(-multiple) 0 |
|
|
| |
| |
| |
| if {$data(-initialdir) ne ""} { |
| |
| if {[file isdirectory $data(-initialdir)]} { |
| set old [pwd] |
| cd $data(-initialdir) |
| set data(selectPath) [pwd] |
| cd $old |
| } else { |
| set data(selectPath) [pwd] |
| } |
| } |
|
|
| if {![winfo exists $data(-parent)]} { |
| return -code error -errorcode [list TK LOOKUP WINDOW $data(-parent)] \ |
| "bad window path name \"$data(-parent)\"" |
| } |
| } |
|
|
| |
| |
| proc ::tk::dialog::file::chooseDir::OkCmd {w} { |
| upvar ::tk::dialog::file::[winfo name $w] data |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set selection [$data(icons) selection get] |
| if {[llength $selection] != 0} { |
| set iconText [$data(icons) get [lindex $selection 0]] |
| set iconText [file join $data(selectPath) $iconText] |
| Done $w $iconText |
| } else { |
| set text [$data(ent) get] |
| if {$text eq ""} { |
| return |
| } |
| set text [file join {*}[file split [string trim $text]]] |
| if {![file exists $text] || ![file isdirectory $text]} { |
| |
| |
| |
| |
| if {$text eq $data(previousEntryText)} { |
| set data(previousEntryText) "" |
| Done $w $text |
| } else { |
| set data(previousEntryText) $text |
| } |
| } else { |
| |
| |
| |
| if {$text eq $data(selectPath)} { |
| Done $w $text |
| } else { |
| set data(selectPath) $text |
| } |
| } |
| } |
| return |
| } |
|
|
| |
| |
| proc ::tk::dialog::file::chooseDir::IsOK? {w text} { |
| upvar ::tk::dialog::file::[winfo name $w] data |
|
|
| set ok [file isdirectory $text] |
| $data(okBtn) configure -state [expr {$ok ? "normal" : "disabled"}] |
|
|
| |
| return 1 |
| } |
|
|
| proc ::tk::dialog::file::chooseDir::DblClick {w} { |
| upvar ::tk::dialog::file::[winfo name $w] data |
| set selection [$data(icons) selection get] |
| if {[llength $selection] != 0} { |
| set filenameFragment [$data(icons) get [lindex $selection 0]] |
| set file $data(selectPath) |
| if {[file isdirectory $file]} { |
| ::tk::dialog::file::ListInvoke $w [list $filenameFragment] |
| return |
| } |
| } |
| } |
|
|
| |
| |
| |
| proc ::tk::dialog::file::chooseDir::ListBrowse {w text} { |
| upvar ::tk::dialog::file::[winfo name $w] data |
|
|
| if {$text eq ""} { |
| return |
| } |
|
|
| set file [::tk::dialog::file::JoinFile $data(selectPath) $text] |
| $data(ent) delete 0 end |
| $data(ent) insert 0 $file |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| proc ::tk::dialog::file::chooseDir::Done {w {selectFilePath ""}} { |
| upvar ::tk::dialog::file::[winfo name $w] data |
| variable ::tk::Priv |
|
|
| if {$selectFilePath eq ""} { |
| set selectFilePath $data(selectPath) |
| } |
| if {$data(-mustexist) && ![file isdirectory $selectFilePath]} { |
| return |
| } |
| set Priv(selectFilePath) $selectFilePath |
| } |
|
|