Class: Canis::Action

Inherits:
Proc show all
Defined in:
lib/canis/core/include/action.rb

Overview

encapsulates behaviour allowing centralization

Example

a = Action.new("&New Row") { commands }
a.accelerator "Alt N"
menu.add(a)
b = Button.new form do
  action a
  ...
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config = {}, &block) ⇒ Action

Returns a new instance of Action.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/canis/core/include/action.rb', line 42

def initialize name, config={}, &block
  super &block
  @name = name
  @name.freeze
  @enabled = true
  # removing dependency from config
  #config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
  @config = config
  keys = @config.keys
  keys.each do |e| 
    variable_set(e, @config[e])
  end
  #@_events = [:FIRE]
end

Instance Attribute Details

#acceleratorObject

Returns the value of attribute accelerator.



40
41
42
# File 'lib/canis/core/include/action.rb', line 40

def accelerator
  @accelerator
end

#enabledObject

Returns the value of attribute enabled.



36
37
38
# File 'lib/canis/core/include/action.rb', line 36

def enabled
  @enabled
end

#help_textObject

Returns the value of attribute help_text.



38
39
40
# File 'lib/canis/core/include/action.rb', line 38

def help_text
  @help_text
end

#mnemonicObject

Returns the value of attribute mnemonic.



39
40
41
# File 'lib/canis/core/include/action.rb', line 39

def mnemonic
  @mnemonic
end

#nameObject

once again commented on 2014-04-28 - 14:37 to keep simple include EventHandler # removed 2012-01-3 maybe you can bind FIRE include ConfigSetup # removed 2012-01-3 name used on button or menu



35
36
37
# File 'lib/canis/core/include/action.rb', line 35

def name
  @name
end

#tooltip_textObject

Returns the value of attribute tooltip_text.



37
38
39
# File 'lib/canis/core/include/action.rb', line 37

def tooltip_text
  @tooltip_text
end

Instance Method Details

#actionObject

to adapt this to CMenuitems



77
78
79
# File 'lib/canis/core/include/action.rb', line 77

def action
  self
end

#call(*args) ⇒ Object



56
57
58
59
60
61
# File 'lib/canis/core/include/action.rb', line 56

def call *args
  return unless @enabled
  # seems to be here, if you've bound :FIRE no this, not on any widget
  #fire_handler :FIRE, self  
  super
end

#hotkeyObject

the next 3 are to adapt this to CMenuitems



65
66
67
68
69
70
71
# File 'lib/canis/core/include/action.rb', line 65

def hotkey
  return @mnemonic if @mnemonic
  ix = @name.index('&')
  if ix
    return @name[ix+1, 1].downcase
  end
end

#labelObject

to adapt this to CMenuitems



73
74
75
# File 'lib/canis/core/include/action.rb', line 73

def label
  @name.sub('&','')
end