#!../bltwish

source bltDemo.tcl

image create photo activeIcon -file ./images/ofolder.gif
image create photo normalIcon -file ./images/folder.gif

image create photo openGadget -file ./images/mini-book2.gif
image create photo closeGadget -file ./images/mini-book1.gif

image create photo bgTexture -file ./images/rain.gif

set imageList {}
foreach f [glob ./images/mini-*.gif] {
    lappend imageList [image create photo -file $f]
}

#option add *Hierbox.Tile	bgTexture
option add *Hierbox.ScrollTile  yes

option add *xHierbox.openCommand	{
    set path /home/gah/src/blt/%P
    if { [file isdirectory $path] } {
	cd $path
	set files [glob -nocomplain * */. ]
	if { $files != "" } {
	    eval %W insert -at %n end $files
	}
    }
}

option add *xHierbox.closeCommand {
    eval %W delete %n 0 end
}

option add *icons	"normalIcon activeIcon"

hierbox .h  \
    -yscrollcommand { .vs set } \
    -xscrollcommand { .hs set } 

scrollbar .vs -orient vertical -command { .h yview }
scrollbar .hs -orient horizontal -command { .h xview }
table . \
    0,0 .h  -fill both \
    0,1 .vs -fill y \
    1,0 .hs -fill x

table configure . c1 r1 -resize none

cd ..
set top [pwd]
set trim "$top/"
set findCmd "find"

if { [info exists tk_platform] } {
    if { $tk_platform(platform) == "windows" } {
        set trim "f:"
	set findCmd "/Cygnus/B19/H-i386-cygwin32/bin/find"
    }
}

.h configure -separator "/" -trim $trim  -autocreate yes

.h entry configure root -label [file tail $top] 
set cmd { set dirList [bgexec status $findCmd $top] }

.h configure -bg grey90
update
puts stderr starting
if { [catch $cmd  errs] != 0 } {
   error $errs
}
.h configure -bg white
after cancel pending
puts stderr done

puts stderr inserting
eval .h insert end [lsort [split $dirList \n]]
puts stderr done

.h find -glob -name *.gif -exec { 
     %W entry configure %n -image [image create photo -file $top/%P]
}

focus .h
.h sort root -recurse

set nodes [.h find -glob -name *.c]
eval .h entry configure $nodes -labelcolor red 

