rbcurse 1.4.0 → 1.4.1.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/NOTES +68 -0
- data/README.markdown +73 -330
- data/TODO2.txt +2 -2
- data/VERSION +1 -1
- data/examples/abasiclist.rb +8 -2
- data/examples/alpmenu.rb +1 -1
- data/examples/app.rb +1 -24
- data/examples/appdirtree.rb +1 -1
- data/examples/appemail.rb +8 -14
- data/examples/appemaillb.rb +2 -2
- data/examples/appgcompose.rb +7 -5
- data/examples/common/file.rb +40 -0
- data/examples/{rmail.rb → common/rmail.rb} +0 -0
- data/examples/data/README.markdown +9 -0
- data/examples/data/brew.txt +38 -0
- data/examples/data/color.2 +37 -0
- data/examples/data/gemlist.txt +60 -0
- data/examples/data/lotr.txt +12 -0
- data/examples/data/ports.txt +136 -0
- data/examples/data/tasks.txt +27 -0
- data/examples/{todocsv.csv → data/todocsv.csv} +0 -0
- data/examples/data/unix1.txt +21 -0
- data/examples/data/unix2.txt +11 -0
- data/examples/dbdemo.rb +49 -14
- data/examples/{appgmail.rb → deprecated/appgmail.rb} +1 -1
- data/examples/{splitp.rb → deprecated/splitp.rb} +0 -0
- data/examples/{testscrolllb.rb → deprecated/testscrolllb.rb} +0 -0
- data/examples/{testscrollp.rb → deprecated/testscrollp.rb} +0 -0
- data/examples/{testscrollta.rb → deprecated/testscrollta.rb} +0 -0
- data/examples/{testscrolltable.rb → deprecated/testscrolltable.rb} +0 -0
- data/examples/{testsplit.rb → deprecated/testsplit.rb} +0 -0
- data/examples/{testsplit2.rb → deprecated/testsplit2.rb} +0 -0
- data/examples/{testsplit3.rb → deprecated/testsplit3.rb} +0 -0
- data/examples/{testsplit3_1.rb → deprecated/testsplit3_1.rb} +0 -0
- data/examples/{testsplit3a.rb → deprecated/testsplit3a.rb} +0 -0
- data/examples/{testsplit3b.rb → deprecated/testsplit3b.rb} +0 -0
- data/examples/{testsplitta.rb → deprecated/testsplitta.rb} +0 -0
- data/examples/{testsplittv.rb → deprecated/testsplittv.rb} +0 -0
- data/examples/{testsplittvv.rb → deprecated/testsplittvv.rb} +0 -0
- data/examples/{testtpane.rb → deprecated/testtpane.rb} +0 -0
- data/examples/{testtpane2.rb → deprecated/testtpane2.rb} +0 -0
- data/examples/{testtpanetable.rb → deprecated/testtpanetable.rb} +0 -0
- data/examples/dirtree.rb +17 -7
- data/examples/experimental/resultsetdemo.rb +280 -0
- data/examples/experimental/testmform.rb +35 -0
- data/examples/{testscroller.rb → experimental/testscroller.rb} +1 -19
- data/examples/experimental/teststackflow.rb +111 -0
- data/examples/menu1.rb +1 -0
- data/examples/multispl.rb +4 -4
- data/examples/newmessagebox.rb +130 -0
- data/examples/newtabbedwindow.rb +100 -0
- data/examples/newtesttabp.rb +0 -3
- data/examples/qdfilechooser.rb +0 -3
- data/examples/rfe.rb +134 -18
- data/examples/rfe_renderer.rb +48 -2
- data/examples/sqlc.rb +2 -1
- data/examples/sqlm.rb +0 -2
- data/examples/table1.rb +1 -7
- data/examples/term2.rb +4 -1
- data/examples/test1.rb +0 -5
- data/examples/test2.rb +42 -31
- data/examples/testapp2.rb +8 -1
- data/examples/testchars.rb +0 -4
- data/examples/testcombo.rb +5 -9
- data/examples/testkeypress.rb +0 -3
- data/examples/testmenu.rb +0 -4
- data/examples/testmulticomp.rb +3 -5
- data/examples/testmulticontainer.rb +94 -0
- data/examples/testtable.rb +0 -5
- data/examples/testtabp.rb +16 -18
- data/examples/testtodo.rb +1 -5
- data/examples/testwsshortcuts.rb +64 -0
- data/examples/testwsshortcuts2.rb +126 -0
- data/examples/viewtodo.rb +1 -4
- data/lib/rbcurse.rb +1 -1
- data/lib/rbcurse/app.rb +92 -69
- data/lib/rbcurse/applicationheader.rb +46 -6
- data/lib/rbcurse/celleditor.rb +1 -9
- data/lib/rbcurse/comboboxcellrenderer.rb +0 -4
- data/lib/rbcurse/common/ansiparser.rb +117 -0
- data/{examples → lib/rbcurse/common}/appmethods.rb +25 -0
- data/lib/rbcurse/common/basestack.rb +407 -0
- data/lib/rbcurse/common/bordertitle.rb +41 -0
- data/lib/rbcurse/common/chunk.rb +177 -0
- data/lib/rbcurse/common/colorparser.rb +71 -0
- data/lib/rbcurse/common/keydefs.rb +30 -0
- data/lib/rbcurse/common/widgetshortcuts.rb +302 -0
- data/lib/rbcurse/deprecated/README.markdown +12 -0
- data/lib/rbcurse/{rscrollpane.rb → deprecated/rscrollpane.rb} +0 -0
- data/lib/rbcurse/{rsplitpane.rb → deprecated/rsplitpane.rb} +0 -0
- data/lib/rbcurse/{rsplitpane2.rb → deprecated/rsplitpane2.rb} +0 -0
- data/lib/rbcurse/{rviewport.rb → deprecated/rviewport.rb} +0 -0
- data/lib/rbcurse/experimental/README.markdown +14 -0
- data/lib/rbcurse/experimental/resultsettextview.rb +585 -0
- data/lib/rbcurse/experimental/stackflow.rb +478 -0
- data/lib/rbcurse/extras/bottomline.rb +85 -16
- data/lib/rbcurse/extras/box.rb +58 -0
- data/lib/rbcurse/extras/directorylist.rb +1 -1
- data/lib/rbcurse/extras/horizlist.rb +203 -0
- data/lib/rbcurse/extras/listselectable.rb +8 -0
- data/lib/rbcurse/extras/multiform.rb +330 -0
- data/lib/rbcurse/extras/multilinelabel.rb +142 -0
- data/lib/rbcurse/extras/newmessagebox.rb +328 -0
- data/lib/rbcurse/extras/newtabbedpane.rb +612 -0
- data/lib/rbcurse/extras/newtabbedwindow.rb +68 -0
- data/lib/rbcurse/extras/padreader.rb +189 -0
- data/lib/rbcurse/extras/rcomboedit.rb +256 -0
- data/lib/rbcurse/extras/resultsetbrowser.rb +281 -0
- data/lib/rbcurse/extras/statusline.rb +44 -6
- data/lib/rbcurse/extras/tabularwidget.rb +141 -104
- data/lib/rbcurse/extras/textpad.rb +516 -0
- data/lib/rbcurse/extras/viewer.rb +2 -0
- data/lib/rbcurse/io.rb +120 -3
- data/lib/rbcurse/listcellrenderer.rb +2 -1
- data/lib/rbcurse/listkeys.rb +1 -1
- data/lib/rbcurse/listscrollable.rb +72 -7
- data/lib/rbcurse/rbasiclistbox.rb +64 -12
- data/lib/rbcurse/rchangeevent.rb +0 -1
- data/lib/rbcurse/rcombo.rb +54 -59
- data/lib/rbcurse/rcommandwindow.rb +46 -10
- data/lib/rbcurse/rcontainer.rb +415 -0
- data/lib/rbcurse/rdialogs.rb +242 -165
- data/lib/rbcurse/rinputdataevent.rb +0 -1
- data/lib/rbcurse/rlistbox.rb +19 -9
- data/lib/rbcurse/rmessagebox.rb +1 -5
- data/lib/rbcurse/rmulticontainer.rb +64 -61
- data/lib/rbcurse/rmultitextview.rb +0 -2
- data/lib/rbcurse/rpopupmenu.rb +0 -2
- data/lib/rbcurse/rscrollform.rb +61 -12
- data/lib/rbcurse/rtabbedpane.rb +89 -73
- data/lib/rbcurse/rtabbedwindow.rb +53 -211
- data/lib/rbcurse/rtable.rb +0 -2
- data/lib/rbcurse/rtextarea.rb +14 -14
- data/lib/rbcurse/rtextview.rb +165 -50
- data/lib/rbcurse/rvimsplit.rb +15 -12
- data/lib/rbcurse/rwidget.rb +404 -150
- data/lib/rbcurse/table/tablecellrenderer.rb +1 -4
- data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -3
- data/lib/ver/ncurses.rb +1 -9
- data/lib/ver/rpad.rb +375 -0
- data/lib/ver/window.rb +262 -440
- metadata +73 -31
data/lib/rbcurse/io.rb
CHANGED
@@ -620,14 +620,30 @@ module Io
|
|
620
620
|
# This allows us to define different menus for different objects on the screen, and not have to map
|
621
621
|
# all kinds of control keys for operations, and have the user remember them. Only one key invokes the menu
|
622
622
|
# and the rest are ordinary characters.
|
623
|
+
#
|
624
|
+
# == Example
|
625
|
+
# menu = PromptMenu.new self do
|
626
|
+
# item :s, :goto_start
|
627
|
+
# item :b, :goto_bottom
|
628
|
+
# item :r, :scroll_backward
|
629
|
+
# item :l, :scroll_forward
|
630
|
+
# submenu :m, "submenu" do
|
631
|
+
# item :p, :goto_last_position
|
632
|
+
# item :r, :scroll_backward
|
633
|
+
# item :l, :scroll_forward
|
634
|
+
# end
|
635
|
+
# end
|
636
|
+
# menu.display @form.window, $error_message_row, $error_message_col, $datacolor #, menu
|
637
|
+
|
623
638
|
class PromptMenu
|
624
639
|
include Io
|
625
640
|
attr_reader :text
|
626
641
|
attr_reader :options
|
627
|
-
def initialize caller, text="Choose:"
|
642
|
+
def initialize caller, text="Choose:", &block
|
628
643
|
@caller = caller
|
629
644
|
@text = text
|
630
645
|
@options = []
|
646
|
+
instance_eval &block if block_given?
|
631
647
|
end
|
632
648
|
def add *menuitem
|
633
649
|
item = nil
|
@@ -636,11 +652,19 @@ module Io
|
|
636
652
|
item = menuitem.first
|
637
653
|
@options << item
|
638
654
|
else
|
639
|
-
|
655
|
+
case menuitem.size
|
656
|
+
when 4
|
657
|
+
item = CMenuItem.new(*menuitem.flatten)
|
658
|
+
when 2
|
659
|
+
# if user only sends key and symbol
|
660
|
+
menuitem[3] = menuitem[1]
|
661
|
+
item = CMenuItem.new(*menuitem.flatten)
|
662
|
+
end
|
640
663
|
@options << item
|
641
664
|
end
|
642
665
|
return item
|
643
666
|
end
|
667
|
+
alias :item :add
|
644
668
|
def create_mitem *args
|
645
669
|
item = CMenuItem.new(*args.flatten)
|
646
670
|
end
|
@@ -659,14 +683,107 @@ module Io
|
|
659
683
|
end
|
660
684
|
}
|
661
685
|
end
|
686
|
+
#
|
687
|
+
# To allow a more rubyesque way of defining menus and submenus
|
688
|
+
def submenu key, label, &block
|
689
|
+
item = CMenuItem.new(key, label)
|
690
|
+
@options << item
|
691
|
+
item.action = PromptMenu.new @caller, label, &block
|
692
|
+
end
|
693
|
+
#
|
694
|
+
# Display prompt_menu in columns using commandwindow
|
695
|
+
# This is an improved way of showing the "most" like menu. The earlier
|
696
|
+
# format would only print in one row.
|
697
|
+
#
|
698
|
+
def display_columns config={}
|
699
|
+
prompt = config[:prompt] || "Choose: "
|
700
|
+
require 'rbcurse/rcommandwindow'
|
701
|
+
layout = { :height => 5, :width => Ncurses.COLS-1, :top => Ncurses.LINES-6, :left => 0 }
|
702
|
+
rc = CommandWindow.new nil, :layout => layout, :box => true, :title => config[:title] || "Menu"
|
703
|
+
w = rc.window
|
704
|
+
r = 4
|
705
|
+
c = 1
|
706
|
+
color = $datacolor
|
707
|
+
begin
|
708
|
+
menu = @options
|
709
|
+
$log.debug " DISP MENU "
|
710
|
+
ret = 0
|
711
|
+
len = 80
|
712
|
+
while true
|
713
|
+
h = {}
|
714
|
+
valid = []
|
715
|
+
labels = []
|
716
|
+
menu.each{ |item|
|
717
|
+
hk = item.hotkey.to_s
|
718
|
+
labels << "%c. %s " % [ hk, item.label ]
|
719
|
+
h[hk] = item
|
720
|
+
valid << hk
|
721
|
+
}
|
722
|
+
#$log.debug " valid are #{valid} "
|
723
|
+
color = $datacolor
|
724
|
+
#print_this(win, str, color, r, c)
|
725
|
+
rc.display_menu labels, :indexing => :custom
|
726
|
+
ch=w.getchar()
|
727
|
+
rc.clear
|
728
|
+
#$log.debug " got ch #{ch} "
|
729
|
+
next if ch < 0 or ch > 255
|
730
|
+
if ch == 3 || ch == ?\C-g.getbyte(0)
|
731
|
+
clear_this w, r, c, color, len
|
732
|
+
print_this(w, "Aborted.", color, r,c)
|
733
|
+
break
|
734
|
+
end
|
735
|
+
ch = ch.chr
|
736
|
+
index = valid.index ch
|
737
|
+
if index.nil?
|
738
|
+
clear_this w, r, c, color, len
|
739
|
+
print_this(w, "Not valid. Valid are #{valid}. C-c/C-g to abort.", color, r,c)
|
740
|
+
sleep 1
|
741
|
+
next
|
742
|
+
end
|
743
|
+
#$log.debug " index is #{index} "
|
744
|
+
item = h[ch]
|
745
|
+
desc = item.desc
|
746
|
+
#desc ||= "Could not find desc for #{ch} "
|
747
|
+
desc ||= ""
|
748
|
+
clear_this w, r, c, color, len
|
749
|
+
print_this(w, desc, color, r,c)
|
750
|
+
action = item.action
|
751
|
+
case action
|
752
|
+
#when Array
|
753
|
+
when PromptMenu
|
754
|
+
# submenu
|
755
|
+
menu = action.options
|
756
|
+
title = rc.title
|
757
|
+
rc.title title +" => " + action.text # set title of window to submenu
|
758
|
+
when Proc
|
759
|
+
ret = action.call
|
760
|
+
break
|
761
|
+
when Symbol
|
762
|
+
ret = @caller.send(action)
|
763
|
+
break
|
764
|
+
else
|
765
|
+
$log.debug " Unidentified flying class #{action.class} "
|
766
|
+
break
|
767
|
+
end
|
768
|
+
end # while
|
769
|
+
ensure
|
770
|
+
rc.destroy
|
771
|
+
rc = nil
|
772
|
+
end
|
773
|
+
end
|
774
|
+
alias :display_new :display_columns
|
775
|
+
|
662
776
|
# Display the top level menu and accept user input
|
663
777
|
# Calls actions or symbols upon selection, or traverses submenus
|
664
778
|
# @return retvalue of last call or send, or 0
|
665
779
|
# @param win window
|
666
780
|
# @param r, c row and col to display on
|
667
781
|
# @param color text color (use $datacolor if in doubt)
|
668
|
-
# @
|
782
|
+
# @see display_new - it presents in a much better manner
|
783
|
+
# and is not restricted to one row. Avoid this.
|
669
784
|
def display win, r, c, color
|
785
|
+
# FIXME use a oneline window, user should not have to give all this crap.
|
786
|
+
# What about panning if we can;t fit, should we use horiz list to show ?
|
670
787
|
menu = @options
|
671
788
|
$log.debug " DISP MENU "
|
672
789
|
ret = 0
|
@@ -66,7 +66,8 @@ module RubyCurses
|
|
66
66
|
create_color_pairs unless @pairs
|
67
67
|
raise ArgumentError, "pairs hash is null. Changes have happened in listcellrenderer" unless @pairs
|
68
68
|
@color_pair = @pairs[:normal]
|
69
|
-
|
69
|
+
#@attr = $row_attr
|
70
|
+
@attr = @row_attr || $row_attr # changed 2011-10-15 since we seem to be ignoring row_attr changes
|
70
71
|
# give precedence to a selected row
|
71
72
|
if selected
|
72
73
|
@color_pair = @pairs[:selected]
|
data/lib/rbcurse/listkeys.rb
CHANGED
@@ -5,7 +5,7 @@ module RubyCurses
|
|
5
5
|
# any changes to the vars after construction won't have an effect.
|
6
6
|
def install_list_keys
|
7
7
|
#@KEY_ROW_SELECTOR ||= ?\C-x.getbyte(0) # need to changed from C-x since used for actions # changed 2011 dts
|
8
|
-
@KEY_ROW_SELECTOR ||=
|
8
|
+
@KEY_ROW_SELECTOR ||= 32 # need to changed from C-x since used for actions
|
9
9
|
@KEY_BLOCK_SELECTOR ||= ?\M-x.getbyte(0) # need to change since M-x used for commands
|
10
10
|
@KEY_GOTO_TOP ||= ?\M-0.getbyte(0)
|
11
11
|
@KEY_GOTO_BOTTOM ||= ?\M-9.getbyte(0)
|
@@ -64,8 +64,11 @@ module ListScrollable
|
|
64
64
|
m = $multiplier == 0? 1 : $multiplier
|
65
65
|
# more rows than box
|
66
66
|
if h * m < rc
|
67
|
-
|
68
|
-
|
67
|
+
# next 2 lines were preventing widget_scrolled from being set to true,
|
68
|
+
# so i've modified it slightly as per scroll_down 2011-11-1
|
69
|
+
#@toprow += h+1 #if @current_index+h < rc
|
70
|
+
#@current_index = @toprow
|
71
|
+
@current_index += h+1
|
69
72
|
else
|
70
73
|
# fewer rows than box
|
71
74
|
@current_index = rc -1
|
@@ -79,6 +82,7 @@ module ListScrollable
|
|
79
82
|
def bounds_check
|
80
83
|
h = scrollatrow()
|
81
84
|
rc = row_count
|
85
|
+
@old_toprow = @toprow
|
82
86
|
|
83
87
|
@current_index = 0 if @current_index < 0 # not lt 0
|
84
88
|
@current_index = rc-1 if @current_index >= rc && rc>0 # not gt rowcount
|
@@ -91,14 +95,19 @@ module ListScrollable
|
|
91
95
|
@toprow = @current_index
|
92
96
|
end
|
93
97
|
|
98
|
+
@row_changed = false
|
94
99
|
if @oldrow != @current_index
|
95
|
-
|
96
100
|
on_leave_row @oldrow if respond_to? :on_leave_row # to be defined by widget that has included this
|
97
101
|
on_enter_row @current_index if respond_to? :on_enter_row # to be defined by widget that has included this
|
102
|
+
set_form_row
|
103
|
+
@row_changed = true
|
104
|
+
end
|
105
|
+
#set_form_row # 2011-10-13
|
106
|
+
|
107
|
+
if @old_toprow != @toprow # only if scrolling has happened should we repaint
|
108
|
+
@repaint_required = true #if @old_toprow != @toprow # only if scrolling has happened should we repaint
|
109
|
+
@widget_scrolled = true
|
98
110
|
end
|
99
|
-
set_form_row
|
100
|
-
#set_form_col 0 # added 2009-02-15 23:33 # this works for lists but we don't want this in TextArea's
|
101
|
-
@repaint_required = true
|
102
111
|
end
|
103
112
|
# the cursor should be appropriately positioned
|
104
113
|
def set_form_row
|
@@ -160,6 +169,7 @@ module ListScrollable
|
|
160
169
|
def scroll_right
|
161
170
|
$log.debug " inside scroll_right "
|
162
171
|
hscrollcols = $multiplier > 0 ? $multiplier : @width/2
|
172
|
+
#hscrollcols = $multiplier > 0 ? $multiplier : 1 # for testing out
|
163
173
|
$log.debug " scroll_right mult:#{$multiplier} , hscrollcols #{hscrollcols}, pcol #{@pcol} w: #{@width} ll:#{@longest_line} "
|
164
174
|
#blen = @buffer.rstrip.length
|
165
175
|
blen = @longest_line
|
@@ -469,7 +479,9 @@ module ListScrollable
|
|
469
479
|
def sanitize content #:nodoc:
|
470
480
|
if content.is_a? String
|
471
481
|
content.chomp!
|
472
|
-
content.
|
482
|
+
content.replace(content.encode("ASCII-8BIT", :invalid => :replace, :undef => :replace, :replace => "?"))
|
483
|
+
content.gsub!(/[\t\r\n]/, ' ') # don't display tab, newline
|
484
|
+
content.gsub!(/\n/, ' ') # don't display tab, newline
|
473
485
|
content.gsub!(/[^[:print:]]/, '') # don't display non print characters
|
474
486
|
else
|
475
487
|
content
|
@@ -494,6 +506,59 @@ module ListScrollable
|
|
494
506
|
end
|
495
507
|
content
|
496
508
|
end
|
509
|
+
#
|
510
|
+
# Is the given index in the visible area
|
511
|
+
# UNTESTED XXX
|
512
|
+
def is_visible? index
|
513
|
+
#(0..scrollatrow()).include? index - @toprow
|
514
|
+
j = index - @toprow
|
515
|
+
j >= 0 && j <= scrollatrow()
|
516
|
+
end
|
517
|
+
# offset in widget like 0..scrollatrow
|
518
|
+
# NOTE can return nil, if user scrolls forward or backward
|
519
|
+
# @private
|
520
|
+
def _convert_index_to_visible_row index=@current_index
|
521
|
+
pos = index - @toprow
|
522
|
+
return nil if pos < 0 || pos > scrollatrow()
|
523
|
+
return pos
|
524
|
+
end
|
525
|
+
# actual position to write on window
|
526
|
+
# NOTE can return nil, if user scrolls forward or backward
|
527
|
+
def _convert_index_to_printable_row index=@current_index
|
528
|
+
r,c = rowcol
|
529
|
+
pos = _convert_index_to_visible_row(index)
|
530
|
+
return nil unless pos
|
531
|
+
pos = r + pos
|
532
|
+
return pos
|
533
|
+
end
|
534
|
+
|
535
|
+
# highlights the focussed (current) and unfocussed (oldrow)
|
536
|
+
# NOTE: when multiselecting ... it will remove selection
|
537
|
+
# so be careful when calling.
|
538
|
+
def highlight_focussed_row type, r=nil, c=nil, acolor=nil
|
539
|
+
return unless @should_show_focus
|
540
|
+
case type
|
541
|
+
when :FOCUSSED
|
542
|
+
ix = @current_index
|
543
|
+
return if is_row_selected ix
|
544
|
+
r = _convert_index_to_printable_row() unless r
|
545
|
+
attrib = @focussed_attrib || 'bold'
|
546
|
+
|
547
|
+
when :UNFOCUSSED
|
548
|
+
return if @oldrow.nil? || @oldrow == @current_index
|
549
|
+
ix = @oldrow
|
550
|
+
return if is_row_selected ix
|
551
|
+
r = _convert_index_to_printable_row(@oldrow) unless r
|
552
|
+
return unless r # row is not longer visible
|
553
|
+
attrib = @attr
|
554
|
+
end
|
555
|
+
unless c
|
556
|
+
_r, c = rowcol
|
557
|
+
end
|
558
|
+
acolor ||= get_color $datacolor
|
559
|
+
att = get_attrib(attrib) #if @focussed_attrib
|
560
|
+
@graphic.mvchgat(y=r, x=c, @width-@internal_width, att , acolor , nil)
|
561
|
+
end
|
497
562
|
|
498
563
|
|
499
564
|
end
|
@@ -69,6 +69,7 @@ module RubyCurses
|
|
69
69
|
# index of selected rows, if multiple selection asked for
|
70
70
|
attr_reader :selected_indices
|
71
71
|
|
72
|
+
dsl_accessor :should_show_focus
|
72
73
|
|
73
74
|
# basic listbox constructor
|
74
75
|
#
|
@@ -78,7 +79,7 @@ module RubyCurses
|
|
78
79
|
@sanitization_required = true # cleanup control and non print chars
|
79
80
|
@truncation_required = true
|
80
81
|
@suppress_borders = false #to_print_borders = 1
|
81
|
-
|
82
|
+
#@row_selected_symbol = '' # thi sprevents default value from being set
|
82
83
|
@row = 0
|
83
84
|
@col = 0
|
84
85
|
# data of listbox this is not an array, its a pointer to the listdatamodel
|
@@ -89,6 +90,7 @@ module RubyCurses
|
|
89
90
|
@selected_indices = []
|
90
91
|
@selected_index = nil
|
91
92
|
@row_offset = @col_offset = 1
|
93
|
+
@should_show_focus = true # Here's its on since the cellrenderer will show it on repaint
|
92
94
|
super
|
93
95
|
@_events.push(*[:ENTER_ROW, :LEAVE_ROW, :LIST_SELECTION_EVENT, :PRESS])
|
94
96
|
@selection_mode ||= :multiple # default is multiple, anything else given becomes single
|
@@ -96,11 +98,9 @@ module RubyCurses
|
|
96
98
|
@win_left = 0
|
97
99
|
@win_top = 0
|
98
100
|
|
99
|
-
# next 2 lines carry a redundancy
|
100
|
-
#select_default_values
|
101
|
-
# when the combo box has a certain row in focus, the popup should have the same row in focus
|
102
|
-
|
103
101
|
init_vars
|
102
|
+
@internal_width = 2
|
103
|
+
@internal_width = 0 if @suppress_borders
|
104
104
|
|
105
105
|
if @list && !@selected_index.nil? # XXX
|
106
106
|
set_focus_on @selected_index # the new version
|
@@ -110,12 +110,14 @@ module RubyCurses
|
|
110
110
|
# and when list data changed, so only put relevant resets here.
|
111
111
|
def init_vars
|
112
112
|
@repaint_required = true
|
113
|
+
@widget_scrolled = true # 2011-10-15
|
113
114
|
@toprow = @pcol = 0
|
114
115
|
if @show_selector
|
115
116
|
@row_selected_symbol ||= '>'
|
116
117
|
@row_unselected_symbol ||= ' '
|
117
118
|
@left_margin ||= @row_selected_symbol.length
|
118
119
|
end
|
120
|
+
@row_selected_symbol ||= ''
|
119
121
|
#@left_margin ||= 0
|
120
122
|
@one_key_selection = false if @one_key_selection.nil?
|
121
123
|
@row_offset = @col_offset = 0 if @suppress_borders
|
@@ -186,8 +188,10 @@ module RubyCurses
|
|
186
188
|
clear_selection
|
187
189
|
|
188
190
|
@repaint_required = true
|
191
|
+
@widget_scrolled = true # 2011-10-15
|
189
192
|
@list
|
190
193
|
end
|
194
|
+
def list_data_model; @list; end
|
191
195
|
# conv method to insert data, trying to keep names same across along with Tabular, TextView,
|
192
196
|
# TextArea and listbox. Don;t use this till i am certain.
|
193
197
|
def data=(val)
|
@@ -237,7 +241,6 @@ module RubyCurses
|
|
237
241
|
### START FOR scrollable ###
|
238
242
|
def get_content
|
239
243
|
@list
|
240
|
-
#@list_variable && @list_variable.value || @list
|
241
244
|
end
|
242
245
|
def get_window #:nodoc:
|
243
246
|
@graphic
|
@@ -383,6 +386,13 @@ module RubyCurses
|
|
383
386
|
true
|
384
387
|
end
|
385
388
|
def on_enter_row arow
|
389
|
+
# copied from resultsettextview, can this not be in one place like listscrollable ? FIXME
|
390
|
+
if @should_show_focus
|
391
|
+
highlight_focussed_row :FOCUSSED
|
392
|
+
unless @oldrow == @selected_index
|
393
|
+
highlight_focussed_row :UNFOCUSSED
|
394
|
+
end
|
395
|
+
end
|
386
396
|
fire_handler :ENTER_ROW, self
|
387
397
|
@repaint_required = true
|
388
398
|
end
|
@@ -398,7 +408,7 @@ module RubyCurses
|
|
398
408
|
end
|
399
409
|
end
|
400
410
|
def create_default_cell_renderer
|
401
|
-
return ListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width
|
411
|
+
return ListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-@internal_width-@left_margin}
|
402
412
|
#return BasicListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-2-@left_margin}
|
403
413
|
end
|
404
414
|
##
|
@@ -408,18 +418,30 @@ module RubyCurses
|
|
408
418
|
# a section of it.
|
409
419
|
def repaint #:nodoc:
|
410
420
|
return unless @repaint_required
|
421
|
+
#
|
422
|
+
# TRYING OUT dangerous 2011-10-15
|
423
|
+
@repaint_required = false
|
424
|
+
@repaint_required = true if @widget_scrolled || @pcol != @old_pcol || @record_changed || @property_changed
|
425
|
+
|
426
|
+
unless @repaint_required
|
427
|
+
unhighlight_row @old_selected_index
|
428
|
+
highlight_selected_row
|
429
|
+
end
|
430
|
+
return unless @repaint_required
|
431
|
+
$log.debug "BASICLIST REPAINT WILL HAPPEN #{current_index} "
|
411
432
|
# not sure where to put this, once for all or repeat 2010-02-17 23:07 RFED16
|
412
433
|
my_win = @form ? @form.window : @target_window
|
413
434
|
@graphic = my_win unless @graphic
|
414
435
|
raise " #{@name} neither form, nor target window given LB paint " unless my_win
|
415
436
|
raise " #{@name} NO GRAPHIC set as yet LB paint " unless @graphic
|
437
|
+
raise "width or height not given w:#{@width} , h:#{@height} " if @width.nil? || @height.nil?
|
416
438
|
@win_left = my_win.left
|
417
439
|
@win_top = my_win.top
|
418
440
|
@left_margin ||= @row_selected_symbol.length
|
419
441
|
# we are making sure display len does not exceed width XXX hope this does not wreak havoc elsewhere
|
420
|
-
_dl = [@display_length || 100, @width
|
442
|
+
_dl = [@display_length || 100, @width-@internal_width-@left_margin].min # 2011-09-17 RK overwriting when we move grabbar in vimsplit
|
421
443
|
|
422
|
-
$log.debug "
|
444
|
+
$log.debug "basiclistbox repaint #{@name} graphic #{@graphic}"
|
423
445
|
#$log.debug "XXX repaint to_print #{@to_print_borders} "
|
424
446
|
print_borders unless @suppress_borders # do this once only, unless everything changes
|
425
447
|
#maxlen = @maxlen || @width-2
|
@@ -463,12 +485,40 @@ module RubyCurses
|
|
463
485
|
renderer.repaint @graphic, r+hh, c+@left_margin, crow, content, focus_type, selected
|
464
486
|
else
|
465
487
|
# clear rows
|
466
|
-
@graphic.printstring r+hh, c, " " * (@width
|
488
|
+
@graphic.printstring r+hh, c, " " * (@width-@internal_width), acolor,@attr
|
467
489
|
end
|
468
490
|
end
|
469
491
|
end # rc == 0
|
470
|
-
#@table_changed = false
|
471
492
|
@repaint_required = false
|
493
|
+
# 2011-10-13
|
494
|
+
@widget_scrolled = false
|
495
|
+
@record_changed = false
|
496
|
+
@property_changed = false
|
497
|
+
@old_pcol = @pcol
|
498
|
+
end
|
499
|
+
def highlight_selected_row r=nil, c=nil, acolor=nil
|
500
|
+
return unless @selected_index # no selection
|
501
|
+
r = _convert_index_to_printable_row(@selected_index) unless r
|
502
|
+
return unless r # not on screen
|
503
|
+
unless c
|
504
|
+
_r, c = rowcol
|
505
|
+
end
|
506
|
+
acolor ||= get_color $datacolor, @selected_color, @selected_bgcolor
|
507
|
+
att = FFI::NCurses::A_REVERSE
|
508
|
+
att = get_attrib(@selected_attrib) if @selected_attrib
|
509
|
+
@graphic.mvchgat(y=r, x=c, @width-@internal_width-@left_margin, att , acolor , nil)
|
510
|
+
end
|
511
|
+
def unhighlight_row index, r=nil, c=nil, acolor=nil
|
512
|
+
return unless index # no selection
|
513
|
+
r = _convert_index_to_printable_row(index) unless r
|
514
|
+
return unless r # not on screen
|
515
|
+
unless c
|
516
|
+
_r, c = rowcol
|
517
|
+
end
|
518
|
+
acolor ||= get_color $datacolor
|
519
|
+
att = FFI::NCurses::A_NORMAL
|
520
|
+
att = get_attrib(@normal_attrib) if @normal_attrib
|
521
|
+
@graphic.mvchgat(y=r, x=c, @width-@internal_width-@left_margin, att , acolor , nil)
|
472
522
|
end
|
473
523
|
# the idea here is to allow users who subclass Listbox to easily override parts of the cumbersome repaint
|
474
524
|
# method. This assumes your List has some data, but you print a lot more. Now you don't need to
|
@@ -498,7 +548,8 @@ module RubyCurses
|
|
498
548
|
# returns only the visible portion of string taking into account display length
|
499
549
|
# and horizontal scrolling. MODIFIES STRING
|
500
550
|
def truncate content # :nodoc:
|
501
|
-
maxlen = @maxlen || @width
|
551
|
+
maxlen = @maxlen || @width-@internal_width
|
552
|
+
maxlen = @width-@internal_width if maxlen > @width-@internal_width
|
502
553
|
if maxlen == 0 # (otherwise it becoems -1 below)
|
503
554
|
content.replace ""
|
504
555
|
return
|
@@ -523,6 +574,7 @@ module RubyCurses
|
|
523
574
|
@current_index = 0
|
524
575
|
set_form_row
|
525
576
|
end
|
577
|
+
@widget_scrolled = true # 2011-10-15
|
526
578
|
@repaint_required = true
|
527
579
|
end
|
528
580
|
|