Annotation of micropolis/src/tk/library/demos/browse, revision 1.1.1.1

1.1       root        1: #!/usr/local/bin/wish -f
                      2: #
                      3: # This script generates a directory browser, which lists the working
                      4: # directory and allows you to open files or subdirectories by
                      5: # double-clicking.
                      6: 
                      7: # Create a scrollbar on the right side of the main window and a listbox
                      8: # on the left side.
                      9: 
                     10: scrollbar .scroll -command ".list yview"
                     11: listbox .list -yscroll ".scroll set" -relief raised -geometry 20x20
                     12: pack append . .scroll {right filly} .list {left expand fill}
                     13: 
                     14: # The procedure below is invoked to open a browser on a given file;  if the
                     15: # file is a directory then another instance of this program is invoked; if
                     16: # the file is a regular file then the Mx editor is invoked to display
                     17: # the file.
                     18: 
                     19: proc browse {dir file} {
                     20:     if {[string compare $dir "."] != 0} {set file $dir/$file}
                     21:     if [file isdirectory $file] {
                     22:        exec browse $file &
                     23:     } else {
                     24:        if [file isfile $file] {
                     25:            exec xedit $file &
                     26:        } else {
                     27:            puts stdout "\"$file\" isn't a directory or regular file"
                     28:        }
                     29:     }
                     30: }
                     31: 
                     32: # Fill the listbox with a list of all the files in the directory (run
                     33: # the "ls" command to get that information).
                     34: 
                     35: if $argc>0 {set dir [lindex $argv 0]} else {set dir "."}
                     36: foreach i [exec ls -a $dir] {
                     37:     .list insert end $i
                     38: }
                     39: 
                     40: # Set up bindings for the browser.
                     41: 
                     42: bind .list <Control-q> {destroy .}
                     43: bind .list <Control-c> {destroy .}
                     44: focus .list
                     45: bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.