Class: ModalDialog
- Inherits:
-
Fox::FXDialogBox
- Object
- Fox::FXDialogBox
- ModalDialog
- Includes:
- Fox, Responder
- Defined in:
- lib/piggy-gui/modal_dialog.rb
Overview
Provide a validation hook for ID_ACCEPT action
Direct Known Subclasses
Constant Summary collapse
- Placement =
PIGGY_WINDOW_PLACEMENT
Instance Method Summary collapse
-
#add_ok_cancel_buttons_to(frame) ⇒ Object
utility method for use in subclasses.
-
#execute(placement = Placement) ⇒ Object
Return a boolean.
-
#initialize(*args) ⇒ ModalDialog
constructor
A new instance of ModalDialog.
-
#on_cmd_accept(p1, p2, p3) ⇒ Object
This is the overwrite that integrates the validation hook.
-
#validate ⇒ Object
Overwrite this hook to check conditions and warn.
-
#view2model ⇒ Object
this method will be sent before validation overwrite to perform conversions from view to model.
-
#warn(title, msg) ⇒ Object
utility method for use in validation usage: return condition | warn(‘Warning’, ‘Please …’).
- #yes?(title, question) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ ModalDialog
Returns a new instance of ModalDialog.
12 13 14 15 |
# File 'lib/piggy-gui/modal_dialog.rb', line 12 def initialize(*args) super(*args) FXMAPFUNC(SEL_COMMAND, FXDialogBox::ID_ACCEPT, :on_cmd_accept) end |
Instance Method Details
#add_ok_cancel_buttons_to(frame) ⇒ Object
utility method for use in subclasses
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/piggy-gui/modal_dialog.rb', line 18 def (frame) FXHorizontalSeparator.new(frame, SEPARATOR_GROOVE) = FXHorizontalFrame.new(frame) cancel = FXButton.new(, "&Cancel", nil, self, ID_CANCEL) accept = FXButton.new(, "&Accept", nil, self, ID_ACCEPT, BUTTON_NORMAL|BUTTON_INITIAL|BUTTON_DEFAULT) .setLayoutHints(LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X) .setPackingHints(PACK_UNIFORM_WIDTH) accept.setLayoutHints(LAYOUT_RIGHT) cancel.setLayoutHints(LAYOUT_RIGHT) end |
#execute(placement = Placement) ⇒ Object
Return a boolean
67 68 69 |
# File 'lib/piggy-gui/modal_dialog.rb', line 67 def execute(placement=Placement) return super(placement) != 0 end |
#on_cmd_accept(p1, p2, p3) ⇒ Object
This is the overwrite that integrates the validation hook
32 33 34 35 36 37 38 39 |
# File 'lib/piggy-gui/modal_dialog.rb', line 32 def on_cmd_accept(p1, p2, p3) begin view2model rescue Error => ex warn(ex.to_s, "Error") end onCmdAccept(p1, p2, p3) if validate end |
#validate ⇒ Object
Overwrite this hook to check conditions and warn. Return false to keep dialog open.
48 49 50 |
# File 'lib/piggy-gui/modal_dialog.rb', line 48 def validate true end |
#view2model ⇒ Object
this method will be sent before validation overwrite to perform conversions from view to model
43 44 |
# File 'lib/piggy-gui/modal_dialog.rb', line 43 def view2model end |
#warn(title, msg) ⇒ Object
utility method for use in validation usage: return condition | warn(‘Warning’, ‘Please …’)
54 55 56 57 58 |
# File 'lib/piggy-gui/modal_dialog.rb', line 54 def warn(title, msg) style = MBOX_OK|DECOR_TITLE|DECOR_CLOSE|Placement FXMessageBox::warning(self, style, title, msg) return false end |
#yes?(title, question) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/piggy-gui/modal_dialog.rb', line 60 def yes?(title, question) style = MBOX_YES_NO|DECOR_TITLE|DECOR_CLOSE|Placement answer = FXMessageBox.question(self, style, title, question) return answer == MBOX_CLICKED_YES end |