home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / vrml / cp2b2x.exe / DATA.Z / browse < prev    next >
Text File  |  1996-04-23  |  2KB  |  57 lines

  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" "$@"
  4.  
  5. # browse --
  6. # This script generates a directory browser, which lists the working
  7. # directory and allows you to open files or subdirectories by
  8. # double-clicking.
  9. #
  10. # @(#) browse 1.7 95/09/07 11:13:15
  11.  
  12. # Create a scrollbar on the right side of the main window and a listbox
  13. # on the left side.
  14.  
  15. scrollbar .scroll -command ".list yview"
  16. pack .scroll -side right -fill y
  17. listbox .list -yscroll ".scroll set" -relief sunken -width 20 -height 20 \
  18.     -setgrid yes
  19. pack .list -side left -fill both -expand yes
  20. wm minsize . 1 1
  21.  
  22. # The procedure below is invoked to open a browser on a given file;  if the
  23. # file is a directory then another instance of this program is invoked; if
  24. # the file is a regular file then the Mx editor is invoked to display
  25. # the file.
  26.  
  27. proc browse {dir file} {
  28.     global env
  29.     if {[string compare $dir "."] != 0} {set file $dir/$file}
  30.     if [file isdirectory $file] {
  31.     exec browse $file &
  32.     } else {
  33.     if [file isfile $file] {
  34.         if [info exists env(EDITOR)] {
  35.         eval exec $env(EDITOR) $file &
  36.         } else {
  37.         exec xedit $file &
  38.         }
  39.     } else {
  40.         puts stdout "\"$file\" isn't a directory or regular file"
  41.     }
  42.     }
  43. }
  44.  
  45. # Fill the listbox with a list of all the files in the directory (run
  46. # the "ls" command to get that information).
  47.  
  48. if $argc>0 {set dir [lindex $argv 0]} else {set dir "."}
  49. foreach i [exec ls -a $dir] {
  50.     .list insert end $i
  51. }
  52.  
  53. # Set up bindings for the browser.
  54.  
  55. bind all <Control-c> {destroy .}
  56. bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}}
  57.