Class: QDA::GUI::CategoryTree
Overview
the category tree list for the side panel
Constant Summary
collapse
- CATEGORY_TREE_STYLE =
Wx::TR_HIDE_ROOT|Wx::TR_HAS_BUTTONS|
Wx::TR_LINES_AT_ROOT|Wx::TR_EDIT_LABELS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#append_item(parent, text, data = nil) ⇒ Object
-
#append_recursively(parent, children) ⇒ Object
-
#delete(id) ⇒ Object
-
#delete_selection ⇒ Object
-
#dont_move(from) ⇒ Object
-
#expand_items(catids) ⇒ Object
Opens the category nodes corresponding to the category ids in catids.
-
#expanded_items ⇒ Object
returns an array of category ids NOT USED?.
-
#get_current_category ⇒ Object
(also: #selected_category)
get the currently active category.
-
#initialize(weft_client, parent, locked = false) ⇒ CategoryTree
constructor
a locked control is one that is not editable, and does not affect the selection of categories in other widgetes.
-
#move(from, to) ⇒ Object
moves the item identifed by the tree id from to be the last child of the category with the tree id to.
-
#move_item(from, to) ⇒ Object
Moves the tree item identified by from so that it is attached the parent identified by new_parent.
-
#on_create_item ⇒ Object
when we’re asked to add an item.
-
#on_drag_begin(evt) ⇒ Object
-
#on_drag_end(evt) ⇒ Object
relocates or merges the coding of the draggee to the drag target.
-
#on_edit_label_begin(evt) ⇒ Object
-
#on_edit_label_end(evt) ⇒ Object
-
#on_item_activated(event) ⇒ Object
-
#on_item_collapsed(evt) ⇒ Object
-
#on_item_expanded(evt) ⇒ Object
-
#on_item_selected(event) ⇒ Object
-
#on_key_down(evt) ⇒ Object
-
#populate(children) ⇒ Object
-
#prepend_item(parent, text, img = -1,, sel_img = -1,, data = nil) ⇒ Object
-
#receive_category_added(cat) ⇒ Object
-
#receive_category_changed(cat) ⇒ Object
-
#receive_category_deleted(cat) ⇒ Object
-
#valid_selection?(event) ⇒ Boolean
Methods included from Subscriber
#notify, #subscribe
#data, #index
Methods included from ItemData
#get_item_data, #set_item_data, #value_to_ident
Constructor Details
#initialize(weft_client, parent, locked = false) ⇒ CategoryTree
a locked control is one that is not editable, and does not affect the selection of categories in other widgetes.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 14
def initialize(weft_client, parent, locked = false)
@client = weft_client
@locked = locked
@expanded = {}
super(parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
CATEGORY_TREE_STYLE)
my_id = self.get_id()
evt_tree_item_activated(my_id) { | e | on_item_activated(e) }
if ! @locked
evt_tree_sel_changed(my_id) { | e | on_item_selected(e) }
evt_tree_end_drag(my_id) { | e | on_drag_end(e) }
evt_tree_begin_drag(my_id) { | e | on_drag_begin(e) }
evt_tree_begin_label_edit(my_id) { | e | on_edit_label_begin(e) }
evt_tree_end_label_edit(my_id) { | e | on_edit_label_end(e) }
evt_tree_key_down(my_id) { | e | on_key_down(e) }
evt_tree_item_expanded(my_id) { | e | on_item_expanded(e) }
evt_tree_item_collapsed(my_id) { | e | on_item_collapsed(e) }
end
subscribe(@client, :category_deleted, :category_changed, :category_added)
end
|
Instance Attribute Details
#root_id ⇒ Object
Returns the value of attribute root_id.
10
11
12
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 10
def root_id
@root_id
end
|
Instance Method Details
#append_item(parent, text, data = nil) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 39
def append_item(parent, text, data = nil)
id = super(parent, text, -1, -1)
set_item_data(id, data)
set_item_bold(id) if parent == @root_id
id
end
|
#append_recursively(parent, children) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 89
def append_recursively(parent, children)
children.each do | child_cat |
name = child_cat.name.empty? ? 'DEFAULT' : child_cat.name
id = append_item(parent, name, child_cat )
@search_id = id if name == 'SEARCHES'
@codes_id = id if name == 'CATEGORIES' or name == 'CODES'
append_recursively(id, child_cat.children)
end
end
|
#delete(id) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 54
def delete(id)
super(id)
del_cat = data.delete(id)
if del_cat.parent and old_parent_id = value_to_ident(del_cat.parent)
set_item_data( old_parent_id,
@client.app.get_category(del_cat.parent.dbid) )
end
return nil
end
|
#delete_selection ⇒ Object
273
274
275
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 273
def delete_selection()
@client.on_delete_category()
end
|
#dont_move(from) ⇒ Object
183
184
185
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 183
def dont_move(from)
select_item(from) if from != 0
end
|
#expand_items(catids) ⇒ Object
Opens the category nodes corresponding to the category ids in catids
79
80
81
82
83
84
85
86
87
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 79
def expand_items(catids)
catids.keys.each do | catid |
if itemid = value_to_ident(catid)
@expanded[catid] = true
expand( itemid )
end
end
end
|
#expanded_items ⇒ Object
returns an array of category ids NOT USED?
74
75
76
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 74
def expanded_items()
@expanded.keys
end
|
#get_current_category ⇒ Object
Also known as:
selected_category
get the currently active category
103
104
105
106
107
108
109
110
111
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 103
def get_current_category()
if curr_sel = get_selection()
return nil if curr_sel == 0
category = get_item_data( curr_sel )
return nil if category.nil?
return nil if category.parent.nil?
category
end
end
|
#move(from, to) ⇒ Object
moves the item identifed by the tree id from to be the last child of the category with the tree id to
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 190
def move(from, to)
return dont_move(from) unless from and to
return dont_move(from) if from == 0 or to == 0
return dont_move(from) if from == to
movee = get_item_data( from )
destination = get_item_data( to )
return dont_move(from) if not movee.parent
return dont_move(from) if movee.parent == destination
return dont_move(from) if destination.is_descendant_of?(movee)
if destination[movee.name]
ErrorDialog.display( Lang::DUPLICATE_CATEGORY_NAME_TITLE,
Lang::DUPLICATE_CATEGORY_NAME_WARNING )
return dont_move(from)
end
Wx::BusyCursor.busy do
movee.parent = destination
@client.app.save_category( movee )
end
end
|
#move_item(from, to) ⇒ Object
Moves the tree item identified by from so that it is attached the parent identified by new_parent. Does nothing if that is already the location of the node.
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 219
def move_item(from, to)
return from if get_item_parent(from) == to
new_child = append_item(to, get_item_text(from), get_item_data(from))
child = get_first_child(from)[0]
while child != 0
move_item(child, new_child)
child = get_first_child(from)[0]
end
delete( from )
new_child
end
|
#on_create_item ⇒ Object
when we’re asked to add an item. This will be attached to the currently selected category in the tree, or the default ‘CATEGORIES’ category if no item is selected
235
236
237
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 235
def on_create_item()
@client.on_add_category()
end
|
#on_drag_begin(evt) ⇒ Object
167
168
169
170
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 167
def on_drag_begin(evt)
@drag_subject = evt.item
evt.allow()
end
|
#on_drag_end(evt) ⇒ Object
relocates or merges the coding of the draggee to the drag target
173
174
175
176
177
178
179
180
181
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 173
def on_drag_end(evt)
@drag_target = evt.item
move(@drag_subject, @drag_target)
@drag_subject = nil
@drag_target = nil
end
|
#on_edit_label_begin(evt) ⇒ Object
129
130
131
132
133
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 129
def on_edit_label_begin(evt)
evt.veto() if bold?(evt.item)
end
|
#on_edit_label_end(evt) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 135
def on_edit_label_end(evt)
new_text = evt.label
if new_text == ""
evt.veto()
return
end
old_text = get_item_text( evt.item )
return if old_text == new_text
c_cdata = get_item_data( evt.item )
category = @client.app.get_category( c_cdata.dbid )
Wx::BusyCursor.busy do
begin
category.name = new_text
@client.app.save_category( category)
rescue QDA::BadNameError
category.name = old_text
ErrorDialog.display( Lang::BAD_CATEGORY_NAME_TITLE,
Lang::BAD_CATEGORY_NAME_WARNING )
evt.veto()
rescue QDA::NotUniqueNameError
category.name = old_text
ErrorDialog.display( Lang::DUPLICATE_CATEGORY_NAME_TITLE,
Lang::DUPLICATE_CATEGORY_NAME_WARNING )
evt.veto()
end
end
set_item_data(evt.item, category )
end
|
#on_item_activated(event) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 247
def on_item_activated(event)
item_id = event.get_item()
category = get_item_data(item_id)
return nil if category.parent.nil?
Wx::BusyCursor.busy() do
category = @client.app.get_category(category.dbid, true)
if category != nil
@client.on_category_open(category)
end
end
end
|
#on_item_collapsed(evt) ⇒ Object
122
123
124
125
126
127
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 122
def on_item_collapsed(evt)
cat = get_item_data(evt.item)
return unless cat
@expanded.delete(cat.dbid)
@client.app.save_preference('TreeLayout', @expanded)
end
|
#on_item_expanded(evt) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 114
def on_item_expanded(evt)
cat = get_item_data(evt.item)
return unless cat
return if @expanded[cat.dbid]
@expanded[cat.dbid] = true
@client.app.save_preference('TreeLayout', @expanded)
end
|
#on_item_selected(event) ⇒ Object
239
240
241
242
243
244
245
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 239
def on_item_selected(event)
if valid_selection?(event)
@client.current_category = get_item_data( event.get_item )
else
@client.current_category = nil
end
end
|
#on_key_down(evt) ⇒ Object
277
278
279
280
281
282
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 277
def on_key_down(evt)
case evt.key_code()
when 127
delete_selection()
end
end
|
#populate(children) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 64
def populate(children)
@root_id = add_root('ROOT')
append_recursively(@root_id, children)
refresh()
end
|
#prepend_item(parent, text, img = -1,, sel_img = -1,, data = nil) ⇒ Object
47
48
49
50
51
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 47
def prepend_item(parent, text, img = -1, sel_img = -1, data = nil)
id = super(parent, text, img, sel_img)
set_item_data(id, data)
return id
end
|
#receive_category_added(cat) ⇒ Object
301
302
303
304
305
306
307
308
309
310
311
312
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 301
def receive_category_added(cat)
if cat.parent.nil?
p_id = @root_id
else
p_id = value_to_ident(cat.parent)
end
return if not p_id
append_item( p_id, cat.name, cat)
expand(p_id)
id = value_to_ident(cat)
select_item(id)
end
|
#receive_category_changed(cat) ⇒ Object
291
292
293
294
295
296
297
298
299
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 291
def receive_category_changed(cat)
if tree_id = value_to_ident(cat)
tree_id = move_item(tree_id, value_to_ident(cat.parent) )
set_item_text( tree_id, cat.name)
set_item_data( tree_id, cat)
end
end
|
#receive_category_deleted(cat) ⇒ Object
284
285
286
287
288
289
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 284
def receive_category_deleted(cat)
if tree_id = value_to_ident(cat)
delete( tree_id )
end
end
|
#valid_selection?(event) ⇒ Boolean
259
260
261
262
263
264
265
266
267
268
269
270
271
|
# File 'lib/weft/wxgui/controls/category_tree.rb', line 259
def valid_selection?( event )
item_id = event.get_item()
if item_id.nil? or item_id == 0 or is_bold(item_id)
return false
elsif not get_item_data( item_id )
return false
else
return true
end
end
|