class Canis::MenuItem
Items in menus. These will usually result in an action which closes the entire
menubar.
Attributes
accelerator[W]
active_index[R]
bgcolor[RW]
coffset[RW]
col[RW]
color[RW]
color_pair[RW]
enabled[RW]
mnemonic[RW]
parent[RW]
row[RW]
attr_accessor :window
text[RW]
width[RW]
Public Class Methods
new(text, mnemonic=nil, &block)
click to toggle source
# 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
Public Instance Methods
accelerator(*val)
click to toggle source
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 @example
accelerator "Ctrl-X"
# File lib/canis/core/widgets/rmenu.rb, line 111 def accelerator(*val) if val.empty? return @accelerator else @accelerator = val[0] end end
command(*args, &block)
click to toggle source
# 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()
click to toggle source
# File lib/canis/core/widgets/rmenu.rb, line 177 def destroy #$log.debug "DESTROY menuitem #{@text}" end
fire()
click to toggle source
XXX it could be a menu again We should not be firing a :NO_MENUITEMS
# 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.clear_menus return :CLOSE # added 2009-01-02 00:09 to close only actions, not submenus end
highlight(tf=true)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/canis/core/widgets/rmenu.rb, line 122 def on_leave highlight false end
repaint()
click to toggle source
# 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()
click to toggle source
# File lib/canis/core/widgets/rmenu.rb, line 94 def to_s "#{@text} #{@accelerator}" end