~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/tk/sample/demos-jp/browse1

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env ruby
2
2
 
3
3
# browse --
4
 
# This script generates a directory browser, which lists the working 
5
 
# directory and allow you to open files or subdirectories by 
6
 
# double-clicking. 
 
4
# This script generates a directory browser, which lists the working
 
5
# directory and allow you to open files or subdirectories by
 
6
# double-clicking.
7
7
 
8
8
require 'tk'
9
9
 
10
 
# Create a scrollbar on the right side of the main window and a listbox 
 
10
# Create a scrollbar on the right side of the main window and a listbox
11
11
# on the left side.
12
12
 
13
 
listbox = TkListbox.new(nil, 'relief'=>'sunken', 
 
13
listbox = TkListbox.new(nil, 'relief'=>'sunken',
14
14
                        'width'=>20, 'height'=>20, 'setgrid'=>'yes') {|l|
15
15
  TkScrollbar.new(nil, 'command'=>proc{|*args| l.yview *args}) {|s|
16
16
    pack('side'=>'right', 'fill'=>'y')
23
23
root = TkRoot.new
24
24
root.minsize(1,1)
25
25
 
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 
29
 
# the file. 
 
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
 
29
# the file.
30
30
 
31
31
def browse (dir, file)
32
32
  file = dir + File::Separator + file if dir != '.'
46
46
  end
47
47
end
48
48
 
49
 
# Fill the listbox with a list of all the files in the directory (run 
 
49
# Fill the listbox with a list of all the files in the directory (run
50
50
# the "ls" command to get that information).
51
51
 
52
52
dir = ARGV[0] ?  ARGV[0] : '.'
57
57
# Set up bindings for the browser.
58
58
 
59
59
Tk.bind_all('Control-c', proc{root.destroy})
60
 
listbox.bind('Double-Button-1', 
 
60
listbox.bind('Double-Button-1',
61
61
             proc{TkSelection.get.each{|f| browse dir, f}})
62
62
 
63
63
Tk.mainloop