author | Claus Gittinger <cg@exept.de> |
Tue, 08 Apr 2003 15:39:36 +0200 | |
changeset 2476 | 298ad746e52f |
parent 2465 | a282c734a816 |
child 2484 | 92f9e42980ab |
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. |
465 |
index == 0 ifTrue:[ self subscriptBoundsError ]. |
|
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. |
483 |
index == 0 ifTrue:[ self subscriptBoundsError ]. |
|
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. |
519 |
index == 0 ifTrue:[ self subscriptBoundsError ]. |
|
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:[ |
|
684 |
^ self subscriptBoundsError |
|
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:[ |
|
747 |
^ self subscriptBoundsError |
|
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 |
" |
1606 | 1162 |
|y0 hF| |
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 |
|
1606 | 1167 |
aLabel isImageOrForm ifTrue:[ |
1168 |
^ aLabel displayOn:aGC x:x y:y0 |
|
1169 |
]. |
|
1170 |
y0 := y0 + (aGC font ascent). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1171 |
|
1606 | 1172 |
aLabel isString ifFalse:[ |
1173 |
^ aLabel displayOn:aGC x:x y:y0 |
|
1174 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1175 |
|
1606 | 1176 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
1177 |
^ aLabel displayOn:aGC x:x y:y0 |
|
1178 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1179 |
|
1606 | 1180 |
hF := aGC font height. |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1181 |
|
1606 | 1182 |
aLabel asCollectionOfLines do:[:el| |
1183 |
el displayOn:aGC x:x y:y0. |
|
1184 |
y0 := y0 + hF |
|
1185 |
] |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1186 |
]. |
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 |
heightOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1190 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1191 |
" |
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 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1195 |
^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1196 |
]. |
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 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1199 |
h := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1200 |
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
|
1201 |
^ h |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1202 |
]. |
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 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1205 |
^ h * (aGC font height) |
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 |
widthOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1209 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1210 |
" |
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 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1214 |
^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1215 |
]. |
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 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1218 |
w := -5. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1219 |
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
|
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 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1223 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1224 |
^ aLabel widthOn:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1225 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1226 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1227 |
w := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1228 |
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
|
1229 |
^ w |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1230 |
! ! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1231 |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1232 |
!HierarchicalItem methodsFor:'private enumerating'! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1233 |
|
2117 | 1234 |
nonCriticalDo:aOneArgBlock |
1235 |
"evaluate a block noncritical on each child. |
|
1236 |
" |
|
1237 |
^ self nonCriticalFrom:1 to:nil do:aOneArgBlock |
|
1238 |
! |
|
1239 |
||
1240 |
nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
1241 |
"evaluate a block noncritical on each child starting with the |
|
2081 | 1242 |
child at startIndex to the endIndex (if nil to end of list). |
1243 |
" |
|
1244 |
|list size resp| |
|
1245 |
||
1246 |
list := self children. |
|
1247 |
size := list size. |
|
1248 |
||
1249 |
startIndex > size ifTrue:[^ nil]. |
|
1250 |
resp := nil. |
|
1251 |
||
1252 |
endIndex notNil ifTrue:[ |
|
1253 |
size := size min:endIndex |
|
1254 |
]. |
|
1255 |
startIndex to:size do:[:i| |item| |
|
1256 |
item := list at:i ifAbsent:nil. |
|
1257 |
item isNil ifTrue:[^ resp]. |
|
1258 |
resp := aOneArgBlock value:item. |
|
1259 |
]. |
|
1260 |
^ resp |
|
1261 |
! |
|
1262 |
||
2117 | 1263 |
nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
1264 |
"evaluate a block non critical on each child starting with the |
|
2081 | 1265 |
child at endIndex (if nil to end of list) to startIndex. |
1266 |
" |
|
1267 |
|list size resp| |
|
1268 |
||
1269 |
list := self children. |
|
1270 |
size := list size. |
|
1271 |
resp := nil. |
|
1272 |
||
1273 |
endIndex notNil ifTrue:[ |
|
1274 |
size := size min:endIndex |
|
1275 |
]. |
|
1276 |
size to:startIndex by:-1 do:[:i| |item| |
|
1277 |
item := list at:i ifAbsent:nil. |
|
1278 |
item isNil ifTrue:[^ resp]. |
|
1279 |
resp := aOneArgBlock value:item. |
|
1280 |
]. |
|
1281 |
^ resp |
|
1282 |
! |
|
1283 |
||
2117 | 1284 |
nonCriticalKeysAndValuesReverseDo:aOneArgBlock |
2081 | 1285 |
"evaluate the argument, aBlock in reverse order for every |
1286 |
child, passing both index and element as arguments. |
|
1287 |
" |
|
1288 |
|list size resp| |
|
1289 |
||
1290 |
list := self children. |
|
1291 |
size := list size. |
|
1292 |
resp := nil. |
|
1293 |
||
1294 |
size to:1 by:-1 do:[:i| |item| |
|
1295 |
item := list at:i ifAbsent:nil. |
|
1296 |
item isNil ifTrue:[^ resp]. |
|
1297 |
resp := aOneArgBlock value:i value:item. |
|
1298 |
]. |
|
1299 |
^ resp |
|
1300 |
! |
|
1301 |
||
2117 | 1302 |
nonCriticalRecursiveDo: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 |
" |
2117 | 1305 |
self nonCriticalFrom:1 to:nil do:[:aChild| |
2081 | 1306 |
anOneArgBlock value:aChild. |
2117 | 1307 |
aChild nonCriticalRecursiveDo:anOneArgBlock |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1308 |
]. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1309 |
! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1310 |
|
2117 | 1311 |
nonCriticalRecursiveReverseDo:anOneArgBlock |
1312 |
"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
|
1313 |
proccesing children in reverse direction |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1314 |
" |
2117 | 1315 |
self nonCriticalFrom:1 to:nil reverseDo:[:aChild| |
1316 |
aChild nonCriticalRecursiveReverseDo:anOneArgBlock. |
|
2081 | 1317 |
anOneArgBlock value:aChild. |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1318 |
]. |
2294 | 1319 |
! |
1320 |
||
1321 |
nonCriticalRecursiveSort:aSortBlock |
|
1322 |
"evaluate a block noncritical on each child. |
|
1323 |
" |
|
1324 |
|unsorted sorted| |
|
1325 |
||
1326 |
unsorted := children. |
|
1327 |
||
1328 |
unsorted size ~~ 0 ifTrue:[ |
|
1329 |
sorted := unsorted sort:aSortBlock. |
|
1330 |
sorted do:[:el| el nonCriticalRecursiveSort:aSortBlock ]. |
|
1331 |
children := sorted. |
|
1332 |
]. |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1333 |
! ! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1334 |
|
1390 | 1335 |
!HierarchicalItem methodsFor:'private hierarchy'! |
1336 |
||
1337 |
recursiveSetCollapsed |
|
1338 |
"collapse all children and sub-children without notifications |
|
1339 |
" |
|
1340 |
isExpanded := false. |
|
1341 |
||
2081 | 1342 |
"/ do not call :#size: children will be autoloaded !!!! |
1343 |
children size ~~ 0 ifTrue:[ |
|
2117 | 1344 |
self nonCriticalFrom:1 to:nil do:[:el| el recursiveSetCollapsed ]. |
1390 | 1345 |
] |
1346 |
! |
|
1347 |
||
1348 |
recursiveSetExpandedAndAddToList:aList |
|
1349 |
"expand all children and sub-children without notifications; |
|
1350 |
add children to list |
|
1351 |
" |
|
1352 |
isExpanded := true. |
|
1353 |
||
2081 | 1354 |
self do:[:anItem| |
1355 |
aList add:anItem. |
|
1356 |
anItem recursiveSetExpandedAndAddToList:aList. |
|
1357 |
]. |
|
1390 | 1358 |
! ! |
1359 |
||
1360 |
!HierarchicalItem methodsFor:'protocol accessing'! |
|
1361 |
||
1362 |
children |
|
1363 |
"returns list of children |
|
1364 |
*** to optimize:redefine by subClass |
|
1365 |
" |
|
1366 |
|model| |
|
1367 |
||
1368 |
children isNil ifTrue:[ |
|
1369 |
(model := self model) notNil ifTrue:[ |
|
1486 | 1370 |
children := model childrenFor:self |
1390 | 1371 |
]. |
1372 |
]. |
|
1373 |
^ children |
|
1374 |
! |
|
1375 |
||
1376 |
icon |
|
1377 |
"returns the icon or nil; |
|
1378 |
*** to optimize:redefine by subClass |
|
1379 |
" |
|
1380 |
|model| |
|
1381 |
||
1382 |
(model := self model) notNil ifTrue:[ |
|
1383 |
^ model iconFor:self |
|
1384 |
]. |
|
1385 |
^ nil |
|
1386 |
! |
|
1387 |
||
1388 |
label |
|
1389 |
"returns the label displayed on aGC; |
|
1390 |
*** to optimize:redefine by subClass |
|
1391 |
" |
|
1392 |
|model| |
|
1393 |
||
1394 |
(model := self model) notNil ifTrue:[ |
|
1395 |
^ model labelFor:self |
|
1396 |
]. |
|
1397 |
^ nil |
|
1398 |
||
1399 |
! |
|
1400 |
||
1401 |
middleButtonMenu |
|
1402 |
"returns the middleButtonMenu or nil if no menu is defined |
|
1403 |
" |
|
1404 |
|model| |
|
1405 |
||
1406 |
(model := self model) notNil ifTrue:[ |
|
1407 |
^ model middleButtonMenuFor:self |
|
1408 |
]. |
|
1409 |
^ nil |
|
1831
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1410 |
! |
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 |
recursiveSortChildren:aSortBlock |
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 |
|children| |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1415 |
|
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1416 |
(children := self children) notNil ifTrue:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1417 |
self criticalDo:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1418 |
children sort:aSortBlock. |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1419 |
children do:[:aChild| aChild recursiveSortChildren:aSortBlock ] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1420 |
] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1421 |
]. |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1422 |
! |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1423 |
|
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1424 |
sortChildren:aSortBlock |
2252 | 1425 |
"sort the children inplace using the 2-arg block sortBlock for comparison |
1426 |
" |
|
1427 |
self obsoleteMethodWarning:'renamed to sort:'. |
|
1428 |
self sort:aSortBlock. |
|
1390 | 1429 |
! ! |
1430 |
||
1431 |
!HierarchicalItem methodsFor:'protocol displaying'! |
|
1432 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1489
diff
changeset
|
1433 |
displayOn:aGC x:x y:y h:h |
1390 | 1434 |
"draw the receiver in the graphicsContext, aGC. |
1435 |
" |
|
1436 |
|label |
|
1398 | 1437 |
x0 "{ Class:SmallInteger }" |
1390 | 1438 |
| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1439 |
(label := self label) isNil ifTrue:[^ self]. |
1398 | 1440 |
|
1441 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1606 | 1442 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h |
1398 | 1443 |
]. |
1444 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1445 |
x0 := x. |
1398 | 1446 |
label do:[:el| |
1447 |
el notNil ifTrue:[ |
|
1606 | 1448 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h. |
1398 | 1449 |
x0 := x0 + 5 + (el widthOn:aGC). |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1450 |
]. |
1390 | 1451 |
] |
1452 |
! |
|
1453 |
||
1454 |
heightOn:aGC |
|
1455 |
"return the width of the receiver, if it is to be displayed on aGC |
|
1456 |
" |
|
1606 | 1457 |
height isNil ifTrue:[ |
1458 |
height := self heightOf:(self label) on:aGC |
|
1459 |
]. |
|
1460 |
^ height |
|
1390 | 1461 |
! |
1462 |
||
1463 |
widthOn:aGC |
|
1464 |
"return the width of the receiver, if it is to be displayed on aGC |
|
1465 |
" |
|
1606 | 1466 |
width isNil ifTrue:[ |
1467 |
width := self widthOf:(self label) on:aGC |
|
1468 |
]. |
|
1469 |
^ width |
|
1470 |
||
1390 | 1471 |
! ! |
1472 |
||
2313 | 1473 |
!HierarchicalItem methodsFor:'protocol event processing'! |
1474 |
||
1475 |
processButtonPress:button x:x y:y |
|
1476 |
"a mouse button was pressed in my label. |
|
1477 |
Return true, if I have eaten the event. |
|
1478 |
On default false is returned (unhandled). |
|
1479 |
" |
|
1480 |
^ false |
|
1481 |
! ! |
|
1482 |
||
1390 | 1483 |
!HierarchicalItem methodsFor:'protocol monitoring'! |
1484 |
||
1485 |
monitoringCycle |
|
1486 |
"called all 'n' seconds by the model, if the monitoring |
|
1487 |
cycle is enabled. The item can perform some checks, .. |
|
1488 |
**** can be redefined by subclass to perform some actions |
|
1489 |
" |
|
1490 |
! ! |
|
1491 |
||
1492 |
!HierarchicalItem methodsFor:'protocol queries'! |
|
1493 |
||
2305 | 1494 |
canCollapse |
1495 |
"called before collapsing the item; can be redefined |
|
1496 |
by subclass to omit the collapse operation |
|
1497 |
" |
|
1498 |
^ (isExpanded == true) |
|
1499 |
! |
|
1500 |
||
1501 |
canExpand |
|
1502 |
"called before expanding the item; can be redefined |
|
1503 |
by subclass to omit the collapse operation |
|
1504 |
" |
|
1505 |
^ (isExpanded == true) not and:[self hasChildren] |
|
1506 |
! |
|
1507 |
||
1571 | 1508 |
drawHorizontalLineUpToText |
1509 |
"draw the horizizontal line for the selected item up to the text |
|
1510 |
or on default to the start of the the vertical line; only used by |
|
1511 |
the hierarchical view |
|
1512 |
" |
|
1513 |
^ false |
|
1514 |
! |
|
1515 |
||
1390 | 1516 |
hasChildren |
1517 |
"checks whether the item has a list of children; the list must not |
|
1518 |
be loaded yet( ex. FileDirectory ). |
|
1519 |
*** to optimize:redefine by subClass |
|
1520 |
" |
|
2081 | 1521 |
^ self children size ~~ 0 |
1390 | 1522 |
! |
1523 |
||
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1524 |
hasIndicator |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1525 |
"on default the indicator is drawn if the item |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1526 |
has children |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1527 |
" |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1528 |
^ self hasChildren |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1529 |
! |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1530 |
|
2305 | 1531 |
isSelectable |
1532 |
"returns true if the item is selectable otherwise false |
|
1533 |
" |
|
1534 |
^ true |
|
1535 |
! |
|
1536 |
||
1390 | 1537 |
string |
1538 |
"access the printable string used for steping through a list |
|
1539 |
searching for an entry starting with a character. |
|
1540 |
*** to optimize:redefine by subClass |
|
1541 |
" |
|
1398 | 1542 |
|label| |
1543 |
||
1544 |
(label := self label) notNil ifTrue:[ |
|
1545 |
label isString ifTrue:[ ^ label string ]. |
|
1546 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
1547 |
||
1548 |
label isSequenceable ifFalse:[ |
|
1549 |
^ label perform:#string ifNotUnderstood:nil |
|
1550 |
]. |
|
1551 |
||
1552 |
label do:[:el||s| |
|
1553 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
1554 |
s := el perform:#string ifNotUnderstood:nil. |
|
1555 |
s notNil ifTrue:[^ s]. |
|
1556 |
] |
|
1557 |
] |
|
1558 |
]. |
|
1559 |
^ nil |
|
1560 |
||
1390 | 1561 |
|
1562 |
! ! |
|
1563 |
||
1564 |
!HierarchicalItem methodsFor:'queries'! |
|
1565 |
||
1804 | 1566 |
isChildOf:anItem |
1567 |
"returns true if the item is a child of anItem |
|
1568 |
" |
|
1569 |
|item| |
|
1570 |
||
1571 |
item := self. |
|
1572 |
||
1573 |
[anItem ~~ item] whileTrue:[ |
|
1574 |
((item := item parent) notNil and:[item isHierarchicalItem]) ifFalse:[ |
|
1575 |
^ false |
|
1576 |
] |
|
1577 |
]. |
|
1578 |
^ true |
|
1579 |
||
1580 |
! |
|
1581 |
||
2305 | 1582 |
isCollapsed |
1583 |
"returns true if the item is collapsed |
|
1584 |
" |
|
1585 |
^ (isExpanded ~~ true) |
|
1586 |
! |
|
1587 |
||
1390 | 1588 |
isExpanded |
2305 | 1589 |
"returns true if the item is expanded |
1390 | 1590 |
" |
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1591 |
^ (isExpanded == true) |
1390 | 1592 |
! |
1593 |
||
1594 |
isHierarchicalItem |
|
1595 |
"used to decide if the parent is a hierarchical item |
|
1596 |
or the model |
|
1597 |
" |
|
1598 |
^ true |
|
1599 |
! |
|
1600 |
||
2033 | 1601 |
isRealChildOf:anItem |
1602 |
"returns true if the item is a child of anItem |
|
1603 |
" |
|
1604 |
|item| |
|
1605 |
item := self parent. |
|
1606 |
||
1607 |
[item notNil] whileTrue:[ |
|
1608 |
item == anItem ifTrue:[^ true]. |
|
1609 |
item := item parent. |
|
1610 |
]. |
|
1611 |
^ false |
|
1612 |
! |
|
1613 |
||
1876 | 1614 |
isRootItem |
1615 |
"returns true if the item is the root item |
|
1616 |
" |
|
1883 | 1617 |
^ parent isHierarchicalItem not |
1618 |
! |
|
1876 | 1619 |
|
1390 | 1620 |
size |
1621 |
"return the number of children |
|
1622 |
" |
|
2081 | 1623 |
^ self children size |
1390 | 1624 |
! ! |
1625 |
||
1626 |
!HierarchicalItem methodsFor:'searching'! |
|
1627 |
||
1628 |
detect:aOneArgBlock |
|
1629 |
"find the first child, for which evaluation of the block returns |
|
1630 |
true; if none does so, report an error |
|
1631 |
" |
|
1632 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
|
1633 |
||
1634 |
! |
|
1635 |
||
2081 | 1636 |
detect:anOneArgBlock ifNone:anExceptionBlock |
1390 | 1637 |
"find the first child, for which evaluation of the block returns |
1638 |
true; if none does so, return the evaluation of anExceptionBlock |
|
1639 |
" |
|
2081 | 1640 |
self do:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ]. |
1641 |
^ anExceptionBlock value |
|
1804 | 1642 |
! |
1643 |
||
1644 |
detectLast:aOneArgBlock |
|
1645 |
"find the last child, for which evaluation of the block returns |
|
1646 |
true; if none does so, an exception is raised |
|
1647 |
" |
|
1648 |
^ self detectLast:aOneArgBlock ifNone:[self errorNotFound] |
|
1649 |
||
1650 |
! |
|
1651 |
||
2081 | 1652 |
detectLast:anOneArgBlock ifNone:anExceptionBlock |
1804 | 1653 |
"find the last child, for which evaluation of the block returns |
1654 |
true; if none does so, return the evaluation of anExceptionBlock |
|
1655 |
" |
|
2081 | 1656 |
self reverseDo:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ]. |
1657 |
^ anExceptionBlock value |
|
1390 | 1658 |
! |
1659 |
||
2081 | 1660 |
findFirst:anOneArgBlock |
1966 | 1661 |
"find the first child, for which evaluation of the argument, aOneArgBlock |
1662 |
returns true; return its index or 0 if none detected. |
|
1663 |
" |
|
2081 | 1664 |
self keysAndValuesDo:[:i :el| (anOneArgBlock value:el) ifTrue:[^ i] ]. |
1665 |
^ 0 |
|
1966 | 1666 |
! |
1667 |
||
2081 | 1668 |
findLast:anOneArgBlock |
1966 | 1669 |
"find the last child, for which evaluation of the argument, aOneArgBlock |
1670 |
returns true; return its index or 0 if none detected. |
|
1671 |
" |
|
2081 | 1672 |
self keysAndValuesReverseDo:[:i :el| (anOneArgBlock value:el) ifTrue:[^ i] ]. |
1673 |
^ 0 |
|
1966 | 1674 |
! |
1675 |
||
1390 | 1676 |
identityIndexOf:aChild |
1677 |
"return the index of aChild or 0 if not found. Compare using == |
|
1678 |
" |
|
1733 | 1679 |
^ self identityIndexOf:aChild startingAt:1 |
1390 | 1680 |
! |
1681 |
||
1682 |
identityIndexOf:aChild startingAt:startIndex |
|
1683 |
"return the index of aChild, starting search at startIndex. |
|
1684 |
Compare using ==; return 0 if not found |
|
1685 |
" |
|
1733 | 1686 |
|index| |
1687 |
||
2081 | 1688 |
index := startIndex. |
1733 | 1689 |
|
2081 | 1690 |
self from:startIndex do:[:el| |
1691 |
el == aChild ifTrue:[^ index ]. |
|
1692 |
index := index + 1. |
|
1390 | 1693 |
]. |
2081 | 1694 |
^ 0 |
1489 | 1695 |
! |
1696 |
||
1697 |
recursiveDetect:aOneArgBlock |
|
1698 |
"recursive find the first child, for which evaluation |
|
1699 |
of the block returns true; if none nil is returned |
|
1700 |
" |
|
1804 | 1701 |
self recursiveDo:[:aChild| |
1702 |
(aOneArgBlock value:aChild) ifTrue:[^ aChild] |
|
1703 |
]. |
|
1704 |
^ nil |
|
1705 |
! |
|
1489 | 1706 |
|
1804 | 1707 |
recursiveDetectLast:aBlock |
1708 |
"find the last child, for which evaluation of the block returns |
|
1709 |
true; if none does so, nil id returned |
|
1710 |
" |
|
1711 |
self recursiveReverseDo:[:aChild| |
|
1712 |
(aBlock value:aChild) ifTrue:[^ aChild]. |
|
1489 | 1713 |
]. |
1714 |
^ nil |
|
1876 | 1715 |
! |
1716 |
||
1717 |
withAllDetect:aOneArgBlock |
|
1718 |
"recursive find the first item including self, for which evaluation |
|
1719 |
of the block returns true; if none nil is returned |
|
1720 |
" |
|
1721 |
(aOneArgBlock value:self) ifTrue:[^ self]. |
|
1722 |
||
1883 | 1723 |
^ self recursiveDetect:aOneArgBlock |
1724 |
! ! |
|
1390 | 1725 |
|
2252 | 1726 |
!HierarchicalItem methodsFor:'sort & reordering'! |
1727 |
||
2294 | 1728 |
recursiveSort:aSortBlock |
1729 |
"recursive sort the children inplace using the 2-arg block sortBlock for comparison |
|
1730 |
" |
|
1731 |
self criticalDo:[ |
|
1732 |
children size ~~ 0 ifTrue:[ |
|
1733 |
self nonCriticalRecursiveSort:aSortBlock. |
|
1734 |
self childrenOrderChanged. |
|
1735 |
] |
|
1736 |
]. |
|
1737 |
! |
|
1738 |
||
2252 | 1739 |
sort:aSortBlock |
1740 |
"sort the children inplace using the 2-arg block sortBlock for comparison |
|
1741 |
" |
|
1742 |
|unsorted| |
|
1743 |
||
1744 |
self criticalDo:[ |
|
2294 | 1745 |
unsorted := children. |
2252 | 1746 |
|
1747 |
unsorted size ~~ 0 ifTrue:[ |
|
1748 |
children := unsorted sort:aSortBlock. |
|
1749 |
self childrenOrderChanged. |
|
1750 |
] |
|
1751 |
]. |
|
1752 |
! ! |
|
1753 |
||
1390 | 1754 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
1755 |
||
1756 |
labeled:aLabel |
|
1757 |
^ self new setLabel:aLabel |
|
1758 |
||
1759 |
||
1760 |
! |
|
1761 |
||
1762 |
labeled:aLabel icon:anIcon |
|
1763 |
^ self new setLabel:aLabel icon:anIcon |
|
1764 |
||
1765 |
||
1766 |
! ! |
|
1767 |
||
1768 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
1769 |
||
1770 |
iconForLevel:aLevel |
|
1771 |
"returns an icon |
|
1772 |
" |
|
1773 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
1774 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
1775 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
1776 |
||
1777 |
^ nil |
|
1778 |
||
1779 |
! |
|
1780 |
||
1781 |
penguinIcon |
|
1782 |
PenguinIcon isNil ifTrue:[ |
|
1794 | 1783 |
PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm' |
1784 |
inPackage:'stx:goodies' |
|
1390 | 1785 |
]. |
1786 |
^ PenguinIcon |
|
1787 |
! ! |
|
1788 |
||
1789 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
1790 |
||
1791 |
children |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1792 |
|lvl lbl txt image img icon tmp| |
1390 | 1793 |
|
1794 |
children notNil ifTrue:[ |
|
1795 |
^ children |
|
1796 |
]. |
|
1797 |
||
1798 |
(lvl := self level) == 5 ifTrue:[ |
|
1799 |
children := #(). |
|
1800 |
^ children |
|
1801 |
]. |
|
1802 |
icon := self class iconForLevel:(lvl + 1). |
|
1803 |
children := OrderedCollection new. |
|
1804 |
||
1805 |
lvl < 4 ifTrue:[ |
|
1806 |
txt := (lvl + 1) printString, ' ['. |
|
1807 |
img := NewLauncher saveImageIcon. |
|
1808 |
||
1809 |
1 to:5 do:[:i| |
|
1810 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
1811 |
lbl := img |
|
1812 |
] ifFalse:[ |
|
1813 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1814 |
lbl := Array with:(self class penguinIcon) |
1733 | 1815 |
with:('penguin#and#text' replaceAll:$# with:(Character cr)). |
1390 | 1816 |
] ifFalse:[ |
1817 |
lbl := txt, (i printString), ']' |
|
1818 |
] |
|
1819 |
]. |
|
1820 |
children add:(self class labeled:lbl icon:icon) |
|
1821 |
]. |
|
1822 |
] ifFalse:[ |
|
1823 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
1824 |
txt := LabelAndIcon icon:image string:'Text'. |
|
1825 |
img := Icon copyIcon. |
|
1826 |
||
1827 |
1 to:5 do:[:i| |
|
1828 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 1829 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 1830 |
children add:(self class labeled:lbl icon:icon). |
1831 |
] |
|
1832 |
]. |
|
1833 |
||
1834 |
children do:[:aChild| aChild parent:self ]. |
|
1835 |
^ children |
|
1836 |
! |
|
1837 |
||
1838 |
icon |
|
1839 |
"returns the icon |
|
1840 |
" |
|
1841 |
^ icon |
|
1842 |
! |
|
1843 |
||
1844 |
icon:anIcon |
|
1845 |
"set the icon; if icon changed, a notification |
|
1846 |
is raised. |
|
1847 |
" |
|
1848 |
icon ~= anIcon ifTrue:[ |
|
1849 |
icon := anIcon. |
|
1850 |
self iconChanged |
|
1851 |
] |
|
1852 |
! |
|
1853 |
||
1854 |
label |
|
1855 |
"returns the label |
|
1856 |
" |
|
1857 |
^ label |
|
1858 |
||
1859 |
! |
|
1860 |
||
1861 |
label:aLabel |
|
1862 |
"set the label; if label changed, a notification |
|
1863 |
is raised. |
|
1864 |
" |
|
1865 |
label ~= aLabel ifTrue:[ |
|
1866 |
label := aLabel. |
|
1867 |
self changed. |
|
1868 |
] |
|
1869 |
||
1870 |
! |
|
1871 |
||
1872 |
setIcon:anIcon |
|
1873 |
"set the icon without any change notification |
|
1874 |
" |
|
1875 |
icon := anIcon |
|
1876 |
! |
|
1877 |
||
1878 |
setLabel:aLabel |
|
1879 |
"set the label without any change notification |
|
1880 |
" |
|
1881 |
label := aLabel |
|
1882 |
! |
|
1883 |
||
1884 |
setLabel:aLabel icon:anIcon |
|
1885 |
"set the label and icon without any change notification |
|
1886 |
" |
|
1887 |
label := aLabel. |
|
1888 |
icon := anIcon. |
|
1889 |
! ! |
|
1890 |
||
1891 |
!HierarchicalItem class methodsFor:'documentation'! |
|
1892 |
||
1893 |
version |
|
2476 | 1894 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.55 2003-04-08 13:39:36 cg Exp $' |
1390 | 1895 |
! ! |