Upgrade to Tcl/Tk 8.5b2
[msysgit.git] / mingw / lib / tk8.5 / demos / browse
blobced8385d740e89a1563e042f269f2f59a60ee2ad
1 #!/bin/sh
2 # the next line restarts using wish \
3 exec wish "$0" ${1+"$@"}
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.
10 # RCS: @(#) $Id: browse,v 1.5 2003/09/30 14:54:29 dkf Exp $
12 package require Tk
14 # Create a scrollbar on the right side of the main window and a listbox
15 # on the left side.
17 scrollbar .scroll -command ".list yview"
18 pack .scroll -side right -fill y
19 listbox .list -yscroll ".scroll set" -relief sunken -width 20 -height 20 \
20 -setgrid yes
21 pack .list -side left -fill both -expand yes
22 wm minsize . 1 1
24 # The procedure below is invoked to open a browser on a given file; if the
25 # file is a directory then another instance of this program is invoked; if
26 # the file is a regular file then the Mx editor is invoked to display
27 # the file.
29 set browseScript [file join [pwd] $argv0]
30 proc browse {dir file} {
31 global env browseScript
32 if {[string compare $dir "."] != 0} {set file $dir/$file}
33 switch [file type $file] {
34 directory {
35 exec [info nameofexecutable] $browseScript $file &
37 file {
38 if {[info exists env(EDITOR)]} {
39 eval exec $env(EDITOR) $file &
40 } else {
41 exec xedit $file &
44 default {
45 puts stdout "\"$file\" isn't a directory or regular file"
50 # Fill the listbox with a list of all the files in the directory.
52 if {$argc>0} {set dir [lindex $argv 0]} else {set dir "."}
53 foreach i [lsort [glob * .* *.*]] {
54 if {[file type $i] eq "directory"} {
55 # Safe to do since it is still a directory.
56 append i /
58 .list insert end $i
61 # Set up bindings for the browser.
63 bind all <Control-c> {destroy .}
64 bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}}
66 # Local Variables:
67 # mode: tcl
68 # End: