3 # This script generates a directory browser, which lists the working
4 # directory and allows you to open files or subdirectories by
7 # Create a scrollbar on the right side of the main window and a listbox
12 # The procedure below is invoked to open a browser on a given file; if the
13 # file is a directory then another instance of this program is invoked; if
14 # the file is a regular file then the Mx editor is invoked to display
23 top = if $dirlist.size > 0 then TkToplevel.new else nil end
24 list = TkScrollbox.new(top) {
31 list.insert 'end', *`ls #{dir}`.split
33 # Set up bindings for the browser.
36 list.bind "Control-q", proc{exit}
37 list.bind "Control-c", proc{exit}
38 list.bind "Control-p", proc{
39 print "selection <", TkSelection.get, ">\n"
42 list.bind "Double-Button-1", proc{
43 for i in TkSelection.get.split
44 print "clicked ", i, "\n"
52 def browse (dir, file)
54 if File.directory? file
59 system format("%s %s&", ENV['EDITOR'], file)
61 system "xedit #{file}&"
64 STDERR.print "\"#{file}\" isn't a directory or regular file"
69 # Fill the listbox with a list of all the files in the directory (run
70 # the "ls" command to get that information).