rbcurse-extras 0.0.0

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.
Files changed (38) hide show
  1. data/README.md +75 -0
  2. data/VERSION +1 -0
  3. data/examples/data/list.txt +300 -0
  4. data/examples/data/lotr.txt +12 -0
  5. data/examples/data/table.txt +36 -0
  6. data/examples/data/tasks.txt +27 -0
  7. data/examples/data/unix1.txt +21 -0
  8. data/examples/inc/qdfilechooser.rb +70 -0
  9. data/examples/inc/rfe_renderer.rb +121 -0
  10. data/examples/newtabbedwindow.rb +100 -0
  11. data/examples/rfe.rb +1236 -0
  12. data/examples/test2.rb +670 -0
  13. data/examples/testeditlist.rb +78 -0
  14. data/examples/testtable.rb +270 -0
  15. data/examples/testvimsplit.rb +141 -0
  16. data/lib/rbcurse/extras/include/celleditor.rb +112 -0
  17. data/lib/rbcurse/extras/include/checkboxcellrenderer.rb +57 -0
  18. data/lib/rbcurse/extras/include/comboboxcellrenderer.rb +30 -0
  19. data/lib/rbcurse/extras/include/defaultlistselectionmodel.rb +79 -0
  20. data/lib/rbcurse/extras/include/listkeys.rb +37 -0
  21. data/lib/rbcurse/extras/include/listselectable.rb +144 -0
  22. data/lib/rbcurse/extras/include/tableextended.rb +40 -0
  23. data/lib/rbcurse/extras/widgets/horizlist.rb +203 -0
  24. data/lib/rbcurse/extras/widgets/menutree.rb +63 -0
  25. data/lib/rbcurse/extras/widgets/multilinelabel.rb +142 -0
  26. data/lib/rbcurse/extras/widgets/rcomboedit.rb +256 -0
  27. data/lib/rbcurse/extras/widgets/rlink.rb.moved +27 -0
  28. data/lib/rbcurse/extras/widgets/rlistbox.rb +1247 -0
  29. data/lib/rbcurse/extras/widgets/rmenulink.rb.moved +21 -0
  30. data/lib/rbcurse/extras/widgets/rmulticontainer.rb +304 -0
  31. data/lib/rbcurse/extras/widgets/rmultisplit.rb +722 -0
  32. data/lib/rbcurse/extras/widgets/rmultitextview.rb +306 -0
  33. data/lib/rbcurse/extras/widgets/rpopupmenu.rb +755 -0
  34. data/lib/rbcurse/extras/widgets/rtable.rb +1758 -0
  35. data/lib/rbcurse/extras/widgets/rvimsplit.rb +800 -0
  36. data/lib/rbcurse/extras/widgets/table/tablecellrenderer.rb +86 -0
  37. data/lib/rbcurse/extras/widgets/table/tabledatecellrenderer.rb +98 -0
  38. metadata +94 -0
