rbcurse 1.4.1 → 1.5.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/CHANGELOG +31 -0
  2. data/README.markdown +69 -11
  3. data/VERSION +1 -1
  4. data/lib/rbcurse.rb +5 -5
  5. metadata +10 -198
  6. data/Makefile +0 -21
  7. data/Manifest.txt +0 -91
  8. data/TODO +0 -372
  9. data/TODO2.txt +0 -118
  10. data/examples/README.txt +0 -67
  11. data/examples/abasiclist.rb +0 -33
  12. data/examples/alpmenu.rb +0 -42
  13. data/examples/app.rb +0 -859
  14. data/examples/app.sample +0 -10
  15. data/examples/appdirtree.rb +0 -75
  16. data/examples/appemail.rb +0 -191
  17. data/examples/appemaillb.rb +0 -308
  18. data/examples/appgcompose.rb +0 -315
  19. data/examples/atree.rb +0 -64
  20. data/examples/common/file.rb +0 -40
  21. data/examples/common/rmail.rb +0 -257
  22. data/examples/data.txt +0 -683
  23. data/examples/data/README.markdown +0 -9
  24. data/examples/data/brew.txt +0 -38
  25. data/examples/data/color.2 +0 -37
  26. data/examples/data/gemlist.txt +0 -60
  27. data/examples/data/lotr.txt +0 -12
  28. data/examples/data/ports.txt +0 -136
  29. data/examples/data/tasks.txt +0 -27
  30. data/examples/data/todocsv.csv +0 -28
  31. data/examples/data/unix1.txt +0 -21
  32. data/examples/data/unix2.txt +0 -11
  33. data/examples/dbdemo.rb +0 -495
  34. data/examples/deprecated/appgmail.rb +0 -952
  35. data/examples/deprecated/splitp.rb +0 -56
  36. data/examples/deprecated/testscrolllb.rb +0 -86
  37. data/examples/deprecated/testscrollp.rb +0 -88
  38. data/examples/deprecated/testscrollta.rb +0 -80
  39. data/examples/deprecated/testscrolltable.rb +0 -165
  40. data/examples/deprecated/testsplit.rb +0 -87
  41. data/examples/deprecated/testsplit2.rb +0 -123
  42. data/examples/deprecated/testsplit3.rb +0 -215
  43. data/examples/deprecated/testsplit3_1.rb +0 -244
  44. data/examples/deprecated/testsplit3a.rb +0 -215
  45. data/examples/deprecated/testsplit3b.rb +0 -237
  46. data/examples/deprecated/testsplitta.rb +0 -148
  47. data/examples/deprecated/testsplittv.rb +0 -142
  48. data/examples/deprecated/testsplittvv.rb +0 -144
  49. data/examples/deprecated/testtpane.rb +0 -215
  50. data/examples/deprecated/testtpane2.rb +0 -145
  51. data/examples/deprecated/testtpanetable.rb +0 -203
  52. data/examples/dirtree.rb +0 -88
  53. data/examples/experimental/resultsetdemo.rb +0 -280
  54. data/examples/experimental/testmform.rb +0 -35
  55. data/examples/experimental/testscroller.rb +0 -117
  56. data/examples/experimental/teststackflow.rb +0 -111
  57. data/examples/menu1.rb +0 -112
  58. data/examples/multispl.rb +0 -86
  59. data/examples/newmessagebox.rb +0 -130
  60. data/examples/newtabbedwindow.rb +0 -100
  61. data/examples/newtesttabp.rb +0 -121
  62. data/examples/qdfilechooser.rb +0 -68
  63. data/examples/rfe.rb +0 -1195
  64. data/examples/rfe_renderer.rb +0 -121
  65. data/examples/sqlc.rb +0 -454
  66. data/examples/sqlm.rb +0 -437
  67. data/examples/sqlt.rb +0 -408
  68. data/examples/status.txt +0 -68
  69. data/examples/table1.rb +0 -24
  70. data/examples/term2.rb +0 -84
  71. data/examples/test1.rb +0 -239
  72. data/examples/test2.rb +0 -674
  73. data/examples/testapp.rb +0 -44
  74. data/examples/testapp2.rb +0 -58
  75. data/examples/testchars.rb +0 -137
  76. data/examples/testcombo.rb +0 -91
  77. data/examples/testkeypress.rb +0 -66
  78. data/examples/testlistbox.rb +0 -113
  79. data/examples/testmenu.rb +0 -101
  80. data/examples/testmulticomp.rb +0 -70
  81. data/examples/testmulticontainer.rb +0 -94
  82. data/examples/testmultispl.rb +0 -199
  83. data/examples/testree.rb +0 -106
  84. data/examples/testtable.rb +0 -263
  85. data/examples/testtabp.rb +0 -107
  86. data/examples/testtodo.rb +0 -584
  87. data/examples/testvimsplit.rb +0 -112
  88. data/examples/testwsshortcuts.rb +0 -64
  89. data/examples/testwsshortcuts2.rb +0 -126
  90. data/examples/todo.db +0 -0
  91. data/examples/todo.yml +0 -191
  92. data/examples/viewtodo.rb +0 -574
  93. data/lib/rbcurse/action.rb +0 -40
  94. data/lib/rbcurse/app.rb +0 -1374
  95. data/lib/rbcurse/applicationheader.rb +0 -102
  96. data/lib/rbcurse/celleditor.rb +0 -112
  97. data/lib/rbcurse/checkboxcellrenderer.rb +0 -57
  98. data/lib/rbcurse/colormap.rb +0 -159
  99. data/lib/rbcurse/comboboxcellrenderer.rb +0 -30
  100. data/lib/rbcurse/common/ansiparser.rb +0 -117
  101. data/lib/rbcurse/common/appmethods.rb +0 -112
  102. data/lib/rbcurse/common/basestack.rb +0 -407
  103. data/lib/rbcurse/common/bordertitle.rb +0 -41
  104. data/lib/rbcurse/common/chunk.rb +0 -177
  105. data/lib/rbcurse/common/colorparser.rb +0 -71
  106. data/lib/rbcurse/common/keydefs.rb +0 -30
  107. data/lib/rbcurse/common/widgetshortcuts.rb +0 -302
  108. data/lib/rbcurse/defaultlistselectionmodel.rb +0 -79
  109. data/lib/rbcurse/deprecated/README.markdown +0 -12
  110. data/lib/rbcurse/deprecated/rscrollpane.rb +0 -512
  111. data/lib/rbcurse/deprecated/rsplitpane.rb +0 -894
  112. data/lib/rbcurse/deprecated/rsplitpane2.rb +0 -1009
  113. data/lib/rbcurse/deprecated/rviewport.rb +0 -204
  114. data/lib/rbcurse/experimental/README.markdown +0 -14
  115. data/lib/rbcurse/experimental/resultsettextview.rb +0 -585
  116. data/lib/rbcurse/experimental/stackflow.rb +0 -478
  117. data/lib/rbcurse/extras/bottomline.rb +0 -1850
  118. data/lib/rbcurse/extras/box.rb +0 -58
  119. data/lib/rbcurse/extras/directorylist.rb +0 -467
  120. data/lib/rbcurse/extras/directorytree.rb +0 -69
  121. data/lib/rbcurse/extras/divider.rb +0 -310
  122. data/lib/rbcurse/extras/focusmanager.rb +0 -31
  123. data/lib/rbcurse/extras/horizlist.rb +0 -203
  124. data/lib/rbcurse/extras/listselectable.rb +0 -264
  125. data/lib/rbcurse/extras/masterdetail.rb +0 -166
  126. data/lib/rbcurse/extras/menutree.rb +0 -63
  127. data/lib/rbcurse/extras/multiform.rb +0 -330
  128. data/lib/rbcurse/extras/multilinelabel.rb +0 -142
  129. data/lib/rbcurse/extras/newmessagebox.rb +0 -328
  130. data/lib/rbcurse/extras/newtabbedpane.rb +0 -612
  131. data/lib/rbcurse/extras/newtabbedwindow.rb +0 -68
  132. data/lib/rbcurse/extras/padreader.rb +0 -189
  133. data/lib/rbcurse/extras/rcomboedit.rb +0 -256
  134. data/lib/rbcurse/extras/resultsetbrowser.rb +0 -281
  135. data/lib/rbcurse/extras/rlink.rb +0 -27
  136. data/lib/rbcurse/extras/rmenulink.rb +0 -21
  137. data/lib/rbcurse/extras/scrollbar.rb +0 -143
  138. data/lib/rbcurse/extras/statusline.rb +0 -94
  139. data/lib/rbcurse/extras/stdscrwindow.rb +0 -309
  140. data/lib/rbcurse/extras/tableextended.rb +0 -40
  141. data/lib/rbcurse/extras/tabular.rb +0 -264
  142. data/lib/rbcurse/extras/tabularwidget.rb +0 -1150
  143. data/lib/rbcurse/extras/textpad.rb +0 -516
  144. data/lib/rbcurse/extras/viewer.rb +0 -136
  145. data/lib/rbcurse/io.rb +0 -850
  146. data/lib/rbcurse/keylabelprinter.rb +0 -178
  147. data/lib/rbcurse/listcellrenderer.rb +0 -140
  148. data/lib/rbcurse/listeditable.rb +0 -310
  149. data/lib/rbcurse/listkeys.rb +0 -37
  150. data/lib/rbcurse/listscrollable.rb +0 -564
  151. data/lib/rbcurse/listselectable.rb +0 -142
  152. data/lib/rbcurse/mapper.rb +0 -130
  153. data/lib/rbcurse/orderedhash.rb +0 -77
  154. data/lib/rbcurse/ractionevent.rb +0 -67
  155. data/lib/rbcurse/rbasiclistbox.rb +0 -768
  156. data/lib/rbcurse/rchangeevent.rb +0 -27
  157. data/lib/rbcurse/rcombo.rb +0 -238
  158. data/lib/rbcurse/rcommandwindow.rb +0 -587
  159. data/lib/rbcurse/rcontainer.rb +0 -415
  160. data/lib/rbcurse/rdialogs.rb +0 -451
  161. data/lib/rbcurse/rinputdataevent.rb +0 -47
  162. data/lib/rbcurse/rlistbox.rb +0 -1196
  163. data/lib/rbcurse/rmenu.rb +0 -939
  164. data/lib/rbcurse/rmessagebox.rb +0 -348
  165. data/lib/rbcurse/rmulticontainer.rb +0 -304
  166. data/lib/rbcurse/rmultisplit.rb +0 -722
  167. data/lib/rbcurse/rmultitextview.rb +0 -306
  168. data/lib/rbcurse/rpopupmenu.rb +0 -755
  169. data/lib/rbcurse/rprogress.rb +0 -118
  170. data/lib/rbcurse/rscrollform.rb +0 -418
  171. data/lib/rbcurse/rtabbedpane.rb +0 -1158
  172. data/lib/rbcurse/rtabbedwindow.rb +0 -167
  173. data/lib/rbcurse/rtable.rb +0 -1718
  174. data/lib/rbcurse/rtextarea.rb +0 -920
  175. data/lib/rbcurse/rtextview.rb +0 -761
  176. data/lib/rbcurse/rtree.rb +0 -780
  177. data/lib/rbcurse/rvimsplit.rb +0 -763
  178. data/lib/rbcurse/rwidget.rb +0 -2915
  179. data/lib/rbcurse/scrollable.rb +0 -301
  180. data/lib/rbcurse/table/tablecellrenderer.rb +0 -86
  181. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -98
  182. data/lib/rbcurse/tree/treecellrenderer.rb +0 -150
  183. data/lib/rbcurse/tree/treemodel.rb +0 -428
  184. data/lib/rbcurse/undomanager.rb +0 -188
  185. data/lib/rbcurse/vieditable.rb +0 -144
  186. data/lib/ver/keyboard.rb +0 -150
  187. data/lib/ver/keyboard2.rb +0 -170
  188. data/lib/ver/ncurses.rb +0 -218
  189. data/lib/ver/panel.rb +0 -162
  190. data/lib/ver/rpad.rb +0 -375
  191. data/lib/ver/window.rb +0 -882
  192. data/test/test_rbcurse.rb +0 -0
