]> git.zerfleddert.de Git - micropolis/blame - src/tk/library/demos/browse
add simple Makefile in top directory
[micropolis] / src / tk / library / demos / browse
CommitLineData
6a5fa4e0
MG
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
10scrollbar .scroll -command ".list yview"
11listbox .list -yscroll ".scroll set" -relief raised -geometry 20x20
12pack 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
19proc 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
35if $argc>0 {set dir [lindex $argv 0]} else {set dir "."}
36foreach i [exec ls -a $dir] {
37 .list insert end $i
38}
39
40# Set up bindings for the browser.
41
42bind .list <Control-q> {destroy .}
43bind .list <Control-c> {destroy .}
44focus .list
45bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}}
Impressum, Datenschutz