rbcurse 1.5.0 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Makefile +21 -0
- data/Manifest.txt +6 -0
- data/README.markdown +6 -4
- data/TODO +372 -0
- data/TODO2.txt +121 -0
- data/VERSION +1 -1
- data/examples/README.txt +67 -0
- data/examples/abasiclist.rb +33 -0
- data/examples/alpmenu.rb +42 -0
- data/examples/app.rb +859 -0
- data/examples/app.sample +17 -0
- data/examples/appdirtree.rb +74 -0
- data/examples/appemail.rb +191 -0
- data/examples/appemaillb.rb +308 -0
- data/examples/appgcompose.rb +315 -0
- data/examples/atree.rb +64 -0
- data/examples/common/file.rb +40 -0
- data/examples/common/rmail.rb +257 -0
- data/examples/data.txt +683 -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/data/todocsv.csv +28 -0
- data/examples/data/unix1.txt +21 -0
- data/examples/data/unix2.txt +11 -0
- data/examples/dbdemo.rb +495 -0
- data/examples/deprecated/appgmail.rb +952 -0
- data/examples/deprecated/splitp.rb +56 -0
- data/examples/deprecated/testscrolllb.rb +86 -0
- data/examples/deprecated/testscrollp.rb +88 -0
- data/examples/deprecated/testscrollta.rb +80 -0
- data/examples/deprecated/testscrolltable.rb +165 -0
- data/examples/deprecated/testsplit.rb +87 -0
- data/examples/deprecated/testsplit2.rb +123 -0
- data/examples/deprecated/testsplit3.rb +215 -0
- data/examples/deprecated/testsplit3_1.rb +244 -0
- data/examples/deprecated/testsplit3a.rb +215 -0
- data/examples/deprecated/testsplit3b.rb +237 -0
- data/examples/deprecated/testsplitta.rb +148 -0
- data/examples/deprecated/testsplittv.rb +142 -0
- data/examples/deprecated/testsplittvv.rb +144 -0
- data/examples/deprecated/testtpane.rb +215 -0
- data/examples/deprecated/testtpane2.rb +145 -0
- data/examples/deprecated/testtpanetable.rb +203 -0
- data/examples/dirtree.rb +88 -0
- data/examples/experimental/resultsetdemo.rb +280 -0
- data/examples/experimental/testmform.rb +35 -0
- data/examples/experimental/testscroller.rb +117 -0
- data/examples/experimental/teststackflow.rb +111 -0
- data/examples/menu1.rb +112 -0
- data/examples/multispl.rb +86 -0
- data/examples/newmessagebox.rb +131 -0
- data/examples/newtabbedwindow.rb +100 -0
- data/examples/newtesttabp.rb +121 -0
- data/examples/qdfilechooser.rb +68 -0
- data/examples/rfe.rb +1239 -0
- data/examples/rfe_renderer.rb +121 -0
- data/examples/sqlc.rb +454 -0
- data/examples/sqlm.rb +437 -0
- data/examples/sqlt.rb +408 -0
- data/examples/status.txt +68 -0
- data/examples/table1.rb +24 -0
- data/examples/term2.rb +84 -0
- data/examples/test1.rb +239 -0
- data/examples/test2.rb +674 -0
- data/examples/testapp.rb +44 -0
- data/examples/testapp2.rb +58 -0
- data/examples/testchars.rb +137 -0
- data/examples/testcombo.rb +91 -0
- data/examples/testkeypress.rb +66 -0
- data/examples/testlistbox.rb +113 -0
- data/examples/testmenu.rb +101 -0
- data/examples/testmulticomp.rb +70 -0
- data/examples/testmulticontainer.rb +94 -0
- data/examples/testmultispl.rb +199 -0
- data/examples/testree.rb +106 -0
- data/examples/testtable.rb +264 -0
- data/examples/testtabp.rb +107 -0
- data/examples/testtodo.rb +584 -0
- data/examples/testvimsplit.rb +112 -0
- data/examples/testwsshortcuts.rb +64 -0
- data/examples/testwsshortcuts2.rb +126 -0
- data/examples/todo.db +0 -0
- data/examples/todo.yml +191 -0
- data/examples/viewtodo.rb +574 -0
- data/lib/rbcurse/deprecated/README.markdown +12 -0
- data/lib/rbcurse/deprecated/rpad.rb +375 -0
- data/lib/rbcurse/deprecated/rscrollpane.rb +512 -0
- data/lib/rbcurse/deprecated/rsplitpane.rb +894 -0
- data/lib/rbcurse/deprecated/rsplitpane2.rb +1009 -0
- data/lib/rbcurse/deprecated/rviewport.rb +204 -0
- data/lib/rbcurse/deprecated/widgets/mapper.rb +130 -0
- data/lib/rbcurse/deprecated/widgets/rmessagebox.rb +348 -0
- data/lib/rbcurse/deprecated/widgets/rtabbedpane.rb +1158 -0
- data/lib/rbcurse/deprecated/widgets/rtabbedwindow.rb +167 -0
- data/lib/rbcurse/deprecated/widgets/scrollable.rb +301 -0
- data/lib/rbcurse/deprecated/widgets/stdscrwindow.rb +309 -0
- data/lib/ver/keyboard2.rb +170 -0
- data/test/test_rbcurse.rb +0 -0
- metadata +131 -9
@@ -0,0 +1,584 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'rbcurse'
|
3
|
+
require 'rbcurse/core/widgets/rcombo'
|
4
|
+
require 'rbcurse/extras/widgets/rtable'
|
5
|
+
require 'rbcurse/extras/include/celleditor'
|
6
|
+
#require 'rbcurse/table/tablecellrenderer'
|
7
|
+
require 'rbcurse/extras/include/comboboxcellrenderer'
|
8
|
+
require 'rbcurse/core/widgets/keylabelprinter'
|
9
|
+
require 'rbcurse/core/widgets/applicationheader'
|
10
|
+
require 'rbcurse/core/include/action'
|
11
|
+
|
12
|
+
include RubyCurses
|
13
|
+
include RubyCurses::Utils # this was resulting in get_color crashing
|
14
|
+
# in rpopupmenu when called from CL, when it was inside _FILE_ block.
|
15
|
+
# TODO move the csv to a database so you can update. this sucketh.
|
16
|
+
#
|
17
|
+
module TestTodo
|
18
|
+
class TodoList
|
19
|
+
def initialize file
|
20
|
+
@file = file
|
21
|
+
end
|
22
|
+
def load
|
23
|
+
#@todomap = YAML::load(File.open(@file));
|
24
|
+
@data =[]
|
25
|
+
@statuses=[]
|
26
|
+
@categories=[]
|
27
|
+
@modules=[]
|
28
|
+
require 'csv'
|
29
|
+
#CSV::Reader.parse(File.open(@file, 'r')) do |row|
|
30
|
+
CSV.foreach(@file) do |row| # 1.9 2009-10-05 11:12
|
31
|
+
@data << row
|
32
|
+
$log.debug " #{row.inspect} "
|
33
|
+
@categories << row[0] unless @categories.include? row[0]
|
34
|
+
@statuses << row[4] unless @statuses.include? row[4]
|
35
|
+
@modules << row[1] unless @modules.include? row[1]
|
36
|
+
end
|
37
|
+
$log.debug " MOD #{@modules}"
|
38
|
+
end
|
39
|
+
def get_statuses
|
40
|
+
# @todomap['__STATUSES']
|
41
|
+
@statuses
|
42
|
+
end
|
43
|
+
def get_modules
|
44
|
+
#@todomap['__MODULES'].sort
|
45
|
+
@modules.sort
|
46
|
+
end
|
47
|
+
def get_categories
|
48
|
+
#@todomap.keys.delete_if {|k| k.match(/^__/) }
|
49
|
+
@categories
|
50
|
+
end
|
51
|
+
def get_tasks_for_category categ
|
52
|
+
@data.select do |row|
|
53
|
+
row[0] == categ
|
54
|
+
end
|
55
|
+
end
|
56
|
+
def insert_task_for_category task, categ
|
57
|
+
task[0] = categ
|
58
|
+
@data << task
|
59
|
+
end
|
60
|
+
def delete_task task
|
61
|
+
@data.delete task
|
62
|
+
end
|
63
|
+
def oldget_tasks_for_category categ
|
64
|
+
c = @todomap[categ]
|
65
|
+
d = []
|
66
|
+
c.each_pair {|k,v|
|
67
|
+
v.each do |r|
|
68
|
+
row=[]
|
69
|
+
row << k
|
70
|
+
r.each { |r1| row << r1 }
|
71
|
+
d << row
|
72
|
+
#$log.debug " ROW = #{row.inspect} "
|
73
|
+
end
|
74
|
+
}
|
75
|
+
return d
|
76
|
+
end
|
77
|
+
def set_tasks_for_category categ, data
|
78
|
+
$log.debug " def set_tasks_for_category #{categ}, #{data.size} old #{@data.size}"
|
79
|
+
@data.delete_if { |row| row[0] == categ }
|
80
|
+
$log.debug " 2 def set_tasks_for_category #{categ}, #{data.size} old #{@data.size}"
|
81
|
+
data.each { |row| row[0] = categ }
|
82
|
+
@data.insert -1, *data
|
83
|
+
$log.debug " 3 def set_tasks_for_category #{categ}, #{data.size} old #{@data.size}"
|
84
|
+
end
|
85
|
+
def old_set_tasks_for_category categ, data
|
86
|
+
d = {}
|
87
|
+
data.each do |row|
|
88
|
+
#key = row.delete_at 0
|
89
|
+
key = row.first
|
90
|
+
d[key] ||= []
|
91
|
+
d[key] << row[1..-1]
|
92
|
+
end
|
93
|
+
@todomap[categ]=d
|
94
|
+
$log.debug " NEW DATA #{categ}: #{data}"
|
95
|
+
end
|
96
|
+
def convert_to_text
|
97
|
+
=begin
|
98
|
+
d = []
|
99
|
+
cats = get_categories
|
100
|
+
cats.each do |c|
|
101
|
+
tasks = get_tasks_for_category c
|
102
|
+
tasks.each do |t|
|
103
|
+
n = t.dup
|
104
|
+
n.insert 0, c
|
105
|
+
d << n
|
106
|
+
end
|
107
|
+
end
|
108
|
+
#File.open("todo.yml", "w") { |f| YAML.dump( d, f )}
|
109
|
+
buf =''
|
110
|
+
=end
|
111
|
+
d = @data
|
112
|
+
require 'csv'
|
113
|
+
#CSV.open('todocsv.csv', 'w') do |writer|
|
114
|
+
CSV.open("data/todocsv.csv", "w") do |writer|
|
115
|
+
#writer << [nil, nil]
|
116
|
+
d.each do |row|
|
117
|
+
#parced_cells = CSV.generate_rows(row, row.size, buf)
|
118
|
+
writer << row
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
def dump
|
123
|
+
f = "#{@file}"
|
124
|
+
#File.open(f, "w") { |f| YAML.dump( @todomap, f )}
|
125
|
+
convert_to_text
|
126
|
+
end
|
127
|
+
end
|
128
|
+
class TodoApp
|
129
|
+
def initialize
|
130
|
+
@window = VER::Window.root_window
|
131
|
+
@form = Form.new @window
|
132
|
+
|
133
|
+
@todo = TestTodo::TodoList.new "todocsv.csv"
|
134
|
+
@todo.load
|
135
|
+
end
|
136
|
+
def get_key_labels
|
137
|
+
key_labels = [
|
138
|
+
['C-q', 'Exit'], nil,
|
139
|
+
['M-s', 'Save'], ['M-m', 'Move']
|
140
|
+
]
|
141
|
+
return key_labels
|
142
|
+
end
|
143
|
+
def get_key_labels_table
|
144
|
+
key_labels = [
|
145
|
+
['M-n','NewRow'], ['M-d','DelRow'],
|
146
|
+
['C-x','Select'], nil,
|
147
|
+
['M-0', 'Top'], ['M-9', 'End'],
|
148
|
+
['C-p', 'PgUp'], ['C-n', 'PgDn'],
|
149
|
+
['M-Tab','Nxt Fld'], ['Tab','Nxt Col'],
|
150
|
+
['+','Widen'], ['-','Narrow']
|
151
|
+
]
|
152
|
+
return key_labels
|
153
|
+
end
|
154
|
+
def make_popup table
|
155
|
+
require 'rbcurse/extras/widgets/rpopupmenu'
|
156
|
+
tablemenu = RubyCurses::PopupMenu.new "Table"
|
157
|
+
#tablemenu.add(item = RubyCurses::PMenuItem.new("Open",'O'))
|
158
|
+
tablemenu.add(item = RubyCurses::PMenuItem.new("&Open"))
|
159
|
+
|
160
|
+
tablemenu.insert_separator 1
|
161
|
+
#tablemenu.add(RubyCurses::PMenuItem.new "New",'N')
|
162
|
+
tablemenu.add(@new_act)
|
163
|
+
tablemenu.add(item = RubyCurses::PMenuItem.new("&Save"))
|
164
|
+
item.command() { @save_cmd.call }
|
165
|
+
|
166
|
+
item=RubyCurses::PMenuItem.new "Select"
|
167
|
+
item.accelerator = "Ctrl-X"
|
168
|
+
item.command() { table.toggle_row_selection() }
|
169
|
+
#item.enabled = false
|
170
|
+
tablemenu.add(item)
|
171
|
+
|
172
|
+
item=RubyCurses::PMenuItem.new "Clr Selection"
|
173
|
+
item.accelerator = "Alt-e"
|
174
|
+
item.command() { table.clear_selection() }
|
175
|
+
item.enabled = table.selected_row_count > 0 ? true : false
|
176
|
+
tablemenu.add(item)
|
177
|
+
|
178
|
+
item=RubyCurses::PMenuItem.new "Delete"
|
179
|
+
item.accelerator = "Alt-D"
|
180
|
+
item.command() { @del_cmd.call }
|
181
|
+
tablemenu.add(item)
|
182
|
+
|
183
|
+
gotomenu = RubyCurses::PMenu.new "&Goto"
|
184
|
+
|
185
|
+
item = RubyCurses::PMenuItem.new "Top"
|
186
|
+
item.accelerator = "Alt-0"
|
187
|
+
item.command() { table.goto_top }
|
188
|
+
gotomenu.add(item)
|
189
|
+
|
190
|
+
item = RubyCurses::PMenuItem.new "Bottom"
|
191
|
+
item.accelerator = "Alt-9"
|
192
|
+
item.command() { table.goto_bottom }
|
193
|
+
gotomenu.add(item)
|
194
|
+
|
195
|
+
item = RubyCurses::PMenuItem.new "Next Page"
|
196
|
+
item.accelerator = "Ctrl-n"
|
197
|
+
item.command() { table.scroll_forward }
|
198
|
+
gotomenu.add(item)
|
199
|
+
|
200
|
+
item = RubyCurses::PMenuItem.new "Prev Page"
|
201
|
+
item.accelerator = "Ctrl-p"
|
202
|
+
item.command() { table.scroll_backward }
|
203
|
+
gotomenu.add(item)
|
204
|
+
|
205
|
+
tablemenu.add(gotomenu)
|
206
|
+
|
207
|
+
searchmenu = RubyCurses::PMenu.new "&Search"
|
208
|
+
|
209
|
+
item = RubyCurses::PMenuItem.new "Find forward"
|
210
|
+
item.accelerator = "Alt-f"
|
211
|
+
item.command() { table.ask_search_forward }
|
212
|
+
searchmenu.add(item)
|
213
|
+
|
214
|
+
item = RubyCurses::PMenuItem.new "Find backward"
|
215
|
+
item.accelerator = "Alt-F"
|
216
|
+
item.command() { table.ask_search_backward }
|
217
|
+
searchmenu.add(item)
|
218
|
+
|
219
|
+
item = RubyCurses::PMenuItem.new "Find Next"
|
220
|
+
item.accelerator = "Alt-g"
|
221
|
+
item.enabled = false if table.table_model.last_regex.nil?
|
222
|
+
item.command() { table.find_next }
|
223
|
+
searchmenu.add(item)
|
224
|
+
|
225
|
+
item = RubyCurses::PMenuItem.new "Find Prev"
|
226
|
+
item.accelerator = "Alt-G"
|
227
|
+
item.enabled = false if table.table_model.last_regex.nil?
|
228
|
+
item.command() { table.find_prev }
|
229
|
+
searchmenu.add(item)
|
230
|
+
|
231
|
+
tablemenu.add(searchmenu)
|
232
|
+
|
233
|
+
tablemenu.show @atable, 0,1
|
234
|
+
end
|
235
|
+
def run
|
236
|
+
todo = @todo
|
237
|
+
statuses = todo.get_statuses
|
238
|
+
cats = todo.get_categories
|
239
|
+
modules = todo.get_modules
|
240
|
+
title = "TODO APP"
|
241
|
+
@header = ApplicationHeader.new @form, title, {:text2=>"Some Text", :text_center=>"Task Entry"}
|
242
|
+
status_row = RubyCurses::Label.new @form, {'text' => "", :row => Ncurses.LINES-4, :col => 0, :display_length=>60}
|
243
|
+
@status_row = status_row
|
244
|
+
$error_message.update_command { status_row.text = $error_message.value }
|
245
|
+
# setting ENTER across all objects on a form
|
246
|
+
@form.bind(:ENTER) {|f| status_row.text = f.help_text unless f.help_text.nil? }
|
247
|
+
#@window.printstring 0,(Ncurses.COLS-title.length)/2,title, $datacolor
|
248
|
+
r = 1; c = 1;
|
249
|
+
categ = ComboBox.new @form do
|
250
|
+
name "categ"
|
251
|
+
row r
|
252
|
+
col 15
|
253
|
+
display_length 10
|
254
|
+
editable false
|
255
|
+
list cats
|
256
|
+
set_buffer 'TODO'
|
257
|
+
set_label Label.new @form, {'text' => "Category", 'color'=>'cyan','col'=>1, "mnemonic"=>"C"}
|
258
|
+
list_config 'height' => 4
|
259
|
+
help_text "Select a category and <TAB> out. KEY_UP, KEY_DOWN, M-Down"
|
260
|
+
bind(:LEAVE){ status_row.text "" }
|
261
|
+
end
|
262
|
+
data = todo.get_tasks_for_category 'TODO'
|
263
|
+
@data = data
|
264
|
+
$log.debug " data is #{data}"
|
265
|
+
colnames = %w[ Categ Module Prior Task Status]
|
266
|
+
|
267
|
+
table_ht = 15
|
268
|
+
atable = Table.new @form do
|
269
|
+
name "tasktable"
|
270
|
+
row r+2
|
271
|
+
col c
|
272
|
+
width 84
|
273
|
+
height table_ht
|
274
|
+
#title "A Table"
|
275
|
+
#title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
276
|
+
cell_editing_allowed true
|
277
|
+
editing_policy :EDITING_AUTO
|
278
|
+
set_data data, colnames
|
279
|
+
end
|
280
|
+
@atable = atable
|
281
|
+
categ.bind(:CHANGED) do |fld| $log.debug " COMBO EXIT XXXXXXXX";
|
282
|
+
data = todo.get_tasks_for_category fld.getvalue;
|
283
|
+
@data = data
|
284
|
+
$log.debug " DATA is #{data.inspect} : #{data.length}"
|
285
|
+
data = [['FIXME',nil, 5, "NEW ", "TODO", Time.now]] if data.nil? or data.empty? or data.size == 0
|
286
|
+
#$log.debug " DATA is #{data.inspect} : #{data.length}"
|
287
|
+
atable.table_model.data = data
|
288
|
+
end
|
289
|
+
|
290
|
+
tcm = atable.get_table_column_model
|
291
|
+
#
|
292
|
+
## key bindings fo atable
|
293
|
+
# column widths
|
294
|
+
#$log.debug " tcm #{tcm.inspect}"
|
295
|
+
#$log.debug " tcms #{tcm.columns}"
|
296
|
+
tcm.column(0).width 5
|
297
|
+
tcm.column(0).editable false
|
298
|
+
tcm.column(1).width 8
|
299
|
+
tcm.column(2).width 5
|
300
|
+
tcm.column(3).width 50
|
301
|
+
tcm.column(3).edit_length 80
|
302
|
+
tcm.column(4).width 8
|
303
|
+
app = self
|
304
|
+
atable.configure() do
|
305
|
+
#bind_key(330) { atable.remove_column(tcm.column(atable.focussed_col)) rescue "" }
|
306
|
+
bind_key(?+) {
|
307
|
+
acolumn = atable.column atable.focussed_col()
|
308
|
+
w = acolumn.width + 1
|
309
|
+
acolumn.width w
|
310
|
+
#atable.table_structure_changed
|
311
|
+
}
|
312
|
+
bind_key(?-) {
|
313
|
+
acolumn = atable.column atable.focussed_col()
|
314
|
+
w = acolumn.width - 1
|
315
|
+
if w > 3
|
316
|
+
acolumn.width w
|
317
|
+
#atable.table_structure_changed
|
318
|
+
end
|
319
|
+
}
|
320
|
+
bind_key(?>) {
|
321
|
+
colcount = tcm.column_count-1
|
322
|
+
#atable.move_column sel_col.value, sel_col.value+1 unless sel_col.value == colcount
|
323
|
+
col = atable.focussed_col
|
324
|
+
atable.move_column col, col+1 unless col == colcount
|
325
|
+
}
|
326
|
+
bind_key(?<) {
|
327
|
+
col = atable.focussed_col
|
328
|
+
atable.move_column col, col-1 unless col == 0
|
329
|
+
#atable.move_column sel_col.value, sel_col.value-1 unless sel_col.value == 0
|
330
|
+
}
|
331
|
+
bind_key(?\M-h, app) {|tab,td| $log.debug " BIND... #{tab.class}, #{td.class}"; app.make_popup atable}
|
332
|
+
end
|
333
|
+
#keylabel = RubyCurses::Label.new @form, {'text' => "", "row" => r+table_ht+3, "col" => c, "color" => "yellow", "bgcolor"=>"blue", "display_length"=>60, "height"=>2}
|
334
|
+
#eventlabel = RubyCurses::Label.new @form, {'text' => "Events:", "row" => r+table_ht+6, "col" => c, "color" => "white", "bgcolor"=>"blue", "display_length"=>60, "height"=>2}
|
335
|
+
|
336
|
+
# report some events
|
337
|
+
#atable.table_model.bind(:TABLE_MODEL_EVENT){|e| #eventlabel.text = "Event: #{e}"}
|
338
|
+
#atable.get_table_column_model.bind(:TABLE_COLUMN_MODEL_EVENT){|e| eventlabel.text = "Event: #{e}"}
|
339
|
+
atable.bind(:TABLE_TRAVERSAL_EVENT){|e| @header.text_right "Row #{e.newrow+1} of #{atable.row_count}" }
|
340
|
+
|
341
|
+
|
342
|
+
str_renderer = TableCellRenderer.new ""
|
343
|
+
num_renderer = TableCellRenderer.new "", { "justify" => :right }
|
344
|
+
bool_renderer = CheckBoxCellRenderer.new "", {"parent" => atable, "display_length"=>5}
|
345
|
+
combo_renderer = RubyCurses::ComboBoxCellRenderer.new nil, {"parent" => atable, "display_length"=> 8}
|
346
|
+
combo_editor = RubyCurses::CellEditor.new(RubyCurses::ComboBox.new nil, {"focusable"=>false, "visible"=>false, "list"=>statuses, "display_length"=>8})
|
347
|
+
combo_editor1 = RubyCurses::CellEditor.new(RubyCurses::ComboBox.new nil, {"focusable"=>false, "visible"=>false, "list"=>modules, "display_length"=>8})
|
348
|
+
atable.set_default_cell_renderer_for_class "String", str_renderer
|
349
|
+
atable.set_default_cell_renderer_for_class "Fixnum", num_renderer
|
350
|
+
atable.set_default_cell_renderer_for_class "Float", num_renderer
|
351
|
+
atable.set_default_cell_renderer_for_class "TrueClass", bool_renderer
|
352
|
+
atable.set_default_cell_renderer_for_class "FalseClass", bool_renderer
|
353
|
+
atable.get_table_column_model.column(4).cell_editor = combo_editor
|
354
|
+
atable.get_table_column_model.column(1).cell_editor = combo_editor1
|
355
|
+
ce = atable.get_default_cell_editor_for_class "String"
|
356
|
+
# increase the maxlen of task
|
357
|
+
# ce.component.maxlen = 80 # this is obsolete, use edit_length
|
358
|
+
# I want up and down to go up and down rows inside the combo box, i can use M-down for changing.
|
359
|
+
combo_editor.component.unbind_key(KEY_UP)
|
360
|
+
combo_editor.component.unbind_key(KEY_DOWN)
|
361
|
+
combo_editor1.component.unbind_key(KEY_UP)
|
362
|
+
combo_editor1.component.unbind_key(KEY_DOWN)
|
363
|
+
atable.bind(:TABLE_EDITING_EVENT) do |evt|
|
364
|
+
#return if evt.oldvalue != evt.newvalue
|
365
|
+
$log.debug " TABLE_EDITING : #{evt} "
|
366
|
+
if evt.type == :EDITING_STOPPED
|
367
|
+
if evt.col == 3
|
368
|
+
if @data[evt.row].size == 4
|
369
|
+
@data[evt.row] << Time.now
|
370
|
+
else
|
371
|
+
@data[evt.row][4] == Time.now
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
#combo_editor.component.bind(:LEAVE){ alert "LEAVE"; $log.debug " LEAVE FIRED" }
|
377
|
+
buttrow = r+table_ht+8 #Ncurses.LINES-4
|
378
|
+
buttrow = Ncurses.LINES-5
|
379
|
+
create_table_actions atable, todo, data, categ.getvalue
|
380
|
+
save_cmd = @save_cmd
|
381
|
+
b_save = Button.new @form do
|
382
|
+
text "&Save"
|
383
|
+
row buttrow
|
384
|
+
col c
|
385
|
+
command {
|
386
|
+
save_cmd.call
|
387
|
+
}
|
388
|
+
help_text "Save changes to todo.yml "
|
389
|
+
end
|
390
|
+
=begin
|
391
|
+
b_newrow = Button.new @form do
|
392
|
+
text "&New"
|
393
|
+
row buttrow
|
394
|
+
col c+10
|
395
|
+
bind(:ENTER) { status_row.text "New button adds a new row below current " }
|
396
|
+
end
|
397
|
+
b_newrow.command { @new_act.call }
|
398
|
+
=end
|
399
|
+
## We use Action to create a button: to test out ampersand with MI and Button
|
400
|
+
new_act = @new_act
|
401
|
+
b_newrow = Button.new @form do
|
402
|
+
action new_act
|
403
|
+
row buttrow
|
404
|
+
col c+10
|
405
|
+
help_text "New button adds a new row below current "
|
406
|
+
#bind(:ENTER) { status_row.text "New button adds a new row below current " }
|
407
|
+
end
|
408
|
+
|
409
|
+
# using ampersand to set mnemonic
|
410
|
+
b_delrow = Button.new @form do
|
411
|
+
text "&Delete"
|
412
|
+
row buttrow
|
413
|
+
col c+25
|
414
|
+
#bind(:ENTER) { status_row.text "Deletes focussed row" }
|
415
|
+
help_text "Deletes focussed row"
|
416
|
+
end
|
417
|
+
b_delrow.command {
|
418
|
+
@del_cmd.call
|
419
|
+
}
|
420
|
+
=begin
|
421
|
+
b_change = Button.new @form do
|
422
|
+
text "&Lock"
|
423
|
+
row buttrow
|
424
|
+
col c+35
|
425
|
+
command {
|
426
|
+
r = atable.focussed_row
|
427
|
+
#c = sel_col.value
|
428
|
+
#$log.debug " Update gets #{field.getvalue.class}"
|
429
|
+
#atable.set_value_at(r, c, field.getvalue)
|
430
|
+
toggle = atable.column(atable.focussed_col()).editable
|
431
|
+
if toggle.nil? or toggle==true
|
432
|
+
toggle = false
|
433
|
+
text "Un&lock"
|
434
|
+
else
|
435
|
+
toggle = true
|
436
|
+
text "&Lock "
|
437
|
+
end
|
438
|
+
#eventlabel.text "Set column #{atable.focussed_col()} editable to #{toggle}"
|
439
|
+
atable.column(atable.focussed_col()).editable toggle
|
440
|
+
alert("Set column #{atable.focussed_col()} editable to #{toggle}")
|
441
|
+
}
|
442
|
+
help_text "Toggles editable state of current column "
|
443
|
+
end
|
444
|
+
=end
|
445
|
+
b_move = Button.new @form do
|
446
|
+
text "&Move"
|
447
|
+
row buttrow
|
448
|
+
col c+45
|
449
|
+
help_text "Move current row to Done"
|
450
|
+
end
|
451
|
+
b_move.command { |form|
|
452
|
+
#mods = cats.delete categ.getvalue
|
453
|
+
|
454
|
+
mods = cats - [categ.getvalue]
|
455
|
+
@mb = RubyCurses::MessageBox.new do
|
456
|
+
title "Change Module"
|
457
|
+
message "Move to? "
|
458
|
+
type :custom
|
459
|
+
button_type :custom
|
460
|
+
buttons mods
|
461
|
+
end
|
462
|
+
#return if categ.getvalue == "DONE"
|
463
|
+
amod = mods[@mb.selected_index]
|
464
|
+
row = atable.focussed_row
|
465
|
+
d = todo.get_tasks_for_category amod
|
466
|
+
$log.debug " retrieved #{d.size} rows for #{amod}"
|
467
|
+
r = []
|
468
|
+
tcm = atable.table_column_model
|
469
|
+
tcm.each_with_index do |acol, colix|
|
470
|
+
r << atable.get_value_at(row, colix)
|
471
|
+
end
|
472
|
+
# here i ignore the 5th row tht coud have been added
|
473
|
+
r << Time.now
|
474
|
+
d << r
|
475
|
+
$log.debug " sending #{d.size} rows for #{amod}"
|
476
|
+
todo.set_tasks_for_category amod, d
|
477
|
+
$log.debug " MOVE #{data.size} rows for #{categ.getvalue}"
|
478
|
+
tm = atable.table_model
|
479
|
+
ret = tm.delete_at row
|
480
|
+
$log.debug " MOVE after del #{data.size} rows for #{categ.getvalue}"
|
481
|
+
todo.set_tasks_for_category categ.getvalue, data
|
482
|
+
alert("Moved row #{row} to #{amod}.")
|
483
|
+
}
|
484
|
+
b_view = Button.new @form do
|
485
|
+
text "View"
|
486
|
+
row r
|
487
|
+
col 65
|
488
|
+
help_text "View sort and filter tasks in another window"
|
489
|
+
command { require './viewtodo'; todo = ViewTodo::TodoApp.new; todo.run }
|
490
|
+
end
|
491
|
+
buttons = [b_save, b_newrow, b_delrow, b_move , b_view ]
|
492
|
+
Button.button_layout buttons, buttrow
|
493
|
+
@klp = RubyCurses::KeyLabelPrinter.new @form, get_key_labels
|
494
|
+
@klp.set_key_labels get_key_labels_table, :table
|
495
|
+
atable.bind(:ENTER){ @klp.mode :table ;
|
496
|
+
status_row.text = "Please press Save (M-s) before changing Category."
|
497
|
+
}
|
498
|
+
atable.bind(:LEAVE){@klp.mode :normal;
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
@form.repaint
|
503
|
+
@window.wrefresh
|
504
|
+
Ncurses::Panel.update_panels
|
505
|
+
begin
|
506
|
+
while((ch = @window.getchar()) != ?\C-q.getbyte(0) )
|
507
|
+
colcount = tcm.column_count-1
|
508
|
+
#s = keycode_tos ch
|
509
|
+
#status_row.text = "Pressed #{ch} , #{s}"
|
510
|
+
@form.handle_key(ch)
|
511
|
+
|
512
|
+
@form.repaint
|
513
|
+
@window.wrefresh
|
514
|
+
end
|
515
|
+
ensure
|
516
|
+
@window.destroy if !@window.nil?
|
517
|
+
end
|
518
|
+
end
|
519
|
+
def create_table_actions atable, todo, data, categ
|
520
|
+
#@new_act = Action.new("New Row", "mnemonic"=>"N") {
|
521
|
+
@new_act = Action.new("&New Row") {
|
522
|
+
mod = nil
|
523
|
+
cat = 'TODO'
|
524
|
+
cc = atable.get_table_column_model.column_count
|
525
|
+
if atable.row_count < 1
|
526
|
+
frow = 0
|
527
|
+
else
|
528
|
+
frow = atable.focussed_row
|
529
|
+
#frow += 1 # why ?
|
530
|
+
cat = atable.get_value_at(frow,0) unless frow.nil?
|
531
|
+
mod = atable.get_value_at(frow,1) unless frow.nil?
|
532
|
+
end
|
533
|
+
tmp = [cat,mod, 5, "", "TODO", Time.now]
|
534
|
+
tm = atable.table_model
|
535
|
+
tm.insert frow, tmp
|
536
|
+
atable.set_focus_on frow
|
537
|
+
@status_row.text = "Added a row. Please press Save before changing Category."
|
538
|
+
alert("Added a row before current one. Use C-k to clear task.")
|
539
|
+
}
|
540
|
+
@new_act.accelerator "Alt-N"
|
541
|
+
@save_cmd = lambda {
|
542
|
+
todo.set_tasks_for_category categ, data
|
543
|
+
todo.dump
|
544
|
+
alert("Rewritten csv file")
|
545
|
+
}
|
546
|
+
@del_cmd = lambda {
|
547
|
+
row = atable.focussed_row
|
548
|
+
if !row.nil?
|
549
|
+
if confirm("Do your really want to delete row #{row+1}?")== :YES
|
550
|
+
tm = atable.table_model
|
551
|
+
tm.delete_at row
|
552
|
+
else
|
553
|
+
@status_row.text = "Delete cancelled"
|
554
|
+
end
|
555
|
+
end
|
556
|
+
}
|
557
|
+
|
558
|
+
end
|
559
|
+
end
|
560
|
+
if $0 == __FILE__
|
561
|
+
|
562
|
+
begin
|
563
|
+
# Initialize curses
|
564
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
565
|
+
$log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
|
566
|
+
$log.level = Logger::DEBUG
|
567
|
+
|
568
|
+
colors = Ncurses.COLORS
|
569
|
+
$log.debug "START #{colors} colors ---------"
|
570
|
+
|
571
|
+
catch(:close) do
|
572
|
+
t = TestTodo::TodoApp.new
|
573
|
+
t.run
|
574
|
+
end
|
575
|
+
rescue => ex
|
576
|
+
ensure
|
577
|
+
VER::stop_ncurses
|
578
|
+
p ex if ex
|
579
|
+
p(ex.backtrace.join("\n")) if ex
|
580
|
+
$log.debug( ex) if ex
|
581
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|