Class: ModalDialog

Inherits:
Fox::FXDialogBox
  • Object
show all
Includes:
Fox, Responder
Defined in:
lib/piggy-gui/modal_dialog.rb

Overview

Provide a validation hook for ID_ACCEPT action

Direct Known Subclasses

HtmlGenerationDialog, OptionsDialog

Constant Summary collapse

Placement =
PIGGY_WINDOW_PLACEMENT

Instance Method Summary collapse

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 add_ok_cancel_buttons_to(frame)
  FXHorizontalSeparator.new(frame, SEPARATOR_GROOVE)
  buttons = FXHorizontalFrame.new(frame)
  cancel = FXButton.new(buttons, "&Cancel", nil, self, ID_CANCEL)
  accept = FXButton.new(buttons, "&Accept", nil, self, ID_ACCEPT,
    BUTTON_NORMAL|BUTTON_INITIAL|BUTTON_DEFAULT)
  buttons.setLayoutHints(LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X)
  buttons.setPackingHints(PACK_UNIFORM_WIDTH)
  accept.setLayoutHints(LAYOUT_RIGHT)
  cancel.setLayoutHints(LAYOUT_RIGHT)
  buttons
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

#validateObject

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

#view2modelObject

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

Returns:

  • (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