@@ -1,348 +0,0 @@
1
- =begin
2
- * Name: rmessagebox: creates messageboxes
3
- * Description
4
- * Author: rkumar (arunachalesha)
5
- * Date: 2008-11-19 12:49
6
- * License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
7
- * file separated on 2009-01-13 22:39
8
-
9
- =end
10
- require 'rbcurse/rwidget'
11
- require 'rbcurse/rlistbox'
12
-
13
- module RubyCurses
14
- ##
15
- # dimensions of window should be derived on content
16
- #
17
- class MessageBox
18
- include RubyCurses::Utils
19
- dsl_accessor :title
20
- dsl_accessor :message
21
- dsl_accessor :type # :ok, :ok_cancel :yes_no :yes_no_cancel :custom
22
- dsl_accessor :default_button # TODO - currently first
23
- dsl_accessor :layout
24
- dsl_accessor :buttons # used if type :custom
25
- dsl_accessor :underlines # offsets of each button to underline
26
- attr_reader :config
27
- attr_reader :selected_index # button index selected by user
28
- attr_reader :window # required for keyboard
29
- dsl_accessor :list_selection_mode # true or false allow multiple selection
30
- dsl_accessor :list # 2009-01-05 23:59
31
- dsl_accessor :button_type # ok, ok_cancel, yes_no
32
- dsl_accessor :default_value #
33
- dsl_accessor :default_values # # 2009-01-06 00:05 after removing meth missing
34
- dsl_accessor :height, :width, :top, :left # 2009-01-06 00:05 after removing meth missing
35
-
36
- dsl_accessor :message_height
37
-
38
-
39
- def initialize form=nil, aconfig={}, &block
40
- @form = form
41
- @config = aconfig
42
- @buttons = []
43
- #@keys = {}
44
- @bcol = 5
45
- @selected_index = -1
46
- @config.each_pair { |k,v| instance_variable_set("@#{k}",v) }
47
- instance_eval &block if block_given?
48
- if @layout.nil?
49
- case @type.to_s
50
- when "input"
51
- layout(10,60, 10, 20)
52
- when "list"
53
- height = [5, @list.length].min
54
- layout(10+height, 60, 5, 20)
55
- when "field_list"
56
- height = @field_list.length
57
- layout(10+height, 60, 5, 20)
58
- when "override"
59
- $log.debug " override: #{@height},#{@width}, #{@top}, #{@left} "
60
- layout(@height,@width, @top, @left)
61
- $log.debug " override: #{@layout.inspect}"
62
- else
63
- height = @form && @form.widgets.length ## quick fix. FIXME
64
- height ||= 0
65
- layout(10+height,60, 10, 20)
66
- end
67
- end
68
- @window = VER::Window.new(@layout)
69
- if @form.nil?
70
- @form = RubyCurses::Form.new @window
71
- else
72
- @form.window = @window
73
- end
74
- acolor = get_color $reversecolor # this implicitly uses color and bgcolor fooling me often
75
- $log.debug " MESSAGE BOX #{@bgcolor} , #{@color} , #{acolor}"
76
- @window.bkgd(Ncurses.COLOR_PAIR(acolor));
77
- @window.wrefresh
78
- @panel = @window.panel
79
- Ncurses::Panel.update_panels
80
- process_field_list
81
- print_borders
82
- print_title
83
- print_message unless @message.nil?
84
- print_input
85
- create_buttons
86
- @form.repaint
87
- @window.wrefresh
88
- handle_keys
89
- end
90
- ##
91
- # takes care of a field list sent in
92
- def process_field_list
93
- return if @field_list.nil? or @field_list.length == 0
94
- @field_list.each do |f|
95
- f.set_form @form
96
- end
97
- end
98
- def default_button offset0
99
- @selected_index = offset0
100
- end
101
- ##
102
- # value entered by user if type = input
103
- def input_value
104
- return @input.buffer if !@input.nil?
105
- return @listbox.getvalue if !@listbox.nil?
106
- end
107
- def create_buttons
108
- case @button_type.to_s.downcase
109
- when "ok"
110
- make_buttons ["&OK"]
111
- when "ok_cancel" #, "input", "list", "field_list"
112
- make_buttons %w[&OK &Cancel]
113
- # experience 2009-02-22 12:52 trapping y and n - hopefully wont cause an edit problem
114
- @form.bind_key(?o){ press(?\M-o) } # called method takes care of getbyte 1.9
115
- @form.bind_key(?c){ press(?\M-c) } # called method takes care of getbyte 1.9
116
- when "yes_no"
117
- make_buttons %w[&Yes &No]
118
- # experience 2009-02-22 12:52 trapping y and n - hopefully wont cause an edit problem
119
- @form.bind_key(?y){ press(?\M-y) } # called method takes care of getbyte 1.9
120
- @form.bind_key(?n){ press(?\M-n) } # called method takes care of getbyte 1.9
121
- when "yes_no_cancel"
122
- make_buttons ["&Yes", "&No", "&Cancel"]
123
- when "custom"
124
- raise "Blank list of buttons passed to custom" if @buttons.nil? or @buttons.size == 0
125
- make_buttons @buttons
126
- else
127
- $log.debug "No type passed for creating messagebox. Using default (OK)"
128
- make_buttons ["&OK"]
129
- end
130
- end
131
- def make_buttons names
132
- total = names.inject(0) {|total, item| total + item.length + 4}
133
- bcol = center_column total
134
-
135
- brow = @layout[:height]-3
136
- button_ct=0
137
- names.each_with_index do |bname, ix|
138
- text = bname
139
- #underline = @underlines[ix] if !@underlines.nil?
140
-
141
- button = Button.new @form do
142
- text text
143
- name bname
144
- row brow
145
- col bcol
146
- #underline underline
147
- highlight_background $datacolor
148
- color $reversecolor
149
- bgcolor $reversecolor
150
- end
151
- index = button_ct
152
- button.command { |form| @selected_index = index; @stop = true; $log.debug "Pressed Button #{bname}";}
153
- button_ct += 1
154
- bcol += text.length+6
155
- end
156
- end
157
- ## message box
158
- def stopping?
159
- @stop
160
- end
161
- def handle_keys
162
- begin
163
- while((ch = @window.getchar()) != 999 )
164
- case ch
165
- when -1
166
- next
167
- else
168
- press ch
169
- break if @stop
170
- end
171
- end
172
- ensure
173
- destroy
174
- end
175
- return @selected_index
176
- end
177
- def press ch
178
- ch = ch.getbyte(0) if ch.class==String ## 1.9
179
- case ch
180
- when -1
181
- return
182
- when KEY_F1, 27, ?\C-q.getbyte(0)
183
- @selected_index = -1
184
- @stop = true
185
- return
186
- when KEY_ENTER, 10, 13
187
- field = @form.get_current_field
188
- if field.respond_to? :fire
189
- field.fire
190
- end
191
- #$log.debug "popup ENTER : #{@selected_index} "
192
- #$log.debug "popup ENTER : #{field.name}" if !field.nil?
193
- @stop = true
194
- return
195
- when KEY_TAB
196
- @form.select_next_field
197
- when KEY_BTAB
198
- @form.select_prev_field
199
- else
200
- # fields must return unhandled else we will miss hotkeys.
201
- # On messageboxes, often if no edit field, then O and C are hot.
202
- field = @form.get_current_field
203
- handled = field.handle_key ch
204
-
205
- if handled == :UNHANDLED
206
- ret = @form.process_key ch, self ## trying out trigger button
207
- end
208
- end
209
- @form.repaint
210
- Ncurses::Panel.update_panels();
211
- Ncurses.doupdate();
212
- @window.wrefresh
213
- end
214
- def print_borders
215
- width = @layout[:width]
216
- height = @layout[:height]
217
- @window.print_border_mb 1,2, height, width, $normalcolor, FFI::NCurses::A_REVERSE
218
- =begin
219
- start = 2
220
- hline = "+%s+" % [ "-"*(width-((start+1)*2)) ]
221
- hline2 = "|%s|" % [ " "*(width-((start+1)*2)) ]
222
- @window.printstring(row=1, col=start, hline, color=$reversecolor)
223
- (start).upto(height-2) do |row|
224
- @window.printstring row, col=start, hline2, color=$normalcolor, A_REVERSE
225
- end
226
- @window.printstring(height-2, col=start, hline, color=$reversecolor)
227
- =end
228
- end
229
- def print_title title=@title
230
- width = @layout[:width]
231
- title = " "+title+" "
232
- @window.printstring(row=1,col=(width-title.length)/2,title, color=$normalcolor)
233
- end
234
- def center_column textlen
235
- width = @layout[:width]
236
- return (width-textlen)/2
237
- end
238
- def print_message message=@message, row=nil
239
- @message_row = @message_col = 2
240
- display_length = @layout[:width]-8
241
- $log.debug " print_message: dl:#{display_length} "
242
- # XXX this needs to go up and decide height of window
243
- if @message_height.nil?
244
- @message_height = (message.length/display_length)+2
245
- #$log.debug " print_message: mh:#{@message_height}, ml: #{message.length}"
246
- end
247
- @message_height ||= 1
248
- width = @layout[:width]
249
- return if message.nil?
250
- case @type.to_s
251
- when "input"
252
- row=(@layout[:height]/3) if row.nil?
253
- @message_col = 4
254
- when "list"
255
- row=3
256
- @message_col = 4
257
- else
258
- row=(@layout[:height]/3) if row.nil?
259
- @message_col = (width-message.length)/2
260
- @message_col = 4 if @message.is_a? Array
261
- @message_col = 4 if @message_col < 4 # this was often disappearing 2010-10-17 13:00
262
- #$log.debug "XX ALERT col #{@message_col} w: #{width} len: #{message.length} "
263
- end
264
- @message_row = row
265
- # added 2009-11-05 14:53 to fix erasure of border
266
- display_length -= @message_col
267
- # 2008-12-30 19:45 experimenting with label so we can get justify and wrapping.
268
- # 2011-09-20 trying to take care of when user changes color and bgcolor while calling.
269
- clr = @color || :black
270
- bgclr = @bgcolor || :white
271
- message_label = RubyCurses::Label.new @form, {'text' => message, "name"=>"message_label","row" => row, "col" => @message_col, "display_length" => display_length, "height" => @message_height, 'bgcolor' => bgclr , 'color' => clr}
272
-
273
- end
274
- def print_input
275
- #return if @type.to_s != "input"
276
- @message_height ||= 0
277
- @message_row ||= 2
278
- @message_col ||= 2
279
- r = @message_row + @message_height + 1
280
- c = @message_col
281
- disp_len = @layout[:width]-8
282
- defaultvalue = @default_value || ""
283
- input_config = @config["input_config"] || {} # see test1.rb for usage example
284
- case @type.to_s
285
- when "input"
286
- @input = RubyCurses::Field.new @form, input_config do
287
- name "input"
288
- row r
289
- col c
290
- display_length disp_len
291
- set_buffer defaultvalue
292
- end
293
- when "list"
294
- list = @list
295
- selection_mode = @list_selection_mode
296
- default_values = @default_values
297
- $log.debug " value of select_mode #{selection_mode}"
298
- @listbox = RubyCurses::Listbox.new @form do
299
- name "input"
300
- row r
301
- col c
302
-
303
- color 'black'
304
- bgcolor 'white'
305
- # now listcellrenderer only uses BOLD for selected, with a white bgcolor
306
- # so here it won't show up on white bg
307
- selected_color 'red'
308
- selected_bgcolor 'black'
309
- # just added 2010-10-14 21:24
310
- border_attrib :reverse
311
- width 30
312
- height 6
313
- list list
314
- # ?? display_length 30
315
- #set_buffer defaultvalue
316
- selection_mode selection_mode
317
- default_values default_values
318
- is_popup false
319
- end
320
- end
321
- end
322
- def configure(*val , &block)
323
- case val.size
324
- when 1
325
- return @config[val[0]]
326
- when 2
327
- @config[val[0]] = val[1]
328
- instance_variable_set("@#{val[0]}", val[1])
329
- end
330
- instance_eval &block if block_given?
331
- end
332
- def cget param
333
- @config[param]
334
- end
335
-
336
- def layout(height=0, width=0, top=0, left=0)
337
- @layout = { :height => height, :width => width, :top => top, :left => left }
338
- end
339
- def destroy
340
- $log.debug "DESTROY : messagebox"
341
- panel = @window.panel
342
- #Ncurses::Panel.del_panel(panel) if !panel.nil?
343
- panel.del_panel if !panel.nil?
344
- @window.delwin if !@window.nil?
345
- Ncurses::Panel.update_panels # 2011-10-1 so window below doesn't have a black rectangle
346
- end
347
- end
348
- end
@@ -1,304 +0,0 @@
1
- =begin
2
- * Name: MultiContainer
3
- * Description View (cycle) multiple components in one container using a key or menu
4
- * Author: rkumar (arunachalesha)
5
- * file created 2010-03-15 10:40
6
- --------
7
- * License:
8
- Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
9
-
10
- =end
11
- require 'rbcurse'
12
-
13
- include RubyCurses
14
- module RubyCurses
15
- extend self
16
-
17
- ##
18
- # Extends TextView with ability to load more than one file or content
19
- # and switch between files (buffers).
20
- # NOTE: ideally, i should be able to dynamically add this functionality to either Textview
21
- # or TextArea or even ListBox or Table someday. Should then be a Module rather than a class.
22
- class MultiContainer < Widget
23
- dsl_accessor :title
24
-
25
-
26
- def initialize form = nil, config={}, &block
27
- @focusable = true
28
- @row_offset = @col_offset = 1
29
- super
30
- @bmanager = BufferManager.new self
31
- init_vars
32
-
33
- end
34
- def init_vars
35
- super
36
- # the following allows us to navigate buffers with :bn :bp etc (with Alt pressed)
37
- bind_key(?\M-:, :buffer_menu)
38
- bind_key(?\M-;, :buffer_menu)
39
- # bind_key([?\C-x, ?f], :file_edit)
40
- bind_key([?\C-x, ?k], :delete_component)
41
- bind_key([?\C-x, ?\C-b], :list_components)
42
- bind_key(?\M-n, :goto_next_component)
43
- bind_key(?\M-p, :goto_prev_component)
44
- bind_key(?\M-1, :goto_first_component)
45
- # easily cycle using p. n is used for next search.
46
- #bind_key(?p, :buffer_previous)
47
- @suppress_borders = false
48
- @repaint_all = true
49
- @name ||= "multicontainer"
50
- end
51
- ## returns current buffer
52
- # @return [RBuffer] current buffer
53
- def current_component
54
- @bmanager.current
55
- end
56
- ##
57
- # Add a component with a title
58
- # @param [Widget] component
59
- # @param [String] title
60
- def add component, title
61
- component.row = @row+@row_offset+0 # FFI changed 1 to 0 2011-09-12
62
- component.col = @col+@col_offset+0 # FFI changed 1 to 0 2011-09-12
63
- component.width = @width-2
64
- component.height = @height-2
65
- component.form = @form
66
- component.override_graphic(@graphic)
67
- @current_buffer = @bmanager.add component, title
68
- @current_component = @current_buffer.component
69
- #set_current_component
70
- #set_form_row ## FFI added 2011-09-12 to get cursor at start when adding
71
- $log.debug "MULTICONT ADD got cb : #{@current_component} "
72
- end
73
- def set_current_component
74
- @current_component = @current_buffer.component
75
- @current_title = @current_component.title # NOTE: unused, don't knw what for
76
- set_form_row
77
- @current_component.repaint_all true
78
- end
79
- # required otherwise some components may not get correct cursor position on entry
80
- # e.g. table
81
- def on_enter
82
- set_form_row
83
- end
84
- def set_form_row #:nodoc:
85
- if !@current_component.nil?
86
- cc = @current_component
87
-
88
- @current_component.on_enter # 2011-10-19 why was this not there earlier
89
-
90
- # 2011-10-21 I've tried removing next 2 lines but there are certain case
91
- # that do need them. See testmulticontainer.rb
92
-
93
- @current_component.set_form_row
94
- @current_component.set_form_col
95
-
96
- end
97
- end
98
- def set_form_col
99
- # deliberately empty since Form will call this and Widgets one is unsuitable
100
- # for us
101
- end
102
- ##
103
- # multi-container
104
- def handle_key ch #:nodoc:
105
- $log.debug " MULTI handlekey #{ch}, #{@current_component}"
106
- ret = :UNHANDLED
107
- return :UNHANDLED unless @current_component
108
-
109
- ret = @current_component.handle_key(ch)
110
- $log.debug " MULTI = current comp #{@current_component} returned #{ret} "
111
- if ret == :UNHANDLED
112
- # check for bindings, these cannot override above keys since placed at end
113
- begin
114
- ret = process_key ch, self
115
- $log.debug " MULTI = process_key returned #{ret} "
116
- if ch > 177 && ch < 187
117
- n = ch - 177
118
-
119
- component_at(n)
120
- ret = 0 # other unhandled goes back
121
- # go to component n
122
- end
123
- rescue => err
124
- $error_message.value = err.to_s
125
- $log.error " Multicomponent process_key #{err} "
126
- $log.debug(err.backtrace.join("\n"))
127
- alert err.to_s
128
- end
129
- return :UNHANDLED if ret == :UNHANDLED
130
- end
131
- # check for any keys not handled and check our own ones
132
- return ret #
133
- end
134
- def repaint
135
- print_border if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
136
- return unless @current_component
137
- $log.debug " MULTI REPAINT - calling current_comps repaint #{@current_component} "
138
- ret = @current_component.repaint
139
- end
140
- def print_border #:nodoc:
141
- #$log.debug " #{@name} print_borders, #{@graphic.name} "
142
- color = $datacolor
143
- @graphic.print_border_only @row, @col, @height-1, @width, color #, Ncurses::A_REVERSE
144
- print_title
145
- end
146
- def print_title #:nodoc:
147
- #$log.debug " print_title #{@row}, #{@col}, #{@width} "
148
- _title = @title || "" + @current_title
149
- @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, $datacolor, @title_attrib) unless _title.nil?
150
- end
151
- # this is just a test of the simple "most" menu
152
- # can use this for next, prev, first, last, new, delete, overwrite etc
153
- def buffer_menu
154
- menu = PromptMenu.new self
155
- menu.add(menu.create_mitem( 'l', "list buffers", "list buffers ", :list_components ))
156
- item = menu.create_mitem( 'b', "Buffer Options", "Buffer Options" )
157
- menu1 = PromptMenu.new( self, "Buffer Options")
158
- menu1.add(menu1.create_mitem( 'n', "Next", "Switched to next buffer", :goto_next_component ))
159
- menu1.add(menu1.create_mitem( 'p', "Prev", "Switched to previous buffer", :goto_prev_component ))
160
- menu1.add(menu1.create_mitem( 'f', "First", "Switched to first buffer", :goto_first_component ))
161
- menu1.add(menu1.create_mitem( 'l', "Last", "Switched to last buffer", :goto_last_component ))
162
- menu1.add(menu1.create_mitem( 'd', "Delete", "Deleted buffer", :delete_component ))
163
- item.action = menu1
164
- menu.add(item)
165
- # how do i know what's available. the application or window should know where to place
166
- menu.display @form.window, $error_message_row, $error_message_col, $datacolor #, menu
167
- end
168
-
169
-
170
- def goto_next_component
171
- perror "No other buffer" and return if @bmanager.size < 2
172
-
173
- @current_buffer = @bmanager.next
174
- set_current_component
175
- end
176
-
177
- def goto_prev_component
178
- perror "No other buffer" and return if @bmanager.size < 2
179
-
180
- @current_buffer = @bmanager.previous
181
- $log.debug " buffer_prev got #{@current_buffer} "
182
- set_current_component
183
- end
184
- def goto_first_component
185
- @current_buffer = @bmanager.first
186
- $log.debug " buffer_first got #{@current_buffer} "
187
- set_current_component
188
- end
189
- def goto_last_component
190
- @current_buffer = @bmanager.last
191
- $log.debug " buffer_last got #{@current_buffer} "
192
- set_current_component
193
- end
194
- def delete_component
195
- if @bmanager.size > 1
196
- @bmanager.delete_at
197
- @current_component = @bmanager.previous
198
- set_current_component
199
- else
200
- perror "Only one buffer. Cannot delete."
201
- end
202
- end
203
-
204
- def component_at index
205
- cc = @bmanager.element_at index
206
- return unless cc
207
- @current_component = cc
208
- #$log.debug " buffer_last got #{@current_component} "
209
- set_current_component
210
- end
211
- def perror errmess
212
- alert errmess
213
- #@form.window.print_error_message errmess
214
- end
215
- def list_components
216
- $log.debug " TODO buffers_list: #{@bmanager.size} "
217
- menu = PromptMenu.new self
218
- @bmanager.each_with_index{ |b, ix|
219
- aproc = Proc.new { component_at(ix) }
220
- name = b.title
221
- num = ix + 1
222
- menu.add(menu.create_mitem( num.to_s, name, "Switched to buffer #{ix}", aproc ))
223
- }
224
- menu.display @form.window, $error_message_row, $error_message_col, $datacolor
225
- end
226
- end # class multicontainer
227
- ##
228
- # Handles multiple buffers, navigation, maintenance etc
229
- # Instantiated at startup of
230
- #
231
- class BufferManager
232
- include Enumerable
233
- def initialize source
234
- @source = source
235
- @buffers = [] # contains RBuffer
236
- @counter = 0
237
- # for each buffer i need to store data, current_index (row), curpos (col offset) and title (filename).
238
- end
239
- def element_at index
240
- @buffers[index]
241
- end
242
- def each
243
- @buffers.each {|k| yield(k)}
244
- end
245
-
246
- ##
247
- # @return [RBuffer] current buffer/file
248
- ##
249
- def current
250
- @buffers[@counter]
251
- end
252
- ##
253
- # Would have liked to just return next buffer and not get lost in details of caller
254
- #
255
- # @return [RBuffer] next buffer/file
256
- ##
257
- def next
258
- @counter += 1
259
- @counter = 0 if @counter >= @buffers.size
260
- @buffers[@counter]
261
- end
262
- ##
263
- # @return [RBuffer] previous buffer/file
264
- ##
265
- def previous
266
- $log.debug " previous bs: #{@buffers.size}, #{@counter} "
267
- @counter -= 1
268
- return last() if @counter < 0
269
- $log.debug " previous ctr #{@counter} "
270
- @buffers[@counter]
271
- end
272
- def first
273
- @counter = 0
274
- @buffers[@counter]
275
- end
276
- def last
277
- @counter = @buffers.size - 1
278
- @buffers[@counter]
279
- end
280
- ##
281
- def delete_at index=@counter
282
- @buffers.delete_at index
283
- end
284
- def delete_by_name name
285
- @buffers.delete_if {|b| b.filename == name }
286
- end
287
- def insert component, position, title=nil
288
- anew = RComponents.new(component, title)
289
- @buffers.insert position, anew
290
- @counter = position
291
- return anew
292
- end
293
- def add component, title=nil
294
- $log.debug " ADD H: #{component.height} C: #{component.width} "
295
- insert component, @buffers.size, title
296
- end
297
- def size
298
- @buffers.size
299
- end
300
- alias :count :size
301
- end
302
- RComponents = Struct.new(:component, :title)
303
-
304
- end # modul