author | Claus Gittinger <cg@exept.de> |
Fri, 09 Jul 2010 09:11:28 +0200 | |
changeset 3915 | f3ec0f55b790 |
parent 3914 | 084e5ac32b90 |
child 3916 | c7913ceffa62 |
permissions | -rw-r--r-- |
1431 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1794 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
1390 | 14 |
Object subclass:#HierarchicalItem |
1606 | 15 |
instanceVariableNames:'parent children isExpanded height width' |
1390 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
1430 | 18 |
category:'Views-Support' |
1390 | 19 |
! |
20 |
||
21 |
HierarchicalItem subclass:#Example |
|
22 |
instanceVariableNames:'label icon' |
|
23 |
classVariableNames:'PenguinIcon' |
|
24 |
poolDictionaries:'' |
|
25 |
privateIn:HierarchicalItem |
|
26 |
! |
|
27 |
||
28 |
!HierarchicalItem class methodsFor:'documentation'! |
|
29 |
||
1431 | 30 |
copyright |
31 |
" |
|
32 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
! |
|
44 |
||
1390 | 45 |
documentation |
46 |
" |
|
47 |
Hierarchical Items are mostly like Models, but the list of |
|
48 |
dependencies are kept by its HierarchicalList. |
|
49 |
The class is used to build up hierarchical trees. |
|
50 |
||
51 |
[Instance variables:] |
|
52 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
53 |
children <Collection or nil> list of children |
|
54 |
isExpanded <Boolean> indicates whether the item is |
|
55 |
expanded or collapsed |
|
56 |
||
57 |
[author:] |
|
58 |
Claus Atzkern |
|
59 |
||
60 |
[see also:] |
|
61 |
HierarchicalList |
|
62 |
HierarchicalListView |
|
63 |
" |
|
64 |
||
65 |
||
66 |
! ! |
|
67 |
||
68 |
!HierarchicalItem class methodsFor:'instance creation'! |
|
69 |
||
70 |
new |
|
71 |
^ (self basicNew) initialize |
|
2314 | 72 |
! |
73 |
||
74 |
parent:aParent |
|
75 |
|item| |
|
76 |
||
77 |
item := self new. |
|
78 |
item parent:aParent. |
|
79 |
^ item |
|
1390 | 80 |
! ! |
81 |
||
2081 | 82 |
!HierarchicalItem class methodsFor:'protocol'! |
83 |
||
84 |
doResetExtentOnChange |
|
85 |
"true: the extent of the item is reset if a change |
|
86 |
notification is raised from the item. the default is true |
|
87 |
" |
|
88 |
^ true |
|
89 |
! ! |
|
90 |
||
1390 | 91 |
!HierarchicalItem methodsFor:'accessing'! |
92 |
||
2081 | 93 |
getChildren |
3912 | 94 |
"returns the children as they are present (or not); not going to the model..." |
95 |
||
2081 | 96 |
^ children |
97 |
! |
|
98 |
||
1390 | 99 |
level |
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
100 |
"returns the level starting with 0 for the root" |
3912 | 101 |
|
2386 | 102 |
|item level| |
103 |
||
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
104 |
item := self. |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
105 |
level := 0. |
1390 | 106 |
|
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
107 |
[ (item := item parentOrModel) notNil] whileTrue:[ |
3090 | 108 |
level := level + 1. |
3562 | 109 |
level > 100000 ifTrue:[ |
110 |
self halt:'possibly recursive item hierarchy' |
|
111 |
]. |
|
1390 | 112 |
]. |
113 |
^ level |
|
3912 | 114 |
|
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
115 |
"Modified: / 09-07-2010 / 08:56:27 / cg" |
1390 | 116 |
! |
117 |
||
118 |
parent |
|
3912 | 119 |
"returns the parent or nil" |
120 |
||
121 |
^ (parent notNil and:[parent isHierarchicalItem]) |
|
122 |
ifTrue:[parent] |
|
123 |
ifFalse:[nil] |
|
1390 | 124 |
! |
125 |
||
126 |
parent:aParent |
|
3912 | 127 |
"set the parent (or the model if the item is the root item)" |
128 |
||
1390 | 129 |
parent := aParent |
1883 | 130 |
! |
131 |
||
132 |
rootItem |
|
3911 | 133 |
"returns the root item" |
134 |
||
1883 | 135 |
parent isHierarchicalItem ifTrue:[ |
136 |
^ parent rootItem |
|
137 |
]. |
|
138 |
^ self |
|
1390 | 139 |
! ! |
140 |
||
1818 | 141 |
!HierarchicalItem methodsFor:'accessing-children'! |
1390 | 142 |
|
143 |
at:anIndex |
|
1900 | 144 |
"return the child at anIndex if valid; |
2927 | 145 |
if the index is invalid, nil is returned" |
146 |
||
1900 | 147 |
^ self at:anIndex ifAbsent:nil |
148 |
! |
|
149 |
||
150 |
at:anIndex ifAbsent:exceptionBlock |
|
151 |
"return the child at anIndex if valid; if the index is |
|
2927 | 152 |
invalid, the result of evaluating the exceptionBlock is returned." |
153 |
||
1900 | 154 |
|list| |
155 |
||
156 |
(list := self children) notNil ifTrue:[ |
|
157 |
^ list at:anIndex ifAbsent:exceptionBlock |
|
158 |
]. |
|
159 |
^ exceptionBlock value |
|
1390 | 160 |
! |
161 |
||
162 |
at:anIndex put:anItem |
|
3613
440f0aa671ce
return value fixed (consistent)
Claus Gittinger <cg@exept.de>
parents:
3562
diff
changeset
|
163 |
"replace a child by a new item. return anItem (sigh)" |
2927 | 164 |
|
2340 | 165 |
|children oldItem visIndex model expFlag| |
1390 | 166 |
|
167 |
anItem isNil ifTrue:[ |
|
3613
440f0aa671ce
return value fixed (consistent)
Claus Gittinger <cg@exept.de>
parents:
3562
diff
changeset
|
168 |
self removeFromIndex:anIndex toIndex:anIndex. |
440f0aa671ce
return value fixed (consistent)
Claus Gittinger <cg@exept.de>
parents:
3562
diff
changeset
|
169 |
^ nil |
1390 | 170 |
]. |
2340 | 171 |
anItem parent:self. |
2081 | 172 |
|
2340 | 173 |
(model := self model) isNil ifTrue:[ |
3613
440f0aa671ce
return value fixed (consistent)
Claus Gittinger <cg@exept.de>
parents:
3562
diff
changeset
|
174 |
self children at:anIndex put:anItem. |
440f0aa671ce
return value fixed (consistent)
Claus Gittinger <cg@exept.de>
parents:
3562
diff
changeset
|
175 |
^ anItem |
2081 | 176 |
]. |
177 |
||
2340 | 178 |
model criticalDo:[ |
179 |
children := self children. |
|
180 |
oldItem := children at:anIndex. |
|
2081 | 181 |
|
2340 | 182 |
oldItem isExpanded ifTrue:[ |
183 |
oldItem collapse |
|
184 |
]. |
|
185 |
visIndex := model identityIndexOf:oldItem. |
|
186 |
expFlag := anItem isExpanded. |
|
187 |
anItem setExpanded:false. |
|
2081 | 188 |
|
2340 | 189 |
children at:anIndex put:anItem. |
190 |
||
191 |
visIndex ~~ 0 ifTrue:[ |
|
2343 | 192 |
model at:visIndex put:anItem. |
2081 | 193 |
]. |
2340 | 194 |
self changed:#redraw. |
195 |
expFlag ifTrue:[ anItem expand ]. |
|
1390 | 196 |
]. |
2081 | 197 |
^ anItem |
1390 | 198 |
! |
199 |
||
200 |
children:aListOfChildren |
|
2927 | 201 |
"set a new list of children" |
202 |
||
1733 | 203 |
self criticalDo:[ |
204 |
self removeAll. |
|
205 |
self addAll:aListOfChildren beforeIndex:1 |
|
206 |
]. |
|
207 |
^ aListOfChildren |
|
1390 | 208 |
! |
209 |
||
210 |
first |
|
211 |
"returns the first child |
|
212 |
" |
|
213 |
^ self at:1 |
|
214 |
! |
|
215 |
||
216 |
last |
|
3912 | 217 |
"returns the last child" |
218 |
||
2081 | 219 |
^ self at:(self size) |
1900 | 220 |
! |
221 |
||
222 |
second |
|
3911 | 223 |
"returns the second child" |
224 |
||
1900 | 225 |
^ self at:2 |
1390 | 226 |
! ! |
227 |
||
1818 | 228 |
!HierarchicalItem methodsFor:'accessing-hierarchy'! |
1390 | 229 |
|
230 |
collapse |
|
2549 | 231 |
"hide all my subitems" |
232 |
||
2081 | 233 |
|visChd index| |
1390 | 234 |
|
235 |
self canCollapse ifTrue:[ |
|
236 |
isExpanded := false. |
|
237 |
||
1733 | 238 |
self criticalDo:[ |
239 |
(index := self listIndex) notNil ifTrue:[ |
|
2081 | 240 |
"/ do not call :#size: children will be autoloaded !!!! |
1733 | 241 |
(visChd := children size) ~~ 0 ifTrue:[ |
2117 | 242 |
self nonCriticalFrom:1 to:nil do:[:el| |
2081 | 243 |
visChd := visChd + el numberOfVisibleChildren |
1733 | 244 |
]. |
245 |
self model itemRemoveFromIndex:(index + 1) toIndex:(index + visChd). |
|
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
246 |
]. |
2549 | 247 |
index ~~ 0 ifTrue:[self hierarchyChanged]. |
1390 | 248 |
] |
249 |
] |
|
250 |
] |
|
251 |
! |
|
252 |
||
2476 | 253 |
enforcedExpand |
2724 | 254 |
"expand children - even if there are no children, |
2476 | 255 |
the item is initially expanded (but this might be undone later, |
256 |
when we know that no children are there" |
|
257 |
||
258 |
self expand:true |
|
259 |
! |
|
260 |
||
1390 | 261 |
expand |
2476 | 262 |
"expand children - but only if there are children |
263 |
(i.e. this cannot be used before the childInfo is valid; |
|
264 |
aka not before the updateTask came along this item)" |
|
265 |
||
266 |
self expand:false |
|
267 |
! |
|
268 |
||
269 |
expand:enforced |
|
2547 | 270 |
"expand children" |
271 |
||
2305 | 272 |
|index list| |
273 |
||
274 |
"/ test whether the item already is expanded; #canExpand could be redefined |
|
275 |
"/ without checking whether the node is expanded (happens already) !! |
|
276 |
||
2547 | 277 |
isExpanded ifTrue:[ ^ self ]. |
2724 | 278 |
(enforced not and:[self canExpand not]) ifTrue:[ ^ self ]. |
1942 | 279 |
|
2305 | 280 |
self criticalDo:[ |
281 |
(index := self listIndex) notNil ifTrue:[ |
|
282 |
"/ must set expand-flag to false, otherwise change notifications |
|
2476 | 283 |
"/ are raised during lazy auto creation (to the list). |
2305 | 284 |
isExpanded := false. |
285 |
list := self children. |
|
286 |
isExpanded := true. |
|
287 |
||
2832 | 288 |
list notEmptyOrNil ifTrue:[ |
3716
ac24a9716024
dont preallocate big OrderedCollections
Claus Gittinger <cg@exept.de>
parents:
3697
diff
changeset
|
289 |
list := OrderedCollection new. |
2832 | 290 |
self addVisibleChildrenTo:list. |
291 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
2305 | 292 |
]. |
293 |
index ~~ 0 ifTrue:[self hierarchyChanged]. |
|
294 |
] ifFalse:[ |
|
295 |
isExpanded := true |
|
1390 | 296 |
] |
2305 | 297 |
]. |
1390 | 298 |
! |
299 |
||
1409 | 300 |
makeVisible |
3912 | 301 |
"expand all my parents" |
302 |
||
1409 | 303 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
1733 | 304 |
self criticalDo:[ |
305 |
parent expand. |
|
306 |
parent makeVisible |
|
307 |
] |
|
1409 | 308 |
]. |
309 |
! |
|
310 |
||
1390 | 311 |
recursiveCollapse |
2081 | 312 |
"collapse all item and sub items |
1390 | 313 |
**** must be expanded |
314 |
" |
|
315 |
|visChd index| |
|
316 |
||
317 |
self canCollapse ifTrue:[ |
|
1733 | 318 |
self criticalDo:[ |
319 |
(index := self listIndex) notNil ifTrue:[ |
|
2081 | 320 |
"/ do not call :#size: children will be autoloaded !!!! |
1733 | 321 |
(visChd := children size) ~~ 0 ifTrue:[ |
2117 | 322 |
self nonCriticalFrom:1 to:nil do:[:el| |
2081 | 323 |
visChd := visChd + el numberOfVisibleChildren |
324 |
]. |
|
1733 | 325 |
]. |
326 |
self recursiveSetCollapsed. |
|
1390 | 327 |
|
1733 | 328 |
visChd ~~ 0 ifTrue:[ |
329 |
self model itemRemoveFromIndex:(index + 1) |
|
330 |
toIndex:(index + visChd) |
|
331 |
]. |
|
332 |
index ~~ 0 ifTrue:[ |
|
333 |
self hierarchyChanged |
|
334 |
] |
|
335 |
] ifFalse:[ |
|
336 |
self recursiveSetCollapsed |
|
1390 | 337 |
] |
338 |
] |
|
339 |
] |
|
340 |
! |
|
341 |
||
342 |
recursiveExpand |
|
343 |
"expand children and sub-children |
|
3911 | 344 |
**** must be collapsed" |
345 |
||
2305 | 346 |
"/ test whether the item already is expanded; #canExpand could be redefined |
347 |
"/ without checking whether the node is expanded (happens already) !! |
|
348 |
||
2846 | 349 |
|index list| |
3716
ac24a9716024
dont preallocate big OrderedCollections
Claus Gittinger <cg@exept.de>
parents:
3697
diff
changeset
|
350 |
|
2547 | 351 |
isExpanded ifTrue:[ ^ self ]. |
2845
fb807c9aa195
Add recursive force expand, to force expand of children independed
ab
parents:
2832
diff
changeset
|
352 |
|
2547 | 353 |
self canExpand ifFalse:[ ^ self ]. |
2305 | 354 |
|
355 |
isExpanded := true. |
|
1390 | 356 |
|
2305 | 357 |
self criticalDo:[ |
358 |
self size ~~ 0 ifTrue:[ |
|
359 |
index := self listIndex. "/ get the visible list index |
|
1390 | 360 |
|
2305 | 361 |
index isNil ifTrue:[ "/ not visible |
362 |
self nonCriticalFrom:1 to:nil do:[:el| |
|
363 |
el setExpanded:true |
|
364 |
]. |
|
365 |
] ifFalse:[ |
|
3716
ac24a9716024
dont preallocate big OrderedCollections
Claus Gittinger <cg@exept.de>
parents:
3697
diff
changeset
|
366 |
list := OrderedCollection new. |
2305 | 367 |
self recursiveSetExpandedAndAddToList:list. |
368 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
369 |
||
370 |
index ~~ 0 ifTrue:[self hierarchyChanged] |
|
1390 | 371 |
] |
372 |
] |
|
2305 | 373 |
]. |
1390 | 374 |
! |
375 |
||
376 |
recursiveToggleExpand |
|
2081 | 377 |
"if the item is collapsed, the item and all its sub-items |
2547 | 378 |
are expanded otherwise collapsed" |
379 |
||
380 |
isExpanded ifTrue:[ |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
381 |
self recursiveCollapse |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
382 |
] ifFalse:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
383 |
self recursiveExpand |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
384 |
] |
1390 | 385 |
! |
386 |
||
387 |
toggleExpand |
|
3910
5166010faa48
comment/format in: #toggleExpand
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
388 |
"if the item is collapsed, the item is expanded otherwise collapsed" |
2547 | 389 |
|
390 |
isExpanded ifTrue:[ |
|
2081 | 391 |
self collapse |
392 |
] ifFalse:[ |
|
393 |
self expand |
|
394 |
]. |
|
1390 | 395 |
! ! |
396 |
||
1818 | 397 |
!HierarchicalItem methodsFor:'accessing-mvc'! |
1390 | 398 |
|
399 |
application |
|
2927 | 400 |
"returns the responsible application or nil" |
401 |
||
1390 | 402 |
|model| |
403 |
||
404 |
(model := self model) notNil ifTrue:[ |
|
405 |
^ model application |
|
406 |
]. |
|
407 |
^ nil |
|
408 |
! |
|
409 |
||
410 |
applicationsDo:aOneArgBlock |
|
2927 | 411 |
"evaluate the block for each dependent application" |
412 |
||
1390 | 413 |
|model| |
414 |
||
415 |
(model := self model) notNil ifTrue:[ |
|
416 |
model applicationsDo:aOneArgBlock |
|
417 |
] |
|
418 |
! |
|
419 |
||
420 |
model |
|
3912 | 421 |
"returns the hierachicalList model or nil. |
422 |
This is a stupid implementation here, in that the top-item's parent is assumed to |
|
423 |
be the model of the tree, and that is returned. |
|
424 |
This saves a slot in every node, but makes some algorithms O(n*log n) or even O(n^2). |
|
425 |
So be aware of the performance penalty" |
|
426 |
||
2386 | 427 |
|item next| |
428 |
||
2716 | 429 |
item := self. |
430 |
[ (next := item parentOrModel) notNil ] whileTrue:[ |
|
431 |
item := next. |
|
432 |
]. |
|
2386 | 433 |
|
434 |
item isHierarchicalItem ifFalse:[^ item]. |
|
435 |
^ nil |
|
1390 | 436 |
! ! |
437 |
||
438 |
!HierarchicalItem methodsFor:'adding & removing'! |
|
439 |
||
440 |
add:aChildItem |
|
2927 | 441 |
"add a child at end" |
442 |
||
1390 | 443 |
^ self add:aChildItem beforeIndex:(self children size + 1). |
444 |
! |
|
445 |
||
446 |
add:aChildItem after:aChild |
|
2927 | 447 |
"add an item after an existing item" |
448 |
||
1390 | 449 |
|index| |
450 |
||
2315 | 451 |
index := self identityIndexOf:aChild. |
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
452 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
2315 | 453 |
|
454 |
self add:aChildItem beforeIndex:(index + 1). |
|
2927 | 455 |
^ aChildItem |
1390 | 456 |
! |
457 |
||
458 |
add:aChildItem afterIndex:anIndex |
|
2927 | 459 |
"add an item after an index" |
460 |
||
1390 | 461 |
^ self add:aChildItem beforeIndex:(anIndex + 1). |
462 |
! |
|
463 |
||
464 |
add:aChildItem before:aChild |
|
2927 | 465 |
"add an item before an existing item" |
466 |
||
1390 | 467 |
|index| |
468 |
||
2315 | 469 |
index := self identityIndexOf:aChild. |
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
470 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
2315 | 471 |
|
472 |
self add:aChildItem beforeIndex:index. |
|
2927 | 473 |
^ aChild |
1390 | 474 |
! |
475 |
||
476 |
add:aChildItem beforeIndex:anIndex |
|
2927 | 477 |
"add an item before an index" |
478 |
||
1390 | 479 |
aChildItem notNil ifTrue:[ |
480 |
self addAll:(Array with:aChildItem) beforeIndex:anIndex |
|
481 |
]. |
|
482 |
^ aChildItem |
|
483 |
! |
|
484 |
||
1488 | 485 |
add:aChild sortBlock:aBlock |
2927 | 486 |
"add a child sorted" |
487 |
||
1733 | 488 |
self criticalDo:[ |
489 |
self basicAdd:aChild sortBlock:aBlock |
|
1488 | 490 |
]. |
1733 | 491 |
^ aChild |
1488 | 492 |
! |
493 |
||
1390 | 494 |
addAll:aList |
2927 | 495 |
"add children at the end" |
496 |
||
1390 | 497 |
^ self addAll:aList beforeIndex:(self children size + 1) |
498 |
! |
|
499 |
||
1650 | 500 |
addAll:aList before:aChild |
2927 | 501 |
"add an item before an existing item" |
502 |
||
1650 | 503 |
|index| |
504 |
||
2315 | 505 |
index := self identityIndexOf:aChild. |
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
506 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
2315 | 507 |
|
2927 | 508 |
^ self addAll:aList beforeIndex:index |
1650 | 509 |
! |
510 |
||
1390 | 511 |
addAll:aList beforeIndex:anIndex |
2927 | 512 |
"add children before an index" |
513 |
||
1733 | 514 |
aList size ~~ 0 ifTrue:[ |
515 |
self criticalDo:[ |
|
516 |
self basicAddAll:aList beforeIndex:anIndex |
|
517 |
] |
|
518 |
]. |
|
519 |
^ aList |
|
520 |
! |
|
521 |
||
522 |
addAll:aList sortBlock:aBlock |
|
2927 | 523 |
"add children sorted" |
524 |
||
2357 | 525 |
aList size == 0 ifTrue:[ ^ aList ]. |
526 |
||
527 |
aBlock isNil ifTrue:[ |
|
528 |
self addAll:aList. |
|
529 |
] ifFalse:[ |
|
530 |
self criticalDo:[ |
|
531 |
aList do:[:el| self basicAdd:el sortBlock:aBlock ] |
|
1733 | 532 |
] |
533 |
]. |
|
534 |
^ aList |
|
535 |
! |
|
536 |
||
537 |
addAllFirst:aCollectionOfItems |
|
2927 | 538 |
"add children at the beginning" |
539 |
||
1733 | 540 |
^ self addAll:aCollectionOfItems beforeIndex:1 |
541 |
! |
|
542 |
||
543 |
addAllLast:aCollectionOfItems |
|
2927 | 544 |
"add children at the end" |
545 |
||
1733 | 546 |
^ self addAll:aCollectionOfItems |
547 |
! |
|
548 |
||
549 |
addFirst:aChildItem |
|
2927 | 550 |
"add a child at the beginning" |
551 |
||
1733 | 552 |
^ self add:aChildItem beforeIndex:1. |
553 |
! |
|
554 |
||
555 |
addLast:anItem |
|
2927 | 556 |
"add a child at the end" |
557 |
||
1733 | 558 |
^ self add:anItem |
559 |
! |
|
560 |
||
1804 | 561 |
remove |
3911 | 562 |
"remove the item" |
563 |
||
1804 | 564 |
parent notNil ifTrue:[ "check whether parent exists" |
565 |
parent isHierarchicalItem ifTrue:[parent remove:self] "parent is HierarchicalItem" |
|
566 |
ifFalse:[parent root:nil] "parent is HierarchicalList" |
|
567 |
]. |
|
568 |
^ self |
|
569 |
! |
|
570 |
||
1733 | 571 |
remove:aChild |
3911 | 572 |
"remove a child" |
573 |
||
1733 | 574 |
self removeIndex:(self identityIndexOf:aChild) |
575 |
! |
|
576 |
||
577 |
removeAll |
|
3911 | 578 |
"remove all children" |
579 |
||
1733 | 580 |
|size| |
581 |
||
1942 | 582 |
(size := children size) ~~ 0 ifTrue:[ |
1733 | 583 |
self removeFromIndex:1 toIndex:size |
584 |
] |
|
585 |
! |
|
586 |
||
587 |
removeAll:aList |
|
3911 | 588 |
"remove all children in the collection" |
589 |
||
1733 | 590 |
|index| |
591 |
||
592 |
aList size ~~ 0 ifTrue:[ |
|
593 |
self criticalDo:[ |
|
594 |
aList do:[:el| |
|
595 |
(index := self identityIndexOf:el) ~~ 0 ifTrue:[ |
|
596 |
self removeIndex:index |
|
597 |
] |
|
598 |
] |
|
599 |
] |
|
600 |
]. |
|
601 |
^ aList |
|
602 |
! |
|
603 |
||
1899 | 604 |
removeFromIndex:startIndex |
3911 | 605 |
"remove the children from startIndex up to end of children" |
606 |
||
1899 | 607 |
^ self removeFromIndex:startIndex toIndex:(children size) |
608 |
! |
|
609 |
||
1733 | 610 |
removeFromIndex:startIndex toIndex:stopIndex |
611 |
"remove the children from startIndex up to and including |
|
3911 | 612 |
the child under stopIndex." |
613 |
||
2853
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
614 |
|nrOfChildren stop| |
1899 | 615 |
|
2853
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
616 |
nrOfChildren := children size. |
1899 | 617 |
|
2853
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
618 |
(startIndex <= stopIndex and:[startIndex <= nrOfChildren]) ifTrue:[ |
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
619 |
stop := stopIndex min:nrOfChildren. |
1899 | 620 |
|
621 |
self criticalDo:[ |
|
622 |
self basicRemoveFromIndex:startIndex toIndex:stop |
|
623 |
] |
|
1733 | 624 |
]. |
2853
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
625 |
|
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
626 |
children size == 0 ifTrue:[ |
2854
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
627 |
self clearExpandedWhenLastChildWasRemoved ifTrue:[ |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
628 |
isExpanded := false. |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
629 |
] |
2853
e852742cbd10
when the last child is removed,
Claus Gittinger <cg@exept.de>
parents:
2851
diff
changeset
|
630 |
]. |
1733 | 631 |
! |
632 |
||
633 |
removeIndex:anIndex |
|
3911 | 634 |
"remove the child at an index" |
635 |
||
1733 | 636 |
anIndex > 0 ifTrue:[ |
637 |
self removeFromIndex:anIndex toIndex:anIndex |
|
638 |
] |
|
639 |
! ! |
|
640 |
||
641 |
!HierarchicalItem methodsFor:'basic adding & removing'! |
|
642 |
||
643 |
basicAdd:aChild sortBlock:aBlock |
|
2927 | 644 |
"add a child sorted" |
645 |
||
2357 | 646 |
|size list| |
647 |
||
648 |
size := children size. |
|
649 |
list := Array with:aChild. |
|
650 |
||
651 |
(aBlock notNil and:[size ~~ 0]) ifTrue:[ |
|
652 |
children keysAndValuesDo:[:i :el| |
|
653 |
(aBlock value:aChild value:el) ifTrue:[ |
|
654 |
self basicAddAll:list beforeIndex:i. |
|
655 |
^ aChild |
|
1733 | 656 |
] |
657 |
] |
|
658 |
]. |
|
2357 | 659 |
self basicAddAll:list beforeIndex:(size + 1). |
660 |
^ aChild. |
|
1733 | 661 |
! |
662 |
||
663 |
basicAddAll:aList beforeIndex:anIndex |
|
2927 | 664 |
"add children before an index" |
665 |
||
1602 | 666 |
|coll model notify index size| |
1390 | 667 |
|
1942 | 668 |
size := children size. |
1390 | 669 |
|
670 |
anIndex == 1 ifTrue:[ |
|
671 |
notify := self |
|
672 |
] ifFalse:[ |
|
673 |
anIndex > size ifTrue:[ |
|
674 |
anIndex > (1 + size) ifTrue:[ |
|
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
675 |
^ self subscriptBoundsError:index |
1390 | 676 |
]. |
677 |
notify := self at:size |
|
678 |
] ifFalse:[ |
|
679 |
notify := nil |
|
680 |
] |
|
681 |
]. |
|
1669 | 682 |
children isArray ifTrue:[ |
683 |
children := children asOrderedCollection |
|
684 |
]. |
|
1390 | 685 |
|
686 |
size == 0 ifTrue:[ |
|
687 |
children := OrderedCollection new |
|
688 |
]. |
|
689 |
aList do:[:anItem| anItem parent:self ]. |
|
690 |
children addAll:aList beforeIndex:anIndex. |
|
691 |
||
692 |
(model := self model) isNil ifTrue:[ |
|
693 |
^ aList |
|
694 |
]. |
|
695 |
||
2547 | 696 |
isExpanded ifFalse:[ |
1390 | 697 |
notify notNil ifTrue:[ |
698 |
notify changed |
|
699 |
]. |
|
2547 | 700 |
^ aList |
1390 | 701 |
]. |
702 |
(index := self listIndex) isNil ifTrue:[ |
|
703 |
^ aList |
|
704 |
]. |
|
705 |
||
706 |
children from:1 to:(anIndex - 1) do:[:anItem| |
|
707 |
index := 1 + index + anItem numberOfVisibleChildren |
|
708 |
]. |
|
709 |
coll := OrderedCollection new. |
|
710 |
||
711 |
aList do:[:anItem| |
|
712 |
coll add:anItem. |
|
713 |
anItem addVisibleChildrenTo:coll. |
|
714 |
]. |
|
715 |
model itemAddAll:coll beforeIndex:(index + 1). |
|
716 |
||
717 |
notify notNil ifTrue:[ |
|
718 |
notify changed |
|
719 |
]. |
|
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
720 |
^ aList |
1390 | 721 |
! |
722 |
||
1733 | 723 |
basicRemoveFromIndex:startIndex toIndex:stopIndex |
1390 | 724 |
"remove the children from startIndex up to and including |
2927 | 725 |
the child under stopIndex." |
726 |
||
1390 | 727 |
|model notify |
728 |
index "{ Class:SmallInteger }" |
|
729 |
start "{ Class:SmallInteger }" |
|
730 |
stop "{ Class:SmallInteger }" |
|
731 |
size "{ Class:SmallInteger }" |
|
732 |
| |
|
733 |
size := self children size. |
|
734 |
stop := stopIndex. |
|
735 |
start := startIndex. |
|
736 |
||
737 |
(stop <= size and:[start between:1 and:stop]) ifFalse:[ |
|
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
738 |
^ self subscriptBoundsError:index |
1390 | 739 |
]. |
740 |
start == 1 ifTrue:[ |
|
741 |
notify := self |
|
742 |
] ifFalse:[ |
|
743 |
stop == size ifTrue:[ |
|
744 |
notify := self at:(start - 1) |
|
745 |
] ifFalse:[ |
|
746 |
notify := nil |
|
747 |
] |
|
748 |
]. |
|
749 |
||
750 |
(model := self model) notNil ifTrue:[ |
|
751 |
index := model identityIndexOf:(children at:start). |
|
752 |
size := stop - start + 1. |
|
753 |
] ifFalse:[ |
|
754 |
index := 0 |
|
755 |
]. |
|
1669 | 756 |
|
1390 | 757 |
children from:start to:stop do:[:aChild| |
758 |
index ~~ 0 ifTrue:[ |
|
759 |
size := size + aChild numberOfVisibleChildren |
|
760 |
]. |
|
761 |
aChild parent:nil |
|
762 |
]. |
|
763 |
children removeFromIndex:start toIndex:stop. |
|
764 |
||
765 |
index ~~ 0 ifTrue:[ |
|
766 |
model itemRemoveFromIndex:index toIndex:(index + size - 1) |
|
767 |
]. |
|
768 |
notify notNil ifTrue:[ |
|
769 |
notify changed |
|
770 |
]. |
|
771 |
! ! |
|
772 |
||
773 |
!HierarchicalItem methodsFor:'change & update'! |
|
774 |
||
1606 | 775 |
changed:what with:anArgument |
1390 | 776 |
"the item changed; raise change notification |
2854
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
777 |
#icon icon is modified; height and width are unchanged |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
778 |
#hierarchy collapsed/expanded; height and width are unchanged |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
779 |
#redraw redraw but height and width are unchanged |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
780 |
....... all others: the height and width are reset |
1390 | 781 |
" |
1974 | 782 |
|model why| |
1390 | 783 |
|
1974 | 784 |
what ~~ #redraw ifTrue:[ |
785 |
(what ~~ #hierarchy and:[what ~~ #icon]) ifTrue:[ |
|
2081 | 786 |
self class doResetExtentOnChange ifTrue:[ |
787 |
width := height := nil |
|
788 |
]. |
|
1974 | 789 |
]. |
790 |
why := what |
|
2230 | 791 |
] ifFalse:[ |
792 |
why := #redraw |
|
1606 | 793 |
]. |
794 |
(model := self model) notNil ifTrue:[ |
|
1974 | 795 |
model itemChanged:why with:anArgument from:self |
1390 | 796 |
]. |
1974 | 797 |
super changed:why with:anArgument |
1390 | 798 |
! |
799 |
||
2193
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
800 |
childrenOrderChanged |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
801 |
"called if the order of the children changed by a user |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
802 |
operation. Update the model and raise a change notification for |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
803 |
each item which has changed its position |
2927 | 804 |
triggered by the user operation !!" |
805 |
||
2193
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
806 |
|model visStart list| |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
807 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
808 |
self isExpanded ifFalse:[ ^ self ]. "/ not expanded |
2206 | 809 |
children size > 1 ifFalse:[ ^ self ]. |
2193
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
810 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
811 |
model := self model. |
3166 | 812 |
model isNil ifTrue:[^ self]. "/ no model |
2193
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
813 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
814 |
visStart := model identityIndexOf:self. |
2260 | 815 |
visStart == 0 ifTrue:[ |
2305 | 816 |
model root ~~ self ifTrue:[ ^ self ]. |
817 |
"/ I'am the root but switched of by setting #showRoot to false |
|
2260 | 818 |
]. |
2193
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
819 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
820 |
self criticalDo:[ |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
821 |
list := OrderedCollection new. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
822 |
self addVisibleChildrenTo:list. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
823 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
824 |
list do:[:el| |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
825 |
visStart := visStart + 1. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
826 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
827 |
(model at:visStart ifAbsent:el) ~~ el ifTrue:[ |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
828 |
model at:visStart put:el |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
829 |
]. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
830 |
] |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
831 |
]. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
832 |
! |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
833 |
|
1843 | 834 |
fontChanged |
3849
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
835 |
"called if the font has changed. |
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
836 |
Clear the precomputed width and height" |
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
837 |
|
1843 | 838 |
width := height := nil. |
839 |
||
840 |
children size ~~ 0 ifTrue:[ |
|
3849
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
841 |
children do:[:el| el fontChanged]. |
1843 | 842 |
]. |
843 |
! |
|
844 |
||
1390 | 845 |
hierarchyChanged |
3912 | 846 |
"hierarchy changed; optimize redrawing" |
847 |
||
1390 | 848 |
self changed:#hierarchy with:nil |
849 |
! |
|
850 |
||
851 |
iconChanged |
|
3912 | 852 |
"icon changed; optimize redrawing" |
853 |
||
1390 | 854 |
self changed:#icon with:nil |
855 |
! ! |
|
856 |
||
857 |
!HierarchicalItem methodsFor:'enumerating'! |
|
858 |
||
1804 | 859 |
collect:aBlock |
860 |
"for each child in the receiver, evaluate the argument, aBlock |
|
2927 | 861 |
and return a new collection with the results" |
862 |
||
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
863 |
|coll| |
1804 | 864 |
|
2081 | 865 |
coll := OrderedCollection new. |
866 |
self do:[:el| coll add:(aBlock value:el) ]. |
|
2927 | 867 |
^ coll |
1804 | 868 |
! |
869 |
||
2465 | 870 |
contains:aBlock |
871 |
"return true if aBlock returns true for any of the receivers items" |
|
872 |
||
873 |
self do:[:el | (aBlock value:el) ifTrue:[^ true] ]. |
|
874 |
^ false |
|
875 |
! |
|
876 |
||
1390 | 877 |
do:aOneArgBlock |
2879 | 878 |
"evaluate a block for each child" |
879 |
||
3882 | 880 |
^ self from:1 to:nil do:aOneArgBlock |
1390 | 881 |
! |
882 |
||
883 |
from:startIndex do:aOneArgBlock |
|
884 |
"evaluate a block on each child starting with the |
|
885 |
child at startIndex to the end. |
|
886 |
" |
|
2117 | 887 |
^ self from:startIndex to:nil do:aOneArgBlock |
2081 | 888 |
! |
889 |
||
890 |
from:startIndex reverseDo:aOneArgBlock |
|
891 |
"evaluate a block on each child starting at end to the startIndex |
|
892 |
" |
|
2117 | 893 |
^ self from:startIndex to:nil reverseDo:aOneArgBlock |
1390 | 894 |
! |
895 |
||
896 |
from:startIndex to:endIndex do:aOneArgBlock |
|
897 |
"evaluate a block on each child starting with the |
|
898 |
child at startIndex to the endIndex. |
|
899 |
" |
|
2081 | 900 |
|res| |
901 |
||
902 |
self size < startIndex ifTrue:[^ nil]. |
|
903 |
res := nil. |
|
904 |
||
905 |
self criticalDo:[ |
|
2117 | 906 |
res := self nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
907 |
]. |
2081 | 908 |
^ res |
1390 | 909 |
! |
910 |
||
911 |
from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
912 |
"evaluate a block on each child starting with the |
|
3912 | 913 |
child at endIndex to the startIndex." |
914 |
||
2081 | 915 |
|res| |
916 |
||
917 |
self size < startIndex ifTrue:[^ nil]. |
|
918 |
res := nil. |
|
919 |
||
920 |
self criticalDo:[ |
|
2117 | 921 |
res := self nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
922 |
]. |
2081 | 923 |
^ res |
1390 | 924 |
! |
925 |
||
1966 | 926 |
keysAndValuesDo:aTwoArgBlock |
927 |
"evaluate the argument, aBlock for every child, |
|
3912 | 928 |
passing both index and element as arguments." |
929 |
||
2081 | 930 |
|key res| |
1966 | 931 |
|
2081 | 932 |
key := 1. |
933 |
res := nil. |
|
934 |
||
935 |
self do:[:el| |
|
936 |
res := el value:key value:el. |
|
937 |
key := key + 1. |
|
1966 | 938 |
]. |
2081 | 939 |
^ res |
1966 | 940 |
! |
941 |
||
942 |
keysAndValuesReverseDo:aTwoArgBlock |
|
943 |
"evaluate the argument, aBlock in reverse order for every |
|
3912 | 944 |
child, passing both index and element as arguments." |
945 |
||
2081 | 946 |
|res| |
1966 | 947 |
|
2081 | 948 |
self size == 0 ifTrue:[^ nil]. |
949 |
res := nil. |
|
950 |
||
951 |
self criticalDo:[ |
|
2117 | 952 |
res := self nonCriticalKeysAndValuesReverseDo:aTwoArgBlock |
1966 | 953 |
]. |
2081 | 954 |
^ res |
1966 | 955 |
! |
956 |
||
1804 | 957 |
recursiveCollect:aBlock |
958 |
"for each child in the receiver, evaluate the argument, aBlock |
|
3911 | 959 |
and return a new collection with the results" |
960 |
||
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
961 |
|coll| |
1804 | 962 |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
963 |
coll := OrderedCollection new. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
964 |
self recursiveDo:[:el| coll add:(aBlock value:el) ]. |
3911 | 965 |
^ coll |
1804 | 966 |
! |
967 |
||
1390 | 968 |
recursiveDo:aOneArgBlock |
3911 | 969 |
"evaluate a block on each item and all the sub-items" |
970 |
||
1390 | 971 |
self do:[:aChild| |
972 |
aOneArgBlock value:aChild. |
|
2117 | 973 |
aChild nonCriticalRecursiveDo:aOneArgBlock |
1390 | 974 |
]. |
975 |
! |
|
976 |
||
1804 | 977 |
recursiveReverseDo:aOneArgBlock |
978 |
"evaluate a block on each item and all the sub-items; |
|
3911 | 979 |
proccesing children in reverse direction" |
980 |
||
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
981 |
self reverseDo:[:aChild| |
2117 | 982 |
aChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
983 |
aOneArgBlock value:aChild. |
1804 | 984 |
]. |
985 |
! |
|
986 |
||
987 |
recursiveSelect:aBlock |
|
988 |
"return a new collection with all children and subChildren from the receiver, for which |
|
3911 | 989 |
the argument aBlock evaluates to true." |
990 |
||
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
991 |
|coll| |
1804 | 992 |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
993 |
coll := OrderedCollection new. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
994 |
self recursiveDo:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
3911 | 995 |
^ coll |
1804 | 996 |
! |
997 |
||
1390 | 998 |
reverseDo:aOneArgBlock |
3911 | 999 |
"evaluate a block on each child in reverse direction" |
1000 |
||
2081 | 1001 |
^ self from:1 reverseDo:aOneArgBlock |
1804 | 1002 |
! |
1003 |
||
1004 |
select:aBlock |
|
2081 | 1005 |
"return a new collection with all items from the receiver, for which |
3911 | 1006 |
the argument aBlock evaluates to true." |
1007 |
||
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1008 |
|coll| |
1831
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1009 |
|
2081 | 1010 |
coll := OrderedCollection new. |
1011 |
self do:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
|
3911 | 1012 |
^ coll |
1876 | 1013 |
! |
1014 |
||
1015 |
withAllDo:aOneArgBlock |
|
3911 | 1016 |
"evaluate the block on each item and subitem including self" |
1017 |
||
2081 | 1018 |
aOneArgBlock value:self. |
1019 |
||
1020 |
self do:[:el| |
|
1021 |
aOneArgBlock value:el. |
|
2117 | 1022 |
el nonCriticalRecursiveDo:aOneArgBlock. |
1883 | 1023 |
]. |
1024 |
! ! |
|
1804 | 1025 |
|
1026 |
!HierarchicalItem methodsFor:'enumerating parents'! |
|
1027 |
||
1028 |
parentsDetect:aBlock |
|
1029 |
"find the first parent, for which evaluation of the block returns |
|
3912 | 1030 |
true; if none does so, report an error" |
1031 |
||
1804 | 1032 |
^ self parentsDetect:aBlock ifNone:[self errorNotFound] |
1033 |
! |
|
1034 |
||
1035 |
parentsDetect:aBlock ifNone:anExceptionBlock |
|
1036 |
"find the first parent, for which evaluation of the block returns |
|
3912 | 1037 |
true; if none does so, return the evaluation of anExceptionBlock" |
1038 |
||
1804 | 1039 |
|prnt| |
1040 |
||
1041 |
prnt := self. |
|
1042 |
||
1043 |
self criticalDo:[ |
|
1044 |
[(prnt := prnt parent) notNil and:[prnt isHierarchicalItem]] whileTrue:[ |
|
1045 |
(aBlock value:prnt) ifTrue:[^ prnt] |
|
1046 |
] |
|
1047 |
]. |
|
1048 |
^ anExceptionBlock value |
|
1049 |
! |
|
1050 |
||
1051 |
parentsDo:aBlock |
|
3912 | 1052 |
"evaluate a block for each parent" |
1053 |
||
1804 | 1054 |
|prnt| |
1055 |
||
1056 |
prnt := self. |
|
1057 |
||
1058 |
self criticalDo:[ |
|
1059 |
[(prnt := prnt parent) notNil and:[prnt isHierarchicalItem]] whileTrue:[ |
|
1060 |
aBlock value:prnt |
|
1061 |
] |
|
1062 |
]. |
|
1390 | 1063 |
! ! |
1064 |
||
1065 |
!HierarchicalItem methodsFor:'initialization'! |
|
1066 |
||
1067 |
initialize |
|
1068 |
isExpanded := false |
|
1069 |
! ! |
|
1070 |
||
1071 |
!HierarchicalItem methodsFor:'private'! |
|
1072 |
||
1073 |
addVisibleChildrenTo:aList |
|
2547 | 1074 |
"add all visible children and sub-children to the list" |
1075 |
||
1076 |
isExpanded ifFalse:[^ self]. |
|
1390 | 1077 |
|
2117 | 1078 |
self nonCriticalFrom:1 to:nil do:[:el| |
2081 | 1079 |
aList add:el. |
1080 |
el addVisibleChildrenTo:aList. |
|
1081 |
]. |
|
1390 | 1082 |
! |
1083 |
||
2854
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
1084 |
clearExpandedWhenLastChildWasRemoved |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
1085 |
^ true |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
1086 |
! |
20b890ba0f6c
allow subclasses to define the collapse-behavior
Claus Gittinger <cg@exept.de>
parents:
2853
diff
changeset
|
1087 |
|
1733 | 1088 |
criticalDo:aBlock |
1089 |
|model| |
|
1090 |
||
1091 |
(model := self model) notNil ifTrue:[ |
|
1092 |
model recursionLock critical:aBlock |
|
1093 |
] ifFalse:[ |
|
1094 |
aBlock value |
|
1095 |
] |
|
1096 |
! |
|
1097 |
||
1390 | 1098 |
listIndex |
3912 | 1099 |
"returns the visible index or nil; for a non-visible root, 0 is returned" |
1100 |
||
1390 | 1101 |
|index model| |
1102 |
||
1103 |
(model := self model) notNil ifTrue:[ |
|
1104 |
index := model identityIndexOf:self. |
|
1105 |
||
1106 |
(index ~~ 0 or:[parent == model]) ifTrue:[ |
|
1107 |
^ index |
|
1108 |
] |
|
1109 |
]. |
|
1110 |
^ nil |
|
1111 |
! |
|
1112 |
||
1113 |
numberOfVisibleChildren |
|
2547 | 1114 |
"returns number of all visible children including subchildren" |
1115 |
||
2081 | 1116 |
|size| |
1117 |
||
2547 | 1118 |
isExpanded ifFalse:[^ 0]. |
2081 | 1119 |
size := 0. |
1120 |
||
2117 | 1121 |
self nonCriticalFrom:1 to:nil do:[:el| |
2081 | 1122 |
size := 1 + size + el numberOfVisibleChildren |
1390 | 1123 |
]. |
2081 | 1124 |
^ size |
1390 | 1125 |
! |
1126 |
||
1127 |
parentOrModel |
|
3912 | 1128 |
"returns the parent without checking for item or model" |
1129 |
||
1390 | 1130 |
^ parent |
1131 |
! |
|
1132 |
||
1133 |
setExpanded:aBoolean |
|
2547 | 1134 |
"set expanded flag without any computation or notification" |
1135 |
||
1390 | 1136 |
isExpanded := aBoolean |
1137 |
! ! |
|
1138 |
||
2493 | 1139 |
!HierarchicalItem methodsFor:'private-displaying'! |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1140 |
|
1606 | 1141 |
displayLabel:aLabel h:lH on:aGC x:x y:y h:h |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1142 |
"display the label at x@y |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1143 |
" |
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
1144 |
|y0| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1145 |
|
1606 | 1146 |
lH ~~ 0 ifTrue:[ |
1147 |
y0 := y - (lH + 1 - h // 2). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1148 |
|
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
1149 |
y0 := y0 + (aLabel ascentOn:aGC). |
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
1150 |
(aLabel isString not |
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
1151 |
or:[(aLabel includes:(Character cr)) not]) ifTrue:[ |
1606 | 1152 |
^ aLabel displayOn:aGC x:x y:y0 |
1153 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1154 |
|
1606 | 1155 |
aLabel asCollectionOfLines do:[:el| |
1156 |
el displayOn:aGC x:x y:y0. |
|
2484
92f9e42980ab
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
2476
diff
changeset
|
1157 |
y0 := y0 + (el heightOn:aGC) |
1606 | 1158 |
] |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1159 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1160 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1161 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1162 |
heightOf:aLabel on:aGC |
3912 | 1163 |
"returns the height of the label or 0" |
1164 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1165 |
|h| |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1166 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1167 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1168 |
^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1169 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1170 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1171 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1172 |
h := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1173 |
aLabel do:[:el|h := h max:(self heightOf:el on:aGC)]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1174 |
^ h |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1175 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1176 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1177 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1178 |
^ h * (aGC font height) |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1179 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1180 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1181 |
widthOf:aLabel on:aGC |
3911 | 1182 |
"returns the height of the label or 0" |
1183 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1184 |
|w| |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1185 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1186 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1187 |
^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1188 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1189 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1190 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1191 |
w := -5. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1192 |
aLabel do:[:el|w := w + 5 + (self widthOf:el on:aGC)]. |
3911 | 1193 |
^ w |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1194 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1195 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1196 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1197 |
^ aLabel widthOn:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1198 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1199 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1200 |
w := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1201 |
aLabel asCollectionOfLines do:[:el|w := w max:(el widthOn:aGC)]. |
3911 | 1202 |
^ w |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1203 |
! ! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1204 |
|
2493 | 1205 |
!HierarchicalItem methodsFor:'private-enumerating'! |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1206 |
|
2117 | 1207 |
nonCriticalDo:aOneArgBlock |
3912 | 1208 |
"evaluate a block noncritical for each child." |
1209 |
||
2117 | 1210 |
^ self nonCriticalFrom:1 to:nil do:aOneArgBlock |
1211 |
! |
|
1212 |
||
1213 |
nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
3912 | 1214 |
"evaluate a block noncritical for each child starting with the |
1215 |
child at startIndex to the endIndex (if nil to end of list)." |
|
1216 |
||
2081 | 1217 |
|list size resp| |
1218 |
||
1219 |
list := self children. |
|
1220 |
size := list size. |
|
1221 |
||
1222 |
startIndex > size ifTrue:[^ nil]. |
|
1223 |
resp := nil. |
|
1224 |
||
1225 |
endIndex notNil ifTrue:[ |
|
1226 |
size := size min:endIndex |
|
1227 |
]. |
|
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1228 |
startIndex to:size do:[:i| |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1229 |
|item| |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1230 |
|
2081 | 1231 |
item := list at:i ifAbsent:nil. |
1232 |
item isNil ifTrue:[^ resp]. |
|
1233 |
resp := aOneArgBlock value:item. |
|
1234 |
]. |
|
1235 |
^ resp |
|
1236 |
! |
|
1237 |
||
2117 | 1238 |
nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
3912 | 1239 |
"evaluate a block non critical for each child starting with the |
1240 |
child at endIndex (if nil to end of list) to startIndex." |
|
1241 |
||
2081 | 1242 |
|list size resp| |
1243 |
||
1244 |
list := self children. |
|
1245 |
size := list size. |
|
1246 |
resp := nil. |
|
1247 |
||
1248 |
endIndex notNil ifTrue:[ |
|
1249 |
size := size min:endIndex |
|
1250 |
]. |
|
3912 | 1251 |
size to:startIndex by:-1 do:[:i| |
1252 |
|item| |
|
1253 |
||
2081 | 1254 |
item := list at:i ifAbsent:nil. |
1255 |
item isNil ifTrue:[^ resp]. |
|
1256 |
resp := aOneArgBlock value:item. |
|
1257 |
]. |
|
1258 |
^ resp |
|
1259 |
! |
|
1260 |
||
2117 | 1261 |
nonCriticalKeysAndValuesReverseDo:aOneArgBlock |
2081 | 1262 |
"evaluate the argument, aBlock in reverse order for every |
3912 | 1263 |
child, passing both index and element as arguments." |
1264 |
||
2081 | 1265 |
|list size resp| |
1266 |
||
1267 |
list := self children. |
|
1268 |
size := list size. |
|
1269 |
resp := nil. |
|
1270 |
||
3912 | 1271 |
size to:1 by:-1 do:[:i| |
1272 |
|item| |
|
1273 |
||
2081 | 1274 |
item := list at:i ifAbsent:nil. |
1275 |
item isNil ifTrue:[^ resp]. |
|
1276 |
resp := aOneArgBlock value:i value:item. |
|
1277 |
]. |
|
1278 |
^ resp |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1279 |
! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1280 |
|
3912 | 1281 |
nonCriticalRecursiveDo:aOneArgBlock |
1282 |
"evaluate the block non critical for each item and all the sub-items" |
|
1283 |
||
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1284 |
self nonCriticalFrom:1 to:nil do:[:eachChild| |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1285 |
aOneArgBlock value:eachChild. |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1286 |
eachChild nonCriticalRecursiveDo:aOneArgBlock |
3912 | 1287 |
]. |
1288 |
! |
|
1289 |
||
1290 |
nonCriticalRecursiveReverseDo:aOneArgBlock |
|
1291 |
"evaluate the block non critical for each item and all the sub-items; |
|
1292 |
proccesing children in reverse direction" |
|
1293 |
||
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1294 |
self nonCriticalFrom:1 to:nil reverseDo:[:eachChild| |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1295 |
eachChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1296 |
aOneArgBlock value:eachChild. |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1297 |
]. |
2294 | 1298 |
! |
1299 |
||
1300 |
nonCriticalRecursiveSort:aSortBlock |
|
3912 | 1301 |
"evaluate a block noncritical for each child." |
1302 |
||
2294 | 1303 |
|unsorted sorted| |
1304 |
||
1305 |
unsorted := children. |
|
1306 |
||
1307 |
unsorted size ~~ 0 ifTrue:[ |
|
1308 |
sorted := unsorted sort:aSortBlock. |
|
1309 |
sorted do:[:el| el nonCriticalRecursiveSort:aSortBlock ]. |
|
1310 |
children := sorted. |
|
1311 |
]. |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1312 |
! ! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1313 |
|
2493 | 1314 |
!HierarchicalItem methodsFor:'private-hierarchy'! |
1390 | 1315 |
|
1316 |
recursiveSetCollapsed |
|
2547 | 1317 |
"collapse all children and sub-children without notifications" |
1318 |
||
3882 | 1319 |
self criticalDo:[ |
1320 |
self recursiveSetCollapsedHelper |
|
1321 |
] |
|
1322 |
! |
|
1323 |
||
1324 |
recursiveSetCollapsedHelper |
|
1325 |
"private helper. |
|
1326 |
collapse all children and sub-children without notifications. |
|
1327 |
Helper only - does not lock" |
|
1328 |
||
1390 | 1329 |
isExpanded := false. |
1330 |
||
2547 | 1331 |
"/ do not call #size: children will be autoloaded !!!! |
2081 | 1332 |
children size ~~ 0 ifTrue:[ |
3882 | 1333 |
self nonCriticalFrom:1 to:nil do:[:eachChild| |
1334 |
eachChild canRecursiveCollapse ifTrue:[ |
|
1335 |
eachChild recursiveSetCollapsedHelper |
|
1336 |
] |
|
1337 |
]. |
|
1390 | 1338 |
] |
1339 |
! |
|
1340 |
||
1341 |
recursiveSetExpandedAndAddToList:aList |
|
1342 |
"expand all children and sub-children without notifications; |
|
2547 | 1343 |
add children to list" |
1344 |
||
3882 | 1345 |
self criticalDo:[ |
1346 |
self recursiveSetExpandedAndAddToListHelper:aList |
|
1347 |
]. |
|
1348 |
! |
|
1349 |
||
1350 |
recursiveSetExpandedAndAddToListHelper:aList |
|
1351 |
"private helper. |
|
1352 |
expand all children and sub-children without notifications; adds children to aList |
|
1353 |
Helper only - does not lock" |
|
1354 |
||
1390 | 1355 |
isExpanded := true. |
1356 |
||
3882 | 1357 |
self nonCriticalFrom:1 to:nil do:[:eachChild| |
2601 | 1358 |
aList add:eachChild. |
1359 |
||
2547 | 1360 |
eachChild canRecursiveExpand ifTrue:[ |
3882 | 1361 |
eachChild recursiveSetExpandedAndAddToListHelper:aList. |
2547 | 1362 |
]. |
2081 | 1363 |
]. |
1390 | 1364 |
! ! |
1365 |
||
2851 | 1366 |
!HierarchicalItem methodsFor:'protocol-accessing'! |
1390 | 1367 |
|
1368 |
children |
|
3914 | 1369 |
"returns a list of children. When first asked, the list is fetched, if it was |
1370 |
built lazyly. |
|
1371 |
*** to optimize: either redefine this or fetchChildren by subClass" |
|
1372 |
||
1373 |
children isNil ifTrue:[ |
|
1374 |
self fetchChildren |
|
1375 |
]. |
|
1376 |
^ children |
|
1377 |
! |
|
1378 |
||
1379 |
fetchChildren |
|
1380 |
"should compute the list of children via the model. |
|
1381 |
Be aware, that the somewhat stupid 'optimization' of how the model is fetched may lead to |
|
3915
f3ec0f55b790
comment/format in: #fetchChildren
Claus Gittinger <cg@exept.de>
parents:
3914
diff
changeset
|
1382 |
a O(n*log n) or even O(n^2) behavior here. |
3914 | 1383 |
Should side-effect-update the list of children. |
2927 | 1384 |
*** to optimize: redefine by subClass" |
1385 |
||
1390 | 1386 |
|model| |
1387 |
||
3914 | 1388 |
(model := self model) notNil ifTrue:[ |
1389 |
children := model childrenFor:self |
|
1390 | 1390 |
]. |
1391 |
^ children |
|
1392 |
! |
|
1393 |
||
1394 |
icon |
|
1395 |
"returns the icon or nil; |
|
3912 | 1396 |
*** to optimize:redefine by subClass" |
1397 |
||
1390 | 1398 |
|model| |
1399 |
||
1400 |
(model := self model) notNil ifTrue:[ |
|
1401 |
^ model iconFor:self |
|
1402 |
]. |
|
1403 |
^ nil |
|
1404 |
! |
|
1405 |
||
1406 |
label |
|
1407 |
"returns the label displayed on aGC; |
|
3912 | 1408 |
*** to optimize:redefine by subClass" |
1409 |
||
1390 | 1410 |
|model| |
1411 |
||
1412 |
(model := self model) notNil ifTrue:[ |
|
1413 |
^ model labelFor:self |
|
1414 |
]. |
|
1415 |
^ nil |
|
1416 |
! |
|
1417 |
||
1418 |
middleButtonMenu |
|
2602 | 1419 |
"returns the items middleButtonMenu or nil if no menu is defined. |
3912 | 1420 |
If nil is returned, the view is asked for a menu." |
1421 |
||
3337 | 1422 |
<resource: #programMenu> |
1423 |
||
1390 | 1424 |
|model| |
1425 |
||
1426 |
(model := self model) notNil ifTrue:[ |
|
1427 |
^ model middleButtonMenuFor:self |
|
1428 |
]. |
|
1429 |
^ nil |
|
1831
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1430 |
! |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1431 |
|
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1432 |
recursiveSortChildren:aSortBlock |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1433 |
|children| |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1434 |
|
2832 | 1435 |
(children := self children) notEmptyOrNil ifTrue:[ |
1831
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1436 |
self criticalDo:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1437 |
children sort:aSortBlock. |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1438 |
children do:[:aChild| aChild recursiveSortChildren:aSortBlock ] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1439 |
] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1440 |
]. |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1441 |
! |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1442 |
|
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1443 |
sortChildren:aSortBlock |
2708 | 1444 |
"sort the children inplace using the 2-arg block sortBlock for comparison" |
1445 |
||
1446 |
<resource: #obsolete> |
|
1447 |
self obsoleteMethodWarning:'use #sort:'. |
|
2252 | 1448 |
self sort:aSortBlock. |
1390 | 1449 |
! ! |
1450 |
||
2851 | 1451 |
!HierarchicalItem methodsFor:'protocol-displaying'! |
1390 | 1452 |
|
3615 | 1453 |
displayIcon:anIcon atX:x y:y on:aGC |
1454 |
"called to draw the icon - canbe redefined to manupulate the icon" |
|
1455 |
||
1456 |
anIcon displayOn:aGC x:x y:y. |
|
1457 |
! |
|
1458 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1489
diff
changeset
|
1459 |
displayOn:aGC x:x y:y h:h |
1390 | 1460 |
"draw the receiver in the graphicsContext, aGC. |
1461 |
" |
|
1462 |
|label |
|
1398 | 1463 |
x0 "{ Class:SmallInteger }" |
1390 | 1464 |
| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1465 |
(label := self label) isNil ifTrue:[^ self]. |
1398 | 1466 |
|
1467 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1606 | 1468 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h |
1398 | 1469 |
]. |
1470 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1471 |
x0 := x. |
1398 | 1472 |
label do:[:el| |
1473 |
el notNil ifTrue:[ |
|
1606 | 1474 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h. |
1398 | 1475 |
x0 := x0 + 5 + (el widthOn:aGC). |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1476 |
]. |
1390 | 1477 |
] |
1478 |
! |
|
1479 |
||
1480 |
heightOn:aGC |
|
3912 | 1481 |
"return the width of the receiver, if it is to be displayed on aGC" |
1482 |
||
1606 | 1483 |
height isNil ifTrue:[ |
1484 |
height := self heightOf:(self label) on:aGC |
|
1485 |
]. |
|
1486 |
^ height |
|
1390 | 1487 |
! |
1488 |
||
1489 |
widthOn:aGC |
|
3911 | 1490 |
"return the width of the receiver, if it is to be displayed on aGC" |
1491 |
||
1606 | 1492 |
width isNil ifTrue:[ |
1493 |
width := self widthOf:(self label) on:aGC |
|
1494 |
]. |
|
1495 |
^ width |
|
1390 | 1496 |
! ! |
1497 |
||
2851 | 1498 |
!HierarchicalItem methodsFor:'protocol-event processing'! |
2313 | 1499 |
|
1500 |
processButtonPress:button x:x y:y |
|
1501 |
"a mouse button was pressed in my label. |
|
2519 | 1502 |
Return true, if the event is eaten (ignored by the gc). |
3912 | 1503 |
By default, false is returned (should be handled by the gc)." |
1504 |
||
2519 | 1505 |
^ false |
1506 |
! |
|
1507 |
||
1508 |
processButtonPress:button x:x y:y on:aGC |
|
1509 |
"a mouse button was pressed in my label. |
|
1510 |
Return true, if the event is eaten (ignored by the gc). |
|
3912 | 1511 |
By default, false is returned (should be handled by the gc)." |
1512 |
||
2519 | 1513 |
^ self processButtonPress:button x:x y:y |
1514 |
! |
|
1515 |
||
1516 |
processButtonPressOnIcon:button on:aGC |
|
1517 |
"a mouse button was pressed in my icon. |
|
1518 |
Return true, if the event is eaten (ignored by the gc). |
|
3912 | 1519 |
By default, false is returned (should be handled by the gc)." |
1520 |
||
2313 | 1521 |
^ false |
1522 |
! ! |
|
1523 |
||
2851 | 1524 |
!HierarchicalItem methodsFor:'protocol-monitoring'! |
1390 | 1525 |
|
1526 |
monitoringCycle |
|
3912 | 1527 |
"called every 'n' seconds by the model, if the monitoring |
1390 | 1528 |
cycle is enabled. The item can perform some checks, .. |
1529 |
**** can be redefined by subclass to perform some actions |
|
1530 |
" |
|
1531 |
! ! |
|
1532 |
||
2851 | 1533 |
!HierarchicalItem methodsFor:'protocol-queries'! |
1390 | 1534 |
|
2305 | 1535 |
canCollapse |
1536 |
"called before collapsing the item; can be redefined |
|
2547 | 1537 |
by subclass to omit the collapse operation" |
1538 |
||
1539 |
^ isExpanded |
|
2305 | 1540 |
! |
1541 |
||
1542 |
canExpand |
|
1543 |
"called before expanding the item; can be redefined |
|
2549 | 1544 |
by subclass to omit the expand operation" |
2547 | 1545 |
|
2549 | 1546 |
^ self hasChildren |
2547 | 1547 |
! |
1548 |
||
1549 |
canRecursiveCollapse |
|
1550 |
"called before collapsing the item; can be redefined |
|
1551 |
by subclass to omit the collapse operation " |
|
1552 |
||
1553 |
^ self canCollapse |
|
1554 |
! |
|
1555 |
||
1556 |
canRecursiveExpand |
|
1557 |
"called before expanding the item; can be redefined |
|
1558 |
by subclass to omit the collapse operation" |
|
1559 |
||
1560 |
^ self canExpand |
|
2305 | 1561 |
! |
1562 |
||
1571 | 1563 |
drawHorizontalLineUpToText |
1564 |
"draw the horizizontal line for the selected item up to the text |
|
1565 |
or on default to the start of the the vertical line; only used by |
|
1566 |
the hierarchical view |
|
1567 |
" |
|
1568 |
^ false |
|
1569 |
! |
|
1570 |
||
1390 | 1571 |
hasChildren |
2851 | 1572 |
"checks whether the item has children; |
1573 |
the list needs not to be loaded yet( example. FileDirectory ). |
|
3912 | 1574 |
*** to optimize: redefine in subClass" |
1575 |
||
2081 | 1576 |
^ self children size ~~ 0 |
1390 | 1577 |
! |
1578 |
||
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1579 |
hasIndicator |
3912 | 1580 |
"on default the indicator is drawn if the item has children" |
1581 |
||
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1582 |
^ self hasChildren |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1583 |
! |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1584 |
|
2305 | 1585 |
isSelectable |
3912 | 1586 |
"returns true if the item is selectable" |
1587 |
||
2305 | 1588 |
^ true |
1589 |
! |
|
1590 |
||
1390 | 1591 |
string |
3913
9b59aafa16d2
comment/format in:59 methods
Claus Gittinger <cg@exept.de>
parents:
3912
diff
changeset
|
1592 |
"access the printable string used for stepping through a list |
1390 | 1593 |
searching for an entry starting with a character. |
3911 | 1594 |
*** to optimize:redefine by subClass" |
1595 |
||
1398 | 1596 |
|label| |
1597 |
||
1598 |
(label := self label) notNil ifTrue:[ |
|
1599 |
label isString ifTrue:[ ^ label string ]. |
|
1600 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
1601 |
||
1602 |
label isSequenceable ifFalse:[ |
|
1603 |
^ label perform:#string ifNotUnderstood:nil |
|
1604 |
]. |
|
1605 |
||
1606 |
label do:[:el||s| |
|
1607 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
1608 |
s := el perform:#string ifNotUnderstood:nil. |
|
1609 |
s notNil ifTrue:[^ s]. |
|
1610 |
] |
|
1611 |
] |
|
1612 |
]. |
|
1613 |
^ nil |
|
1390 | 1614 |
! ! |
1615 |
||
1616 |
!HierarchicalItem methodsFor:'queries'! |
|
1617 |
||
1804 | 1618 |
isChildOf:anItem |
3912 | 1619 |
"returns true if the item is a child of anItem" |
1620 |
||
1804 | 1621 |
|item| |
1622 |
||
1623 |
item := self. |
|
1624 |
||
1625 |
[anItem ~~ item] whileTrue:[ |
|
1626 |
((item := item parent) notNil and:[item isHierarchicalItem]) ifFalse:[ |
|
1627 |
^ false |
|
1628 |
] |
|
1629 |
]. |
|
1630 |
^ true |
|
1631 |
! |
|
1632 |
||
2305 | 1633 |
isCollapsed |
2547 | 1634 |
"returns true if the item is collapsed" |
1635 |
||
1636 |
^ isExpanded not |
|
2305 | 1637 |
! |
1638 |
||
3173 | 1639 |
isDirectoryItem |
1640 |
^ false |
|
1641 |
||
1642 |
"Created: / 23-06-2006 / 12:47:05 / fm" |
|
1643 |
"Modified: / 23-02-2007 / 12:04:23 / User" |
|
1644 |
! |
|
1645 |
||
1390 | 1646 |
isExpanded |
2547 | 1647 |
"returns true if the item is expanded" |
1648 |
||
1649 |
^ isExpanded |
|
1390 | 1650 |
! |
1651 |
||
1652 |
isHierarchicalItem |
|
3912 | 1653 |
"used to decide if the parent is a hierarchical item or the model" |
1654 |
||
1390 | 1655 |
^ true |
1656 |
! |
|
1657 |
||
2033 | 1658 |
isRealChildOf:anItem |
3912 | 1659 |
"returns true if the item is a child of anItem" |
1660 |
||
2033 | 1661 |
|item| |
1662 |
item := self parent. |
|
1663 |
||
1664 |
[item notNil] whileTrue:[ |
|
1665 |
item == anItem ifTrue:[^ true]. |
|
1666 |
item := item parent. |
|
1667 |
]. |
|
1668 |
^ false |
|
1669 |
! |
|
1670 |
||
1876 | 1671 |
isRootItem |
3912 | 1672 |
"returns true if the item is the root item" |
1673 |
||
1883 | 1674 |
^ parent isHierarchicalItem not |
1675 |
! |
|
1876 | 1676 |
|
1390 | 1677 |
size |
3911 | 1678 |
"return the number of children" |
1679 |
||
2081 | 1680 |
^ self children size |
1390 | 1681 |
! ! |
1682 |
||
1683 |
!HierarchicalItem methodsFor:'searching'! |
|
1684 |
||
1685 |
detect:aOneArgBlock |
|
1686 |
"find the first child, for which evaluation of the block returns |
|
2927 | 1687 |
true; if none does so, report an error" |
1688 |
||
1390 | 1689 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
1690 |
! |
|
1691 |
||
3071 | 1692 |
detect:aOneArgBlock ifNone:exceptionBlock |
1390 | 1693 |
"find the first child, for which evaluation of the block returns |
2927 | 1694 |
true; if none does so, return the evaluation of anExceptionBlock" |
1695 |
||
3071 | 1696 |
self do:[:el| |
1697 |
(aOneArgBlock value:el) ifTrue:[^ el] |
|
1698 |
]. |
|
1699 |
^ exceptionBlock value |
|
1804 | 1700 |
! |
1701 |
||
1702 |
detectLast:aOneArgBlock |
|
1703 |
"find the last child, for which evaluation of the block returns |
|
2927 | 1704 |
true; if none does so, an exception is raised" |
1705 |
||
1804 | 1706 |
^ self detectLast:aOneArgBlock ifNone:[self errorNotFound] |
1707 |
! |
|
1708 |
||
2081 | 1709 |
detectLast:anOneArgBlock ifNone:anExceptionBlock |
1804 | 1710 |
"find the last child, for which evaluation of the block returns |
2927 | 1711 |
true; if none does so, return the evaluation of anExceptionBlock" |
1712 |
||
2081 | 1713 |
self reverseDo:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ]. |
2927 | 1714 |
^ anExceptionBlock value |
1390 | 1715 |
! |
1716 |
||
3697 | 1717 |
findFirst:aOneArgBlock |
1966 | 1718 |
"find the first child, for which evaluation of the argument, aOneArgBlock |
3914 | 1719 |
returns true; return its index or 0 if none detected." |
1720 |
||
3697 | 1721 |
|
1722 |
self keysAndValuesDo:[:i :el| (aOneArgBlock value:el) ifTrue:[^ i] ]. |
|
1723 |
^ 0 |
|
1966 | 1724 |
! |
1725 |
||
2081 | 1726 |
findLast:anOneArgBlock |
1966 | 1727 |
"find the last child, for which evaluation of the argument, aOneArgBlock |
3914 | 1728 |
returns true; return its index or 0 if none detected." |
1729 |
||
2081 | 1730 |
self keysAndValuesReverseDo:[:i :el| (anOneArgBlock value:el) ifTrue:[^ i] ]. |
3914 | 1731 |
^ 0 |
1966 | 1732 |
! |
1733 |
||
1390 | 1734 |
identityIndexOf:aChild |
3912 | 1735 |
"return the index of aChild or 0 if not found. Compare using ==" |
1736 |
||
1733 | 1737 |
^ self identityIndexOf:aChild startingAt:1 |
1390 | 1738 |
! |
1739 |
||
1740 |
identityIndexOf:aChild startingAt:startIndex |
|
1741 |
"return the index of aChild, starting search at startIndex. |
|
3912 | 1742 |
Compare using ==; return 0 if not found" |
1743 |
||
1733 | 1744 |
|index| |
1745 |
||
2081 | 1746 |
index := startIndex. |
1733 | 1747 |
|
2081 | 1748 |
self from:startIndex do:[:el| |
1749 |
el == aChild ifTrue:[^ index ]. |
|
1750 |
index := index + 1. |
|
1390 | 1751 |
]. |
2081 | 1752 |
^ 0 |
1489 | 1753 |
! |
1754 |
||
1755 |
recursiveDetect:aOneArgBlock |
|
1756 |
"recursive find the first child, for which evaluation |
|
3911 | 1757 |
of the block returns true; if none nil is returned" |
1758 |
||
1804 | 1759 |
self recursiveDo:[:aChild| |
1760 |
(aOneArgBlock value:aChild) ifTrue:[^ aChild] |
|
1761 |
]. |
|
1762 |
^ nil |
|
1763 |
! |
|
1489 | 1764 |
|
1804 | 1765 |
recursiveDetectLast:aBlock |
1766 |
"find the last child, for which evaluation of the block returns |
|
3911 | 1767 |
true; if none does so, nil id returned" |
1768 |
||
1804 | 1769 |
self recursiveReverseDo:[:aChild| |
1770 |
(aBlock value:aChild) ifTrue:[^ aChild]. |
|
1489 | 1771 |
]. |
1772 |
^ nil |
|
1876 | 1773 |
! |
1774 |
||
1775 |
withAllDetect:aOneArgBlock |
|
1776 |
"recursive find the first item including self, for which evaluation |
|
3911 | 1777 |
of the block returns true; if none nil is returned" |
1778 |
||
1876 | 1779 |
(aOneArgBlock value:self) ifTrue:[^ self]. |
1780 |
||
1883 | 1781 |
^ self recursiveDetect:aOneArgBlock |
1782 |
! ! |
|
1390 | 1783 |
|
2486 | 1784 |
!HierarchicalItem methodsFor:'sorting & reordering'! |
2252 | 1785 |
|
2294 | 1786 |
recursiveSort:aSortBlock |
3911 | 1787 |
"recursive sort the children inplace using the 2-arg block sortBlock for comparison" |
1788 |
||
2294 | 1789 |
self criticalDo:[ |
3914 | 1790 |
children notEmptyOrNil ifTrue:[ |
2294 | 1791 |
self nonCriticalRecursiveSort:aSortBlock. |
1792 |
self childrenOrderChanged. |
|
1793 |
] |
|
1794 |
]. |
|
1795 |
! |
|
1796 |
||
2252 | 1797 |
sort:aSortBlock |
3911 | 1798 |
"sort the children inplace using the 2-arg block sortBlock for comparison" |
1799 |
||
3914 | 1800 |
children notEmptyOrNil ifTrue: [ |
1801 |
self criticalDo:[ |
|
1802 |
"/ check again (asynchronous update was possible before) |
|
1803 |
children notEmptyOrNil ifTrue: [ |
|
1804 |
children := children sort:aSortBlock. |
|
1805 |
self childrenOrderChanged. |
|
1806 |
] |
|
1807 |
]. |
|
1808 |
] |
|
2252 | 1809 |
! ! |
1810 |
||
1390 | 1811 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
1812 |
||
1813 |
labeled:aLabel |
|
1814 |
^ self new setLabel:aLabel |
|
1815 |
||
1816 |
||
1817 |
! |
|
1818 |
||
1819 |
labeled:aLabel icon:anIcon |
|
1820 |
^ self new setLabel:aLabel icon:anIcon |
|
1821 |
||
1822 |
||
1823 |
! ! |
|
1824 |
||
1825 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
1826 |
||
1827 |
iconForLevel:aLevel |
|
1828 |
"returns an icon |
|
1829 |
" |
|
1830 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
1831 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
1832 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
1833 |
||
1834 |
^ nil |
|
1835 |
! |
|
1836 |
||
1837 |
penguinIcon |
|
1838 |
PenguinIcon isNil ifTrue:[ |
|
1794 | 1839 |
PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm' |
1840 |
inPackage:'stx:goodies' |
|
1390 | 1841 |
]. |
1842 |
^ PenguinIcon |
|
1843 |
! ! |
|
1844 |
||
1845 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
1846 |
||
1847 |
children |
|
2781 | 1848 |
|lvl lbl txt image img icon| |
1390 | 1849 |
|
1850 |
children notNil ifTrue:[ |
|
1851 |
^ children |
|
1852 |
]. |
|
1853 |
||
1854 |
(lvl := self level) == 5 ifTrue:[ |
|
1855 |
children := #(). |
|
1856 |
^ children |
|
1857 |
]. |
|
1858 |
icon := self class iconForLevel:(lvl + 1). |
|
1859 |
children := OrderedCollection new. |
|
1860 |
||
1861 |
lvl < 4 ifTrue:[ |
|
1862 |
txt := (lvl + 1) printString, ' ['. |
|
2781 | 1863 |
img := Icon saveIcon. |
1390 | 1864 |
|
1865 |
1 to:5 do:[:i| |
|
1866 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
1867 |
lbl := img |
|
1868 |
] ifFalse:[ |
|
1869 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1870 |
lbl := Array with:(self class penguinIcon) |
1733 | 1871 |
with:('penguin#and#text' replaceAll:$# with:(Character cr)). |
1390 | 1872 |
] ifFalse:[ |
1873 |
lbl := txt, (i printString), ']' |
|
1874 |
] |
|
1875 |
]. |
|
1876 |
children add:(self class labeled:lbl icon:icon) |
|
1877 |
]. |
|
1878 |
] ifFalse:[ |
|
1879 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
1880 |
txt := LabelAndIcon icon:image string:'Text'. |
|
1881 |
img := Icon copyIcon. |
|
1882 |
||
1883 |
1 to:5 do:[:i| |
|
1884 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 1885 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 1886 |
children add:(self class labeled:lbl icon:icon). |
3333 | 1887 |
]. |
1888 |
children add:(self class labeled:'Edit Text'). |
|
1390 | 1889 |
]. |
1890 |
||
1891 |
children do:[:aChild| aChild parent:self ]. |
|
1892 |
^ children |
|
1893 |
! |
|
1894 |
||
1895 |
icon |
|
1896 |
"returns the icon |
|
1897 |
" |
|
1898 |
^ icon |
|
1899 |
! |
|
1900 |
||
1901 |
icon:anIcon |
|
1902 |
"set the icon; if icon changed, a notification |
|
1903 |
is raised. |
|
1904 |
" |
|
1905 |
icon ~= anIcon ifTrue:[ |
|
1906 |
icon := anIcon. |
|
1907 |
self iconChanged |
|
1908 |
] |
|
1909 |
! |
|
1910 |
||
1911 |
label |
|
1912 |
"returns the label |
|
1913 |
" |
|
1914 |
^ label |
|
1915 |
||
1916 |
! |
|
1917 |
||
1918 |
label:aLabel |
|
1919 |
"set the label; if label changed, a notification |
|
1920 |
is raised. |
|
1921 |
" |
|
1922 |
label ~= aLabel ifTrue:[ |
|
1923 |
label := aLabel. |
|
1924 |
self changed. |
|
1925 |
] |
|
1926 |
||
1927 |
! |
|
1928 |
||
1929 |
setIcon:anIcon |
|
1930 |
"set the icon without any change notification |
|
1931 |
" |
|
1932 |
icon := anIcon |
|
1933 |
! |
|
1934 |
||
1935 |
setLabel:aLabel |
|
1936 |
"set the label without any change notification |
|
1937 |
" |
|
1938 |
label := aLabel |
|
1939 |
! |
|
1940 |
||
1941 |
setLabel:aLabel icon:anIcon |
|
1942 |
"set the label and icon without any change notification |
|
1943 |
" |
|
1944 |
label := aLabel. |
|
1945 |
icon := anIcon. |
|
1946 |
! ! |
|
1947 |
||
1948 |
!HierarchicalItem class methodsFor:'documentation'! |
|
1949 |
||
1950 |
version |
|
3915
f3ec0f55b790
comment/format in: #fetchChildren
Claus Gittinger <cg@exept.de>
parents:
3914
diff
changeset
|
1951 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.96 2010-07-09 07:11:28 cg Exp $' |
3849
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
1952 |
! |
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
1953 |
|
05e3fe811288
changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents:
3716
diff
changeset
|
1954 |
version_CVS |
3915
f3ec0f55b790
comment/format in: #fetchChildren
Claus Gittinger <cg@exept.de>
parents:
3914
diff
changeset
|
1955 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.96 2010-07-09 07:11:28 cg Exp $' |
1390 | 1956 |
! ! |