Class: RubyCurses::Action

Inherits:
Proc
  • Object
show all
Includes:
EventHandler
Defined in:
lib/rbcurse/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 Method Summary collapse

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

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

Returns a new instance of Action.



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

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 Method Details

#actionObject

to adapt this to CMenuitems



74
75
76
# File 'lib/rbcurse/core/include/action.rb', line 74

def action
  self
end

#callObject



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

def call
  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



62
63
64
65
66
67
68
# File 'lib/rbcurse/core/include/action.rb', line 62

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



70
71
72
# File 'lib/rbcurse/core/include/action.rb', line 70

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