rbcurse-core 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +7 -0
- data/VERSION +1 -1
- data/examples/dbdemo.rb +8 -2
- data/examples/testlistbox.rb +4 -1
- data/lib/rbcurse/core/include/bordertitle.rb +7 -2
- data/lib/rbcurse/core/include/chunk.rb +1 -1
- data/lib/rbcurse/core/include/listbindings.rb +70 -0
- data/lib/rbcurse/core/include/listscrollable.rb +20 -15
- data/lib/rbcurse/core/include/listselectable.rb +1 -1
- data/lib/rbcurse/core/system/window.rb +4 -2
- data/lib/rbcurse/core/widgets/applicationheader.rb +2 -1
- data/lib/rbcurse/core/widgets/rlist.rb +36 -80
- data/lib/rbcurse/core/widgets/rmenu.rb +21 -2
- data/lib/rbcurse/core/widgets/rtextarea.rb +45 -65
- data/lib/rbcurse/core/widgets/rtextview.rb +16 -59
- data/lib/rbcurse/core/widgets/rtree.rb +26 -45
- data/lib/rbcurse/core/widgets/tabularwidget.rb +17 -90
- data/rbcurse-core.gemspec +3 -2
- metadata +5 -4
@@ -685,6 +685,7 @@ module RubyCurses
|
|
685
685
|
end
|
686
686
|
def init_vars
|
687
687
|
@active_index = 0
|
688
|
+
@repaint_required = true
|
688
689
|
end
|
689
690
|
def focusable
|
690
691
|
false
|
@@ -745,6 +746,7 @@ module RubyCurses
|
|
745
746
|
# menubar LEFT, RIGHT, DOWN
|
746
747
|
def handle_keys
|
747
748
|
@selected = false
|
749
|
+
@repaint_required = true # added 2011-12-12 otherwise keeps repainting and you see a flicker
|
748
750
|
@toggle_key ||= 27 # default switch off with ESC, if nothing else defined
|
749
751
|
set_menu 0
|
750
752
|
begin
|
@@ -804,6 +806,7 @@ module RubyCurses
|
|
804
806
|
#ensure is required becos one can throw a :close
|
805
807
|
$log.debug " DESTROY IN ENSURE"
|
806
808
|
current_menu.clear_menus #@@menus = [] # added 2009-01-23 13:21
|
809
|
+
@repaint_required = false
|
807
810
|
destroy # Note that we destroy the menu bar upon exit
|
808
811
|
end
|
809
812
|
end
|
@@ -843,12 +846,14 @@ module RubyCurses
|
|
843
846
|
end
|
844
847
|
## menubar
|
845
848
|
# TODO: check for menu to be flush right (only for last one).
|
849
|
+
# TODO: repaint only if needed
|
846
850
|
def repaint
|
847
851
|
return if !@visible
|
852
|
+
return unless @repaint_required
|
853
|
+
@repaint_required = false
|
848
854
|
@color_pair = get_color($reversecolor, @color, @bgcolor)
|
849
855
|
@window ||= create_window_menubar
|
850
|
-
|
851
|
-
@window.printstring( 0, 0, "%-*s" % [@cols," "], @color_pair)
|
856
|
+
#@window.printstring( 0, 0, "%-*s" % [@cols," "], @color_pair) # this becomes blank in some terms
|
852
857
|
c = 1; r = 0;
|
853
858
|
@items.each do |item|
|
854
859
|
item.row = r; item.col = c; item.coffset = c; item.parent = self
|
@@ -871,15 +876,29 @@ module RubyCurses
|
|
871
876
|
@layout = { :height => 1, :width => 0, :top => 0, :left => 0 }
|
872
877
|
@win = VER::Window.new(@layout)
|
873
878
|
@window = @win
|
879
|
+
att = get_attrib @attr
|
874
880
|
@win.bkgd(Ncurses.COLOR_PAIR(5)); # <---- FIXME
|
881
|
+
len = @window.width
|
882
|
+
len = Ncurses.COLS-0 if len == 0
|
883
|
+
# print a bar across the screen , which hopefully will not go blank in some terms
|
884
|
+
@window.attron(Ncurses.COLOR_PAIR(@color_pair) | att)
|
885
|
+
@window.mvhline(0, 0, 1, len)
|
886
|
+
@window.attroff(Ncurses.COLOR_PAIR(@color_pair) | att)
|
875
887
|
@panel = @win.panel
|
876
888
|
return @window
|
877
889
|
end
|
878
890
|
def destroy
|
879
891
|
$log.debug "DESTRY menubar "
|
892
|
+
|
893
|
+
# when we close, but keep visible, we don't want menu to still be hightlighted
|
894
|
+
# added on 2011-12-12
|
895
|
+
menu = @items[@active_index]
|
896
|
+
menu.on_leave # hide its window, if open
|
897
|
+
|
880
898
|
@items.each do |item|
|
881
899
|
item.destroy
|
882
900
|
end
|
901
|
+
# TODO the current menu should not be highlighted
|
883
902
|
return if @keep_visible
|
884
903
|
@visible = false
|
885
904
|
panel = @window.panel
|
@@ -20,6 +20,7 @@ require 'rbcurse'
|
|
20
20
|
require 'rbcurse/core/include/listscrollable'
|
21
21
|
require 'rbcurse/core/include/rinputdataevent'
|
22
22
|
require 'rbcurse/core/include/listeditable'
|
23
|
+
require 'rbcurse/core/include/bordertitle'
|
23
24
|
|
24
25
|
#include Ncurses # FFI 2011-09-8
|
25
26
|
include RubyCurses
|
@@ -37,16 +38,16 @@ module RubyCurses
|
|
37
38
|
include ListScrollable
|
38
39
|
# NOTE: common editing functions moved to listeditable
|
39
40
|
include ListEditable
|
40
|
-
dsl_accessor :title
|
41
|
-
dsl_accessor :title_attrib # bold, reverse, normal
|
42
|
-
dsl_accessor :footer_attrib # bold, reverse, normal added 2009-12-26 18:25 was this missing or delib
|
41
|
+
#dsl_accessor :title
|
42
|
+
#dsl_accessor :title_attrib # bold, reverse, normal
|
43
|
+
#dsl_accessor :footer_attrib # bold, reverse, normal added 2009-12-26 18:25 was this missing or delib
|
43
44
|
dsl_accessor :list # the array of data to be sent by user
|
44
45
|
dsl_accessor :maxlen # max display length of a row/line
|
45
46
|
attr_reader :toprow
|
46
47
|
dsl_accessor :auto_scroll # boolean, keeps view at end as data is inserted.
|
47
48
|
dsl_accessor :print_footer
|
48
49
|
dsl_accessor :editable # allow editing
|
49
|
-
dsl_accessor :suppress_borders # added 2010-02-12 12:21 values true or false
|
50
|
+
#dsl_accessor :suppress_borders # added 2010-02-12 12:21 values true or false
|
50
51
|
attr_accessor :overwrite_mode # boolean: insert or overwrite, default false.
|
51
52
|
|
52
53
|
def initialize form = nil, config={}, &block
|
@@ -72,21 +73,18 @@ module RubyCurses
|
|
72
73
|
# 2010-01-10 19:35 compute locally if not set
|
73
74
|
install_keys
|
74
75
|
init_vars
|
76
|
+
bordertitle_init
|
75
77
|
end
|
76
78
|
def init_vars
|
77
79
|
@repaint_required = true
|
78
80
|
@repaint_footer_required = true # 2010-01-23 22:41
|
79
81
|
@toprow = @current_index = @pcol = 0
|
80
82
|
@repaint_all=true
|
81
|
-
|
82
|
-
@row_offset = @col_offset = 0 if @suppress_borders == true
|
83
|
-
# added 2010-02-11 15:11 RFED16 so we don't need a form.
|
84
|
-
@win_left = 0
|
85
|
-
@win_top = 0
|
83
|
+
@row_offset = @col_offset = 0 if @suppress_borders
|
86
84
|
@longest_line = 0
|
87
85
|
# if borders used, reduce 2 from width else 0
|
88
86
|
@internal_width = 2
|
89
|
-
@internal_width = 2 if @suppress_borders
|
87
|
+
@internal_width = 2 if @suppress_borders # WHAT THE !!!! It should be zero
|
90
88
|
bind_key(?\M-w, :kill_ring_save)
|
91
89
|
bind_key(?\C-y, :yank)
|
92
90
|
bind_key(?\M-y, :yank_pop)
|
@@ -180,7 +178,7 @@ module RubyCurses
|
|
180
178
|
end
|
181
179
|
##
|
182
180
|
# private
|
183
|
-
def
|
181
|
+
def OLDprint_borders
|
184
182
|
window = @graphic # 2009-12-26 14:54 BUFFERED
|
185
183
|
@color_pair = get_color($datacolor) # 2011-09-28 V1.3.1
|
186
184
|
bordercolor = @border_color || @color_pair
|
@@ -202,7 +200,7 @@ module RubyCurses
|
|
202
200
|
|
203
201
|
end
|
204
202
|
# private
|
205
|
-
def
|
203
|
+
def OLDprint_title
|
206
204
|
# truncate title if longer than width
|
207
205
|
return unless @title
|
208
206
|
@color_pair ||= get_color($datacolor)
|
@@ -279,33 +277,49 @@ module RubyCurses
|
|
279
277
|
|
280
278
|
def map_keys
|
281
279
|
return if @keys_mapped
|
282
|
-
|
283
|
-
|
284
|
-
|
280
|
+
@key_map = :both # get both vim and emacs keys
|
281
|
+
require 'rbcurse/core/include/listbindings'
|
282
|
+
bindings
|
283
|
+
#
|
284
|
+
# There's one issue, if using vim keys, most of them won't
|
285
|
+
# work in text area. So you will need emacs keys in text area.
|
286
|
+
|
287
|
+
# moved to listbin
|
288
|
+
#bind_key(Ncurses::KEY_LEFT){ cursor_backward }
|
289
|
+
#bind_key(Ncurses::KEY_RIGHT){ cursor_forward }
|
290
|
+
#bind_key(Ncurses::KEY_UP){ ret = up; get_window.ungetch(KEY_BTAB) if ret == :NO_PREVIOUS_ROW }
|
285
291
|
# the next was irritating if user wanted to add a row ! 2011-10-10
|
286
|
-
|
287
|
-
bind_key(Ncurses::KEY_DOWN){ ret = down ; }
|
288
|
-
bind_key(?\C-a, 'start of line'){ cursor_bol }
|
289
|
-
bind_key(?\C-e, 'end of line'){ cursor_eol }
|
290
|
-
bind_key(?\C-d, 'scroll forward') { scroll_forward }
|
291
|
-
bind_key(?\C-b, 'scroll backward') { scroll_backward }
|
292
|
-
bind_key(?\C-[, 'goto start') { goto_start }
|
293
|
-
bind_key(?\C-], 'goto end') { goto_end }
|
292
|
+
##bind_key(Ncurses::KEY_DOWN){ ret = down ; get_window.ungetch(KEY_TAB) if ret == :NO_NEXT_ROW }
|
293
|
+
#bind_key(Ncurses::KEY_DOWN){ ret = down ; }
|
294
294
|
|
295
295
|
bind_key(KEY_BACKSPACE){ delete_prev_char if @editable }
|
296
296
|
bind_key(KEY_BSPACE){ delete_prev_char if @editable}
|
297
297
|
bind_key(?\M-d, :delete_word)
|
298
298
|
bind_key(?\M-f, :forward_word)
|
299
299
|
|
300
|
-
#
|
301
|
-
bind_key(
|
302
|
-
|
303
|
-
|
300
|
+
# earlier 330
|
301
|
+
bind_key(FFI::NCurses::KEY_DC, 'delete current char'){ delete_curr_char if @editable }
|
302
|
+
bind_key(?\C-k, 'kill line'){ kill_line }
|
303
|
+
bind_key(?\C-_, 'undo'){ undo }
|
304
|
+
bind_key(?\C-r, 'redo') { text_redo }
|
304
305
|
#bind_key(27){ set_buffer @original_value }
|
305
|
-
bind_key([?\C-x, ?e], :edit_external)
|
306
|
-
bind_key([?\C-x, ?\C-s], :saveas)
|
306
|
+
#bind_key([?\C-x, ?e], :edit_external)
|
307
|
+
#bind_key([?\C-x, ?\C-s], :saveas)
|
307
308
|
@keys_mapped = true
|
308
309
|
end
|
310
|
+
# mimicking emacs behavior of C-k.
|
311
|
+
# delete entire line if at start, else delete till eol
|
312
|
+
def kill_line
|
313
|
+
# i'ved added curpos == 0 since emacs deletes a line if cursor is at 0
|
314
|
+
# Earlier behavior was based on alpine which leaves a blank line
|
315
|
+
if @editable
|
316
|
+
if @buffer.chomp == "" || @curpos == 0
|
317
|
+
delete_line
|
318
|
+
else
|
319
|
+
delete_eol
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
309
323
|
|
310
324
|
# textarea
|
311
325
|
def handle_key ch
|
@@ -332,49 +346,15 @@ module RubyCurses
|
|
332
346
|
end
|
333
347
|
#$log.debug "TA: after : curpos #{@curpos} blen: #{@buffer.length}, w: #{@width} max #{@maxlen}"
|
334
348
|
|
349
|
+
#NOTE C-d being used for del what of scroll !!
|
335
350
|
case ch
|
336
|
-
when KEY_ENTER,
|
351
|
+
when KEY_ENTER, KEY_RETURN, FFI::NCurses::KEY_ENTER # numeric enter
|
337
352
|
insert_break
|
338
|
-
when Ncurses.KEY_BACKSPACE, Ncurses.KEY_BSPACE
|
339
|
-
if @editable # checking here means that i can programmatically bypass!!
|
340
|
-
delete_prev_char
|
341
|
-
end
|
342
|
-
when Ncurses.KEY_DELETE, ?\C-d.getbyte(0) # delete char
|
343
|
-
if @editable
|
344
|
-
delete_curr_char
|
345
|
-
end
|
346
|
-
when ?\C-k.getbyte(0) # delete till eol
|
347
|
-
# i'ved added curpos == 0 since emacs deletes a line if cursor is at 0
|
348
|
-
# Earlier behavior was based on alpine which leaves a blank line
|
349
|
-
if @editable
|
350
|
-
#if @buffer == ""
|
351
|
-
if @buffer.chomp == "" || @curpos == 0
|
352
|
-
delete_line
|
353
|
-
else
|
354
|
-
delete_eol
|
355
|
-
end
|
356
|
-
end
|
357
353
|
#when ?\C-u.getbyte(0)
|
358
354
|
## since textareas are editable we use a control key to increase
|
359
355
|
## multiplier. Series is 4 16 64
|
360
356
|
#@multiplier = (@multiplier == 0 ? 4 : @multiplier *= 4)
|
361
357
|
#return 0
|
362
|
-
when ?\C-_.getbyte(0) # changed from C-u so i can use C-u for multipliers
|
363
|
-
undo
|
364
|
-
when ?\C-r.getbyte(0) # redo if UndoHandler installed
|
365
|
-
text_redo # won't accept name redo
|
366
|
-
#when @KEY_ASK_FIND_FORWARD
|
367
|
-
# ask_search_forward
|
368
|
-
#when @KEY_ASK_FIND_BACKWARD
|
369
|
-
# ask_search_backward
|
370
|
-
when @KEY_ASK_FIND
|
371
|
-
ask_search
|
372
|
-
when @KEY_FIND_MORE
|
373
|
-
find_more
|
374
|
-
#when @KEY_FIND_NEXT
|
375
|
-
# find_next
|
376
|
-
#when @KEY_FIND_PREV
|
377
|
-
# find_prev
|
378
358
|
else
|
379
359
|
#$log.debug(" textarea ch #{ch}")
|
380
360
|
ret = putc ch
|
@@ -14,6 +14,7 @@ TODO
|
|
14
14
|
require 'logger'
|
15
15
|
require 'rbcurse'
|
16
16
|
require 'rbcurse/core/include/listscrollable'
|
17
|
+
require 'rbcurse/core/include/bordertitle'
|
17
18
|
require 'forwardable'
|
18
19
|
|
19
20
|
include RubyCurses
|
@@ -30,19 +31,15 @@ module RubyCurses
|
|
30
31
|
include ListScrollable
|
31
32
|
extend Forwardable
|
32
33
|
#dsl_accessor :height # height of viewport cmmented on 2010-01-09 19:29 since widget has method
|
33
|
-
dsl_accessor :title # set this on top
|
34
|
-
dsl_accessor :title_attrib # bold, reverse, normal
|
34
|
+
#dsl_accessor :title # set this on top
|
35
|
+
#dsl_accessor :title_attrib # bold, reverse, normal
|
35
36
|
dsl_accessor :footer_attrib # bold, reverse, normal
|
36
37
|
dsl_accessor :list # the array of data to be sent by user
|
37
38
|
dsl_accessor :maxlen # max len to be displayed
|
38
39
|
attr_reader :toprow # the toprow in the view (offsets are 0)
|
39
|
-
# attr_reader :prow # the row on which cursor/focus is
|
40
|
-
#attr_reader :winrow # the row in the viewport/window
|
41
40
|
# painting the footer does slow down cursor painting slightly if one is moving cursor fast
|
42
41
|
dsl_accessor :print_footer
|
43
|
-
dsl_accessor :suppress_borders # added 2010-02-10 20:05 values true or false
|
44
42
|
attr_reader :current_index
|
45
|
-
dsl_accessor :border_attrib, :border_color #
|
46
43
|
dsl_accessor :sanitization_required
|
47
44
|
|
48
45
|
def initialize form = nil, config={}, &block
|
@@ -65,6 +62,7 @@ module RubyCurses
|
|
65
62
|
@_events << :PRESS # new, in case we want to use this for lists and allow ENTER
|
66
63
|
@_events << :ENTER_ROW # new, should be there in listscrollable ??
|
67
64
|
install_keys # do something about this nonsense FIXME
|
65
|
+
bordertitle_init
|
68
66
|
init_vars
|
69
67
|
end
|
70
68
|
def init_vars #:nodoc:
|
@@ -81,23 +79,16 @@ module RubyCurses
|
|
81
79
|
# longest line on screen.
|
82
80
|
@longest_line = 0 # the longest line printed on this page, used to determine if scrolling shd work
|
83
81
|
@internal_width = 2
|
84
|
-
@internal_width = 0 if @suppress_borders
|
82
|
+
@internal_width = 0 if @suppress_borders # NOTE bordertitle says 1
|
85
83
|
|
84
|
+
@search_found_ix = nil # so old searches don't get highlighted
|
86
85
|
end
|
87
86
|
def map_keys
|
88
|
-
|
89
|
-
|
90
|
-
bind_key([
|
91
|
-
bind_key(
|
92
|
-
bind_key(
|
93
|
-
bind_key([?\C-x, ?>], :scroll_right)
|
94
|
-
bind_key([?\C-x, ?<], :scroll_left)
|
95
|
-
bind_key(?\M-l, :scroll_right)
|
96
|
-
bind_key(?\M-h, :scroll_left)
|
97
|
-
bind_key([?\C-x, ?\C-s], :saveas)
|
98
|
-
bind_key([?\C-x, ?e], :edit_external)
|
99
|
-
bind_keys([?\C-d, 32], 'scroll forward'){ scroll_forward() }
|
100
|
-
bind_key(?\C-b, 'scroll backward'){ scroll_backward() }
|
87
|
+
require 'rbcurse/core/include/listbindings'
|
88
|
+
bindings()
|
89
|
+
#bind_key([?\C-x, ?\C-s], :saveas)
|
90
|
+
#bind_key([?\C-x, ?e], :edit_external)
|
91
|
+
bind_key(32, 'scroll forward'){ scroll_forward() }
|
101
92
|
# have placedhere so multi-bufer can override BS to prev buffer
|
102
93
|
bind_keys([KEY_BACKSPACE,KEY_BSPACE,KEY_DELETE], :cursor_backward)
|
103
94
|
bind_key(?r) { getstr("Enter a word: ") } if $log.debug?
|
@@ -215,33 +206,6 @@ module RubyCurses
|
|
215
206
|
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
|
216
207
|
"\\1\\3\n")
|
217
208
|
end
|
218
|
-
## print a border
|
219
|
-
## Note that print_border clears the area too, so should be used sparingly.
|
220
|
-
def print_borders #:nodoc:
|
221
|
-
raise "textview needs width" unless @width
|
222
|
-
raise "textview needs height" unless @height
|
223
|
-
|
224
|
-
$log.debug " #{@name} print_borders, #{@graphic.name} "
|
225
|
-
|
226
|
-
@color_pair = get_color($datacolor) # added 2011-09-28 as in rlistbox
|
227
|
-
# bordercolor = @border_color || $datacolor # changed 2011 dts
|
228
|
-
bordercolor = @border_color || @color_pair # 2011-09-28 V1.3.1
|
229
|
-
borderatt = @border_attrib || Ncurses::A_NORMAL
|
230
|
-
@graphic.print_border @row, @col, @height-1, @width, bordercolor, borderatt
|
231
|
-
print_title
|
232
|
-
end
|
233
|
-
def print_title #:nodoc:
|
234
|
-
return unless @title
|
235
|
-
raise "textview needs width" unless @width
|
236
|
-
@color_pair ||= get_color($datacolor) # should we not use this ??? XXX
|
237
|
-
|
238
|
-
# check title.length and truncate if exceeds width
|
239
|
-
_title = @title
|
240
|
-
if @title.length > @width - 2
|
241
|
-
_title = @title[0..@width-2]
|
242
|
-
end
|
243
|
-
@graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil?
|
244
|
-
end
|
245
209
|
def print_foot #:nodoc:
|
246
210
|
@footer_attrib ||= Ncurses::A_REVERSE
|
247
211
|
footer = "R: #{@current_index+1}, C: #{@curpos+@pcol}, #{@list.length} lines "
|
@@ -309,7 +273,7 @@ module RubyCurses
|
|
309
273
|
$log.debug " textview got ch #{ch} "
|
310
274
|
@old_pcol = @pcol
|
311
275
|
@buffer = @list[@current_index]
|
312
|
-
if @buffer.nil?
|
276
|
+
if @buffer.nil? && row_count == 0
|
313
277
|
@list << "\r"
|
314
278
|
@buffer = @list[@current_index]
|
315
279
|
end
|
@@ -334,12 +298,10 @@ module RubyCurses
|
|
334
298
|
# This should be configurable, or only if all rows are visible
|
335
299
|
#get_window.ungetch(KEY_TAB) if ret == :NO_NEXT_ROW
|
336
300
|
check_curpos
|
337
|
-
when KEY_LEFT, ?h.getbyte(0)
|
338
|
-
cursor_backward
|
339
|
-
when KEY_RIGHT, ?l.getbyte(0)
|
340
|
-
cursor_forward
|
341
|
-
#when KEY_BACKSPACE, KEY_BSPACE, KEY_DELETE
|
301
|
+
#when KEY_LEFT, ?h.getbyte(0)
|
342
302
|
#cursor_backward
|
303
|
+
#when KEY_RIGHT, ?l.getbyte(0)
|
304
|
+
#cursor_forward
|
343
305
|
when ?\C-a.getbyte(0) #, ?0.getbyte(0)
|
344
306
|
# take care of data that exceeds maxlen by scrolling and placing cursor at start
|
345
307
|
@repaint_required = true if @pcol > 0 # tried other things but did not work
|
@@ -351,12 +313,7 @@ module RubyCurses
|
|
351
313
|
# it only goes to end of visible screen, set_form probably does a sanity check
|
352
314
|
blen = row_length # @buffer.rstrip.length FIXME
|
353
315
|
set_form_col blen
|
354
|
-
|
355
|
-
when @KEY_ASK_FIND
|
356
|
-
ask_search
|
357
|
-
when @KEY_FIND_MORE
|
358
|
-
find_more
|
359
|
-
when 10, 13, KEY_ENTER
|
316
|
+
when KEY_ENTER, FFI::NCurses::KEY_ENTER
|
360
317
|
#fire_handler :PRESS, self
|
361
318
|
fire_action_event
|
362
319
|
when ?0.getbyte(0)..?9.getbyte(0)
|
@@ -16,6 +16,7 @@ TODO:
|
|
16
16
|
require 'rbcurse'
|
17
17
|
require 'rbcurse/core/widgets/tree/treemodel'
|
18
18
|
require 'rbcurse/core/widgets/tree/treecellrenderer'
|
19
|
+
require 'rbcurse/core/include/bordertitle'
|
19
20
|
|
20
21
|
TreeSelectionEvent = Struct.new(:node, :tree, :state, :previous_node, :row_first)
|
21
22
|
|
@@ -32,9 +33,9 @@ module RubyCurses
|
|
32
33
|
include ListScrollable
|
33
34
|
#extend Forwardable
|
34
35
|
dsl_accessor :height
|
35
|
-
dsl_accessor :title
|
36
|
-
dsl_property :title_attrib # bold, reverse, normal
|
37
|
-
dsl_accessor :border_attrib, :border_color # FIXME not used currently
|
36
|
+
#dsl_accessor :title
|
37
|
+
#dsl_property :title_attrib # bold, reverse, normal
|
38
|
+
#dsl_accessor :border_attrib, :border_color # FIXME not used currently
|
38
39
|
|
39
40
|
attr_reader :toprow
|
40
41
|
# attr_reader :prow
|
@@ -44,7 +45,7 @@ module RubyCurses
|
|
44
45
|
dsl_accessor :selected_color, :selected_bgcolor, :selected_attr
|
45
46
|
dsl_accessor :max_visible_items # how many to display 2009-01-11 16:15
|
46
47
|
dsl_accessor :cell_editing_allowed # obsolete
|
47
|
-
dsl_accessor :suppress_borders
|
48
|
+
#dsl_accessor :suppress_borders
|
48
49
|
dsl_property :show_selector
|
49
50
|
dsl_property :row_selected_symbol # 2009-01-12 12:01 changed from selector to selected
|
50
51
|
dsl_property :row_unselected_symbol # added 2009-01-12 12:00
|
@@ -82,14 +83,15 @@ module RubyCurses
|
|
82
83
|
@longest_line = 0
|
83
84
|
|
84
85
|
|
85
|
-
|
86
|
-
|
86
|
+
#@win_left = 0
|
87
|
+
#@win_top = 0
|
87
88
|
@_events.push(*[:ENTER_ROW, :LEAVE_ROW, :TREE_COLLAPSED_EVENT, :TREE_EXPANDED_EVENT, :TREE_SELECTION_EVENT, :TREE_WILL_COLLAPSE_EVENT, :TREE_WILL_EXPAND_EVENT])
|
88
89
|
|
89
90
|
|
90
91
|
bind(:PROPERTY_CHANGE){|e| @cell_renderer = nil } # will be recreated if anything changes 2011-09-28 V1.3.1
|
91
92
|
# FIXME the above is dangerous if user set his own renderer with some values XXX
|
92
93
|
init_vars
|
94
|
+
bordertitle_init
|
93
95
|
|
94
96
|
#if !@list.selected_index.nil?
|
95
97
|
#set_focus_on @list.selected_index # the new version
|
@@ -109,48 +111,28 @@ module RubyCurses
|
|
109
111
|
@row_offset = @col_offset = 0 if @suppress_borders
|
110
112
|
@internal_width = 2 # taking into account borders accounting for 2 cols
|
111
113
|
@internal_width = 0 if @suppress_borders # should it be 0 ???
|
114
|
+
map_keys unless @keys_mapped
|
112
115
|
|
113
116
|
end
|
114
117
|
# maps keys to methods
|
115
118
|
# checks @key_map can be :emacs or :vim.
|
116
119
|
def map_keys
|
117
120
|
@keys_mapped = true
|
118
|
-
|
119
|
-
bind_key(
|
120
|
-
bind_key(
|
121
|
-
bind_key(?
|
122
|
-
bind_key(
|
123
|
-
bind_key(
|
124
|
-
bind_key(
|
125
|
-
bind_key(KEY_UP){ previous_row() }
|
126
|
-
bind_key(?O){ expand_children() }
|
127
|
-
bind_key(?X){ collapse_children() }
|
121
|
+
bind_key(32, 'toggle row selection'){ toggle_row_selection() }
|
122
|
+
bind_key(KEY_ENTER, 'toggle expanded state') { toggle_expanded_state() }
|
123
|
+
bind_key(?o, 'toggle expanded state') { toggle_expanded_state() }
|
124
|
+
bind_key(?f, 'first row starting with char'){ ask_selection_for_char() }
|
125
|
+
bind_key(?\M-v, 'one key selection toggle'){ @one_key_selection = !@one_key_selection }
|
126
|
+
bind_key(?O, 'expand children'){ expand_children() }
|
127
|
+
bind_key(?X, 'collapse children'){ collapse_children() }
|
128
128
|
bind_key(?>, :scroll_right)
|
129
129
|
bind_key(?<, :scroll_left)
|
130
|
-
bind_key(?\M-l, :scroll_right)
|
131
|
-
bind_key(?\M-h, :scroll_left)
|
132
130
|
# TODO
|
133
|
-
bind_key(?x){ collapse_parent() }
|
134
|
-
bind_key(?p){ goto_parent() }
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
bind_key(?\M-v){ scroll_backward }
|
139
|
-
bind_key(?\C-s){ ask_search() }
|
140
|
-
bind_key(?\C-n){ next_row() }
|
141
|
-
bind_key(?\C-p){ previous_row() }
|
142
|
-
bind_key(?\M->){ goto_bottom() }
|
143
|
-
bind_key(?\M-<){ goto_top() }
|
144
|
-
else # :vim
|
145
|
-
$log.debug " VIM cam in XXXX map keys"
|
146
|
-
bind_key(?j){ next_row() }
|
147
|
-
bind_key(?k){ previous_row() }
|
148
|
-
bind_key(?\C-d){ scroll_forward }
|
149
|
-
bind_key(?\C-b){ scroll_backward }
|
150
|
-
bind_key(?G){ goto_bottom() }
|
151
|
-
bind_key([?g,?g]){ goto_top() }
|
152
|
-
bind_key(?/){ ask_search() }
|
153
|
-
end
|
131
|
+
bind_key(?x, 'collapse parent'){ collapse_parent() }
|
132
|
+
bind_key(?p, 'goto parent'){ goto_parent() }
|
133
|
+
require 'rbcurse/core/include/listbindings'
|
134
|
+
#ListBindings.bindings
|
135
|
+
bindings
|
154
136
|
end
|
155
137
|
|
156
138
|
##
|
@@ -270,7 +252,7 @@ module RubyCurses
|
|
270
252
|
toggle_row_selection
|
271
253
|
@default_value = nil
|
272
254
|
end
|
273
|
-
def
|
255
|
+
def OLDprint_borders
|
274
256
|
width = @width
|
275
257
|
height = @height-1 # 2010-01-04 15:30 BUFFERED HEIGHT
|
276
258
|
window = @graphic # 2010-01-04 12:37 BUFFERED
|
@@ -284,7 +266,7 @@ module RubyCurses
|
|
284
266
|
window.print_border startrow, startcol, height, width, bordercolor, borderatt
|
285
267
|
print_title
|
286
268
|
end
|
287
|
-
def
|
269
|
+
def OLDprint_title
|
288
270
|
return unless @title
|
289
271
|
_title = @title
|
290
272
|
if @title.length > @width - 2
|
@@ -301,7 +283,7 @@ module RubyCurses
|
|
301
283
|
@list
|
302
284
|
end
|
303
285
|
def get_window
|
304
|
-
@graphic
|
286
|
+
@graphic
|
305
287
|
end
|
306
288
|
### END FOR scrollable ###
|
307
289
|
# override widgets text
|
@@ -313,7 +295,6 @@ module RubyCurses
|
|
313
295
|
return if @list.nil? || @list.empty?
|
314
296
|
@current_index ||= 0
|
315
297
|
@toprow ||= 0
|
316
|
-
map_keys unless @keys_mapped
|
317
298
|
h = scrollatrow()
|
318
299
|
rc = row_count
|
319
300
|
$log.debug " tree got ch #{ch}"
|
@@ -451,8 +432,8 @@ module RubyCurses
|
|
451
432
|
|
452
433
|
raise " #{@name} neither form, nor target window given TV paint " unless my_win
|
453
434
|
raise " #{@name} NO GRAPHIC set as yet TV paint " unless @graphic
|
454
|
-
|
455
|
-
|
435
|
+
#@win_left = my_win.left
|
436
|
+
#@win_top = my_win.top
|
456
437
|
|
457
438
|
$log.debug "rtree repaint #{@name} graphic #{@graphic}"
|
458
439
|
print_borders unless @suppress_borders # do this once only, unless everything changes
|