Class: RubyCurses::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcurse/rmenu.rb,
lib/rbcurse/rpopupmenu.rb

Direct Known Subclasses

CheckBoxMenuItem, Menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txt, mnemonic = nil, &block) ⇒ MenuItem

Returns a new instance of MenuItem.



65
66
67
68
69
70
# File 'lib/rbcurse/rmenu.rb', line 65

def initialize text, mnemonic=nil, &block
  @text = text
  @enabled = true
  @mnemonic = mnemonic
  instance_eval &block if block_given?
end

Instance Attribute Details

#acceleratorObject

Returns the value of attribute accelerator.



62
63
64
# File 'lib/rbcurse/rmenu.rb', line 62

def accelerator
  @accelerator
end

#colObject

Returns the value of attribute col.



60
61
62
# File 'lib/rbcurse/rmenu.rb', line 60

def col
  @col
end

#enabledObject

Returns the value of attribute enabled.



63
64
65
# File 'lib/rbcurse/rmenu.rb', line 63

def enabled
  @enabled
end

#mnemonicObject

changed reader to accessor



64
65
66
# File 'lib/rbcurse/rmenu.rb', line 64

def mnemonic
  @mnemonic
end

#parentObject

Returns the value of attribute parent.



57
58
59
# File 'lib/rbcurse/rmenu.rb', line 57

def parent
  @parent
end

#rowObject

attr_accessor :window



59
60
61
# File 'lib/rbcurse/rmenu.rb', line 59

def row
  @row
end

#text(s) ⇒ Object

changed so ampersand can be mnemonic esp when action comes in



64
65
66
# File 'lib/rbcurse/rmenu.rb', line 64

def text
  @text
end

#widthObject

Returns the value of attribute width.



61
62
63
# File 'lib/rbcurse/rmenu.rb', line 61

def width
  @width
end

Instance Method Details

#command(*args, &block) ⇒ Object



74
75
76
77
78
# File 'lib/rbcurse/rmenu.rb', line 74

def command *args, &block 
  $log.debug ">>>command : #{@text} "
  @command = block if block_given?
  @args = args
end

#destroyObject



129
130
131
# File 'lib/rbcurse/rmenu.rb', line 129

def destroy
 $log.debug "DESTRY menuitem #{@text}"
end

#fireObject

XXX it could be a menu again



88
89
90
91
92
93
# File 'lib/rbcurse/rmenu.rb', line 88

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) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rbcurse/rmenu.rb', line 94

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 = $datacolor
    #@parent.window.mvchgat(y=@row, x=1, @width, Ncurses::A_NORMAL, color, nil)
    # above line did not work in vt100, 200 terminals, next works.
    @parent.window.mvchgat(y=@row, x=1, @width, Ncurses::A_REVERSE, $reversecolor, nil)
  else
    repaint
  end
  @parent.window.wrefresh  unless @parent.window.nil? ## XXX 2009-01-21 22:00 
end

#on_enterObject



79
80
81
82
# File 'lib/rbcurse/rmenu.rb', line 79

def on_enter
  $log.debug ">>>on enter menuitem : #{@text} #{@row} #{@width} "
  highlight
end

#on_leaveObject



83
84
85
86
# File 'lib/rbcurse/rmenu.rb', line 83

def on_leave
  $log.debug ">>>on leave menuitem : #{@text} "
  highlight false
end

#repaintObject

menuitem.repaint



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rbcurse/rmenu.rb', line 109

def repaint # menuitem.repaint
  if @parent.nil? or @parent.window.nil?
    $log.debug "repaint #{self} parent nil"
  #  return
  end
  r = @row
  acolor = $reversecolor
  acolor = get_color($reversecolor, 'green', 'white') if !@enabled
  @parent.window.printstring( @row, 0, "|%-*s|" % [@width, text], acolor)
  if !@accelerator.nil?
    @parent.window.printstring( r, (@width+1)-@accelerator.length, @accelerator, acolor)
  elsif !@mnemonic.nil?
    m = @mnemonic
    ix = text.index(m) || text.index(m.swapcase)
    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

#to_sObject



71
72
73
# File 'lib/rbcurse/rmenu.rb', line 71

def to_s
  "#{@text} #{@accelerator}"
end