Class: Canis::MenuItem
Overview
Items in menus. These will usually result in an action which closes the entire
menubar.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#accelerator(*val) ⇒ Object
add accelerator for a menu item NOTE: accelerator means that the application has tied this string to some action, outside of the menu bar.
-
#active_index ⇒ Object
readonly
2011-09-24 V1.3.1 trying to do a right.
-
#bgcolor ⇒ Object
2011-09-25 V1.3.1.
-
#coffset ⇒ Object
Returns the value of attribute coffset.
-
#col ⇒ Object
Returns the value of attribute col.
-
#color ⇒ Object
2011-09-25 V1.3.1.
-
#color_pair ⇒ Object
2011-09-25 V1.3.1.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#mnemonic ⇒ Object
changed reader to accessor.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#row ⇒ Object
attr_accessor :window.
-
#text ⇒ Object
changed reader to accessor.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #command(*args, &block) ⇒ Object
- #destroy ⇒ Object
-
#fire ⇒ Object
XXX it could be a menu again We should not be firing a :NO_MENUITEMS.
- #highlight(tf = true) ⇒ Object
-
#initialize(text, mnemonic = nil, &block) ⇒ MenuItem
constructor
A new instance of MenuItem.
-
#on_enter ⇒ Object
item.
- #on_leave ⇒ Object
-
#repaint ⇒ Object
menuitem.repaint.
- #to_s ⇒ Object
Constructor Details
#initialize(text, mnemonic = nil, &block) ⇒ MenuItem
Returns a new instance of MenuItem.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/canis/core/widgets/rmenu.rb', line 82 def initialize text, mnemonic=nil, &block @text = text @enabled = true # check for mnem that is not one char, could be an accelerator if mnemonic if mnemonic.length != 1 $log.error "MenuItem #{text} mnemonic #{mnemonic} should be one character. Maybe you meant accelerator? " mnemonic = nil end end @mnemonic = mnemonic instance_eval &block if block_given? end |
Instance Attribute Details
#accelerator(*val) ⇒ Object
add accelerator for a menu item NOTE: accelerator means that the application has tied this string to some action, outside of the menu bar. It does not mean that the menu bar will trigger the action. So the app still has to define the action and bind a key to that accelerator. This is only informative. Had to do this since dsl_accessor was throwing some nilclass does not have []= nomethod error This allows user to put accelerator inside dsl block
112 113 114 115 116 117 118 |
# File 'lib/canis/core/widgets/rmenu.rb', line 112 def accelerator(*val) if val.empty? return @accelerator else @accelerator = val[0] end end |
#active_index ⇒ Object (readonly)
2011-09-24 V1.3.1 trying to do a right
80 81 82 |
# File 'lib/canis/core/widgets/rmenu.rb', line 80 def active_index @active_index end |
#bgcolor ⇒ Object
2011-09-25 V1.3.1
78 79 80 |
# File 'lib/canis/core/widgets/rmenu.rb', line 78 def bgcolor @bgcolor end |
#coffset ⇒ Object
Returns the value of attribute coffset.
74 75 76 |
# File 'lib/canis/core/widgets/rmenu.rb', line 74 def coffset @coffset end |
#col ⇒ Object
Returns the value of attribute col.
73 74 75 |
# File 'lib/canis/core/widgets/rmenu.rb', line 73 def col @col end |
#color ⇒ Object
2011-09-25 V1.3.1
78 79 80 |
# File 'lib/canis/core/widgets/rmenu.rb', line 78 def color @color end |
#color_pair ⇒ Object
2011-09-25 V1.3.1
79 80 81 |
# File 'lib/canis/core/widgets/rmenu.rb', line 79 def color_pair @color_pair end |
#enabled ⇒ Object
Returns the value of attribute enabled.
77 78 79 |
# File 'lib/canis/core/widgets/rmenu.rb', line 77 def enabled @enabled end |
#mnemonic ⇒ Object
changed reader to accessor
81 82 83 |
# File 'lib/canis/core/widgets/rmenu.rb', line 81 def mnemonic @mnemonic end |
#parent ⇒ Object
Returns the value of attribute parent.
70 71 72 |
# File 'lib/canis/core/widgets/rmenu.rb', line 70 def parent @parent end |
#row ⇒ Object
attr_accessor :window
72 73 74 |
# File 'lib/canis/core/widgets/rmenu.rb', line 72 def row @row end |
#text ⇒ Object
changed reader to accessor
81 82 83 |
# File 'lib/canis/core/widgets/rmenu.rb', line 81 def text @text end |
#width ⇒ Object
Returns the value of attribute width.
75 76 77 |
# File 'lib/canis/core/widgets/rmenu.rb', line 75 def width @width end |
Instance Method Details
#command(*args, &block) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/canis/core/widgets/rmenu.rb', line 98 def command *args, &block $log.debug ">>>command : #{@text} " @command = block if block_given? alert "Command nil or some error! #{text} " unless @command @args = args end |
#destroy ⇒ Object
178 179 180 |
# File 'lib/canis/core/widgets/rmenu.rb', line 178 def destroy #$log.debug "DESTROY menuitem #{@text}" end |
#fire ⇒ Object
XXX it could be a menu again
We should not be firing a :NO_MENUITEMS
128 129 130 131 132 133 |
# File 'lib/canis/core/widgets/rmenu.rb', line 128 def fire $log.debug ">>>fire menuitem : #{@text} #{@command} " @command.call self, *@args if !@command.nil? @parent. return :CLOSE # added 2009-01-02 00:09 to close only actions, not submenus end |
#highlight(tf = true) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/canis/core/widgets/rmenu.rb', line 134 def highlight tf=true if @parent.nil? or @parent.window.nil? #$log.debug "HL XXX #{self} parent nil" #$log.debug "HL XXX #{self} - > #{@parent} parent nil" end if tf @color_pair ||= get_color($reversecolor, @color, @bgcolor) @parent.window.mvchgat(y=@row, x=@col+1, @width, Ncurses::A_REVERSE, @color_pair, nil) else repaint end @parent.window.wrefresh unless @parent.window.nil? ## XXX 2009-01-21 22:00 end |
#on_enter ⇒ Object
item
119 120 121 122 |
# File 'lib/canis/core/widgets/rmenu.rb', line 119 def on_enter #item highlight #@parent.window.wmove @row, @col+1 # 2011-09-25 V1.3.1 NO EFFECT end |
#on_leave ⇒ Object
123 124 125 |
# File 'lib/canis/core/widgets/rmenu.rb', line 123 def on_leave highlight false end |
#repaint ⇒ Object
menuitem.repaint
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/canis/core/widgets/rmenu.rb', line 147 def repaint # menuitem.repaint if @parent.nil? or @parent.window.nil? # return end r = @row c = @col ltext = text ltext = "* No Items *" if text == :NO_MENUITEMS @color_pair = get_color($reversecolor, @color, @bgcolor) #acolor = $reversecolor acolor = @color_pair acolor = get_color($reversecolor, 'green', @bgcolor) if !@enabled # @parent.window.printstring( @row, 0, "|%-*s|" % [@width, ltext], acolor) # changed 2011 2011-09-24 @parent.window.printstring( @row, c, "|%-*s|" % [@width, ltext], acolor) if @enabled # 2010-09-10 23:56 if !@accelerator.nil? # FIXME add c earlier 0 was offset @parent.window.printstring( r, (@width+1)-@accelerator.length, @accelerator, acolor) elsif !@mnemonic.nil? m = @mnemonic ix = text.index(m) || text.index(m.swapcase) if ix charm = text[ix,1] #@parent.window.printstring( r, ix+1, charm, $datacolor) if !ix.nil? # prev line changed since not working in vt100 and vt200 @parent.window.printstring( r, ix+1, charm, $reversecolor, 'reverse') if !ix.nil? end end #@parent.window.wmove r, c # NO EFFECT end end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/canis/core/widgets/rmenu.rb', line 95 def to_s "#{@text} #{@accelerator}" end |