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,264 +0,0 @@
1
- # File created: 2010-10-29 14:09
2
- # Author : rkumar
3
- #
4
- # this is a new, simpler version of listselectable
5
- # the original gets into models and has complicated operation as well
6
- # as difficult to remember method names. This attempts to be a simple plugin.
7
- # Currently being used by rbasiclistbox and now tabularwidget.
8
- # NOTE: pls define @_header_adjustment to 0 if you don't use it or know what it means.
9
- # TODO: of course we need to fire events so user can do something.
10
- module RubyCurses
11
- module NewListSelectable
12
-
13
- # @group selection related
14
-
15
- # change selection of current row on pressing space bar
16
- # If mode is multiple, then other selections are cleared and this is added
17
- # @example
18
- # bind_key(32) { toggle_row_selection }
19
- # current_index is not account for header_adjustment
20
- # if current row is selected in mulitple we should deselect ?? FIXME
21
- def toggle_row_selection crow=@current_index-@_header_adjustment
22
- @last_clicked = crow
23
- @repaint_required = true
24
- case @selection_mode
25
- when :multiple
26
- @widget_scrolled = true # FIXME we need a better name
27
- if @selected_indices.include? crow
28
- @selected_indices.delete crow
29
- lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
30
- fire_handler :LIST_SELECTION_EVENT, lse
31
- else
32
- @selected_indices << crow
33
- lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
34
- fire_handler :LIST_SELECTION_EVENT, lse
35
- end
36
- else
37
- if @selected_index == crow
38
- @old_selected_index = @selected_index # 2011-10-15 so we can unhighlight
39
- @selected_index = nil
40
- lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
41
- fire_handler :LIST_SELECTION_EVENT, lse
42
- else
43
- @old_selected_index = @selected_index # 2011-10-15 so we can unhighlight
44
- @selected_index = crow
45
- lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
46
- fire_handler :LIST_SELECTION_EVENT, lse
47
- end
48
- end
49
- end
50
- #
51
- # Only for multiple mode.
52
- # add an item to selection, if selection mode is multiple
53
- # if item already selected, it is deselected, else selected
54
- # typically bound to Ctrl-Space
55
- # @example
56
- # bind_key(0) { add_to_selection }
57
- def add_to_selection crow=@current_index-@_header_adjustment
58
- @last_clicked ||= crow
59
- min = [@last_clicked, crow].min
60
- max = [@last_clicked, crow].max
61
- case @selection_mode
62
- when :multiple
63
- @widget_scrolled = true # FIXME we need a better name
64
- if @selected_indices.include? crow
65
- # delete from last_clicked until this one in any direction
66
- min.upto(max){ |i| @selected_indices.delete i }
67
- lse = ListSelectionEvent.new(min, max, self, :DELETE)
68
- fire_handler :LIST_SELECTION_EVENT, lse
69
- else
70
- # add to selection from last_clicked until this one in any direction
71
- min.upto(max){ |i| @selected_indices << i unless @selected_indices.include?(i) }
72
- lse = ListSelectionEvent.new(min, max, self, :INSERT)
73
- fire_handler :LIST_SELECTION_EVENT, lse
74
- end
75
- else
76
- end
77
- @repaint_required = true
78
- self
79
- end
80
- # clears selected indices, typically called when multiple select
81
- # Key binding is application specific
82
- def clear_selection
83
- return if @selected_indices.nil? || @selected_indices.empty?
84
- @selected_indices = []
85
- @selected_index = nil
86
- @old_selected_index = nil
87
- # Not sure what event type I should give, DELETE or a new one, user should
88
- # understand that selection has been cleared, and ignore first two params
89
- lse = ListSelectionEvent.new(0, @list.size, self, :CLEAR)
90
- fire_handler :LIST_SELECTION_EVENT, lse
91
- @repaint_required = true
92
- @widget_scrolled = true # FIXME we need a better name
93
- end
94
- def is_row_selected crow=@current_index-@_header_adjustment
95
- case @selection_mode
96
- when :multiple
97
- @selected_indices.include? crow
98
- else
99
- crow == @selected_index
100
- end
101
- end
102
- alias :is_selected? is_row_selected
103
- # FIXME add adjustment and test
104
- def goto_next_selection
105
- return if selected_rows().length == 0
106
- row = selected_rows().sort.find { |i| i > @current_index }
107
- row ||= @current_index
108
- @current_index = row
109
- @repaint_required = true # fire list_select XXX
110
- end
111
- # FIXME add adjustment and test
112
- def goto_prev_selection
113
- return if selected_rows().length == 0
114
- row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @current_index }
115
- row ||= @current_index
116
- @current_index = row
117
- @repaint_required = true # fire list_select XXX
118
- end
119
- # add the following range to selected items, unless already present
120
- # should only be used if multiple selection interval
121
- def add_selection_interval ix0, ix1
122
- return if @selection_mode != :multiple
123
- @widget_scrolled = true # FIXME we need a better name
124
- @anchor_selection_index = ix0
125
- @lead_selection_index = ix1
126
- ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i }
127
- lse = ListSelectionEvent.new(ix0, ix1, self, :INSERT)
128
- fire_handler :LIST_SELECTION_EVENT, lse
129
- #$log.debug " DLSM firing LIST_SELECTION EVENT #{lse}"
130
- end
131
- alias :add_row_selection_interval :add_selection_interval
132
- def remove_selection_interval ix0, ix1
133
- @anchor_selection_index = ix0
134
- @lead_selection_index = ix1
135
- @selected_indices.delete_if {|x| x >= ix0 and x <= ix1}
136
- lse = ListSelectionEvent.new(ix0, ix1, self, :DELETE)
137
- fire_handler :LIST_SELECTION_EVENT, lse
138
- end
139
- alias :remove_row_selection_interval :remove_selection_interval
140
- # convenience method to select next len rows
141
- def insert_index_interval ix0, len
142
- @anchor_selection_index = ix0
143
- @lead_selection_index = ix0+len
144
- add_selection_interval @anchor_selection_index, @lead_selection_index
145
- end
146
- # select all rows, you may specify starting row.
147
- # if header row, then 1 else should be 0. Actually we should have a way to determine
148
- # this, and the default should be zero.
149
- def select_all start_row=0 #+@_header_adjustment
150
- @repaint_required = true
151
- # don't select header row - need to make sure this works for all cases. we may
152
- # need a variable instead of hardoded value
153
- add_row_selection_interval start_row, row_count()
154
- end
155
- def invert_selection start_row=0 #+@_header_adjustment
156
- start_row.upto(row_count()){|i| invert_row_selection i }
157
- end
158
-
159
- def invert_row_selection row=@current_index-@_header_adjustment
160
- @repaint_required = true
161
- if is_selected? row
162
- remove_row_selection_interval(row, row)
163
- else
164
- add_row_selection_interval(row, row)
165
- end
166
- end
167
- # selects all rows with the values given, leaving existing selections
168
- # intact. Typically used after accepting search criteria, and getting a list of values
169
- # to select (such as file names). Will not work with tables (array or array)
170
- def select_values values
171
- return unless values
172
- values.each do |val|
173
- row = @list.index val
174
- add_row_selection_interval row, row unless row.nil?
175
- end
176
- end
177
- # unselects all rows with the values given, leaving all other rows intact
178
- # You can map "-" to ask_select and call this from there.
179
- # bind_key(?+, :ask_select) # --> calls select_values
180
- # bind_key(?-, :ask_unselect)
181
- def unselect_values values
182
- return unless values
183
- values.each do |val|
184
- row = @list.index val
185
- remove_row_selection_interval row, row unless row.nil?
186
- end
187
- end
188
- # please override this, this is just very basic and default
189
- # Please implement get_matching_indices(String).
190
- def ask_select prompt="Enter selection pattern: "
191
- ret = ask(prompt, String) {|q| yield q if block_given? }
192
- return if ret.nil? || ret == ""
193
- indices = get_matching_indices ret
194
- return if indices.nil? || indices.empty?
195
- indices.each { |e|
196
- # will not work if single select !! FIXME
197
- add_row_selection_interval e,e
198
- }
199
- @repaint_required = true
200
- end
201
- def get_matching_indices pattern
202
- alert "please implement this method get_matching_indices(pattern)->[] in your class "
203
- return []
204
- end # mod
205
- # Applications may call this or just copy and modify
206
- def list_bindings
207
- # what about users wanting 32 and ENTER to also go to next row automatically
208
- # should make that optional, TODO
209
- bind_key(32) { toggle_row_selection }
210
- bind_key(0) { add_to_selection }
211
- bind_key(?+, :ask_select) # --> calls select_values
212
- bind_key(?-, :ask_unselect) # please implement FIXME TODO
213
- bind_key(?a, :select_all)
214
- bind_key(?*, :invert_selection)
215
- bind_key(?u, :clear_selection)
216
- @_header_adjustment ||= 0 # incase caller does not use
217
- @_events << :LIST_SELECTION_EVENT unless @_events.include? :LIST_SELECTION_EVENT
218
- end
219
- def list_init_vars
220
- @selected_indices = []
221
- @selected_index = nil
222
- @old_selected_index = nil
223
- #@row_selected_symbol = ''
224
- if @show_selector
225
- @row_selected_symbol ||= '*'
226
- @row_unselected_symbol ||= ' '
227
- @left_margin ||= @row_selected_symbol.length
228
- end
229
- end
230
- # paint the selector. Called from repaint, prior to printing data row
231
- # remember to set left_margin at top of repaint method as:
232
- # @left_margin ||= @row_selected_symbol.length
233
- def paint_selector crow, r, c, acolor, attrib
234
- selected = is_row_selected crow
235
- selection_symbol = ''
236
- if @show_selector
237
- if selected
238
- selection_symbol = @row_selected_symbol
239
- else
240
- selection_symbol = @row_unselected_symbol
241
- end
242
- @graphic.printstring r, c, selection_symbol, acolor,attrib
243
- end
244
- end
245
- def selected_rows
246
- @selected_indices
247
- end
248
- end # mod
249
- class ListSelectionEvent
250
- attr_accessor :firstrow, :lastrow, :source, :type
251
- def initialize firstrow, lastrow, source, type
252
- @firstrow = firstrow
253
- @lastrow = lastrow
254
- @source = source
255
- @type = type
256
- end
257
- def to_s
258
- "#{@type.to_s}, firstrow: #{@firstrow}, lastrow: #{@lastrow}, source: #{@source}"
259
- end
260
- def inspect
261
- to_s
262
- end
263
- end
264
- end # mod
@@ -1,166 +0,0 @@
1
- require 'rbcurse/rvimsplit'
2
- require 'forwardable'
3
- # A convenience class that implements a 3 way Master Detail like form
4
- # as in some email clients. See appemail.rb for usage.
5
- # You may use this class or extend it. It takes care of expanding,
6
- # increasing etc the 3 splits.
7
- # This class is not fully tested beyond appemail.rb, and can change
8
- # quite a bit. Users may want to copy this to prevent from major changes
9
- # that could take place.
10
- class MasterDetail < Widget
11
- dsl_property :weight
12
- attr_reader :vim # the vimsplit for any further configuration such as min_weight etc
13
- extend Forwardable
14
- def_delegators :@vim, :on_enter, :on_leave, :handle_key, :current_component
15
- def initialize form, config={}, &block
16
- @focusable = true
17
- @height = Ncurses.LINES-2
18
- @weight = 0.25
19
- super
20
- _create_vimsplit
21
- init_vars
22
- end
23
- def init_vars #:nodoc:
24
- @first_time = true
25
- @repaint_required = true
26
- end
27
- def repaint
28
- if @first_time
29
- @first_time = nil
30
- [@vim, @left, @right1, @right2].each { |e|
31
- e.set_buffering(:target_window => @target_window || @form.window, :form => @form) # removed on 2011-09-29
32
- }
33
- end
34
- @vim.repaint
35
- end
36
- # set the single component on the left side/pane, typically a +Listbox+.
37
- # If an array is passed, the Listbox created is returned for further
38
- # manipulation.
39
- # @param [Widget] component to set on left
40
- # @return [Widget] component added
41
- def set_left_component comp, weight=nil
42
- @left = @vim.add comp, :FIRST, weight
43
- _add_component comp
44
- @left
45
- end
46
- # set the first component on the right side/pane, typically a +Listbox+.
47
- # @param [Widget] component to set on right
48
- # @return [Widget] component added
49
- def set_right_top_component comp, weight=0.5
50
- @added_top = true
51
- @right1 = @vim.add comp, :SECOND, weight
52
- _add_component comp
53
- @right1
54
- end
55
- # set the second component on the right side/pane, typically a
56
- # +TextView+
57
- # @param [Widget] component to set on right
58
- # @return [Widget] component added
59
- def set_right_bottom_component comp, weight=nil
60
- raise "Please add top component first!" unless @added_top
61
- # what if user gives in wrong order !!
62
- @gb = @vim.add :divider, :SECOND, 0
63
- @right2 = @vim.add comp, :SECOND, weight
64
- @gb.next_component(@right2)
65
- _add_component comp
66
- @right2
67
- end
68
- def focus comp
69
- case comp
70
- when :left
71
- @vim.goto_component @left
72
- when :top_right
73
- @vim.goto_component @right1
74
- when :bottom_right
75
- @vim.goto_component @right2
76
- else
77
- @vim.goto_component comp
78
- end
79
- end
80
- private
81
- # does nothing at present
82
- def _add_component comp #:nodoc:
83
- end
84
- # creates a Vimplit containing 3 panes. Sets events in order to
85
- # increase and decrease panes/windows.
86
- def _create_vimsplit #:nodoc:
87
- @vim = VimSplit.new nil, :row => @row, :col => @col, :width => @width, :height => @height, :weight => @weight, :orientation => :VERTICAL, :suppress_borders => true do |s|
88
- s.parent_component = self
89
- #s.target_window = @form.window
90
- #s.add @left, :FIRST
91
- #s.add @right1, :SECOND
92
- #s.add @right2, :SECOND
93
- s.bind :COMPONENT_RESIZE_EVENT do |e|
94
- alert "masterdetail got a resize event #{e.type}, #{e.source} "
95
- case e.type
96
- when :INCREASE
97
- case e.source
98
- when @right2
99
- increase_body
100
- when @right1
101
- increase_headers
102
- when @left
103
- alert "masterdetail left increase - not handled"
104
-
105
- end
106
- when :DECREASE
107
- case e.source
108
- when @right2
109
- increase_headers
110
- when @right1
111
- increase_body
112
- when @left
113
- @left.width -= 1
114
- @right2.col -=1
115
- @right1.col -=1
116
- @right1.width +=1
117
- @right2.width +=1
118
- @right2.repaint_required true
119
- @right1.repaint_required true
120
- @left.repaint_required true
121
- alert "masterdetail left decrease"
122
- end
123
- when :EXPAND
124
- case e.source
125
- when @right2
126
- h = 3
127
- @right2.row(@right1.row + h)
128
- oldh = @right1.height
129
- @right1.height = h
130
- @right1.current_index = 0
131
- @right2.height += (oldh - h)
132
- @right2.repaint_required true
133
- @right1.repaint_required true
134
- when @right1
135
- h = 3
136
- @right2.row(@right2.row + (@right2.height - 3))
137
- oldh = @right2.height
138
- @right2.height = h
139
- #@right1.current_index = 0
140
- @right1.height += (oldh - h)
141
- @right2.repaint_required true
142
- @right1.repaint_required true
143
- end
144
- end
145
- end # bind
146
- end
147
- end # def
148
- # increase the top right pane and reduces lower one
149
- # TODO: to take into account multiplier
150
- def increase_headers #:nodoc:
151
- @right2.row @right2.row()+1
152
- @right1.height +=1
153
- @right2.height -=1
154
- @right2.repaint_required true
155
- @right1.repaint_required true
156
- end
157
- # decrease the top right pane and increase lower one
158
- # TODO: to take into account multiplier
159
- def increase_body #:nodoc:
160
- @right2.row @right2.row()-1
161
- @right1.height -=1
162
- @right2.height +=1
163
- @right2.repaint_required true
164
- @right1.repaint_required true
165
- end
166
- end # class
@@ -1,63 +0,0 @@
1
- module RubyCurses
2
- # Create a simple tree-ish structure.
3
- # Each node is not a tree, only submenus are trees
4
- # Others contain a hash with menu character and code
5
- # Typically the code is not a method symbol, it is to be
6
- # used to decode a description or method symbol from anoterh hash
7
- # @usage
8
- # menu = MenuTree.new "Main", { c: :goprev, d: :gonext, e: :gonext, s: :submenu }
9
- # menu.submenu :s, "submenu", {a: :next1, b: :next2, f: :next3 }
10
- # puts menu.hash
11
- # puts "each ..."
12
- # menu.each { |e| puts e }
13
- # menu.each_pair { |e, v| puts "#{e} #{v}" }
14
- # puts " -- :c -- "
15
- # puts menu[:c]
16
- # puts " -- :s -- "
17
- # puts menu[:s].children
18
- class MenuTree
19
- attr_reader :value
20
- def initialize value, hash = {}
21
- @value = [value, hash]
22
- end
23
- def << kv
24
- @value[1][kv[0]] = kv[1]
25
- end
26
- def hash
27
- @value[1]
28
- end
29
- alias :children :hash
30
- def push hsh
31
- hash().merge hsh
32
- end
33
- def [](x)
34
- hash()[x]
35
- end
36
- def []=(x,y)
37
- hash()[x] = y
38
- end
39
- def submenu key, value, hash = {}
40
- m = MenuTree.new value, hash
41
- #hash()[key] = [value, hash]
42
- hash()[key] = m
43
- end
44
- def each
45
- hash().keys.each { |e| yield e }
46
- end
47
- def each_pair
48
- hash().each_pair { |name, val| yield name, val }
49
- end
50
- end
51
- end
52
- if __FILE__ == $PROGRAM_NAME
53
- menu = RubyCurses::MenuTree.new "Main", { c: :goprev, d: :gonext, e: :gonext, s: :submenu }
54
- menu.submenu :s, "submenu", {a: :next1, b: :next2, f: :next3 }
55
- puts menu.hash
56
- puts "each ..."
57
- menu.each { |e| puts e }
58
- menu.each_pair { |e, v| puts "#{e} #{v}" }
59
- puts " -- :c -- "
60
- puts menu[:c]
61
- puts " -- :s -- "
62
- puts menu[:s].children
63
- end