Class: KeepYourHead::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/Keepyourhead/gui/Action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, name) ⇒ Action

Returns a new instance of Action.



26
27
28
29
30
31
# File 'lib/Keepyourhead/gui/Action.rb', line 26

def initialize(object, name)
  @widgets = []
  @handler_id = {}
  @object = object
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/Keepyourhead/gui/Action.rb', line 24

def name
  @name
end

#objectObject (readonly)

Returns the value of attribute object.



23
24
25
# File 'lib/Keepyourhead/gui/Action.rb', line 23

def object
  @object
end

#procExecuteableObject

Returns the value of attribute procExecuteable.



22
23
24
# File 'lib/Keepyourhead/gui/Action.rb', line 22

def procExecuteable
  @procExecuteable
end

Instance Method Details

#activate(*args) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/Keepyourhead/gui/Action.rb', line 77

def activate(*args)
  if self.executeable? then
    object.actionBefore
    ret = object.send("onAction#{name}", *args)
    object.actionAfter
  else
    ret = nil
  end

  ret
end

#addActivator(widget) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/Keepyourhead/gui/Action.rb', line 37

def addActivator(widget)
  assert( @handler_id[widget] == nil )
  @handler_id[widget] =
    case widget
    when Gtk::MenuItem
      widget.signal_connect("activate") { 
        self.activate
      }
    when Gtk::ToolButton
      widget.signal_connect("clicked") { 
        self.activate
      }
    else
      throw ExceptionNotImplemented
    end
end

#disableObject



62
63
64
# File 'lib/Keepyourhead/gui/Action.rb', line 62

def disable
  widgets.each{ |w| w.sensitive = false }
end

#enableObject



59
60
61
# File 'lib/Keepyourhead/gui/Action.rb', line 59

def enable
  widgets.each{ |w| w.sensitive = true }
end

#executeable?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/Keepyourhead/gui/Action.rb', line 66

def executeable?
  (not self.procExecuteable) || self.procExecuteable.call(object)
end

#removeActivator(widget) ⇒ Object



53
54
55
56
57
# File 'lib/Keepyourhead/gui/Action.rb', line 53

def removeActivator(widget)
  assert( @handler_id[widget] )
  widget.signal_handler_disconnect @handler_id[widget]
  @handler_id.delete widget
end

#updateEnableObject



69
70
71
72
73
74
75
# File 'lib/Keepyourhead/gui/Action.rb', line 69

def updateEnable
  if executeable? then
    enable
  else
    disable
  end
end

#widgetsObject



33
34
35
# File 'lib/Keepyourhead/gui/Action.rb', line 33

def widgets
  @handler_id.keys
end