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.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/canis/core/widgets/rmenu.rb', line 81 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
111 112 113 114 115 116 117 |
# File 'lib/canis/core/widgets/rmenu.rb', line 111 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
79 80 81 |
# File 'lib/canis/core/widgets/rmenu.rb', line 79 def active_index @active_index end |
#bgcolor ⇒ Object
2011-09-25 V1.3.1
77 78 79 |
# File 'lib/canis/core/widgets/rmenu.rb', line 77 def bgcolor @bgcolor end |
#coffset ⇒ Object
Returns the value of attribute coffset.
73 74 75 |
# File 'lib/canis/core/widgets/rmenu.rb', line 73 def coffset @coffset end |
#col ⇒ Object
Returns the value of attribute col.
72 73 74 |
# File 'lib/canis/core/widgets/rmenu.rb', line 72 def col @col end |
#color ⇒ Object
2011-09-25 V1.3.1
77 78 79 |
# File 'lib/canis/core/widgets/rmenu.rb', line 77 def color @color end |
#color_pair ⇒ Object
2011-09-25 V1.3.1
78 79 80 |
# File 'lib/canis/core/widgets/rmenu.rb', line 78 def color_pair @color_pair end |
#enabled ⇒ Object
Returns the value of attribute enabled.
76 77 78 |
# File 'lib/canis/core/widgets/rmenu.rb', line 76 def enabled @enabled end |
#mnemonic ⇒ Object
changed reader to accessor
80 81 82 |
# File 'lib/canis/core/widgets/rmenu.rb', line 80 def mnemonic @mnemonic end |
#parent ⇒ Object
Returns the value of attribute parent.
69 70 71 |
# File 'lib/canis/core/widgets/rmenu.rb', line 69 def parent @parent end |
#row ⇒ Object
attr_accessor :window
71 72 73 |
# File 'lib/canis/core/widgets/rmenu.rb', line 71 def row @row end |
#text ⇒ Object
changed reader to accessor
80 81 82 |
# File 'lib/canis/core/widgets/rmenu.rb', line 80 def text @text end |
#width ⇒ Object
Returns the value of attribute width.
74 75 76 |
# File 'lib/canis/core/widgets/rmenu.rb', line 74 def width @width end |
Instance Method Details
#command(*args, &block) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/canis/core/widgets/rmenu.rb', line 97 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
177 178 179 |
# File 'lib/canis/core/widgets/rmenu.rb', line 177 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
127 128 129 130 131 132 |
# File 'lib/canis/core/widgets/rmenu.rb', line 127 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
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/canis/core/widgets/rmenu.rb', line 133 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
118 119 120 121 |
# File 'lib/canis/core/widgets/rmenu.rb', line 118 def on_enter #item highlight #@parent.window.wmove @row, @col+1 # 2011-09-25 V1.3.1 NO EFFECT end |
#on_leave ⇒ Object
122 123 124 |
# File 'lib/canis/core/widgets/rmenu.rb', line 122 def on_leave highlight false end |
#repaint ⇒ Object
menuitem.repaint
146 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 |
# File 'lib/canis/core/widgets/rmenu.rb', line 146 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
94 95 96 |
# File 'lib/canis/core/widgets/rmenu.rb', line 94 def to_s "#{@text} #{@accelerator}" end |