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