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