Class: DirChooser

Inherits:
Fox::FXHorizontalFrame
  • Object
show all
Includes:
Fox
Defined in:
lib/piggy-gui/dir_chooser.rb

Overview

Combobox like input field to choose an existing directory

Instance Method Summary collapse

Constructor Details

#initialize(owner, init_value, &on_changed_dir) ⇒ DirChooser

Returns a new instance of DirChooser.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/piggy-gui/dir_chooser.rb', line 10

def initialize(owner, init_value, &on_changed_dir)
  super(owner, FRAME_NONE, 0, 0, 0 , 0, 0, 0, 0, 0) {}
  @field = FXTextField.new(self, 32)
  @button = FXButton.new(self, '...')
  @block = on_changed_dir
  @shell = WinShell.instance
  connect_button_to_field
  init_layout
  set_path(init_value)
  @field.connect(SEL_COMMAND) {
    @block.call(get_path)
  }
end

Instance Method Details

#connect_button_to_fieldObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/piggy-gui/dir_chooser.rb', line 28

def connect_button_to_field
  @button.connect(SEL_COMMAND) {
    dialog = FXDirDialog.new(self, "Choose directory")
    dialog.directory = @field.getText
    unless dialog.execute == 0
      @field.setText(dialog.directory)
      @block.call(get_path)
    end
  }
end

#get_pathObject



39
40
41
# File 'lib/piggy-gui/dir_chooser.rb', line 39

def get_path
  @shell.ruby_path(fox_2_ruby(@field.getText))
end

#init_layoutObject



24
25
26
# File 'lib/piggy-gui/dir_chooser.rb', line 24

def init_layout
  @field.setLayoutHints(LAYOUT_LEFT|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
end

#set_path(value) ⇒ Object



43
44
45
# File 'lib/piggy-gui/dir_chooser.rb', line 43

def set_path(value)
  @field.setText(ruby_2_fox(@shell.os_path(value)))
end