Class: RubyCurses::MultiContainer
- Defined in:
- lib/rbcurse/rmulticontainer.rb
Overview
Extends TextView with ability to load more than one file or content and switch between files (buffers). NOTE: ideally, i should be able to dynamically add this functionality to either Textview or TextArea or even ListBox or Table someday. Should then be a Module rather than a class.
Constant Summary
Constants included from Io
Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR
Instance Attribute Summary
Attributes inherited from Widget
#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #state
Instance Method Summary collapse
-
#add(component, title) ⇒ Object
Add a component with a title.
- #buffer_at(index) ⇒ Object
- #buffer_delete ⇒ Object
- #buffer_first ⇒ Object
- #buffer_last ⇒ Object
-
#buffer_menu ⇒ Object
this is just a test of the simple “most” menu can use this for next, prev, first, last, new, delete, overwrite etc.
-
#buffer_next ⇒ Object
end.
- #buffer_previous ⇒ Object
- #buffers_list ⇒ Object
-
#current_buffer ⇒ RBuffer
returns current buffer.
-
#handle_key(ch) ⇒ Object
multi-container.
- #init_vars ⇒ Object
-
#initialize(form = nil, config = {}, &block) ⇒ MultiContainer
constructor
include ListScrollable.
-
#on_enter ⇒ Object
required otherwise some components may not get correct cursor position on entry e.g.
- #perror(errmess = $error_message) ⇒ Object
- #print_border ⇒ Object
- #print_title ⇒ Object
- #repaint ⇒ Object
- #set_current_buffer ⇒ Object
- #set_form_row ⇒ Object
Methods inherited from Widget
#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #getvalue, #getvalue_for_paint, #height, #height=, #hide, #is_double_buffered?, #modified?, #move, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #safe_create_buffer, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Methods included from DSL
Constructor Details
#initialize(form = nil, config = {}, &block) ⇒ MultiContainer
include ListScrollable
30 31 32 33 34 35 36 37 |
# File 'lib/rbcurse/rmulticontainer.rb', line 30 def initialize form = nil, config={}, &block @focusable = true @row_offset = @col_offset = 1 super @bmanager = BufferManager.new self init_vars end |
Instance Method Details
#add(component, title) ⇒ Object
Add a component with a title
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/rbcurse/rmulticontainer.rb', line 205 def add component, title component.row = @row+@row_offset+1 component.col = @col+@col_offset+1 component.width = @width-2 component.height = @height-2 component.form = @form component.override_graphic(@graphic) @current_buffer = @bmanager.add component, title set_current_buffer $log.debug " ADD got cb : #{@current_buffer} " end |
#buffer_at(index) ⇒ Object
196 197 198 199 200 |
# File 'lib/rbcurse/rmulticontainer.rb', line 196 def buffer_at index @current_buffer = @bmanager.element_at index $log.debug " buffer_last got #{@current_buffer} " set_current_buffer end |
#buffer_delete ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/rbcurse/rmulticontainer.rb', line 145 def buffer_delete if @bmanager.size > 1 @bmanager.delete_at @current_buffer = @bmanager.previous set_current_buffer else perror "Only one buffer. Cannot delete." end end |
#buffer_first ⇒ Object
135 136 137 138 139 |
# File 'lib/rbcurse/rmulticontainer.rb', line 135 def buffer_first @current_buffer = @bmanager.first $log.debug " buffer_first got #{@current_buffer} " set_current_buffer end |
#buffer_last ⇒ Object
140 141 142 143 144 |
# File 'lib/rbcurse/rmulticontainer.rb', line 140 def buffer_last @current_buffer = @bmanager.last $log.debug " buffer_last got #{@current_buffer} " set_current_buffer end |
#buffer_menu ⇒ Object
this is just a test of the simple “most” menu can use this for next, prev, first, last, new, delete, overwrite etc
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbcurse/rmulticontainer.rb', line 97 def = PromptMenu.new self .add(.create_mitem( 'l', "list buffers", "list buffers ", :buffers_list )) item = .create_mitem( 'b', "Buffer Options", "Buffer Options" ) = PromptMenu.new( self, "Buffer Options") .add(.create_mitem( 'n', "Next", "Switched to next buffer", :buffer_next )) .add(.create_mitem( 'p', "Prev", "Switched to previous buffer", :buffer_previous )) .add(.create_mitem( 'f', "First", "Switched to first buffer", :buffer_first )) .add(.create_mitem( 'l', "Last", "Switched to last buffer", :buffer_last )) .add(.create_mitem( 'd', "Delete", "Deleted buffer", :buffer_delete )) item.action = .add(item) # how do i know what's available. the application or window should know where to place .display @form.window, , , $datacolor #, menu end |
#buffer_next ⇒ Object
end
122 123 124 125 126 127 |
# File 'lib/rbcurse/rmulticontainer.rb', line 122 def buffer_next perror "No other buffer" and return if @bmanager.size < 2 @current_buffer = @bmanager.next set_current_buffer end |
#buffer_previous ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/rbcurse/rmulticontainer.rb', line 128 def buffer_previous perror "No other buffer" and return if @bmanager.size < 2 @current_buffer = @bmanager.previous $log.debug " buffer_prev got #{@current_buffer} " set_current_buffer end |
#buffers_list ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/rbcurse/rmulticontainer.rb', line 224 def buffers_list $log.debug " TODO buffers_list: #{@bmanager.size} " = PromptMenu.new self @bmanager.each_with_index{ |b, ix| aproc = Proc.new { buffer_at(ix) } name = b.title num = ix + 1 .add(.create_mitem( num.to_s, name, "Switched to buffer #{ix}", aproc )) } .display @form.window, , , $datacolor end |
#current_buffer ⇒ RBuffer
returns current buffer
52 53 54 |
# File 'lib/rbcurse/rmulticontainer.rb', line 52 def current_buffer @bmanager.current end |
#handle_key(ch) ⇒ Object
multi-container
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rbcurse/rmulticontainer.rb', line 57 def handle_key ch $log.debug " MULTI handlekey #{ch}, #{@current_component} " ret = :UNHANDLED return :UNHANDLED unless @current_component ret = @current_component.handle_key(ch) $log.debug " MULTI = comp returned #{ret} " if ret == :UNHANDLED # check for bindings, these cannot override above keys since placed at end begin ret = process_key ch, self $log.debug " MULTI = process_key returned #{ret} " rescue => err = err @form.window. $log.error " Multicomponent process_key #{err} " $log.debug(err.backtrace.join("\n")) end return :UNHANDLED if ret == :UNHANDLED end # check for any keys not handled and check our own ones return ret # end |
#init_vars ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rbcurse/rmulticontainer.rb', line 38 def init_vars super bind_key(?\M-:, :buffer_menu) # bind_key([?\C-x, ?f], :file_edit) bind_key([?\C-x, ?k], :buffer_delete) bind_key([?\C-x, ?\C-b], :buffers_list) # easily cycle using p. n is used for next search. #bind_key(?p, :buffer_previous) @suppress_borders = false @repaint_all = true @name ||= "multicontainer" end |
#on_enter ⇒ Object
required otherwise some components may not get correct cursor position on entry e.g. table
237 238 239 |
# File 'lib/rbcurse/rmulticontainer.rb', line 237 def on_enter set_form_row end |
#perror(errmess = $error_message) ⇒ Object
221 222 223 |
# File 'lib/rbcurse/rmulticontainer.rb', line 221 def perror errmess= @form.window. errmess end |
#print_border ⇒ Object
85 86 87 88 89 90 |
# File 'lib/rbcurse/rmulticontainer.rb', line 85 def print_border $log.debug " #{@name} print_borders, #{@graphic.name} " color = $datacolor @graphic.print_border_only @row, @col, @height-1, @width, color #, Ncurses::A_REVERSE print_title end |
#print_title ⇒ Object
91 92 93 94 |
# File 'lib/rbcurse/rmulticontainer.rb', line 91 def print_title $log.debug " print_title #{@row}, #{@col}, #{@width} " @graphic.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil? end |
#repaint ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rbcurse/rmulticontainer.rb', line 79 def repaint print_border if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes return unless @current_component $log.debug " MULTI REPAINT " ret = @current_component.repaint end |
#set_current_buffer ⇒ Object
216 217 218 219 220 |
# File 'lib/rbcurse/rmulticontainer.rb', line 216 def set_current_buffer @current_component = @current_buffer.component @current_title = @current_buffer.title @current_component.repaint_all true end |
#set_form_row ⇒ Object
240 241 242 243 244 245 246 |
# File 'lib/rbcurse/rmulticontainer.rb', line 240 def set_form_row if !@current_component.nil? $log.debug " #{@name} set_form_row calling sfr for #{@current_component.name} " @current_component.set_form_row @current_component.set_form_col end end |