Class: DirChooser
- Inherits:
-
Fox::FXHorizontalFrame
- Object
- Fox::FXHorizontalFrame
- DirChooser
- Includes:
- Fox
- Defined in:
- lib/piggy-gui/dir_chooser.rb
Overview
Combobox like input field to choose an existing directory
Instance Method Summary collapse
- #connect_button_to_field ⇒ Object
- #get_path ⇒ Object
- #init_layout ⇒ Object
-
#initialize(owner, init_value, &on_changed_dir) ⇒ DirChooser
constructor
A new instance of DirChooser.
- #set_path(value) ⇒ Object
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 init_layout set_path(init_value) @field.connect(SEL_COMMAND) { @block.call(get_path) } end |
Instance Method Details
#connect_button_to_field ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/piggy-gui/dir_chooser.rb', line 28 def @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_path ⇒ Object
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_layout ⇒ Object
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 |