Class: MittensUi::FilePicker

Inherits:
Object
  • Object
show all
Defined in:
lib/mittens_ui/file_picker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FilePicker

Returns a new instance of FilePicker.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mittens_ui/file_picker.rb', line 5

def initialize(options={})
  @path = ""
  
  dialog_options = {
    title: "Select File",
    parent: $app_window,
    action: options[:action] || :open,
    buttons: [
      [Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT], 
      [Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL]
    ]
  }.freeze
  
  @dialog = Gtk::FileChooserDialog.new(dialog_options)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/mittens_ui/file_picker.rb', line 3

def path
  @path
end

Instance Method Details

#renderObject



21
22
23
24
25
26
27
# File 'lib/mittens_ui/file_picker.rb', line 21

def render
  if @dialog.run == :accept
    @path = @dialog.filename
  end

  @dialog.destroy
end