Class: RubyCurses::MultiContainer
- Inherits:
-
Widget
- Object
- Widget
- RubyCurses::MultiContainer
- Defined in:
- lib/rbcurse/extras/widgets/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.
Instance Method Summary collapse
-
#add(component, title) ⇒ Object
Add a component with a title.
-
#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.
- #component_at(index) ⇒ Object
-
#current_component ⇒ RBuffer
returns current buffer.
- #delete_component ⇒ Object
- #goto_first_component ⇒ Object
- #goto_last_component ⇒ Object
- #goto_next_component ⇒ Object
- #goto_prev_component ⇒ Object
-
#handle_key(ch) ⇒ Object
multi-container.
- #init_vars ⇒ Object
-
#initialize(form = nil, config = {}, &block) ⇒ MultiContainer
constructor
A new instance of MultiContainer.
- #list_components ⇒ Object
-
#on_enter ⇒ Object
required otherwise some components may not get correct cursor position on entry e.g.
- #perror(errmess) ⇒ Object
-
#print_border ⇒ Object
:nodoc:.
-
#print_title ⇒ Object
:nodoc:.
- #repaint ⇒ Object
- #set_current_component ⇒ Object
- #set_form_col ⇒ Object
-
#set_form_row ⇒ Object
:nodoc:.
Constructor Details
#initialize(form = nil, config = {}, &block) ⇒ MultiContainer
Returns a new instance of MultiContainer.
26 27 28 29 30 31 32 33 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 26 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
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 60 def add component, title component.row = @row+@row_offset+0 # FFI changed 1 to 0 2011-09-12 component.col = @col+@col_offset+0 # FFI changed 1 to 0 2011-09-12 component.width = @width-2 component.height = @height-2 component.form = @form component.override_graphic(@graphic) @current_buffer = @bmanager.add component, title @current_component = @current_buffer.component #set_current_component #set_form_row ## FFI added 2011-09-12 to get cursor at start when adding $log.debug "MULTICONT ADD got cb : #{@current_component} " 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
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 153 def = PromptMenu.new self .add(.create_mitem( 'l', "list buffers", "list buffers ", :list_components )) item = .create_mitem( 'b', "Buffer Options", "Buffer Options" ) = PromptMenu.new( self, "Buffer Options") .add(.create_mitem( 'n', "Next", "Switched to next buffer", :goto_next_component )) .add(.create_mitem( 'p', "Prev", "Switched to previous buffer", :goto_prev_component )) .add(.create_mitem( 'f', "First", "Switched to first buffer", :goto_first_component )) .add(.create_mitem( 'l', "Last", "Switched to last buffer", :goto_last_component )) .add(.create_mitem( 'd', "Delete", "Deleted buffer", :delete_component )) item.action = .add(item) # how do i know what's available. the application or window should know where to place .display @form.window, $error_message_row, $error_message_col, $datacolor #, menu end |
#component_at(index) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 204 def component_at index cc = @bmanager.element_at index return unless cc @current_component = cc #$log.debug " buffer_last got #{@current_component} " set_current_component end |
#current_component ⇒ RBuffer
returns current buffer
53 54 55 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 53 def current_component @bmanager.current end |
#delete_component ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 194 def delete_component if @bmanager.size > 1 @bmanager.delete_at @current_component = @bmanager.previous set_current_component else perror "Only one buffer. Cannot delete." end end |
#goto_first_component ⇒ Object
184 185 186 187 188 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 184 def goto_first_component @current_buffer = @bmanager.first $log.debug " buffer_first got #{@current_buffer} " set_current_component end |
#goto_last_component ⇒ Object
189 190 191 192 193 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 189 def goto_last_component @current_buffer = @bmanager.last $log.debug " buffer_last got #{@current_buffer} " set_current_component end |
#goto_next_component ⇒ Object
170 171 172 173 174 175 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 170 def goto_next_component perror "No other buffer" and return if @bmanager.size < 2 @current_buffer = @bmanager.next set_current_component end |
#goto_prev_component ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 177 def goto_prev_component perror "No other buffer" and return if @bmanager.size < 2 @current_buffer = @bmanager.previous $log.debug " buffer_prev got #{@current_buffer} " set_current_component end |
#handle_key(ch) ⇒ Object
multi-container
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 104 def handle_key ch #:nodoc: $log.debug " MULTI handlekey #{ch}, #{@current_component}" ret = :UNHANDLED return :UNHANDLED unless @current_component ret = @current_component.handle_key(ch) $log.debug " MULTI = current comp #{@current_component} 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} " if ch > 177 && ch < 187 n = ch - 177 component_at(n) ret = 0 # other unhandled goes back # go to component n end rescue => err $error_message.value = err.to_s $log.error " Multicomponent process_key #{err} " $log.debug(err.backtrace.join("\n")) alert err.to_s end return :UNHANDLED if ret == :UNHANDLED end # check for any keys not handled and check our own ones return ret # end |
#init_vars ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 34 def init_vars super # the following allows us to navigate buffers with :bn :bp etc (with Alt pressed) bind_key(?\M-:, :buffer_menu) bind_key(?\M-;, :buffer_menu) # bind_key([?\C-x, ?f], :file_edit) bind_key([?\C-x, ?k], :delete_component) bind_key([?\C-x, ?\C-b], :list_components) bind_key(?\M-n, :goto_next_component) bind_key(?\M-p, :goto_prev_component) bind_key(?\M-1, :goto_first_component) # easily cycle using p. n is used for next search. #bind_key(?p, :buffer_previous) @suppress_borders = false @repaint_all = true @name ||= "multicontainer" end |
#list_components ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 215 def list_components $log.debug " TODO buffers_list: #{@bmanager.size} " = PromptMenu.new self @bmanager.each_with_index{ |b, ix| aproc = Proc.new { component_at(ix) } name = b.title num = ix + 1 .add(.create_mitem( num.to_s, name, "Switched to buffer #{ix}", aproc )) } .display @form.window, $error_message_row, $error_message_col, $datacolor end |
#on_enter ⇒ Object
required otherwise some components may not get correct cursor position on entry e.g. table
81 82 83 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 81 def on_enter set_form_row end |
#perror(errmess) ⇒ Object
211 212 213 214 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 211 def perror errmess alert errmess #@form.window.print_error_message errmess end |
#print_border ⇒ Object
:nodoc:
140 141 142 143 144 145 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 140 def print_border #:nodoc: #$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
:nodoc:
146 147 148 149 150 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 146 def print_title #:nodoc: #$log.debug " print_title #{@row}, #{@col}, #{@width} " _title = @title || "" + @current_title @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless _title.nil? end |
#repaint ⇒ Object
134 135 136 137 138 139 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 134 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 - calling current_comps repaint #{@current_component} " ret = @current_component.repaint end |
#set_current_component ⇒ Object
73 74 75 76 77 78 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 73 def set_current_component @current_component = @current_buffer.component @current_title = @current_component.title # NOTE: unused, don't knw what for set_form_row @current_component.repaint_all true end |
#set_form_col ⇒ Object
98 99 100 101 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 98 def set_form_col # deliberately empty since Form will call this and Widgets one is unsuitable # for us end |
#set_form_row ⇒ Object
:nodoc:
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rbcurse/extras/widgets/rmulticontainer.rb', line 84 def set_form_row #:nodoc: if !@current_component.nil? cc = @current_component @current_component.on_enter # 2011-10-19 why was this not there earlier # 2011-10-21 I've tried removing next 2 lines but there are certain case # that do need them. See testmulticontainer.rb @current_component.set_form_row @current_component.set_form_col end end |