class Canis::TabbedPane
Attributes
index of tab that is currently open
Public Class Methods
# File lib/canis/core/widgets/rtabbedpane.rb, line 33 def initialize form=nil, config={}, &block @_events ||= [] @_events.push(:PRESS) @button_gap = 2 init_vars super @focusable = true @editable = true @col_offset = 2 raise ArgumentError, "NewTabbedPane : row or col not set: r: #{@row} c: #{@col} " unless @row && @col end
Public Instance Methods
a shortcut for binding a command to a press of an action button The block will be passed This is only relevant if you have asked for buttons to be created, which is only relevant in a TabbedWindow
ActionEvent has source event and action_command
# File lib/canis/core/widgets/rtabbedpane.rb, line 60 def command *args, &block bind :PRESS, *args, &block end
set focus on given component Sometimes you have the handle to component, and you want to move focus to it
# File lib/canis/core/widgets/rtabbedpane.rb, line 323 def goto_component comp return if comp == @current_component leave_current_component @current_component = comp set_form_row end
takes focus to first item (after buttons)
# File lib/canis/core/widgets/rtabbedpane.rb, line 206 def goto_first_item bc = @buttons.count @components[bc..-1].each { |c| if c.focusable leave_current_component @current_component = c set_form_row break end } end
takes focus to last item
# File lib/canis/core/widgets/rtabbedpane.rb, line 219 def goto_last_item bc = @buttons.count f = nil @components[bc..-1].each { |c| if c.focusable f = c end } if f leave_current_component @current_component = f set_form_row end end
take focus to the next component or item Called from DOWN, RIGHT or Tab
# File lib/canis/core/widgets/rtabbedpane.rb, line 235 def goto_next_component if @current_component != nil leave_current_component if on_last_component? @_entered = false return :UNHANDLED end @current_index = @components.index(@current_component) index = @current_index + 1 index.upto(@components.length-1) do |i| f = @components[i] if f.focusable @current_index = i @current_component = f return set_form_row end end end @_entered = false return :UNHANDLED end
take focus to prev component or item Called from LEFT, UP or Back Tab
# File lib/canis/core/widgets/rtabbedpane.rb, line 258 def goto_prev_component if @current_component != nil leave_current_component if on_first_component? @_entered = false return :UNHANDLED end @current_index = @components.index(@current_component) index = @current_index -= 1 index.downto(0) do |i| f = @components[i] if f.focusable @current_index = i @current_component = f return set_form_row end end end return :UNHANDLED end
# File lib/canis/core/widgets/rtabbedpane.rb, line 117 def handle_key ch $log.debug " NEWTABBED handle_key #{ch} " return if @components.empty? _multiplier = ($multiplier == 0 ? 1 : $multiplier ) # should this go here 2011-10-19 unless @_entered $log.warn "WARN: calling ON_ENTER since in this situation it was not called" on_enter end #if ch == KEY_TAB #$log.debug "NEWTABBED GOTO NEXT" #return goto_next_component #elsif ch == KEY_BTAB #return goto_prev_component #end comp = @current_component $log.debug " NEWTABBED handle_key #{ch}: #{comp}" if comp ret = comp.handle_key(ch) $log.debug " NEWTABBED handle_key#{ch}: #{comp} returned #{ret} " if ret != :UNHANDLED comp.repaint # NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL # in repaint of this. return ret end $log.debug "XXX NEWTABBED key unhandled by comp #{comp.name} " else Ncurses.beep $log.warn "XXX NEWTABBED key unhandled NULL comp" end case ch when ?\C-c.getbyte(0) $multiplier = 0 return 0 when ?0.getbyte(0)..?9.getbyte(0) $log.debug " VIM coming here to set multiplier #{$multiplier} " $multiplier *= 10 ; $multiplier += (ch-48) return 0 end ret = process_key ch, self # allow user to map left and right if he wants if ret == :UNHANDLED case ch when KEY_UP, KEY_BTAB # form will pick this up and do needful return goto_prev_component #unless on_first_component? when KEY_LEFT # if i don't check for first component, key will go back to form, # but not be processes. so focussed remain here, but be false. # In case of returnign an unhandled TAB, on_leave will happen and cursor will move to # previous component outside of this. return goto_prev_component unless on_first_component? when KEY_RIGHT, KEY_TAB return goto_next_component #unless on_last_component? when KEY_DOWN if on_a_button? return goto_first_item else return goto_next_component #unless on_last_component? end else #@_entered = false return :UNHANDLED end end $multiplier = 0 return 0 end
insert a tab at index, with title
# File lib/canis/core/widgets/rtabbedpane.rb, line 67 def insert_tab index, title, config={}, &block @tabs.insert(index, Tab.new(title, self, config, &block) ) end
leave the component we are on. This should be followed by all containers, so that the on_leave
action of earlier comp can be displayed, such as dimming components selections
# File lib/canis/core/widgets/rtabbedpane.rb, line 298 def leave_current_component @current_component.on_leave # NOTE this is required, since repaint will just not happen otherwise # Some components are erroneously repainting all, after setting this to true so it is # working there. @current_component.repaint_required true $log.debug " after on_leave VIMS XXX #{@current_component.focussed} #{@current_component.name}" @current_component.repaint end
on enter processing Very often the first may be a label !
# File lib/canis/core/widgets/rtabbedpane.rb, line 189 def on_enter # if BTAB, the last comp if $current_key == KEY_BTAB @current_component = @components.last else @current_component = @components.first end return unless @current_component $log.debug " NEWTABBED came to ON_ENTER #{@current_component} " set_form_row @_entered = true end
is focus on first component
# File lib/canis/core/widgets/rtabbedpane.rb, line 309 def on_first_component? @current_component == @components.first end
is focus on last component
# File lib/canis/core/widgets/rtabbedpane.rb, line 313 def on_last_component? @current_component == @components.last end
# File lib/canis/core/widgets/rtabbedpane.rb, line 201 def on_leave @_entered = false super end
remove all tabs
# File lib/canis/core/widgets/rtabbedpane.rb, line 76 def remove_all @tabs = [] self end
remove given tab
# File lib/canis/core/widgets/rtabbedpane.rb, line 71 def remove_tab tab @tabs.delete tab self end
remove tab at given index, defaulting to current
# File lib/canis/core/widgets/rtabbedpane.rb, line 81 def remove_tab_at index = @current_tab @tabs.delete_at index end
# File lib/canis/core/widgets/rtabbedpane.rb, line 85 def repaint @current_tab ||= 0 @button_row ||= @row + 2 @separator_row = @button_row + 1 # hope we have it by now, where to print separator @separator_row0 = @button_row - 1 unless @button_row == @row + 1 @separator_row2 = @row + @height - 3 # hope we have it by now, where to print separator #return unless @repaint_required if @buttons.empty? _create_buttons @components = @buttons.dup @components.push(*@tabs[@current_tab].items) create_action_buttons @components.push(*@action_buttons) elsif @tab_changed @components = @buttons.dup @components.push(*@tabs[@current_tab].items) @components.push(*@action_buttons) @tab_changed = false end # if some major change has happened then repaint everything if @repaint_required $log.debug " NEWTAB repaint graphic #{@graphic} " print_borders unless @suppress_borders # do this once only, unless everything changes print_separator1 @components.each { |e| e.repaint_all(true); e.repaint } else @components.each { |e| e.repaint } end # if repaint_required # next line is not called. earlier the 's' was missing, suppress_borders is not false print_borders if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes @repaint_required = false end
set current tab to given tab @return self
# File lib/canis/core/widgets/rtabbedpane.rb, line 331 def set_current_tab t return if @current_tab == t @current_tab = t goto_component @components[t] @tab_changed = true @repaint_required = true self end
private
# File lib/canis/core/widgets/rtabbedpane.rb, line 290 def set_form_col return if @current_component.nil? $log.debug " #{@name} NEWTABBED set_form_col calling sfc for #{@current_component.name} " @current_component.set_form_col end
private
# File lib/canis/core/widgets/rtabbedpane.rb, line 279 def set_form_row return :UNHANDLED if @current_component.nil? $log.debug " NEWTABBED on enter sfr #{@current_component} " @current_component.on_enter @current_component.set_form_row # why was this missing in vimsplit. is it # that on_enter does a set_form_row @current_component.set_form_col # XXX @current_component.repaint # XXX compo should do set_form_row and col if it has that end
Add a tab @param String
name of tab, may have ampersand for hotkey/accelerator
# File lib/canis/core/widgets/rtabbedpane.rb, line 47 def tab title, config={}, &block #@tab_components[title]=[] #@tabs << Tab.new(title, self, config, &block) insert_tab @tabs.count, title, config, &block self end
Private Instance Methods
# File lib/canis/core/widgets/rtabbedpane.rb, line 532 def center_column textlen width = @col + @width return (width-textlen)/2 end
Put all the housekeeping stuff at the end
# File lib/canis/core/widgets/rtabbedpane.rb, line 343 def init_vars @buttons = [] @tabs = [] #@tab_components = {} @bottombuttons = [] # # I'll keep current tabs comps in this to simplify @components = [] @_entered = false # added on 2014-05-30 - 12:13 otherwise borders not printed first time @repaint_all = true @repaint_required = true end
# File lib/canis/core/widgets/rtabbedpane.rb, line 357 def map_keys @keys_mapped = true #bind_key(?q, :myproc) #bind_key(32, :myproc) end
# File lib/canis/core/widgets/rtabbedpane.rb, line 393 def print_borders width = @width height = @height-1 window = @graphic startcol = @col startrow = @row @color_pair = get_color($datacolor) $log.debug "NTP #{name}: window.print_border #{startrow}, #{startcol} , h:#{height}, w:#{width} , @color_pair, @attr " window.print_border startrow, startcol, height, width, @color_pair, @attr print_title end
# File lib/canis/core/widgets/rtabbedpane.rb, line 404 def print_separator1 width = @width height = @height-1 window = @graphic startcol = @col startrow = @row @color_pair = get_color($datacolor) r = @separator_row c = @col + @col_offset urcorner = [] #window.printstring r, c, '-' * (@width-2), @color_pair, @attr window.mvwhline( r, @col+1, Ncurses::ACS_HLINE, @width-2) @buttons.each_with_index do |b, i| l = b.text.length if b.selected? if false #c == @col + @col_offset cc = c ll = l+1 else cc = c-1 ll = l+2 end #rr = r -1 #unless rr == @col window.printstring r, cc, " "*ll, @color_pair, @attr #window.printstring r, cc-1, FFI::NCurses::ACS_HLINE.chr*ll, @color_pair, @attr #window.printstring r-2, cc, FFI::NCurses::ACS_HLINE.chr*ll, @color_pair, @attr window.mvwaddch r, cc-1, FFI::NCurses::ACS_LRCORNER unless cc-1 <= @col window.mvwaddch r, c+l+1, FFI::NCurses::ACS_LLCORNER else window.mvwaddch r, c+l+1, FFI::NCurses::ACS_BTEE end #window.printstring r-2, c, FFI::NCurses::ACS_HLINE*l, @color_pair, @attr #tt = b.text #window.printstring r, c, tt, @color_pair, @attr c += l + 1 #window.mvwaddch r, c, '+'.ord window.mvwaddch r-1, c, FFI::NCurses::ACS_VLINE window.mvwaddch r-2, c, FFI::NCurses::ACS_URCORNER #ACS_TTEE #window.mvwaddch r-2, c+1, '/'.ord urcorner << c c+=@button_gap end window.mvwhline( @separator_row0, @col + 1, Ncurses::ACS_HLINE, c-@col-1-@button_gap) window.mvwhline( @separator_row2, @col + 1, Ncurses::ACS_HLINE, @width-2) urcorner.each do |c| window.mvwaddch r-2, c, FFI::NCurses::ACS_URCORNER #ACS_TTEE end end
# File lib/canis/core/widgets/rtabbedpane.rb, line 455 def print_title return unless @title _title = @title if @title.length > @width - 2 _title = @title[0..@width-2] end @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil? end