@@ -0,0 +1,112 @@
1
+
2
+ ##
3
+ # This file gives us a mean of using a component as an editor in a list or later table.
4
+ # The component is created once and used with each row.
5
+ # It does not really have a form associated with it, although we do set a form
6
+ # so it can display itself. Otherwise it is not added to the forms widget list, so the
7
+ # form has no idea tha this widget exists.
8
+ #
9
+ # Tested with Field, combo and checkbox, tables.
10
+ #
11
+ module RubyCurses
12
+ class CellEditor
13
+ include ConfigSetup
14
+ include RubyCurses::Utils
15
+
16
+ def initialize component, config={}, &block
17
+ @component = component
18
+ s = @component.class.to_s.downcase()
19
+ s.slice!("rubycurses::")
20
+ @_class = s.to_sym
21
+ config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
22
+ instance_eval &block if block_given?
23
+ end
24
+ def getvalue
25
+ case @_class
26
+ when :field
27
+ return field_getvalue
28
+ when :checkbox
29
+ return checkbox_getvalue
30
+ when :combobox
31
+ return combobox_getvalue
32
+ else
33
+ raise "Unknown class #{@_class} in CellEditor getv"
34
+ end
35
+ end
36
+ # maybe this should check valid (on_leave) and throw exception
37
+ def field_getvalue
38
+ #@component.on_leave # throws exception! Added 2009-01-17 00:47
39
+ @component.init_vars # 2009-01-18 01:13 should not carry over to next row curpos and pcol
40
+ return @component.getvalue
41
+ end
42
+ def checkbox_getvalue
43
+ @component.getvalue
44
+ end
45
+ def combobox_getvalue
46
+ #@component.on_leave # added 2009-01-19 12:12
47
+ @component.getvalue
48
+ #@component.selected_item
49
+ end
50
+ def setvalue value
51
+ case @_class
52
+ when :field
53
+ @component.set_buffer value
54
+ when :checkbox
55
+ @component.checked value
56
+ when :combobox
57
+ @component.set_buffer value
58
+ #index = @component.list.index value
59
+ #@component.current_index = index
60
+ else
61
+ raise "Unknown class #{@_class} in CellEditor setv"
62
+ end
63
+ end
64
+ def component
65
+ @component
66
+ end
67
+ # should be called from on_leave_cell of table, but is beng called from editing_stopped FIXME
68
+ def on_leave row, col
69
+ f = @component
70
+ f.on_leave
71
+ if f.respond_to? :editable and f.modified?
72
+ f.fire_handler(:CHANGED, f)
73
+ end
74
+ end
75
+ def prepare_editor parent, row, col, value
76
+ #value = value.dup if value.respond_to? :dup
77
+ value = value.dup rescue value
78
+ setvalue value #.dup
79
+ widget = component()
80
+ widget.row = row
81
+ widget.col = col
82
+ # unfortunately 2009-01-11 19:47 combo boxes editable allows changing value
83
+ # FIXME so combo's can be editable, but no new value added
84
+ if @_class == :combobox
85
+ widget.editable = false if widget.respond_to? :editable # chb's don't ???
86
+ else
87
+ widget.editable = true if widget.respond_to? :editable # chb's don't ???
88
+ end
89
+ widget.focusable = true
90
+ widget.visible = true
91
+ widget.form = parent.form
92
+ #$log.debug " prepare editor value #{widget.display_length} displlen #{widget.maxlen}"
93
+ #$log.debug " prepare editor form: #{widget.form} " # 2011-11-15 12:54:41
94
+ #widget.display_length = widget.display_length -1
95
+ widget.bgcolor = 'yellow'
96
+ widget.color = 'black'
97
+ widget.on_enter
98
+ #widget.attr = Ncurses::A_REVERSE | Ncurses::A_BOLD
99
+ end
100
+ #This may not really be necessary since we paint the cell editor only if editing is on
101
+ def cancel_editor
102
+ widget = component()
103
+ # NOOO THIS IS CALLED BY CANCEL AND STOP
104
+ # somehow we need to ensure that if on_leave fails you can't get out. Here its a bit late
105
+ # i think FIXME TODO
106
+ #widget.on_leave # call so any triggers or validations can fire
107
+ widget.focusable = false
108
+ widget.visible = false
109
+ widget.attr = Ncurses::A_REVERSE
110
+ end
111
+ end # class
112
+ end # module
@@ -0,0 +1,57 @@
1
+ require 'rbcurse/core/include/listcellrenderer'
2
+ module RubyCurses
3
+
4
+ ##
5
+ # This is a basic list cell renderer that will render the to_s value of anything.
6
+ # Using alignment one can use for numbers too.
7
+ # However, for booleans it will print true and false. If editing, you may want checkboxes
8
+ class CheckBoxCellRenderer < ListCellRenderer
9
+ dsl_accessor :value # text of label
10
+ dsl_accessor :surround_chars
11
+
12
+ def initialize boolean=nil, config={}, &block
13
+ @value = boolean
14
+ @text = "" # what if someone wants to show a label later. ??? XXX
15
+ @editable = false
16
+ @focusable = false
17
+ config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
18
+ instance_eval &block if block_given?
19
+ init_vars
20
+ end
21
+ def init_vars
22
+ @justify ||= :left
23
+ @display_length ||= 5
24
+ @surround_chars = ['[',']']
25
+ end
26
+ def getvalue
27
+ @value
28
+ end
29
+
30
+ ##
31
+ #
32
+ def repaint graphic, r=@row,c=@col, row_index=-1,value=@value, focussed=false, selected=false
33
+ #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} "
34
+
35
+ prepare_default_colors focussed, selected
36
+
37
+ buttontext = value ? "X" : " "
38
+ # HOW TO DO THE TEXT ??? XXX
39
+ # the space in dtext next line is a cheat, to clear off the space that the
40
+ # editor is leaving.
41
+ dtext = " " #@display_length.nil? ? @text : "%-*s" % [@display_length, @text]
42
+ if @align_right
43
+ #@text_offset = 0
44
+ #@col_offset = dtext.length + @surround_chars[0].length + 1
45
+ str = "#{dtext} " + @surround_chars[0] + buttontext + @surround_chars[1]
46
+ else
47
+ pretext = @surround_chars[0] + buttontext + @surround_chars[1]
48
+ #@text_offset = pretext.length + 1
49
+ #@col_offset = @surround_chars[0].length
50
+ #@surround_chars[0] + buttontext + @surround_chars[1] + " #{@text}"
51
+ str = pretext + " #{dtext}"
52
+ end
53
+ graphic.printstring r, c, str, @color_pair,@attr
54
+ end
55
+ # ADD HERE
56
+ end
57
+ end
@@ -0,0 +1,30 @@
1
+ module RubyCurses
2
+
3
+ ##
4
+ # This is a list cell renderer that will render combo boxes.
5
+ # Since a combo box extends a field therefore the repaint of field is used.
6
+ # In other words there is nothing much to do here.
7
+ #
8
+ class ComboBoxCellRenderer < ListCellRenderer
9
+ include ConfigSetup
10
+ include RubyCurses::Utils
11
+
12
+ def initialize text="", config={}, &block
13
+ @text = text
14
+ @editable = false
15
+ @focusable = false
16
+ config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
17
+ instance_eval &block if block_given?
18
+ init_vars
19
+ end
20
+ ## me thinks this is unused
21
+ def getvalue
22
+ raise "I think this is unused. comboboxcellrenderer line 36"
23
+ @text
24
+ end
25
+
26
+ ##
27
+ #
28
+ # ADD HERE
29
+ end
30
+ end
@@ -0,0 +1,79 @@
1
+ require 'rbcurse/extras/include/listselectable'
2
+ ##
3
+ # Added ListSelectionEvents on 2009-02-13 23:33
4
+ # Data model for list selections. Uses index or indices, or value/values. Please avoid using "row"
5
+ # as this is not clear to user, and will be deprecated.
6
+ # 2010-09-21 19:43 source now contains List object, not this class
7
+
8
+ module RubyCurses
9
+ class DefaultListSelectionModel
10
+ include EventHandler
11
+ attr_accessor :selection_mode
12
+ attr_reader :anchor_selection_index
13
+ attr_reader :lead_selection_index
14
+ attr_reader :parent
15
+ def initialize parent
16
+ raise ArgumentError "Parent cannot be nil. Please pass List while creating" if parent.nil?
17
+ @parent = parent
18
+
19
+ @selected_indices=[]
20
+ @anchor_selection_index = -1
21
+ @lead_selection_index = -1
22
+ @selection_mode = 'multiple'
23
+ @_events = [:LIST_SELECTION_EVENT]
24
+
25
+ #$log.debug " created DefaultListSelectionModel XXX"
26
+ end
27
+ #def event_list
28
+ #return @@events if defined? @@events
29
+ #nil
30
+ #end
31
+
32
+ def clear_selection
33
+ ix0 = @selected_indices.first
34
+ ix1 = @selected_indices.last
35
+ @selected_indices=[]
36
+ return if ix0.nil?
37
+ lse = ListSelectionEvent.new(ix0, ix1, @parent, :DELETE)
38
+ fire_handler :LIST_SELECTION_EVENT, lse
39
+ end
40
+ def is_selected_index ix
41
+ @selected_indices.include? ix
42
+ end
43
+ def get_max_selection_index
44
+ @selected_indices[-1]
45
+ end
46
+ def get_min_selection_index
47
+ @selected_indices[0]
48
+ end
49
+ def get_selected_indices
50
+ @selected_indices
51
+ end
52
+ alias :get_selected_rows :get_selected_indices
53
+ ## TODO should go in sorted, and no dupes
54
+ def add_selection_interval ix0, ix1
55
+ $log.debug " def add_selection_interval #{ix0}, #{ix1}, mode: #{@selection_mode} "
56
+ if @selection_mode != :multiple
57
+ clear_selection
58
+ end
59
+ @anchor_selection_index = ix0
60
+ @lead_selection_index = ix1
61
+ ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i }
62
+ lse = ListSelectionEvent.new(ix0, ix1, @parent, :INSERT)
63
+ fire_handler :LIST_SELECTION_EVENT, lse
64
+ $log.debug " DLSM firing LIST_SELECTION EVENT #{lse}"
65
+ end
66
+ def remove_selection_interval ix0, ix1
67
+ @anchor_selection_index = ix0
68
+ @lead_selection_index = ix1
69
+ @selected_indices.delete_if {|x| x >= ix0 and x <= ix1}
70
+ lse = ListSelectionEvent.new(ix0, ix1, @parent, :DELETE)
71
+ fire_handler :LIST_SELECTION_EVENT, lse
72
+ end
73
+ def insert_index_interval ix0, len
74
+ @anchor_selection_index = ix0
75
+ @lead_selection_index = ix0+len
76
+ add_selection_interval @anchor_selection_index, @lead_selection_index
77
+ end
78
+ end # class DefaultListSelectionModel
79
+ end
@@ -0,0 +1,37 @@
1
+ module RubyCurses
2
+ module ListKeys
3
+ ## Note: keeping variables gives the false feeling that one can change the var anytime.
4
+ # That was possible earlier, but now that i am binding the key at construction time
5
+ # any changes to the vars after construction won't have an effect.
6
+ def install_list_keys
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 ||= 32 # need to changed from C-x since used for actions
9
+ @KEY_BLOCK_SELECTOR ||= ?\M-x.getbyte(0) # need to change since M-x used for commands
10
+ @KEY_GOTO_TOP ||= ?\M-0.getbyte(0)
11
+ @KEY_GOTO_BOTTOM ||= ?\M-9.getbyte(0)
12
+ #@KEY_ASK_FIND_FORWARD ||= ?\M-f.getbyte(0)
13
+ #@KEY_ASK_FIND_BACKWARD ||= ?\M-F.getbyte(0)
14
+ #@KEY_FIND_NEXT ||= ?\M-g.getbyte(0)
15
+ #@KEY_FIND_PREV ||= ?\M-G.getbyte(0)
16
+ @KEY_SCROLL_FORWARD ||= ?\C-d.getbyte(0)
17
+ @KEY_SCROLL_BACKWARD ||= ?\C-b.getbyte(0)
18
+ @KEY_SCROLL_RIGHT ||= ?\M-8.getbyte(0)
19
+ @KEY_SCROLL_LEFT ||= ?\M-7.getbyte(0)
20
+
21
+ @KEY_CLEAR_SELECTION ||= ?\M-e.getbyte(0)
22
+ @KEY_PREV_SELECTION ||= ?\M-".getbyte(0)
23
+ @KEY_NEXT_SELECTION ||= ?\M-'.getbyte(0)
24
+
25
+ =begin
26
+ bind_key(@KEY_ROW_SELECTOR) { toggle_row_selection }
27
+ bind_key(@KEY_GOTO_TOP) { goto_top }
28
+ bind_key(@KEY_GOTO_BOTTOM) { goto_bottom }
29
+ bind_key(@KEY_CLEAR_SELECTION) { clear_selection }
30
+ bind_key(@KEY_ASK_FIND_FORWARD) { ask_search_forward }
31
+ bind_key(@KEY_ASK_FIND_BACKWARD) { ask_search_backward }
32
+ bind_key(@KEY_FIND_NEXT) { find_next }
33
+ bind_key(@KEY_FIND_PREV) { find_prev }
34
+ =end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,144 @@
1
+ # this is a companion file to defaultlistselectionmodel
2
+ # if you use that, include this to get all the methods to use it
3
+ require 'rbcurse/extras/include/defaultlistselectionmodel'
4
+
5
+ module RubyCurses
6
+ module ListSelectable
7
+
8
+ ## modified on 2009-02-13 23:41 to return model if no param passed
9
+ # sets or returns a list selection model
10
+ # Also listbox listens to it for selections, so it can tell those
11
+ # who are interested 2010-09-21 16:02
12
+ def list_selection_model(*lsm)
13
+ if lsm.empty?
14
+ @list_selection_model
15
+ else
16
+ @list_selection_model = lsm[0]
17
+ # the listbox is listening to selection events on the
18
+ # selection model and will inform any listeners of the same.
19
+ @list_selection_model.bind :LIST_SELECTION_EVENT do |ev|
20
+ fire_handler :LIST_SELECTION_EVENT, ev
21
+ end
22
+ end
23
+ #@list_selection_model.selection_mode = @selection_mode || :MULTIPLE
24
+ end
25
+ def is_selected? row
26
+ @list_selection_model.is_selected_index row
27
+ end
28
+ # this is the old name, should be deprecated
29
+ alias :is_row_selected :is_selected?
30
+
31
+ def add_row_selection_interval ix0, ix1
32
+ $log.debug " def add_row_selection_interval #{ix0}, #{ix1}"
33
+ # if row_selection_allowed
34
+ @list_selection_model.add_selection_interval ix0, ix1
35
+ @repaint_required = true
36
+ end
37
+ def remove_row_selection_interval ix0, ix1
38
+ @list_selection_model.remove_selection_interval ix0, ix1
39
+ end
40
+ def toggle_row_selection row=@current_index
41
+ if is_selected? row
42
+ #$log.debug " deleting row #{row}"
43
+ remove_row_selection_interval(row, row)
44
+ else
45
+ #$log.debug " adding row #{row}"
46
+ add_row_selection_interval(row, row)
47
+ end
48
+ @repaint_required = true
49
+ end
50
+
51
+ def clear_selection
52
+ @list_selection_model.clear_selection
53
+ @repaint_required = true
54
+ end
55
+ # why is this commented off XXX could it override listscrollable
56
+ #def selected_item
57
+ #$log.warn "came in dummy selected_item of listselectable.rb"
58
+ # @list[@current_index]
59
+ #end
60
+ # returns selected indices
61
+ # TODO : if array passed, set those as selected indices
62
+ def selected_rows
63
+ @list_selection_model.get_selected_rows
64
+ end
65
+ def selected_row_count
66
+ selected_rows.size
67
+ end
68
+ # returns index of first selected row (lowest index)
69
+ # TODO: if param passed set that as selected_index
70
+ def selected_row
71
+ @list_selection_model.get_min_selection_index
72
+ end
73
+ alias :selected_index :selected_row
74
+
75
+ # returns value of first selected row (lowest index)
76
+ def selected_value
77
+ #@list[@current_index].to_s # old behavior since curr row was in reverse
78
+ return nil if selected_row().nil?
79
+ @list[selected_row()].to_s
80
+ end
81
+ # returns an array of selected values
82
+ # or yields values to given block
83
+ def selected_values &block
84
+ ar = []
85
+ selected_rows().each do |i|
86
+ val = @list[i]
87
+ if block_given?
88
+ yield val
89
+ else
90
+ ar << val
91
+ end
92
+ end
93
+ return ar unless block_given?
94
+ end
95
+
96
+ def do_next_selection
97
+ return if selected_rows().length == 0
98
+ row = selected_rows().sort.find { |i| i > @current_index }
99
+ row ||= @current_index
100
+ @current_index = row
101
+ @repaint_required = true # fire list_select XXX
102
+ end
103
+ def do_prev_selection
104
+ return if selected_rows().length == 0
105
+ row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @current_index }
106
+ row ||= @current_index
107
+ @current_index = row
108
+ @repaint_required = true # fire list_select XXX
109
+ end
110
+ # NOTE: I HAD removed this and put in listbox, but its required by rtable also
111
+ # create a default list selection model and set it
112
+ # NOTE: I am now checking if one is not already created, since
113
+ # a second creation would wipe out any listeners on it.
114
+ # @see ListSelectable
115
+ # @see DefaultListSelectionModel
116
+ def create_default_list_selection_model
117
+ if @list_selection_model.nil?
118
+ list_selection_model DefaultListSelectionModel.new(self)
119
+ end
120
+ end
121
+ alias :selected_index :selected_row
122
+ attr_accessor :row_selection_allowed
123
+ attr_accessor :column_selection_allowed
124
+ end
125
+ # class containing information relating to selections on a list
126
+ # 2010-09-21 19:46 NOTE: Earlier source contained the model object, now it returns the parent
127
+ # You may do source.list_data_model() to get the model
128
+ # Typical operations on source would get selected_value(s), or selected_index
129
+ class ListSelectionEvent
130
+ attr_accessor :firstrow, :lastrow, :source, :type
131
+ def initialize firstrow, lastrow, source, type
132
+ @firstrow = firstrow
133
+ @lastrow = lastrow
134
+ @source = source
135
+ @type = type
136
+ end
137
+ def to_s
138
+ "#{@type.to_s}, firstrow: #{@firstrow}, lastrow: #{@lastrow}, source: #{@source}"
139
+ end
140
+ def inspect
141
+ to_s
142
+ end
143
+ end
144
+ end