home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Cayenne Software Inc. 1997
- #
- # File: @(#)dirselectd.tcl /main/titanic/7
- # Author: <generated>
- # Description:
- #---------------------------------------------------------------------------
- # SccsId = @(#)dirselectd.tcl /main/titanic/7 6 Nov 1997 Copyright 1997 Cayenne Software Inc.
-
- # Start user added include file section
- require dirnode.tcl
- # End user added include file section
-
-
- Class DirSelectDialog : {TemplateDialog} {
- constructor
- method destructor
- method popUp
- method selChanged
- method handleOk
- method handleDriveChanged
- method updateTree
- method makeVisible
- attribute directory
- attribute savedDrive
- attribute windows
- attribute update
- attribute firstPopup
- attribute curSelected
- }
-
- constructor DirSelectDialog {class this name} {
- set this [TemplateDialog::constructor $class $this $name]
- $this update 1
- $this firstPopup 1
- # Start constructor user section
- interface DlgColumn $this.c {
- Label dirlbl {
- text "Directory:"
- }
- SingleLineText dirslt { }
- BrowsTree dirtree {
- rowCount 20
- columnCount 30
- }
- }
- if {![string compare $tcl_platform(platform) windows]} {
- $this windows 1
- Label new $this.c.dirlbl -text "Drive:"
- DropDwnList new $this.c.dirdrop
- $this.c.dirdrop config -entrySet [logdrives] \
- -selectionChanged {
- [[%this parent] parent] handleDriveChanged }
- } else {
- $this windows 0
- }
- $this.c.dirtree selectionChanged "$this selChanged"
- $this config -modal yes \
- -okPressed {%this handleOk}
- $this delHelpButton
- $this TemplateDialog::title "Select Directory"
- # End constructor user section
- return $this
- }
-
- method DirSelectDialog::destructor {this} {
- # Start destructor user section
- # End destructor user section
- }
-
- proc DirSelectDialog::hasChildren {dir} {
- set dirs ""
- catch {set dirs [glob -nocomplain [file join $dir *]]}
- foreach subf $dirs {
- if {[file isdirectory $subf] && [file readable $subf]} {
- return 1
- }
- }
- return 0
- }
-
- proc DirSelectDialog::unfold {parent dir} {
- if [catch {$parent tree}] {
- resetErrorVars
- set nrOfNodes [llength [$parent rootSet]]
- set tree $parent
- } else {
- set nrOfNodes [llength [$parent childSet]]
- set tree [$parent tree]
- if {! [[[$tree parent] parent] windows]} {
- $parent foldState 0
- }
- }
- set dial [[$tree parent] parent]
- busy {
- set dirList [glob -nocomplain [file join $dir *]]
- if [lempty $dirList] {
- catch {$parent hasChildren 0}
- return 0
- }
- if [$dial windows] {
- set sortDirList [lsort -command DirSelectDialog::wsort $dirList]
- } else {
- set sortDirList [lsort $dirList]
- }
-
- set notFoundDir 1
- set count 0
- foreach f $sortDirList {
- if {! [file isdirectory $f]} {
- continue
- }
-
- set notFoundDir 0
- set node $parent.$count
- if {! [isCommand $node]} {
- DirNode new $node \
- -icon fld_close_16 \
- -unFolded {
- DirSelectDialog::unfold \
- %this [%this directory]
- }
- if [$dial windows] {
- $node folded {
- foreach el [%this childSet] {
- $el delete
- }
- }
- }
- }
- $node config \
- -label [file tail $f] \
- -directory $f \
- -hasChildren 1
-
- incr count
- }
- for {set node $parent.$count} {$count < $nrOfNodes} {incr count} {
- if [isCommand $node] {
- $node delete
- }
- }
-
- if $notFoundDir {
- catch {$parent hasChildren 0}
- }
- }
- return 1
- }
-
- proc DirSelectDialog::wsort {a b} {
- set a1 [string tolower $a]
- set b1 [string tolower $b]
- return [string compare $a1 $b1]
- }
-
- method DirSelectDialog::popUp {this} {
-
- if {![$this update] && ![$this firstPopup]} {
- $this TemplateDialog::popUp
- return
- }
-
- $this firstPopup 0
-
- busy {
- if [$this windows] {
- foreach el [$this.c.dirtree rootSet] {
- $el delete
- }
- }
- $this updateTree
- $this TemplateDialog::popUp
- $this makeVisible
- $this curSelected [$this.c.dirtree selected]
- if [isCommand [$this curSelected]] {
- [$this curSelected] icon fld_open_16
- [$this curSelected] activeIcon fld_open_16
- }
- }
- }
-
- method DirSelectDialog::selChanged {this} {
- set sel [$this.c.dirtree selected]
- if {$sel == ""} {
- return
- }
- set str [$sel directory]
- if [$this windows] {
- regsub -all / $str \\ str
- }
- $this.c.dirslt text $str
- if [isCommand [$this curSelected]] {
- [$this curSelected] icon fld_close_16
- [$this curSelected] activeIcon fld_close_16
- }
- $this curSelected $sel
- if [isCommand [$this curSelected]] {
- [$this curSelected] icon fld_open_16
- [$this curSelected] activeIcon fld_open_16
- }
- }
-
- method DirSelectDialog::handleOk {this} {
- $this directory [$this.c.dirslt text]
- }
-
- method DirSelectDialog::handleDriveChanged {this} {
- set tr $this.c.dirtree
- set dd $this.c.dirdrop
- busy {
- if [$this windows] {
- foreach el [$tr rootSet] {
- $el delete
- }
- }
- if {! [DirSelectDialog::unfold $tr [$dd selected]]} {
- $dd selected [$this savedDrive]
- DirSelectDialog::unfold $tr [$dd selected]
- }
- catch { $tr selected $tr.0 }
- }
- }
-
- method DirSelectDialog::updateTree {this} {
- set dir [$this directory]
- set pathtype [file pathtype $dir]
- if {![string compare relative $pathtype]} {
- set dir [file join [pwd] $dir]
- } elseif {![string compare volumerelative $pathtype]} {
- set dir [file split $dir]
- lvarpop dir
- set dir [file join [lindex [file split [pwd]] 0] $dir]
- }
- set splitdir [file split $dir]
- if [$this windows] {
- # find drive
- $this.c.dirdrop config -entrySet [logdrives]
- set root [lindex $splitdir 0]
- regsub -all / $root \\ root
- set root [string toupper $root]
- $this.c.dirdrop selected $root
- $this savedDrive $root
- }
- set par $this.c.dirtree
- set el [lvarpop splitdir]
- set growDir $el
- DirSelectDialog::unfold $par $growDir
- set chSet [$par rootSet]
- set nextEl [lvarpop splitdir]
- while {[string length $nextEl] != 0} {
- set growDir [file join $growDir $nextEl]
- set a [string tolower $growDir]
- set found 0
- foreach ch $chSet {
- set b [string tolower [$ch directory]]
- if {![string compare $a $b]} {
- set par $ch
- set found 1
- break
- }
- }
- if $found {
- DirSelectDialog::unfold $par $growDir
- set chSet [$par childSet]
- set nextEl [lvarpop splitdir]
- } else {
- set nextEl ""
- }
- }
- if [string compare $par $this.c.dirtree] {
- $this.c.dirtree selected $par
- } else {
- catch { $this.c.dirtree selected $this.c.dirtree.0 }
- }
- if [$this windows] {
- regsub -all / $growDir \\ search
- } else {
- set search $growDir
- }
- $this.c.dirslt text $search
- }
-
- method DirSelectDialog::makeVisible {this} {
- set sel [$this.c.dirtree selected]
- if {! [isCommand $sel]} {
- return
- }
- $sel foldState 1
- if [$this windows] {
- set rC [$this.c.dirtree rowCount]
- set totalRows 0
- while {$totalRows < $rC} {
- regsub {.*\.} $sel "" cnt
- incr cnt
- incr totalRows $cnt
- set ptSel [$sel parent]
- if {$ptSel != ""} {
- set sel $ptSel
- } else {
- set totalRows $rC
- }
- }
- if {$totalRows > $rC} {
- set idx [expr $totalRows - $rC]
- $sel.$idx makeVisible
- } else {
- $sel makeVisible
- }
- } else {
- $sel makeVisible
- }
- }
-
- # Do not delete this line -- regeneration end marker
-
-