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