# tcl procs saved on Fri Nov 08 18:11:48 PST 1996

proc fileBox {win filt initfile startdir execproc} {

  set win_title $win
  regsub -all {_} $win_title " " win_title
  set win [translit A-Z a-z $win]
  
  catch {destroy $win}
  toplevel $win
  wm title $win [string range $win_title 1 end]

  wm transient $win .
  set xpos [expr [winfo rootx .]+[winfo width .]/6]
  set ypos [expr [winfo rooty .]+[winfo height .]/6]

  wm geom $win 350x400+${xpos}+$ypos
  wm minsize $win 350 200

  if {[string length $startdir] == 0} {
    set startdir [pwd]
  }

#	text, data (side by side) then list below

  frame $win.td -background antiquewhite
  frame $win.td.t -background antiquewhite
  frame $win.td.d -background antiquewhite
  frame $win.l   -background antiquewhite

  label $win.td.t.l4   -text "Directory:" -anchor w -background antiquewhite
  button $win.td.md -text "Create\nDir" -command "mkDirectory \[$win.td.d.dir get\]" -background lavender -activebackground lavender -activeforeground magenta2
  entry $win.td.d.dir -relief sunken -width 30 -background ivory
  $win.td.d.dir insert 0 $startdir

  label $win.td.t.l1   -text "Filter:" -anchor w -background antiquewhite
  entry $win.td.d.fil  -relief sunken -width 30 -background ivory
  $win.td.d.fil insert 0 $filt

  label $win.l2   -text "Files:" -anchor w -background antiquewhite

  scrollbar $win.l.hor -orient horizontal -command "$win.l.lst xview"  -relief sunken -troughcolor bisque -background ivory -activebackground mistyrose
  scrollbar $win.l.ver -orient vertical   -command "$win.l.lst yview"  -relief sunken -troughcolor bisque -background ivory -activebackground mistyrose
  listbox $win.l.lst -yscroll "$win.l.ver set" -xscroll "$win.l.hor set"  -relief sunken -selectmode single -height 12 -background azure
  selection handle $win.l.lst "handleList1 $win.l.lst NoFilterProc"
  label $win.l3   -text "Selection:" -anchor w -background antiquewhite
  scrollbar $win.scrl -orient horizontal -relief sunken  -command "$win.sel xview" -troughcolor bisque -background ivory -activebackground mistyrose
  entry $win.sel  -relief sunken -xscroll "$win.scrl set" -background ivory
  selInsert $win $initfile
  frame $win.o  -relief sunken -border 1
  button $win.o.ok -text "Ok" -command "fileOK $win \"$execproc\"" -background lavender -activebackground lavender -activeforeground magenta2
  button $win.filter -text "Filter"  -command "fillLst $win \[$win.td.d.fil get\] \[pwd\]" -background lavender -activebackground lavender -activeforeground magenta2
  button $win.can    -text "Cancel" -command "destroy $win" -background white -foreground red -activebackground black -activeforeground yellow

  pack $win.td.t.l4 -side top -fill x
  pack $win.td.t.l1 -side top -fill x
  pack $win.td.d.dir -side top -fill x
  pack $win.td.d.fil -side top -fill x
  pack $win.td.t -side left
  pack $win.td.md -side right 
  pack $win.td.d -side right
  pack $win.td -side top
  
  pack $win.l2 $win.l  $win.l3 -side top -fill x
  
  pack $win.sel -side top -fill x
  pack $win.scrl -side top -fill x
  pack $win.o $win.filter $win.can  -side left -expand 1 -padx 20

  pack $win.l.ver -side right -fill y
  pack $win.l.hor -side bottom -fill x
  pack $win.l.lst -side left   -fill both  -expand 1

  pack $win.o.ok -side left -expand 1 -padx 5

  bind $win.td.d.fil <KeyPress-Return> "$win.filter invoke; break"
  bind $win.td.d.dir <KeyPress-Return> "catch \{cd \[$win.td.d.dir get\]\}; $win.filter invoke; break"
  bind $win.sel <KeyPress-Return> "$win.o.ok   invoke; break"
  bind $win.l.lst <ButtonRelease-1>  "+selInsert $win \"\[$win.td.d.dir get\]/\[%W get \[ %W nearest %y \] \]\" "
  bind $win.l.lst <Double-1>  "selInsert $win \[lindex \[selection get\] 0\];  $win.o.ok invoke; break"
  bind $win <Return> "$win.o.ok invoke; break"

  fillLst $win $filt $startdir
  selection own $win
  focus $win.sel

}

