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,574 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'rbcurse'
|
3
|
+
require 'rbcurse/core/widgets/rcombo'
|
4
|
+
require 'rbcurse/extras/widgets/rtable'
|
5
|
+
require 'rbcurse/extras/include/tableextended'
|
6
|
+
require 'rbcurse/core/widgets/keylabelprinter'
|
7
|
+
require 'rbcurse/core/widgets/applicationheader'
|
8
|
+
require 'rbcurse/core/include/action'
|
9
|
+
require 'sqlite3' # changing to sqlite3 since yml, csv a pain for updating
|
10
|
+
#require 'yaml' # 1.9 2009-10-05 13:11
|
11
|
+
###############################
|
12
|
+
## This uses todo.db, if not in gem, please take from github
|
13
|
+
## Please look at testtodo.rb
|
14
|
+
##############################
|
15
|
+
|
16
|
+
class Table
|
17
|
+
# so we can increase and decrease column width using keys
|
18
|
+
include TableExtended
|
19
|
+
end
|
20
|
+
# 2010-09-13 12:00 Added module since class names are same as testtodo
|
21
|
+
# and clashing when called from a menu
|
22
|
+
# end
|
23
|
+
module ViewTodo
|
24
|
+
class TodoList
|
25
|
+
def initialize file
|
26
|
+
@file = file
|
27
|
+
end
|
28
|
+
def load
|
29
|
+
#@todomap = YAML::load(File.open(@file));
|
30
|
+
@db = SQLite3::Database.new(@file)
|
31
|
+
#@records = convert_to_text
|
32
|
+
end
|
33
|
+
# get columns and datatypes, prefetch - copied from sqlc.rb
|
34
|
+
def get_data command
|
35
|
+
@columns, *rows = @db.execute2(command)
|
36
|
+
@content = rows
|
37
|
+
return nil if @content.nil? or @content[0].nil?
|
38
|
+
@datatypes = @content[0].types #if @datatypes.nil?
|
39
|
+
@command = command
|
40
|
+
return @content
|
41
|
+
end
|
42
|
+
def get_statuses
|
43
|
+
#@todomap['__STATUSES']
|
44
|
+
## temporary due to structure change
|
45
|
+
#['TODO', 'TOTEST', 'TESTED']
|
46
|
+
c = get_data "select * from status"
|
47
|
+
c.flatten
|
48
|
+
end
|
49
|
+
def get_modules
|
50
|
+
#@todomap['__MODULES'].sort
|
51
|
+
## temporary due to structure change
|
52
|
+
['GEN', 'FIELD', 'FORM', 'TABLE']
|
53
|
+
#get_data "select * from status"
|
54
|
+
end
|
55
|
+
def get_categories
|
56
|
+
#@todomap.keys.delete_if {|k| k.match(/^__/) }
|
57
|
+
## temporary due to structure change
|
58
|
+
#['TODO', 'FIXME','DONE']# earlier i used to keep todo items in a text file in these sections
|
59
|
+
c = get_data "select * from categ"
|
60
|
+
c.flatten
|
61
|
+
end
|
62
|
+
def get_tasks_for_category categ
|
63
|
+
get_data "select * from todo where categ = '#{categ}' "
|
64
|
+
=begin
|
65
|
+
c = @todomap[categ]
|
66
|
+
d = []
|
67
|
+
c.each_pair {|k,v|
|
68
|
+
v.each do |r|
|
69
|
+
row=[]
|
70
|
+
row << k
|
71
|
+
r.each { |r1| row << r1 }
|
72
|
+
d << row
|
73
|
+
#$log.debug " ROW = #{row.inspect} "
|
74
|
+
end
|
75
|
+
}
|
76
|
+
return d
|
77
|
+
=end
|
78
|
+
end
|
79
|
+
# today i really don't know how this differs from previous one (records vs tasks)
|
80
|
+
def get_records_for_category categ
|
81
|
+
if categ.nil? or categ == ""
|
82
|
+
#return @records
|
83
|
+
get_data "select * from todo"
|
84
|
+
else
|
85
|
+
#return @records.select { |row| row[0] == categ }
|
86
|
+
get_data "select * from todo where categ = '#{categ}' "
|
87
|
+
end
|
88
|
+
end
|
89
|
+
def sort categ, column, descending=false
|
90
|
+
d = get_records_for_category categ
|
91
|
+
d = d.sort { |y,x|
|
92
|
+
if descending
|
93
|
+
if x[column].nil?
|
94
|
+
$log.debug "sort -1"
|
95
|
+
-1
|
96
|
+
elsif y[column].nil?
|
97
|
+
$log.debug "sort 1"
|
98
|
+
1
|
99
|
+
else
|
100
|
+
$log.debug "sort <> #{x[column]} <=> #{y[column]} "
|
101
|
+
x[column] <=> y[column]
|
102
|
+
end
|
103
|
+
else
|
104
|
+
if x[column].nil?
|
105
|
+
1
|
106
|
+
elsif y[column].nil?
|
107
|
+
-1
|
108
|
+
else
|
109
|
+
y[column] <=> x[column]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
}
|
113
|
+
return d
|
114
|
+
end
|
115
|
+
def set_tasks_for_category categ, data
|
116
|
+
d = {}
|
117
|
+
data.each do |row|
|
118
|
+
#key = row.delete_at 0
|
119
|
+
key = row.first
|
120
|
+
d[key] ||= []
|
121
|
+
d[key] << row[1..-1]
|
122
|
+
end
|
123
|
+
@todomap[categ]=d
|
124
|
+
$log.debug " NEW DATA #{categ}: #{data}"
|
125
|
+
end
|
126
|
+
def convert_to_text
|
127
|
+
d = []
|
128
|
+
cats = get_categories
|
129
|
+
cats.each do |c|
|
130
|
+
tasks = get_tasks_for_category c
|
131
|
+
tasks.each do |t|
|
132
|
+
n = t.dup
|
133
|
+
n.insert 0, c
|
134
|
+
d << n
|
135
|
+
end
|
136
|
+
end
|
137
|
+
return d
|
138
|
+
end
|
139
|
+
=begin
|
140
|
+
File.open("todo.csv", "w") { |f| YAML.dump( d, f )}
|
141
|
+
buf =''
|
142
|
+
require 'csv'
|
143
|
+
CSV.open('data/todocsv.csv', 'w') do |writer|
|
144
|
+
#writer << [nil, nil]
|
145
|
+
d.each do |row|
|
146
|
+
#parced_cells = CSV.generate_rows(row, row.size, buf)
|
147
|
+
writer << row
|
148
|
+
end
|
149
|
+
end
|
150
|
+
=end
|
151
|
+
def dump
|
152
|
+
f = "#{@file}"
|
153
|
+
#File.open(f, "w") { |f| YAML.dump( @todomap, f )}
|
154
|
+
convert_to_text
|
155
|
+
end
|
156
|
+
end # class
|
157
|
+
class TodoApp
|
158
|
+
def initialize
|
159
|
+
@window = VER::Window.root_window
|
160
|
+
@form = Form.new @window
|
161
|
+
@sort_dir = true
|
162
|
+
|
163
|
+
#@todo = TodoList.new "todo.yml"
|
164
|
+
@todo = ViewTodo::TodoList.new "todo.db"
|
165
|
+
@todo.load
|
166
|
+
end
|
167
|
+
def run
|
168
|
+
todo = @todo
|
169
|
+
statuses = todo.get_statuses
|
170
|
+
cats = todo.get_categories
|
171
|
+
cats.insert 0,""
|
172
|
+
modules = todo.get_modules
|
173
|
+
title = "TODO APP"
|
174
|
+
@header = ApplicationHeader.new @form, title, {:text2=>"Some Text", :text_center=>"Task View"}
|
175
|
+
status_row = RubyCurses::Label.new @form, {'text' => "", :row => Ncurses.LINES-4, :col => 0, :display_length=>60}
|
176
|
+
@status_row = status_row
|
177
|
+
# setting ENTER across all objects on a form
|
178
|
+
@form.bind(:ENTER) {|f| status_row.text = f.help_text unless f.help_text.nil? }
|
179
|
+
#@window.printstring 0,(Ncurses.COLS-title.length)/2,title, $datacolor
|
180
|
+
r = 1; c = 1;
|
181
|
+
categ = ComboBox.new @form do
|
182
|
+
name "categ"
|
183
|
+
row r
|
184
|
+
col 15
|
185
|
+
display_length 10
|
186
|
+
editable false
|
187
|
+
list cats
|
188
|
+
set_label Label.new @form, {'text' => "Category", 'color'=>'cyan','col'=>1, "mnemonic"=>"C"}
|
189
|
+
list_config 'height' => 4
|
190
|
+
help_text "Select a category and <TAB> out. KEY_UP, KEY_DOWN, M-Down"
|
191
|
+
end
|
192
|
+
colnames = %w[Sno Categ Module Prior Task Status Date]
|
193
|
+
|
194
|
+
colnames_cbl = colnames.dup
|
195
|
+
colnames_cbl.insert 0, ""
|
196
|
+
col_combo = ComboBox.new @form do
|
197
|
+
name "col_combo"
|
198
|
+
row r
|
199
|
+
col 45
|
200
|
+
display_length 10
|
201
|
+
editable false
|
202
|
+
list colnames_cbl
|
203
|
+
set_label Label.new @form, {'text' => "Filter on:", 'color'=>'cyan',"mnemonic"=>"F"}
|
204
|
+
list_config 'height' => 6
|
205
|
+
help_text "Select a field to filter on"
|
206
|
+
end
|
207
|
+
col_value = Field.new @form do
|
208
|
+
name "col_value"
|
209
|
+
row r+1
|
210
|
+
col 45
|
211
|
+
bgcolor 'cyan'
|
212
|
+
color 'white'
|
213
|
+
display_length 10
|
214
|
+
set_label Label.new @form, {'text' => "Pattern:", 'color'=>'cyan',:bgcolor => 'black',"mnemonic"=>"P"}
|
215
|
+
help_text "Pattern/Regex to filter on"
|
216
|
+
end
|
217
|
+
# prepopulate screen, else error in table
|
218
|
+
data = todo.get_records_for_category 'TODO' # earlier TODO
|
219
|
+
@data = data
|
220
|
+
b_filter = Button.new @form do
|
221
|
+
text "Fi<er"
|
222
|
+
row r
|
223
|
+
col 65
|
224
|
+
help_text "Filter on selected filter column and value"
|
225
|
+
#bind(:ENTER) { status_row.text "New button adds a new row below current " }
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
table_ht = 15
|
230
|
+
atable = Table.new @form do
|
231
|
+
name "tasktable"
|
232
|
+
row r+2
|
233
|
+
col c
|
234
|
+
width 104
|
235
|
+
height table_ht
|
236
|
+
#title "A Table"
|
237
|
+
#title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
|
238
|
+
cell_editing_allowed false
|
239
|
+
set_data data, colnames
|
240
|
+
end
|
241
|
+
@atable = atable
|
242
|
+
categ.bind(:CHANGED) do |fld| $log.debug " COMBO EXIT XXXXXXXX";
|
243
|
+
data = todo.get_records_for_category fld.getvalue;
|
244
|
+
@data = data
|
245
|
+
atable.table_model.data = data
|
246
|
+
end
|
247
|
+
b_filter.command {
|
248
|
+
alert("Data is blank") if data.nil? or data.size == 0
|
249
|
+
raise("Data is blank") if data.nil? or data.size == 0
|
250
|
+
raise("selected is blank") if col_combo.selected_item.nil?
|
251
|
+
raise("col_val is blank") if col_value.getvalue.nil?
|
252
|
+
|
253
|
+
$log.debug "#{col_combo.selected_index}, .#{col_value.getvalue}"
|
254
|
+
d = data.select {|row| row[col_combo.selected_index-1].to_s.match(col_value.getvalue) }
|
255
|
+
atable.table_model.data = d unless d.nil? or d.size == 0
|
256
|
+
}
|
257
|
+
|
258
|
+
tcm = atable.get_table_column_model
|
259
|
+
#
|
260
|
+
## key bindings fo atable
|
261
|
+
# column widths
|
262
|
+
x = 0
|
263
|
+
tcm.column(x).width 2 # RK 2010-05-11 19:59 added serial number for updating
|
264
|
+
x += 1
|
265
|
+
tcm.column(x).width 8
|
266
|
+
x += 1
|
267
|
+
tcm.column(x).width 8
|
268
|
+
x += 1
|
269
|
+
tcm.column(x).width 5
|
270
|
+
x += 1
|
271
|
+
tcm.column(x).width 50
|
272
|
+
x += 1
|
273
|
+
tcm.column(x).width 8
|
274
|
+
x += 1
|
275
|
+
tcm.column(x).width 16
|
276
|
+
app = self
|
277
|
+
atable.configure() do
|
278
|
+
#bind_key(330) { atable.remove_column(tcm.column(atable.focussed_col)) rescue "" }
|
279
|
+
#bind_key(?+) {
|
280
|
+
#acolumn = atable.column atable.focussed_col()
|
281
|
+
##num = $multiplier || 1
|
282
|
+
#num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
|
283
|
+
#$multiplier = 0
|
284
|
+
#w = acolumn.width + num
|
285
|
+
#acolumn.width w
|
286
|
+
##atable.table_structure_changed
|
287
|
+
#}
|
288
|
+
bind_key(?+) {
|
289
|
+
# this automatically takes care of numeric arguments such as 12+ 22+ etc
|
290
|
+
atable.increase_column
|
291
|
+
}
|
292
|
+
bind_key(?-) {
|
293
|
+
# this automatically takes care of numeric arguments such as 12- 22- etc
|
294
|
+
atable.decrease_column
|
295
|
+
}
|
296
|
+
#bind_key(?-) {
|
297
|
+
#acolumn = atable.column atable.focussed_col()
|
298
|
+
#num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
|
299
|
+
#w = acolumn.width - num
|
300
|
+
#$multiplier = 0
|
301
|
+
#if w > 3
|
302
|
+
#acolumn.width w
|
303
|
+
##atable.table_structure_changed
|
304
|
+
#end
|
305
|
+
#}
|
306
|
+
bind_key(?>) {
|
307
|
+
colcount = tcm.column_count-1
|
308
|
+
#atable.move_column sel_col.value, sel_col.value+1 unless sel_col.value == colcount
|
309
|
+
col = atable.focussed_col
|
310
|
+
atable.move_column col, col+1 unless col == colcount
|
311
|
+
}
|
312
|
+
bind_key(?<) {
|
313
|
+
col = atable.focussed_col
|
314
|
+
atable.move_column col, col-1 unless col == 0
|
315
|
+
#atable.move_column sel_col.value, sel_col.value-1 unless sel_col.value == 0
|
316
|
+
}
|
317
|
+
bind_key(?\M-h, app) {|tab,td| $log.debug " BIND... #{tab.class}, #{td.class}"; app.make_popup atable}
|
318
|
+
end
|
319
|
+
#keylabel = RubyCurses::Label.new @form, {'text' => "", "row" => r+table_ht+3, "col" => c, "color" => "yellow", "bgcolor"=>"blue", "display_length"=>60, "height"=>2}
|
320
|
+
#eventlabel = RubyCurses::Label.new @form, {'text' => "Events:", "row" => r+table_ht+6, "col" => c, "color" => "white", "bgcolor"=>"blue", "display_length"=>60, "height"=>2}
|
321
|
+
|
322
|
+
# report some events
|
323
|
+
#atable.table_model.bind(:TABLE_MODEL_EVENT){|e| #eventlabel.text = "Event: #{e}"}
|
324
|
+
#atable.get_table_column_model.bind(:TABLE_COLUMN_MODEL_EVENT){|e| eventlabel.text = "Event: #{e}"}
|
325
|
+
atable.bind(:TABLE_TRAVERSAL_EVENT){|e| @header.text_right "Row #{e.newrow+1} of #{atable.row_count}" }
|
326
|
+
|
327
|
+
|
328
|
+
#str_renderer = TableCellRenderer.new ""
|
329
|
+
#num_renderer = TableCellRenderer.new "", { "justify" => :right }
|
330
|
+
#bool_renderer = CheckBoxCellRenderer.new "", {"parent" => atable, "display_length"=>5}
|
331
|
+
#combo_renderer = RubyCurses::ComboBoxCellRenderer.new nil, {"parent" => atable, "display_length"=> 8}
|
332
|
+
#combo_editor = RubyCurses::CellEditor.new(RubyCurses::ComboBox.new nil, {"focusable"=>false, "visible"=>false, "list"=>statuses, "display_length"=>8})
|
333
|
+
#combo_editor1 = RubyCurses::CellEditor.new(RubyCurses::ComboBox.new nil, {"focusable"=>false, "visible"=>false, "list"=>modules, "display_length"=>8})
|
334
|
+
#atable.set_default_cell_renderer_for_class "String", str_renderer
|
335
|
+
#atable.set_default_cell_renderer_for_class "Fixnum", num_renderer
|
336
|
+
#atable.set_default_cell_renderer_for_class "Float", num_renderer
|
337
|
+
#atable.set_default_cell_renderer_for_class "TrueClass", bool_renderer
|
338
|
+
#atable.set_default_cell_renderer_for_class "FalseClass", bool_renderer
|
339
|
+
#atable.get_table_column_model.column(3).cell_editor = combo_editor
|
340
|
+
#atable.get_table_column_model.column(0).cell_editor = combo_editor1
|
341
|
+
#ce = atable.get_default_cell_editor_for_class "String"
|
342
|
+
# increase the maxlen of task
|
343
|
+
#ce.component.maxlen = 80
|
344
|
+
# I want up and down to go up and down rows inside the combo box, i can use M-down for changing.
|
345
|
+
#combo_editor.component.unbind_key(KEY_UP)
|
346
|
+
#combo_editor.component.unbind_key(KEY_DOWN)
|
347
|
+
#combo_editor1.component.unbind_key(KEY_UP)
|
348
|
+
#combo_editor1.component.unbind_key(KEY_DOWN)
|
349
|
+
buttrow = r+table_ht+8 #Ncurses.LINES-4
|
350
|
+
buttrow = Ncurses.LINES-5
|
351
|
+
create_table_actions atable, todo, data, categ.getvalue
|
352
|
+
=begin
|
353
|
+
b_newrow = Button.new @form do
|
354
|
+
text "&New"
|
355
|
+
row buttrow
|
356
|
+
col c+10
|
357
|
+
bind(:ENTER) { status_row.text "New button adds a new row below current " }
|
358
|
+
end
|
359
|
+
b_newrow.command { @new_act.call }
|
360
|
+
=end
|
361
|
+
## We use Action to create a button: to test out ampersand with MI and Button
|
362
|
+
new_act = @new_act
|
363
|
+
# using ampersand to set mnemonic
|
364
|
+
b_sort = Button.new @form do
|
365
|
+
text "&Sort"
|
366
|
+
row buttrow
|
367
|
+
col c+25
|
368
|
+
#bind(:ENTER) { status_row.text "Deletes focussed row" }
|
369
|
+
help_text "Sort focussed row"
|
370
|
+
end
|
371
|
+
b_sort.command {
|
372
|
+
if @sorted_key == atable.focussed_col
|
373
|
+
@sort_dir = !@sort_dir
|
374
|
+
else
|
375
|
+
@sort_dir = true
|
376
|
+
end
|
377
|
+
@sorted_key = atable.focussed_col
|
378
|
+
|
379
|
+
$log.debug " SORT = #{categ.getvalue}, #{atable.focussed_col}, sort:#{@sort_dir}"
|
380
|
+
d = @todo.sort categ.getvalue, atable.focussed_col, @sort_dir
|
381
|
+
atable.table_model.data = d
|
382
|
+
}
|
383
|
+
=begin
|
384
|
+
b_change = Button.new @form do
|
385
|
+
text "&Lock"
|
386
|
+
row buttrow
|
387
|
+
col c+35
|
388
|
+
command {
|
389
|
+
r = atable.focussed_row
|
390
|
+
#c = sel_col.value
|
391
|
+
#$log.debug " Update gets #{field.getvalue.class}"
|
392
|
+
#atable.set_value_at(r, c, field.getvalue)
|
393
|
+
toggle = atable.column(atable.focussed_col()).editable
|
394
|
+
if toggle.nil? or toggle==true
|
395
|
+
toggle = false
|
396
|
+
text "Un&lock"
|
397
|
+
else
|
398
|
+
toggle = true
|
399
|
+
text "&Lock "
|
400
|
+
end
|
401
|
+
#eventlabel.text "Set column #{atable.focussed_col()} editable to #{toggle}"
|
402
|
+
atable.column(atable.focussed_col()).editable toggle
|
403
|
+
alert("Set column #{atable.focussed_col()} editable to #{toggle}")
|
404
|
+
}
|
405
|
+
help_text "Toggles editable state of current column "
|
406
|
+
end
|
407
|
+
=end
|
408
|
+
#buttons = [b_save, b_newrow, b_delrow, b_move ]
|
409
|
+
#Button.button_layout buttons, buttrow
|
410
|
+
@klp = RubyCurses::KeyLabelPrinter.new @form, get_key_labels
|
411
|
+
@klp.set_key_labels get_key_labels_table, :table
|
412
|
+
atable.bind(:ENTER){ @klp.mode :table ;
|
413
|
+
}
|
414
|
+
atable.bind(:LEAVE){@klp.mode :normal;
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
@form.repaint
|
419
|
+
@window.wrefresh
|
420
|
+
Ncurses::Panel.update_panels
|
421
|
+
begin
|
422
|
+
while((ch = @window.getchar()) != ?\C-q.getbyte(0) )
|
423
|
+
colcount = tcm.column_count-1
|
424
|
+
s = keycode_tos ch
|
425
|
+
#status_row.text = "Pressed #{ch} , #{s}"
|
426
|
+
@form.handle_key(ch)
|
427
|
+
|
428
|
+
@form.repaint
|
429
|
+
@window.wrefresh
|
430
|
+
end
|
431
|
+
ensure
|
432
|
+
@window.destroy if !@window.nil?
|
433
|
+
end
|
434
|
+
end
|
435
|
+
# Adding was done in testtodo.rb. this is view only
|
436
|
+
def create_table_actions atable, todo, data, categ
|
437
|
+
#@new_act = Action.new("New Row", "mnemonic"=>"N") {
|
438
|
+
@new_act = Action.new("&New Row") {
|
439
|
+
cc = atable.get_table_column_model.column_count
|
440
|
+
if atable.row_count < 1
|
441
|
+
categ = nil
|
442
|
+
frow = 0
|
443
|
+
else
|
444
|
+
frow = atable.focussed_row
|
445
|
+
categ = atable.get_value_at(frow,1)
|
446
|
+
frow += 1
|
447
|
+
end
|
448
|
+
tmp = [nil, categ, "", 5, "", "TODO", Time.now]
|
449
|
+
tm = atable.table_model
|
450
|
+
tm.insert frow, tmp
|
451
|
+
atable.set_focus_on frow
|
452
|
+
@status_row.text = "Added a row. Please press Save before changing Category."
|
453
|
+
alert("Added a row below current one. Use C-k to clear task.")
|
454
|
+
}
|
455
|
+
@new_act.accelerator "Alt-N"
|
456
|
+
@save_cmd = lambda {
|
457
|
+
todo.set_tasks_for_category categ, data
|
458
|
+
todo.dump
|
459
|
+
alert("Rewritten yaml file")
|
460
|
+
}
|
461
|
+
@del_cmd = lambda {
|
462
|
+
row = atable.focussed_row
|
463
|
+
if confirm("Do your really want to delete row #{row+1}?")== :YES
|
464
|
+
tm = atable.table_model
|
465
|
+
tm.delete_at row
|
466
|
+
else
|
467
|
+
@status_row.text = "Delete cancelled"
|
468
|
+
end
|
469
|
+
}
|
470
|
+
|
471
|
+
end
|
472
|
+
def make_popup table
|
473
|
+
require 'rbcurse/extras/widgets/rpopupmenu'
|
474
|
+
tablemenu = RubyCurses::PopupMenu.new "Table"
|
475
|
+
#tablemenu.add(item = RubyCurses::PMenuItem.new("Open",'O'))
|
476
|
+
tablemenu.add(item = RubyCurses::PMenuItem.new("&Open"))
|
477
|
+
|
478
|
+
tablemenu.insert_separator 1
|
479
|
+
#tablemenu.add(RubyCurses::PMenuItem.new "New",'N')
|
480
|
+
tablemenu.add(@new_act)
|
481
|
+
tablemenu.add(item = RubyCurses::PMenuItem.new("&Save"))
|
482
|
+
item.command() { @save_cmd.call }
|
483
|
+
|
484
|
+
item=RubyCurses::PMenuItem.new "Select"
|
485
|
+
item.accelerator = "Ctrl-X"
|
486
|
+
item.command() { table.toggle_row_selection() }
|
487
|
+
#item.enabled = false
|
488
|
+
tablemenu.add(item)
|
489
|
+
|
490
|
+
item=RubyCurses::PMenuItem.new "Clr Selection"
|
491
|
+
item.accelerator = "Alt-e"
|
492
|
+
item.command() { table.clear_selection() }
|
493
|
+
item.enabled = table.selected_row_count > 0 ? true : false
|
494
|
+
tablemenu.add(item)
|
495
|
+
|
496
|
+
item=RubyCurses::PMenuItem.new "Delete"
|
497
|
+
item.accelerator = "Alt-D"
|
498
|
+
item.command() { @del_cmd.call }
|
499
|
+
tablemenu.add(item)
|
500
|
+
|
501
|
+
gotomenu = RubyCurses::PMenu.new "&Goto"
|
502
|
+
|
503
|
+
item = RubyCurses::PMenuItem.new "Top"
|
504
|
+
item.accelerator = "Alt-0"
|
505
|
+
item.command() { table.goto_top }
|
506
|
+
gotomenu.add(item)
|
507
|
+
|
508
|
+
item = RubyCurses::PMenuItem.new "Bottom"
|
509
|
+
item.accelerator = "Alt-9"
|
510
|
+
item.command() { table.goto_bottom }
|
511
|
+
gotomenu.add(item)
|
512
|
+
|
513
|
+
item = RubyCurses::PMenuItem.new "Next Page"
|
514
|
+
item.accelerator = "Ctrl-n"
|
515
|
+
item.command() { table.scroll_forward }
|
516
|
+
gotomenu.add(item)
|
517
|
+
|
518
|
+
item = RubyCurses::PMenuItem.new "Prev Page"
|
519
|
+
item.accelerator = "Ctrl-p"
|
520
|
+
item.command() { table.scroll_backward }
|
521
|
+
gotomenu.add(item)
|
522
|
+
|
523
|
+
tablemenu.add(gotomenu)
|
524
|
+
|
525
|
+
|
526
|
+
tablemenu.show @atable, 0,1
|
527
|
+
end
|
528
|
+
def get_key_labels
|
529
|
+
key_labels = [
|
530
|
+
['C-q', 'Exit'], nil,
|
531
|
+
['M-c', 'Category'], nil,
|
532
|
+
['M-f', 'Filter Fld'], ['M-p', 'Pattern'],
|
533
|
+
['M-s', 'Sort'], ['M-i', 'Filter']
|
534
|
+
]
|
535
|
+
return key_labels
|
536
|
+
end
|
537
|
+
def get_key_labels_table
|
538
|
+
key_labels = [
|
539
|
+
#['M-n','NewRow'], ['M-d','DelRow'],
|
540
|
+
['C-x','Select'], ['M-h', 'Popup'],
|
541
|
+
['M-0', 'Top'], ['M-9', 'End'],
|
542
|
+
['C-p', 'PgUp'], ['C-n', 'PgDn'],
|
543
|
+
['M-Tab','Nxt Fld'], ['Tab','Nxt Col'],
|
544
|
+
['+','Widen'], ['-','Narrow']
|
545
|
+
]
|
546
|
+
return key_labels
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end # module
|
550
|
+
if $0 == __FILE__
|
551
|
+
include RubyCurses
|
552
|
+
include RubyCurses::Utils
|
553
|
+
|
554
|
+
begin
|
555
|
+
# Initialize curses
|
556
|
+
VER::start_ncurses # this is initializing colors via ColorMap.setup
|
557
|
+
$log = Logger.new("rbc13.log")
|
558
|
+
$log.level = Logger::DEBUG
|
559
|
+
|
560
|
+
colors = Ncurses.COLORS
|
561
|
+
|
562
|
+
catch(:close) do
|
563
|
+
t = ViewTodo::TodoApp.new
|
564
|
+
t.run
|
565
|
+
end
|
566
|
+
rescue => ex
|
567
|
+
ensure
|
568
|
+
VER::stop_ncurses
|
569
|
+
p ex if ex
|
570
|
+
p(ex.backtrace.join("\n")) if ex
|
571
|
+
$log.debug( ex) if ex
|
572
|
+
$log.debug(ex.backtrace.join("\n")) if ex
|
573
|
+
end
|
574
|
+
end
|