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
@@ -23,6 +23,7 @@ module RubyCurses
|
|
23
23
|
@repaint_required = true
|
24
24
|
case @selection_mode
|
25
25
|
when :multiple
|
26
|
+
@widget_scrolled = true # FIXME we need a better name
|
26
27
|
if @selected_indices.include? crow
|
27
28
|
@selected_indices.delete crow
|
28
29
|
lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
|
@@ -34,10 +35,12 @@ module RubyCurses
|
|
34
35
|
end
|
35
36
|
else
|
36
37
|
if @selected_index == crow
|
38
|
+
@old_selected_index = @selected_index # 2011-10-15 so we can unhighlight
|
37
39
|
@selected_index = nil
|
38
40
|
lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
|
39
41
|
fire_handler :LIST_SELECTION_EVENT, lse
|
40
42
|
else
|
43
|
+
@old_selected_index = @selected_index # 2011-10-15 so we can unhighlight
|
41
44
|
@selected_index = crow
|
42
45
|
lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
|
43
46
|
fire_handler :LIST_SELECTION_EVENT, lse
|
@@ -57,6 +60,7 @@ module RubyCurses
|
|
57
60
|
max = [@last_clicked, crow].max
|
58
61
|
case @selection_mode
|
59
62
|
when :multiple
|
63
|
+
@widget_scrolled = true # FIXME we need a better name
|
60
64
|
if @selected_indices.include? crow
|
61
65
|
# delete from last_clicked until this one in any direction
|
62
66
|
min.upto(max){ |i| @selected_indices.delete i }
|
@@ -79,11 +83,13 @@ module RubyCurses
|
|
79
83
|
return if @selected_indices.nil? || @selected_indices.empty?
|
80
84
|
@selected_indices = []
|
81
85
|
@selected_index = nil
|
86
|
+
@old_selected_index = nil
|
82
87
|
# Not sure what event type I should give, DELETE or a new one, user should
|
83
88
|
# understand that selection has been cleared, and ignore first two params
|
84
89
|
lse = ListSelectionEvent.new(0, @list.size, self, :CLEAR)
|
85
90
|
fire_handler :LIST_SELECTION_EVENT, lse
|
86
91
|
@repaint_required = true
|
92
|
+
@widget_scrolled = true # FIXME we need a better name
|
87
93
|
end
|
88
94
|
def is_row_selected crow=@current_index-@_header_adjustment
|
89
95
|
case @selection_mode
|
@@ -114,6 +120,7 @@ module RubyCurses
|
|
114
120
|
# should only be used if multiple selection interval
|
115
121
|
def add_selection_interval ix0, ix1
|
116
122
|
return if @selection_mode != :multiple
|
123
|
+
@widget_scrolled = true # FIXME we need a better name
|
117
124
|
@anchor_selection_index = ix0
|
118
125
|
@lead_selection_index = ix1
|
119
126
|
ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i }
|
@@ -212,6 +219,7 @@ module RubyCurses
|
|
212
219
|
def list_init_vars
|
213
220
|
@selected_indices = []
|
214
221
|
@selected_index = nil
|
222
|
+
@old_selected_index = nil
|
215
223
|
#@row_selected_symbol = ''
|
216
224
|
if @show_selector
|
217
225
|
@row_selected_symbol ||= '*'
|
@@ -0,0 +1,330 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: Multiform.rb
|
3
|
+
* Description View (cycle) multiple forms
|
4
|
+
* Author: rkumar (arunachalesha)
|
5
|
+
* file created 2011-10-17 8:18 PM
|
6
|
+
--------
|
7
|
+
* License:
|
8
|
+
Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
9
|
+
|
10
|
+
=end
|
11
|
+
require 'rbcurse'
|
12
|
+
|
13
|
+
include RubyCurses
|
14
|
+
module RubyCurses
|
15
|
+
extend self
|
16
|
+
|
17
|
+
# Trying to implement TabbedPanes using a multiform approach, but no more windows
|
18
|
+
# or pads. Try to keep it as simple as possible
|
19
|
+
class MultiForm < Widget
|
20
|
+
dsl_accessor :title
|
21
|
+
|
22
|
+
|
23
|
+
def initialize form = nil, config={}, &block
|
24
|
+
@focusable = true
|
25
|
+
@window = form.window
|
26
|
+
@row_offset = @col_offset = 1
|
27
|
+
@bmanager = BufferManager.new self
|
28
|
+
@forms = []
|
29
|
+
super
|
30
|
+
init_vars
|
31
|
+
|
32
|
+
end
|
33
|
+
def init_vars
|
34
|
+
super
|
35
|
+
# the following allows us to navigate buffers with :bn :bp etc (with Alt pressed)
|
36
|
+
bind_key(?\M-:, :buffer_menu)
|
37
|
+
bind_key(?\M-;, :buffer_menu)
|
38
|
+
# bind_key([?\C-x, ?f], :file_edit)
|
39
|
+
bind_key([?\C-x, ?k], :delete_component)
|
40
|
+
bind_key([?\C-x, ?\C-b], :list_components)
|
41
|
+
bind_key(?\M-n, :goto_next_component)
|
42
|
+
bind_key(?\M-p, :goto_prev_component)
|
43
|
+
bind_key(?\M-1, :goto_first_component)
|
44
|
+
# easily cycle using p. n is used for next search.
|
45
|
+
#bind_key(?p, :buffer_previous)
|
46
|
+
@suppress_borders = false
|
47
|
+
@repaint_all = true
|
48
|
+
@name ||= "multiform"
|
49
|
+
end
|
50
|
+
## returns current buffer
|
51
|
+
# @return [RBuffer] current buffer
|
52
|
+
def current_component
|
53
|
+
@bmanager.current
|
54
|
+
end
|
55
|
+
##
|
56
|
+
# multi-container
|
57
|
+
def handle_key ch #:nodoc:
|
58
|
+
@current_component.repaint
|
59
|
+
@current_component.window.wrefresh
|
60
|
+
$log.debug " MULTI handle_key #{ch}, #{@current_component}"
|
61
|
+
ret = :UNHANDLED
|
62
|
+
return :UNHANDLED unless @current_component
|
63
|
+
ret = @current_component.handle_key(ch)
|
64
|
+
$log.debug " MULTI comp #{@current_component} returned #{ret} "
|
65
|
+
if ret == :UNHANDLED
|
66
|
+
# check for bindings, these cannot override above keys since placed at end
|
67
|
+
begin
|
68
|
+
ret = process_key ch, self
|
69
|
+
$log.debug " MULTI = process_key returned #{ret} "
|
70
|
+
if ch > 177 && ch < 187
|
71
|
+
n = ch - 177
|
72
|
+
component_at(n)
|
73
|
+
# go to component n
|
74
|
+
end
|
75
|
+
rescue => err
|
76
|
+
# $error_message = err # changed 2010 dts
|
77
|
+
$error_message.value = err.to_s
|
78
|
+
#@form.window.print_error_message PLEASE CREATE LABEL
|
79
|
+
$log.error " Multicomponent process_key #{err} "
|
80
|
+
$log.debug(err.backtrace.join("\n"))
|
81
|
+
alert err.to_s
|
82
|
+
end
|
83
|
+
return :UNHANDLED if ret == :UNHANDLED
|
84
|
+
end
|
85
|
+
@current_component.repaint
|
86
|
+
@current_component.window.wrefresh
|
87
|
+
FFI::NCurses.update_panels
|
88
|
+
|
89
|
+
# check for any keys not handled and check our own ones
|
90
|
+
return ret #
|
91
|
+
end
|
92
|
+
def repaint
|
93
|
+
print_border if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
|
94
|
+
return unless @current_component
|
95
|
+
$log.debug " MULTIFORM REPAINT "
|
96
|
+
ret = @current_component.repaint
|
97
|
+
end
|
98
|
+
def print_border #:nodoc:
|
99
|
+
$log.debug " #{@name} print_borders, #{@graphic.name} "
|
100
|
+
color = $datacolor
|
101
|
+
@graphic.print_border_only @row, @col, @height-1, @width, color #, Ncurses::A_REVERSE
|
102
|
+
print_title
|
103
|
+
end
|
104
|
+
def print_title #:nodoc:
|
105
|
+
$log.debug " print_title #{@row}, #{@col}, #{@width} #{@title} "
|
106
|
+
@graphic.printstring( @row, @col+(@width-@title.length)/2, @title, $datacolor, @title_attrib) unless @title.nil?
|
107
|
+
end
|
108
|
+
# this is just a test of the simple "most" menu
|
109
|
+
# can use this for next, prev, first, last, new, delete, overwrite etc
|
110
|
+
def buffer_menu
|
111
|
+
menu = PromptMenu.new self
|
112
|
+
menu.add(menu.create_mitem( 'l', "list buffers", "list buffers ", :list_components ))
|
113
|
+
item = menu.create_mitem( 'b', "Buffer Options", "Buffer Options" )
|
114
|
+
menu1 = PromptMenu.new( self, "Buffer Options")
|
115
|
+
menu1.add(menu1.create_mitem( 'n', "Next", "Switched to next buffer", :goto_next_component ))
|
116
|
+
menu1.add(menu1.create_mitem( 'p', "Prev", "Switched to previous buffer", :goto_prev_component ))
|
117
|
+
menu1.add(menu1.create_mitem( 'f', "First", "Switched to first buffer", :goto_first_component ))
|
118
|
+
menu1.add(menu1.create_mitem( 'l', "Last", "Switched to last buffer", :goto_last_component ))
|
119
|
+
menu1.add(menu1.create_mitem( 'd', "Delete", "Deleted buffer", :delete_component ))
|
120
|
+
item.action = menu1
|
121
|
+
menu.add(item)
|
122
|
+
# how do i know what's available. the application or window should know where to place
|
123
|
+
menu.display @form.window, $error_message_row, $error_message_col, $datacolor #, menu
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def goto_next_component
|
128
|
+
perror "No other buffer" and return if @bmanager.size < 2
|
129
|
+
|
130
|
+
@current_component = @bmanager.next
|
131
|
+
set_current_component
|
132
|
+
# set_form_row and shit
|
133
|
+
end
|
134
|
+
|
135
|
+
def goto_prev_component
|
136
|
+
perror "No other buffer" and return if @bmanager.size < 2
|
137
|
+
|
138
|
+
@current_component = @bmanager.previous
|
139
|
+
$log.debug " buffer_prev got #{@current_component} "
|
140
|
+
set_current_component
|
141
|
+
end
|
142
|
+
def goto_first_component
|
143
|
+
@current_component = @bmanager.first
|
144
|
+
$log.debug " buffer_first got #{@current_component} "
|
145
|
+
set_current_component
|
146
|
+
end
|
147
|
+
def goto_last_component
|
148
|
+
@current_component = @bmanager.last
|
149
|
+
$log.debug " buffer_last got #{@current_component} "
|
150
|
+
set_current_component
|
151
|
+
end
|
152
|
+
def delete_component
|
153
|
+
if @bmanager.size > 1
|
154
|
+
@bmanager.delete_at
|
155
|
+
@current_component = @bmanager.previous
|
156
|
+
set_current_component
|
157
|
+
else
|
158
|
+
perror "Only one buffer. Cannot delete."
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def component_at index
|
163
|
+
cc = @bmanager.element_at index
|
164
|
+
return unless cc
|
165
|
+
@current_component = cc
|
166
|
+
#$log.debug " buffer_last got #{@current_component} "
|
167
|
+
set_current_component
|
168
|
+
end
|
169
|
+
def add_form title, config={}, &blk
|
170
|
+
$log.debug "XXX: add_form window coords were hwtl #{@height} , #{@width} , #{@top} , #{@left} "
|
171
|
+
#w = VER::Window.new 16, 30, 2, 2 #@height-1, @width-1, @top, @left
|
172
|
+
w = VER::Window.new @height-2, @width-2, @row+1, @col+1
|
173
|
+
#w.box(0,0)
|
174
|
+
frm = Form.new w
|
175
|
+
@forms << frm
|
176
|
+
frm.parent_form = @form
|
177
|
+
frm.add_cols=@col+@col_offset
|
178
|
+
frm.add_rows=@row+@row_offset
|
179
|
+
@current_component = @bmanager.add frm, title
|
180
|
+
set_current_component
|
181
|
+
yield frm if block_given?
|
182
|
+
return @current_component # not a form but a Rcomponent containing component and title
|
183
|
+
end
|
184
|
+
def _add_to(index, component)
|
185
|
+
raise ArgumentError, "index out of bounds" unless @forms[index]
|
186
|
+
component.set_form(@forms[index])
|
187
|
+
$log.debug "XXX: comp r c #{component.row} #{component.col} "
|
188
|
+
component.row += @row
|
189
|
+
component.col += @col
|
190
|
+
$log.debug "XXX: after comp r c #{component.row} #{component.col} "
|
191
|
+
end
|
192
|
+
##
|
193
|
+
# Add a component with a title
|
194
|
+
# @param [Widget] component
|
195
|
+
# @param [String] title
|
196
|
+
def add component, title
|
197
|
+
component.row = @row+@row_offset+0 # FFI changed 1 to 0 2011-09-12
|
198
|
+
component.col = @col+@col_offset+0 # FFI changed 1 to 0 2011-09-12
|
199
|
+
component.width = @width-2
|
200
|
+
component.height = @height-2
|
201
|
+
component.form = @form
|
202
|
+
component.override_graphic(@graphic)
|
203
|
+
@current_component = @bmanager.add component, title
|
204
|
+
set_current_component
|
205
|
+
set_form_row ## FFI added 2011-09-12 to get cursor at start when adding
|
206
|
+
$log.debug " ADD got cb : #{@current_component} "
|
207
|
+
end
|
208
|
+
def set_current_component
|
209
|
+
@title = @current_component.title
|
210
|
+
@current_component = @current_component.component
|
211
|
+
@current_component.repaint #2011-10-17 need to set all comps to repaint XXX
|
212
|
+
@current_component.window.wrefresh
|
213
|
+
@current_component.window.show
|
214
|
+
FFI::NCurses.update_panels
|
215
|
+
set_form_row
|
216
|
+
#@current_title = @current_component.title
|
217
|
+
#@current_component.repaint_all true 2011-10-17 need to set all comps to repaint XXX
|
218
|
+
end
|
219
|
+
def perror errmess
|
220
|
+
alert errmess
|
221
|
+
#@form.window.print_error_message errmess
|
222
|
+
end
|
223
|
+
def list_components
|
224
|
+
$log.debug " TODO buffers_list: #{@bmanager.size} "
|
225
|
+
menu = PromptMenu.new self
|
226
|
+
@bmanager.each_with_index{ |b, ix|
|
227
|
+
aproc = Proc.new { component_at(ix) }
|
228
|
+
name = b.title
|
229
|
+
num = ix + 1
|
230
|
+
menu.add(menu.create_mitem( num.to_s, name, "Switched to buffer #{ix}", aproc ))
|
231
|
+
}
|
232
|
+
menu.display @form.window, $error_message_row, $error_message_col, $datacolor
|
233
|
+
end
|
234
|
+
# required otherwise some components may not get correct cursor position on entry
|
235
|
+
# e.g. table
|
236
|
+
def on_enter
|
237
|
+
set_form_row # 2011-10-17
|
238
|
+
end
|
239
|
+
# nothing happening, the cursor goes to 1,1 and does not move
|
240
|
+
# alhough the fields can be edited XXX
|
241
|
+
def set_form_row #:nodoc:
|
242
|
+
if !@current_component.nil?
|
243
|
+
#$log.debug " #{@name} set_form_row calling sfr for #{@current_component.name} "
|
244
|
+
#fc = @current_component.widgets[0]
|
245
|
+
fc = @current_component.get_current_field
|
246
|
+
fc ||= @current_component.widgets[0]
|
247
|
+
fc.set_form_row if fc
|
248
|
+
#fc.set_form_col
|
249
|
+
end
|
250
|
+
end
|
251
|
+
# ADD HERE
|
252
|
+
end # class multicontainer
|
253
|
+
##
|
254
|
+
# Handles multiple buffers, navigation, maintenance etc
|
255
|
+
# Instantiated at startup of
|
256
|
+
#
|
257
|
+
class BufferManager
|
258
|
+
include Enumerable
|
259
|
+
def initialize source
|
260
|
+
@source = source
|
261
|
+
@buffers = [] # contains RBuffer
|
262
|
+
@counter = 0
|
263
|
+
# for each buffer i need to store data, current_index (row), curpos (col offset) and title (filename).
|
264
|
+
end
|
265
|
+
def element_at index
|
266
|
+
@buffers[index]
|
267
|
+
end
|
268
|
+
def each
|
269
|
+
@buffers.each {|k| yield(k)}
|
270
|
+
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# @return [RBuffer] current buffer/file
|
274
|
+
##
|
275
|
+
def current
|
276
|
+
@buffers[@counter]
|
277
|
+
end
|
278
|
+
##
|
279
|
+
# Would have liked to just return next buffer and not get lost in details of caller
|
280
|
+
#
|
281
|
+
# @return [RBuffer] next buffer/file
|
282
|
+
##
|
283
|
+
def next
|
284
|
+
@counter += 1
|
285
|
+
@counter = 0 if @counter >= @buffers.size
|
286
|
+
@buffers[@counter]
|
287
|
+
end
|
288
|
+
##
|
289
|
+
# @return [RBuffer] previous buffer/file
|
290
|
+
##
|
291
|
+
def previous
|
292
|
+
$log.debug " previous bs: #{@buffers.size}, #{@counter} "
|
293
|
+
@counter -= 1
|
294
|
+
return last() if @counter < 0
|
295
|
+
$log.debug " previous ctr #{@counter} "
|
296
|
+
@buffers[@counter]
|
297
|
+
end
|
298
|
+
def first
|
299
|
+
@counter = 0
|
300
|
+
@buffers[@counter]
|
301
|
+
end
|
302
|
+
def last
|
303
|
+
@counter = @buffers.size - 1
|
304
|
+
@buffers[@counter]
|
305
|
+
end
|
306
|
+
##
|
307
|
+
def delete_at index=@counter
|
308
|
+
@buffers.delete_at index
|
309
|
+
end
|
310
|
+
def delete_by_name name
|
311
|
+
@buffers.delete_if {|b| b.filename == name }
|
312
|
+
end
|
313
|
+
def insert component, position, title=nil
|
314
|
+
anew = RComponents.new(component, title)
|
315
|
+
@buffers.insert position, anew
|
316
|
+
@counter = position
|
317
|
+
return anew
|
318
|
+
end
|
319
|
+
def add component, title=nil
|
320
|
+
#$log.debug " ADD H: #{component.height} C: #{component.width} "
|
321
|
+
insert component, @buffers.size, title
|
322
|
+
end
|
323
|
+
def size
|
324
|
+
@buffers.size
|
325
|
+
end
|
326
|
+
alias :count :size
|
327
|
+
end
|
328
|
+
RComponents = Struct.new(:component, :title)
|
329
|
+
|
330
|
+
end # modul
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# ----------------------------------------------------------------------------- #
|
2
|
+
# File: multilinelabel.rb
|
3
|
+
# Description: Prints a label on the screen.
|
4
|
+
# This is the original label that was present in rwidgets.rb
|
5
|
+
# It allowed for multiple lines. I am simplifying that to a simple
|
6
|
+
# single line label.
|
7
|
+
# I am basically moving multiline labels out of hte core package
|
8
|
+
# Author: rkumar http://github.com/rkumar/rbcurse/
|
9
|
+
# Date: 2011-11-12 - 12:04
|
10
|
+
# License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
|
11
|
+
# Last update: 2011-11-12 - 12:05
|
12
|
+
# ----------------------------------------------------------------------------- #
|
13
|
+
#
|
14
|
+
module RubyCurses
|
15
|
+
|
16
|
+
# print static text on a form, allowing for text to be wrapped.
|
17
|
+
#
|
18
|
+
class MultiLineLabel < Widget
|
19
|
+
dsl_accessor :mnemonic # keyboard focus is passed to buddy based on this key (ALT mask)
|
20
|
+
|
21
|
+
# justify required a display length, esp if center.
|
22
|
+
dsl_property :justify #:right, :left, :center
|
23
|
+
dsl_property :display_length #please give this to ensure the we only print this much
|
24
|
+
#dsl_property :height #if you want a multiline label. already added to widget
|
25
|
+
# for consistency with others 2011-11-5
|
26
|
+
alias :width :display_length
|
27
|
+
alias :width= :display_length=
|
28
|
+
|
29
|
+
def initialize form, config={}, &block
|
30
|
+
|
31
|
+
# this crap was used in position_label, find another way. where is it used ?
|
32
|
+
#@row = config.fetch("row",-1) # why on earth this monstrosity ? 2011-11-5
|
33
|
+
#@col = config.fetch("col",-1)
|
34
|
+
#@bgcolor = config.fetch("bgcolor", $def_bg_color)
|
35
|
+
#@color = config.fetch("color", $def_fg_color)
|
36
|
+
@text = config.fetch("text", "NOTFOUND")
|
37
|
+
@editable = false
|
38
|
+
@focusable = false
|
39
|
+
super
|
40
|
+
@justify ||= :left
|
41
|
+
@name ||= @text
|
42
|
+
@repaint_required = true
|
43
|
+
end
|
44
|
+
#
|
45
|
+
# get the value for the label
|
46
|
+
def getvalue
|
47
|
+
@text_variable && @text_variable.value || @text
|
48
|
+
end
|
49
|
+
def label_for field
|
50
|
+
@label_for = field
|
51
|
+
#$log.debug " label for: #{@label_for}"
|
52
|
+
if @form
|
53
|
+
bind_hotkey
|
54
|
+
else
|
55
|
+
@when_form ||= []
|
56
|
+
@when_form << lambda { bind_hotkey }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# for a button, fire it when label invoked without changing focus
|
62
|
+
# for other widgets, attempt to change focus to that field
|
63
|
+
def bind_hotkey
|
64
|
+
if !@mnemonic.nil?
|
65
|
+
ch = @mnemonic.downcase()[0].ord ## 1.9 DONE
|
66
|
+
# meta key
|
67
|
+
mch = ?\M-a.getbyte(0) + (ch - ?a.getbyte(0)) ## 1.9
|
68
|
+
if @label_for.is_a? RubyCurses::Button and @label_for.respond_to? :fire
|
69
|
+
@form.bind_key(mch, @label_for) { |_form, _butt| _butt.fire }
|
70
|
+
else
|
71
|
+
$log.debug " bind_hotkey label for: #{@label_for}"
|
72
|
+
@form.bind_key(mch, @label_for) { |_form, _field| _field.focus }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# XXX need to move wrapping etc up and done once.
|
79
|
+
def repaint
|
80
|
+
return unless @repaint_required
|
81
|
+
raise "Label row or col nil #{@row} , #{@col}, #{@text} " if @row.nil? || @col.nil?
|
82
|
+
r,c = rowcol
|
83
|
+
|
84
|
+
@bgcolor ||= $def_bg_color
|
85
|
+
@color ||= $def_fg_color
|
86
|
+
# value often nil so putting blank, but usually some application error
|
87
|
+
value = getvalue_for_paint || ""
|
88
|
+
lablist = []
|
89
|
+
# trying out array values 2011-10-16 more for messageboxes.
|
90
|
+
if value.is_a? Array
|
91
|
+
lablist = text
|
92
|
+
@height = text.size
|
93
|
+
elsif @height && @height > 1
|
94
|
+
lablist = wrap_text(value, @display_length).split("\n")
|
95
|
+
else
|
96
|
+
# ensure we do not exceed
|
97
|
+
if !@display_length.nil?
|
98
|
+
if value.length > @display_length
|
99
|
+
value = value[0..@display_length-1]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
lablist << value
|
103
|
+
end
|
104
|
+
len = @display_length || value.length
|
105
|
+
acolor = get_color $datacolor
|
106
|
+
$log.debug "label :#{@text}, #{value}, r #{r}, c #{c} col= #{@color}, #{@bgcolor} acolor #{acolor} j:#{@justify} dlL: #{@display_length} "
|
107
|
+
firstrow = r
|
108
|
+
_height = @height || 1
|
109
|
+
str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05
|
110
|
+
# loop added for labels that are wrapped.
|
111
|
+
# TODO clear separately since value can change in status like labels
|
112
|
+
|
113
|
+
@graphic = @form.window if @graphic.nil? ## HACK messagebox givig this in repaint, 423 not working ??
|
114
|
+
0.upto(_height-1) { |i|
|
115
|
+
@graphic.printstring r+i, c, " " * len , acolor,@attr
|
116
|
+
}
|
117
|
+
lablist.each_with_index do |_value, ix|
|
118
|
+
break if ix >= _height
|
119
|
+
if @justify.to_sym == :center
|
120
|
+
padding = (@display_length - _value.length)/2
|
121
|
+
_value = " "*padding + _value + " "*padding # so its cleared if we change it midway
|
122
|
+
end
|
123
|
+
@graphic.printstring r, c, str % [len, _value], acolor,@attr
|
124
|
+
r += 1
|
125
|
+
end
|
126
|
+
if !@mnemonic.nil?
|
127
|
+
ulindex = value.index(@mnemonic) || value.index(@mnemonic.swapcase)
|
128
|
+
@graphic.mvchgat(y=firstrow, x=c+ulindex, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, acolor, nil)
|
129
|
+
end
|
130
|
+
#@form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, color, nil)
|
131
|
+
@repaint_required = false
|
132
|
+
end
|
133
|
+
# Added 2011-10-22 to prevent some naive components from putting focus here.
|
134
|
+
def on_enter
|
135
|
+
raise "Cannot enter Label"
|
136
|
+
end
|
137
|
+
def on_leave
|
138
|
+
raise "Cannot leave Label"
|
139
|
+
end
|
140
|
+
# ADD HERE LABEL
|
141
|
+
end # class
|
142
|
+
end # module
|