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