4
# This script generates a directory browser, which lists the working
5
# directory and allow you to open files or subdirectories by
10
# Create a scrollbar on the right side of the main window and a listbox
13
listbox = TkListbox.new(nil, 'relief'=>'sunken',
14
'width'=>20, 'height'=>20, 'setgrid'=>'yes') {|l|
15
TkScrollbar.new(nil, 'command'=>proc{|*args| l.yview *args}) {|s|
16
pack('side'=>'right', 'fill'=>'y')
17
l.yscrollcommand(proc{|first,last| s.set(first,last)})
20
pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes')
26
# The procedure below is invoked to open a browser on a given file; if the
27
# file is a directory then another instance of this program is invoked; if
28
# the file is a regular file then the Mx editor is invoked to display
31
def browse (dir, file)
32
file = dir + File::Separator + file if dir != '.'
33
type = File.ftype(file)
34
if type == 'directory'
35
system($0 + ' ' + file + ' &')
39
system(ENV['EDITOR'] + ' ' + file + ' &')
41
system('xedit ' + file + ' &')
44
STDOUT.print "\"#{file}\" isn't a directory or regular file"
49
# Fill the listbox with a list of all the files in the directory (run
50
# the "ls" command to get that information).
52
dir = ARGV[0] ? ARGV[0] : '.'
53
open("|ls -a #{dir}", 'r'){|fid| fid.readlines}.each{|fname|
54
listbox.insert('end', fname.chomp)
57
# Set up bindings for the browser.
59
Tk.bind_all('Control-c', proc{root.destroy})
60
listbox.bind('Double-Button-1',
61
proc{TkSelection.get.each{|f| browse dir, f}})