Module: FileChooser

Extended by:
FileChooser
Included in:
FileChooser
Defined in:
lib/file_chooser.rb

Instance Method Summary collapse

Instance Method Details

#choose_file(title, use_this_dir = nil) ⇒ Object

show a popup dialog prompting for them to select a file pretty ugly



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/file_chooser.rb', line 7

def choose_file(title, use_this_dir = nil)

  fc = java.awt.FileDialog.new(nil, title)
  if use_this_dir
    # FileDialog only accepts it a certain way.
    dir = File.expand_path(use_this_dir).gsub(File::Separator, File::ALT_SEPARATOR)
    fc.setDirectory(dir) 
  end
  # lodo allow for a FileFilter, too...
  Thread.new { sleep 2; fc.to_front } # it gets hidden, unfortunately, so try and bring it again to the front...
  fc.show
  if fc.get_file
    out = fc.get_directory + fc.get_file
  end
  fc.remove_notify # allow out app to exit
  out
end