author | ca |
Thu, 19 Sep 2002 11:17:30 +0200 | |
changeset 2201 | aa74fa6137a5 |
parent 2193 | 41d5d33c9f78 |
child 2206 | e62f6df90972 |
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 |
|
1606 | 749 |
]. |
750 |
(model := self model) notNil ifTrue:[ |
|
1974 | 751 |
model itemChanged:why with:anArgument from:self |
1390 | 752 |
]. |
1974 | 753 |
super changed:why with:anArgument |
1390 | 754 |
! |
755 |
||
2193
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
756 |
childrenOrderChanged |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
757 |
"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
|
758 |
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
|
759 |
each item which has changed its position |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
760 |
triggered by the user operation !! |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
761 |
" |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
762 |
|model visStart list| |
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 |
self isExpanded ifFalse:[ ^ self ]. "/ not expanded |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
765 |
children size ~~ 0 ifTrue:[ ^ self ]. "/ no children |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
766 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
767 |
model := self model. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
768 |
model ifNil:[^ self]. "/ no model |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
769 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
770 |
visStart := model identityIndexOf:self. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
771 |
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
|
772 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
773 |
self criticalDo:[ |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
774 |
list := OrderedCollection new. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
775 |
self addVisibleChildrenTo:list. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
776 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
777 |
list do:[:el| |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
778 |
visStart := visStart + 1. |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
779 |
|
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
780 |
(model at:visStart ifAbsent:el) ~~ el ifTrue:[ |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
781 |
model at:visStart put:el |
41d5d33c9f78
add method to synchronize the model with the changed children order
ca
parents:
2117
diff
changeset
|
782 |
]. |
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 |
]. |
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 |
|
1843 | 787 |
fontChanged |
788 |
"called if the font has changed |
|
789 |
" |
|
790 |
width := height := nil. |
|
791 |
||
792 |
children size ~~ 0 ifTrue:[ |
|
793 |
children do:[:el| el fontChanged ]. |
|
794 |
]. |
|
795 |
! |
|
796 |
||
1390 | 797 |
hierarchyChanged |
798 |
"hierarchy changed; optimize redrawing |
|
799 |
" |
|
800 |
self changed:#hierarchy with:nil |
|
801 |
! |
|
802 |
||
803 |
iconChanged |
|
804 |
"icon changed; optimize redrawing |
|
805 |
" |
|
806 |
self changed:#icon with:nil |
|
807 |
! ! |
|
808 |
||
809 |
!HierarchicalItem methodsFor:'enumerating'! |
|
810 |
||
1804 | 811 |
collect:aBlock |
812 |
"for each child in the receiver, evaluate the argument, aBlock |
|
813 |
and return a new collection with the results |
|
814 |
" |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
815 |
|coll| |
1804 | 816 |
|
2081 | 817 |
coll := OrderedCollection new. |
818 |
self do:[:el| coll add:(aBlock value:el) ]. |
|
819 |
^ coll |
|
1804 | 820 |
! |
821 |
||
1390 | 822 |
do:aOneArgBlock |
823 |
"evaluate a block on each child |
|
824 |
" |
|
2081 | 825 |
^ self from:1 do:aOneArgBlock |
1390 | 826 |
! |
827 |
||
828 |
from:startIndex do:aOneArgBlock |
|
829 |
"evaluate a block on each child starting with the |
|
830 |
child at startIndex to the end. |
|
831 |
" |
|
2117 | 832 |
^ self from:startIndex to:nil do:aOneArgBlock |
2081 | 833 |
! |
834 |
||
835 |
from:startIndex reverseDo:aOneArgBlock |
|
836 |
"evaluate a block on each child starting at end to the startIndex |
|
837 |
" |
|
2117 | 838 |
^ self from:startIndex to:nil reverseDo:aOneArgBlock |
1390 | 839 |
! |
840 |
||
841 |
from:startIndex to:endIndex do:aOneArgBlock |
|
842 |
"evaluate a block on each child starting with the |
|
843 |
child at startIndex to the endIndex. |
|
844 |
" |
|
2081 | 845 |
|res| |
846 |
||
847 |
self size < startIndex ifTrue:[^ nil]. |
|
848 |
res := nil. |
|
849 |
||
850 |
self criticalDo:[ |
|
2117 | 851 |
res := self nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
852 |
]. |
2081 | 853 |
^ res |
1390 | 854 |
! |
855 |
||
856 |
from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
857 |
"evaluate a block on each child starting with the |
|
858 |
child at endIndex to the startIndex. |
|
859 |
" |
|
2081 | 860 |
|res| |
861 |
||
862 |
self size < startIndex ifTrue:[^ nil]. |
|
863 |
res := nil. |
|
864 |
||
865 |
self criticalDo:[ |
|
2117 | 866 |
res := self nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
867 |
]. |
2081 | 868 |
^ res |
1390 | 869 |
! |
870 |
||
1966 | 871 |
keysAndValuesDo:aTwoArgBlock |
872 |
"evaluate the argument, aBlock for every child, |
|
2081 | 873 |
passing both index and element as arguments. |
874 |
" |
|
875 |
|key res| |
|
1966 | 876 |
|
2081 | 877 |
key := 1. |
878 |
res := nil. |
|
879 |
||
880 |
self do:[:el| |
|
881 |
res := el value:key value:el. |
|
882 |
key := key + 1. |
|
1966 | 883 |
]. |
2081 | 884 |
^ res |
1966 | 885 |
! |
886 |
||
887 |
keysAndValuesReverseDo:aTwoArgBlock |
|
888 |
"evaluate the argument, aBlock in reverse order for every |
|
2081 | 889 |
child, passing both index and element as arguments. |
890 |
" |
|
891 |
|res| |
|
1966 | 892 |
|
2081 | 893 |
self size == 0 ifTrue:[^ nil]. |
894 |
res := nil. |
|
895 |
||
896 |
self criticalDo:[ |
|
2117 | 897 |
res := self nonCriticalKeysAndValuesReverseDo:aTwoArgBlock |
1966 | 898 |
]. |
2081 | 899 |
^ res |
1966 | 900 |
! |
901 |
||
1804 | 902 |
recursiveCollect:aBlock |
903 |
"for each child in the receiver, evaluate the argument, aBlock |
|
904 |
and return a new collection with the results |
|
905 |
" |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
906 |
|coll| |
1804 | 907 |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
908 |
coll := OrderedCollection new. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
909 |
self recursiveDo:[:el| coll add:(aBlock value:el) ]. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
910 |
^ coll |
1804 | 911 |
! |
912 |
||
1390 | 913 |
recursiveDo:aOneArgBlock |
914 |
"evaluate a block on each item and all the sub-items |
|
915 |
" |
|
916 |
self do:[:aChild| |
|
917 |
aOneArgBlock value:aChild. |
|
2117 | 918 |
aChild nonCriticalRecursiveDo:aOneArgBlock |
1390 | 919 |
]. |
920 |
! |
|
921 |
||
1804 | 922 |
recursiveReverseDo:aOneArgBlock |
923 |
"evaluate a block on each item and all the sub-items; |
|
924 |
proccesing children in reverse direction |
|
925 |
" |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
926 |
self reverseDo:[:aChild| |
2117 | 927 |
aChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
928 |
aOneArgBlock value:aChild. |
1804 | 929 |
]. |
930 |
! |
|
931 |
||
932 |
recursiveSelect:aBlock |
|
933 |
"return a new collection with all children and subChildren from the receiver, for which |
|
934 |
the argument aBlock evaluates to true. |
|
935 |
" |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
936 |
|coll| |
1804 | 937 |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
938 |
coll := OrderedCollection new. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
939 |
self recursiveDo:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
940 |
^ coll |
1804 | 941 |
! |
942 |
||
1390 | 943 |
reverseDo:aOneArgBlock |
2081 | 944 |
"evaluate a block on each child in reverse direction |
1390 | 945 |
" |
2081 | 946 |
^ self from:1 reverseDo:aOneArgBlock |
1804 | 947 |
! |
948 |
||
949 |
select:aBlock |
|
2081 | 950 |
"return a new collection with all items from the receiver, for which |
1804 | 951 |
the argument aBlock evaluates to true. |
952 |
" |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
953 |
|coll| |
1831
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
954 |
|
2081 | 955 |
coll := OrderedCollection new. |
956 |
self do:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
|
957 |
^ coll |
|
1876 | 958 |
! |
959 |
||
960 |
withAllDo:aOneArgBlock |
|
2081 | 961 |
"evaluate the block on each item and subitem including self |
1876 | 962 |
" |
2081 | 963 |
aOneArgBlock value:self. |
964 |
||
965 |
self do:[:el| |
|
966 |
aOneArgBlock value:el. |
|
2117 | 967 |
el nonCriticalRecursiveDo:aOneArgBlock. |
1883 | 968 |
]. |
969 |
! ! |
|
1804 | 970 |
|
971 |
!HierarchicalItem methodsFor:'enumerating parents'! |
|
972 |
||
973 |
parentsDetect:aBlock |
|
974 |
"find the first parent, for which evaluation of the block returns |
|
975 |
true; if none does so, report an error |
|
976 |
" |
|
977 |
^ self parentsDetect:aBlock ifNone:[self errorNotFound] |
|
978 |
! |
|
979 |
||
980 |
parentsDetect:aBlock ifNone:anExceptionBlock |
|
981 |
"find the first parent, for which evaluation of the block returns |
|
982 |
true; if none does so, return the evaluation of anExceptionBlock |
|
983 |
" |
|
984 |
|prnt| |
|
985 |
||
986 |
prnt := self. |
|
987 |
||
988 |
self criticalDo:[ |
|
989 |
[(prnt := prnt parent) notNil and:[prnt isHierarchicalItem]] whileTrue:[ |
|
990 |
(aBlock value:prnt) ifTrue:[^ prnt] |
|
991 |
] |
|
992 |
]. |
|
993 |
^ anExceptionBlock value |
|
994 |
! |
|
995 |
||
996 |
parentsDo:aBlock |
|
997 |
"evaluate a block on each parent |
|
998 |
" |
|
999 |
|prnt| |
|
1000 |
||
1001 |
prnt := self. |
|
1002 |
||
1003 |
self criticalDo:[ |
|
1004 |
[(prnt := prnt parent) notNil and:[prnt isHierarchicalItem]] whileTrue:[ |
|
1005 |
aBlock value:prnt |
|
1006 |
] |
|
1007 |
]. |
|
1390 | 1008 |
! ! |
1009 |
||
1010 |
!HierarchicalItem methodsFor:'initialization'! |
|
1011 |
||
1012 |
initialize |
|
1013 |
isExpanded := false |
|
1014 |
! ! |
|
1015 |
||
1016 |
!HierarchicalItem methodsFor:'private'! |
|
1017 |
||
1018 |
addVisibleChildrenTo:aList |
|
1019 |
"add all visible children and sub-children to the list |
|
1020 |
" |
|
2081 | 1021 |
isExpanded == true ifFalse:[^ self]. |
1390 | 1022 |
|
2117 | 1023 |
self nonCriticalFrom:1 to:nil do:[:el| |
2081 | 1024 |
aList add:el. |
1025 |
el addVisibleChildrenTo:aList. |
|
1026 |
]. |
|
1390 | 1027 |
! |
1028 |
||
1733 | 1029 |
criticalDo:aBlock |
1030 |
|model| |
|
1031 |
||
1032 |
(model := self model) notNil ifTrue:[ |
|
1033 |
model recursionLock critical:aBlock |
|
1034 |
] ifFalse:[ |
|
1035 |
aBlock value |
|
1036 |
] |
|
1037 |
! |
|
1038 |
||
1390 | 1039 |
listIndex |
1040 |
"returns the visible index or nil; for a none visible root |
|
1041 |
0 is returned |
|
1042 |
" |
|
1043 |
|index model| |
|
1044 |
||
1045 |
(model := self model) notNil ifTrue:[ |
|
1046 |
index := model identityIndexOf:self. |
|
1047 |
||
1048 |
(index ~~ 0 or:[parent == model]) ifTrue:[ |
|
1049 |
^ index |
|
1050 |
] |
|
1051 |
]. |
|
1052 |
^ nil |
|
1053 |
! |
|
1054 |
||
1055 |
numberOfVisibleChildren |
|
1056 |
"returns number of all visible children including subchildren |
|
1057 |
" |
|
2081 | 1058 |
|size| |
1059 |
||
1060 |
isExpanded == true ifFalse:[^ 0]. |
|
1061 |
size := 0. |
|
1062 |
||
2117 | 1063 |
self nonCriticalFrom:1 to:nil do:[:el| |
2081 | 1064 |
size := 1 + size + el numberOfVisibleChildren |
1390 | 1065 |
]. |
2081 | 1066 |
^ size |
1390 | 1067 |
! |
1068 |
||
1069 |
parentOrModel |
|
1070 |
"returns the parent without checking for item or model |
|
1071 |
" |
|
1072 |
^ parent |
|
1073 |
! |
|
1074 |
||
1075 |
setExpanded:aBoolean |
|
1076 |
"set expanded flag without any computation or notification |
|
1077 |
" |
|
1078 |
isExpanded := aBoolean |
|
1079 |
! ! |
|
1080 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1081 |
!HierarchicalItem methodsFor:'private displaying'! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1082 |
|
1606 | 1083 |
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
|
1084 |
"display the label at x@y |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1085 |
" |
1606 | 1086 |
|y0 hF| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1087 |
|
1606 | 1088 |
lH ~~ 0 ifTrue:[ |
1089 |
y0 := y - (lH + 1 - h // 2). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1090 |
|
1606 | 1091 |
aLabel isImageOrForm ifTrue:[ |
1092 |
^ aLabel displayOn:aGC x:x y:y0 |
|
1093 |
]. |
|
1094 |
y0 := y0 + (aGC font ascent). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1095 |
|
1606 | 1096 |
aLabel isString ifFalse:[ |
1097 |
^ aLabel displayOn:aGC x:x y:y0 |
|
1098 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1099 |
|
1606 | 1100 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
1101 |
^ aLabel displayOn:aGC x:x y:y0 |
|
1102 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1103 |
|
1606 | 1104 |
hF := aGC font height. |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1105 |
|
1606 | 1106 |
aLabel asCollectionOfLines do:[:el| |
1107 |
el displayOn:aGC x:x y:y0. |
|
1108 |
y0 := y0 + hF |
|
1109 |
] |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1110 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1111 |
! |
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 |
heightOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1114 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1115 |
" |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1116 |
|h| |
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 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1119 |
^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1120 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1121 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1122 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1123 |
h := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1124 |
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
|
1125 |
^ h |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1126 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1127 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1128 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1129 |
^ h * (aGC font height) |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1130 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1131 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1132 |
widthOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1133 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1134 |
" |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1135 |
|w| |
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 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1138 |
^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1139 |
]. |
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 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1142 |
w := -5. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1143 |
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
|
1144 |
^ w |
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 indexOf:(Character cr)) == 0 ifTrue:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1148 |
^ aLabel widthOn:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1149 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1150 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1151 |
w := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1152 |
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
|
1153 |
^ w |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1154 |
! ! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1155 |
|
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1156 |
!HierarchicalItem methodsFor:'private enumerating'! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1157 |
|
2117 | 1158 |
nonCriticalDo:aOneArgBlock |
1159 |
"evaluate a block noncritical on each child. |
|
1160 |
" |
|
1161 |
^ self nonCriticalFrom:1 to:nil do:aOneArgBlock |
|
1162 |
! |
|
1163 |
||
1164 |
nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
1165 |
"evaluate a block noncritical on each child starting with the |
|
2081 | 1166 |
child at startIndex to the endIndex (if nil to end of list). |
1167 |
" |
|
1168 |
|list size resp| |
|
1169 |
||
1170 |
list := self children. |
|
1171 |
size := list size. |
|
1172 |
||
1173 |
startIndex > size ifTrue:[^ nil]. |
|
1174 |
resp := nil. |
|
1175 |
||
1176 |
endIndex notNil ifTrue:[ |
|
1177 |
size := size min:endIndex |
|
1178 |
]. |
|
1179 |
startIndex to:size do:[:i| |item| |
|
1180 |
item := list at:i ifAbsent:nil. |
|
1181 |
item isNil ifTrue:[^ resp]. |
|
1182 |
resp := aOneArgBlock value:item. |
|
1183 |
]. |
|
1184 |
^ resp |
|
1185 |
! |
|
1186 |
||
2117 | 1187 |
nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
1188 |
"evaluate a block non critical on each child starting with the |
|
2081 | 1189 |
child at endIndex (if nil to end of list) to startIndex. |
1190 |
" |
|
1191 |
|list size resp| |
|
1192 |
||
1193 |
list := self children. |
|
1194 |
size := list size. |
|
1195 |
resp := nil. |
|
1196 |
||
1197 |
endIndex notNil ifTrue:[ |
|
1198 |
size := size min:endIndex |
|
1199 |
]. |
|
1200 |
size to:startIndex by:-1 do:[:i| |item| |
|
1201 |
item := list at:i ifAbsent:nil. |
|
1202 |
item isNil ifTrue:[^ resp]. |
|
1203 |
resp := aOneArgBlock value:item. |
|
1204 |
]. |
|
1205 |
^ resp |
|
1206 |
! |
|
1207 |
||
2117 | 1208 |
nonCriticalKeysAndValuesReverseDo:aOneArgBlock |
2081 | 1209 |
"evaluate the argument, aBlock in reverse order for every |
1210 |
child, passing both index and element as arguments. |
|
1211 |
" |
|
1212 |
|list size resp| |
|
1213 |
||
1214 |
list := self children. |
|
1215 |
size := list size. |
|
1216 |
resp := nil. |
|
1217 |
||
1218 |
size to:1 by:-1 do:[:i| |item| |
|
1219 |
item := list at:i ifAbsent:nil. |
|
1220 |
item isNil ifTrue:[^ resp]. |
|
1221 |
resp := aOneArgBlock value:i value:item. |
|
1222 |
]. |
|
1223 |
^ resp |
|
1224 |
! |
|
1225 |
||
2117 | 1226 |
nonCriticalRecursiveDo:anOneArgBlock |
1227 |
"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
|
1228 |
" |
2117 | 1229 |
self nonCriticalFrom:1 to:nil do:[:aChild| |
2081 | 1230 |
anOneArgBlock value:aChild. |
2117 | 1231 |
aChild nonCriticalRecursiveDo:anOneArgBlock |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1232 |
]. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1233 |
! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1234 |
|
2117 | 1235 |
nonCriticalRecursiveReverseDo:anOneArgBlock |
1236 |
"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
|
1237 |
proccesing children in reverse direction |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1238 |
" |
2117 | 1239 |
self nonCriticalFrom:1 to:nil reverseDo:[:aChild| |
1240 |
aChild nonCriticalRecursiveReverseDo:anOneArgBlock. |
|
2081 | 1241 |
anOneArgBlock value:aChild. |
2008
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1242 |
]. |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1243 |
! ! |
916175defb9e
add none critical blocks for recursive operations (optimize)
ca
parents:
1974
diff
changeset
|
1244 |
|
1390 | 1245 |
!HierarchicalItem methodsFor:'private hierarchy'! |
1246 |
||
1247 |
recursiveSetCollapsed |
|
1248 |
"collapse all children and sub-children without notifications |
|
1249 |
" |
|
1250 |
isExpanded := false. |
|
1251 |
||
2081 | 1252 |
"/ do not call :#size: children will be autoloaded !!!! |
1253 |
children size ~~ 0 ifTrue:[ |
|
2117 | 1254 |
self nonCriticalFrom:1 to:nil do:[:el| el recursiveSetCollapsed ]. |
1390 | 1255 |
] |
1256 |
! |
|
1257 |
||
1258 |
recursiveSetExpandedAndAddToList:aList |
|
1259 |
"expand all children and sub-children without notifications; |
|
1260 |
add children to list |
|
1261 |
" |
|
1262 |
isExpanded := true. |
|
1263 |
||
2081 | 1264 |
self do:[:anItem| |
1265 |
aList add:anItem. |
|
1266 |
anItem recursiveSetExpandedAndAddToList:aList. |
|
1267 |
]. |
|
1390 | 1268 |
! ! |
1269 |
||
1270 |
!HierarchicalItem methodsFor:'protocol accessing'! |
|
1271 |
||
1272 |
children |
|
1273 |
"returns list of children |
|
1274 |
*** to optimize:redefine by subClass |
|
1275 |
" |
|
1276 |
|model| |
|
1277 |
||
1278 |
children isNil ifTrue:[ |
|
1279 |
(model := self model) notNil ifTrue:[ |
|
1486 | 1280 |
children := model childrenFor:self |
1390 | 1281 |
]. |
1282 |
]. |
|
1283 |
^ children |
|
1284 |
! |
|
1285 |
||
1286 |
icon |
|
1287 |
"returns the icon or nil; |
|
1288 |
*** to optimize:redefine by subClass |
|
1289 |
" |
|
1290 |
|model| |
|
1291 |
||
1292 |
(model := self model) notNil ifTrue:[ |
|
1293 |
^ model iconFor:self |
|
1294 |
]. |
|
1295 |
^ nil |
|
1296 |
! |
|
1297 |
||
1298 |
label |
|
1299 |
"returns the label displayed on aGC; |
|
1300 |
*** to optimize:redefine by subClass |
|
1301 |
" |
|
1302 |
|model| |
|
1303 |
||
1304 |
(model := self model) notNil ifTrue:[ |
|
1305 |
^ model labelFor:self |
|
1306 |
]. |
|
1307 |
^ nil |
|
1308 |
||
1309 |
! |
|
1310 |
||
1311 |
middleButtonMenu |
|
1312 |
"returns the middleButtonMenu or nil if no menu is defined |
|
1313 |
" |
|
1314 |
|model| |
|
1315 |
||
1316 |
(model := self model) notNil ifTrue:[ |
|
1317 |
^ model middleButtonMenuFor:self |
|
1318 |
]. |
|
1319 |
^ nil |
|
1831
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1320 |
! |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1321 |
|
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1322 |
recursiveSortChildren:aSortBlock |
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 |
|children| |
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 := self children) notNil ifTrue:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1327 |
self criticalDo:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1328 |
children sort:aSortBlock. |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1329 |
children do:[:aChild| aChild recursiveSortChildren:aSortBlock ] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1330 |
] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1331 |
]. |
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 |
sortChildren:aSortBlock |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1335 |
|children| |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1336 |
|
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1337 |
(children := self children) notNil ifTrue:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1338 |
self criticalDo:[ |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1339 |
children sort:aSortBlock |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1340 |
] |
8efa00e1247a
sort stuff; height fix when label changes
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1341 |
]. |
1390 | 1342 |
! ! |
1343 |
||
1344 |
!HierarchicalItem methodsFor:'protocol displaying'! |
|
1345 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1489
diff
changeset
|
1346 |
displayOn:aGC x:x y:y h:h |
1390 | 1347 |
"draw the receiver in the graphicsContext, aGC. |
1348 |
" |
|
1349 |
|label |
|
1398 | 1350 |
x0 "{ Class:SmallInteger }" |
1390 | 1351 |
| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1352 |
(label := self label) isNil ifTrue:[^ self]. |
1398 | 1353 |
|
1354 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1606 | 1355 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h |
1398 | 1356 |
]. |
1357 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1358 |
x0 := x. |
1398 | 1359 |
label do:[:el| |
1360 |
el notNil ifTrue:[ |
|
1606 | 1361 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h. |
1398 | 1362 |
x0 := x0 + 5 + (el widthOn:aGC). |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1363 |
]. |
1390 | 1364 |
] |
1365 |
! |
|
1366 |
||
1367 |
heightOn:aGC |
|
1368 |
"return the width of the receiver, if it is to be displayed on aGC |
|
1369 |
" |
|
1606 | 1370 |
height isNil ifTrue:[ |
1371 |
height := self heightOf:(self label) on:aGC |
|
1372 |
]. |
|
1373 |
^ height |
|
1390 | 1374 |
! |
1375 |
||
1376 |
widthOn:aGC |
|
1377 |
"return the width of the receiver, if it is to be displayed on aGC |
|
1378 |
" |
|
1606 | 1379 |
width isNil ifTrue:[ |
1380 |
width := self widthOf:(self label) on:aGC |
|
1381 |
]. |
|
1382 |
^ width |
|
1383 |
||
1390 | 1384 |
! ! |
1385 |
||
1386 |
!HierarchicalItem methodsFor:'protocol monitoring'! |
|
1387 |
||
1388 |
monitoringCycle |
|
1389 |
"called all 'n' seconds by the model, if the monitoring |
|
1390 |
cycle is enabled. The item can perform some checks, .. |
|
1391 |
**** can be redefined by subclass to perform some actions |
|
1392 |
" |
|
1393 |
! ! |
|
1394 |
||
1395 |
!HierarchicalItem methodsFor:'protocol queries'! |
|
1396 |
||
1571 | 1397 |
drawHorizontalLineUpToText |
1398 |
"draw the horizizontal line for the selected item up to the text |
|
1399 |
or on default to the start of the the vertical line; only used by |
|
1400 |
the hierarchical view |
|
1401 |
" |
|
1402 |
^ false |
|
1403 |
! |
|
1404 |
||
1390 | 1405 |
hasChildren |
1406 |
"checks whether the item has a list of children; the list must not |
|
1407 |
be loaded yet( ex. FileDirectory ). |
|
1408 |
*** to optimize:redefine by subClass |
|
1409 |
" |
|
2081 | 1410 |
^ self children size ~~ 0 |
1390 | 1411 |
! |
1412 |
||
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1413 |
hasIndicator |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1414 |
"on default the indicator is drawn if the item |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1415 |
has children |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1416 |
" |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1417 |
^ self hasChildren |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1418 |
! |
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1419 |
|
1390 | 1420 |
string |
1421 |
"access the printable string used for steping through a list |
|
1422 |
searching for an entry starting with a character. |
|
1423 |
*** to optimize:redefine by subClass |
|
1424 |
" |
|
1398 | 1425 |
|label| |
1426 |
||
1427 |
(label := self label) notNil ifTrue:[ |
|
1428 |
label isString ifTrue:[ ^ label string ]. |
|
1429 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
1430 |
||
1431 |
label isSequenceable ifFalse:[ |
|
1432 |
^ label perform:#string ifNotUnderstood:nil |
|
1433 |
]. |
|
1434 |
||
1435 |
label do:[:el||s| |
|
1436 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
1437 |
s := el perform:#string ifNotUnderstood:nil. |
|
1438 |
s notNil ifTrue:[^ s]. |
|
1439 |
] |
|
1440 |
] |
|
1441 |
]. |
|
1442 |
^ nil |
|
1443 |
||
1390 | 1444 |
|
1445 |
! ! |
|
1446 |
||
1447 |
!HierarchicalItem methodsFor:'queries'! |
|
1448 |
||
1449 |
canCollapse |
|
1450 |
"called before collapsing the item |
|
1451 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1452 |
^ (isExpanded == true) |
1390 | 1453 |
! |
1454 |
||
1455 |
canExpand |
|
1456 |
"called before expanding the item |
|
1457 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1458 |
^ (isExpanded == true) not and:[self hasChildren] |
1390 | 1459 |
! |
1460 |
||
1804 | 1461 |
isChildOf:anItem |
1462 |
"returns true if the item is a child of anItem |
|
1463 |
" |
|
1464 |
|item| |
|
1465 |
||
1466 |
item := self. |
|
1467 |
||
1468 |
[anItem ~~ item] whileTrue:[ |
|
1469 |
((item := item parent) notNil and:[item isHierarchicalItem]) ifFalse:[ |
|
1470 |
^ false |
|
1471 |
] |
|
1472 |
]. |
|
1473 |
^ true |
|
1474 |
||
1475 |
! |
|
1476 |
||
1390 | 1477 |
isExpanded |
1478 |
"return true if item is expanded |
|
1479 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1480 |
^ (isExpanded == true) |
1390 | 1481 |
! |
1482 |
||
1483 |
isHierarchicalItem |
|
1484 |
"used to decide if the parent is a hierarchical item |
|
1485 |
or the model |
|
1486 |
" |
|
1487 |
^ true |
|
1488 |
! |
|
1489 |
||
2033 | 1490 |
isRealChildOf:anItem |
1491 |
"returns true if the item is a child of anItem |
|
1492 |
" |
|
1493 |
|item| |
|
1494 |
item := self parent. |
|
1495 |
||
1496 |
[item notNil] whileTrue:[ |
|
1497 |
item == anItem ifTrue:[^ true]. |
|
1498 |
item := item parent. |
|
1499 |
]. |
|
1500 |
^ false |
|
1501 |
! |
|
1502 |
||
1876 | 1503 |
isRootItem |
1504 |
"returns true if the item is the root item |
|
1505 |
" |
|
1883 | 1506 |
^ parent isHierarchicalItem not |
1507 |
! |
|
1876 | 1508 |
|
1650 | 1509 |
isSelectable |
1510 |
"returns true if the item is selectable otherwise false |
|
1511 |
" |
|
1512 |
^ true |
|
1513 |
! |
|
1514 |
||
1390 | 1515 |
size |
1516 |
"return the number of children |
|
1517 |
" |
|
2081 | 1518 |
^ self children size |
1390 | 1519 |
! ! |
1520 |
||
1521 |
!HierarchicalItem methodsFor:'searching'! |
|
1522 |
||
1523 |
detect:aOneArgBlock |
|
1524 |
"find the first child, for which evaluation of the block returns |
|
1525 |
true; if none does so, report an error |
|
1526 |
" |
|
1527 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
|
1528 |
||
1529 |
! |
|
1530 |
||
2081 | 1531 |
detect:anOneArgBlock ifNone:anExceptionBlock |
1390 | 1532 |
"find the first child, for which evaluation of the block returns |
1533 |
true; if none does so, return the evaluation of anExceptionBlock |
|
1534 |
" |
|
2081 | 1535 |
self do:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ]. |
1536 |
^ anExceptionBlock value |
|
1804 | 1537 |
! |
1538 |
||
1539 |
detectLast:aOneArgBlock |
|
1540 |
"find the last child, for which evaluation of the block returns |
|
1541 |
true; if none does so, an exception is raised |
|
1542 |
" |
|
1543 |
^ self detectLast:aOneArgBlock ifNone:[self errorNotFound] |
|
1544 |
||
1545 |
! |
|
1546 |
||
2081 | 1547 |
detectLast:anOneArgBlock ifNone:anExceptionBlock |
1804 | 1548 |
"find the last child, for which evaluation of the block returns |
1549 |
true; if none does so, return the evaluation of anExceptionBlock |
|
1550 |
" |
|
2081 | 1551 |
self reverseDo:[:el| (anOneArgBlock value:el) ifTrue:[^ el] ]. |
1552 |
^ anExceptionBlock value |
|
1390 | 1553 |
! |
1554 |
||
2081 | 1555 |
findFirst:anOneArgBlock |
1966 | 1556 |
"find the first child, for which evaluation of the argument, aOneArgBlock |
1557 |
returns true; return its index or 0 if none detected. |
|
1558 |
" |
|
2081 | 1559 |
self keysAndValuesDo:[:i :el| (anOneArgBlock value:el) ifTrue:[^ i] ]. |
1560 |
^ 0 |
|
1966 | 1561 |
! |
1562 |
||
2081 | 1563 |
findLast:anOneArgBlock |
1966 | 1564 |
"find the last child, for which evaluation of the argument, aOneArgBlock |
1565 |
returns true; return its index or 0 if none detected. |
|
1566 |
" |
|
2081 | 1567 |
self keysAndValuesReverseDo:[:i :el| (anOneArgBlock value:el) ifTrue:[^ i] ]. |
1568 |
^ 0 |
|
1966 | 1569 |
! |
1570 |
||
1390 | 1571 |
identityIndexOf:aChild |
1572 |
"return the index of aChild or 0 if not found. Compare using == |
|
1573 |
" |
|
1733 | 1574 |
^ self identityIndexOf:aChild startingAt:1 |
1390 | 1575 |
! |
1576 |
||
1577 |
identityIndexOf:aChild startingAt:startIndex |
|
1578 |
"return the index of aChild, starting search at startIndex. |
|
1579 |
Compare using ==; return 0 if not found |
|
1580 |
" |
|
1733 | 1581 |
|index| |
1582 |
||
2081 | 1583 |
index := startIndex. |
1733 | 1584 |
|
2081 | 1585 |
self from:startIndex do:[:el| |
1586 |
el == aChild ifTrue:[^ index ]. |
|
1587 |
index := index + 1. |
|
1390 | 1588 |
]. |
2081 | 1589 |
^ 0 |
1489 | 1590 |
! |
1591 |
||
1592 |
recursiveDetect:aOneArgBlock |
|
1593 |
"recursive find the first child, for which evaluation |
|
1594 |
of the block returns true; if none nil is returned |
|
1595 |
" |
|
1804 | 1596 |
self recursiveDo:[:aChild| |
1597 |
(aOneArgBlock value:aChild) ifTrue:[^ aChild] |
|
1598 |
]. |
|
1599 |
^ nil |
|
1600 |
! |
|
1489 | 1601 |
|
1804 | 1602 |
recursiveDetectLast:aBlock |
1603 |
"find the last child, for which evaluation of the block returns |
|
1604 |
true; if none does so, nil id returned |
|
1605 |
" |
|
1606 |
self recursiveReverseDo:[:aChild| |
|
1607 |
(aBlock value:aChild) ifTrue:[^ aChild]. |
|
1489 | 1608 |
]. |
1609 |
^ nil |
|
1876 | 1610 |
! |
1611 |
||
1612 |
withAllDetect:aOneArgBlock |
|
1613 |
"recursive find the first item including self, for which evaluation |
|
1614 |
of the block returns true; if none nil is returned |
|
1615 |
" |
|
1616 |
(aOneArgBlock value:self) ifTrue:[^ self]. |
|
1617 |
||
1883 | 1618 |
^ self recursiveDetect:aOneArgBlock |
1619 |
! ! |
|
1390 | 1620 |
|
1621 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
|
1622 |
||
1623 |
labeled:aLabel |
|
1624 |
^ self new setLabel:aLabel |
|
1625 |
||
1626 |
||
1627 |
! |
|
1628 |
||
1629 |
labeled:aLabel icon:anIcon |
|
1630 |
^ self new setLabel:aLabel icon:anIcon |
|
1631 |
||
1632 |
||
1633 |
! ! |
|
1634 |
||
1635 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
1636 |
||
1637 |
iconForLevel:aLevel |
|
1638 |
"returns an icon |
|
1639 |
" |
|
1640 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
1641 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
1642 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
1643 |
||
1644 |
^ nil |
|
1645 |
||
1646 |
! |
|
1647 |
||
1648 |
penguinIcon |
|
1649 |
PenguinIcon isNil ifTrue:[ |
|
1794 | 1650 |
PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm' |
1651 |
inPackage:'stx:goodies' |
|
1390 | 1652 |
]. |
1653 |
^ PenguinIcon |
|
1654 |
! ! |
|
1655 |
||
1656 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
1657 |
||
1658 |
children |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1659 |
|lvl lbl txt image img icon tmp| |
1390 | 1660 |
|
1661 |
children notNil ifTrue:[ |
|
1662 |
^ children |
|
1663 |
]. |
|
1664 |
||
1665 |
(lvl := self level) == 5 ifTrue:[ |
|
1666 |
children := #(). |
|
1667 |
^ children |
|
1668 |
]. |
|
1669 |
icon := self class iconForLevel:(lvl + 1). |
|
1670 |
children := OrderedCollection new. |
|
1671 |
||
1672 |
lvl < 4 ifTrue:[ |
|
1673 |
txt := (lvl + 1) printString, ' ['. |
|
1674 |
img := NewLauncher saveImageIcon. |
|
1675 |
||
1676 |
1 to:5 do:[:i| |
|
1677 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
1678 |
lbl := img |
|
1679 |
] ifFalse:[ |
|
1680 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1681 |
lbl := Array with:(self class penguinIcon) |
1733 | 1682 |
with:('penguin#and#text' replaceAll:$# with:(Character cr)). |
1390 | 1683 |
] ifFalse:[ |
1684 |
lbl := txt, (i printString), ']' |
|
1685 |
] |
|
1686 |
]. |
|
1687 |
children add:(self class labeled:lbl icon:icon) |
|
1688 |
]. |
|
1689 |
] ifFalse:[ |
|
1690 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
1691 |
txt := LabelAndIcon icon:image string:'Text'. |
|
1692 |
img := Icon copyIcon. |
|
1693 |
||
1694 |
1 to:5 do:[:i| |
|
1695 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 1696 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 1697 |
children add:(self class labeled:lbl icon:icon). |
1698 |
] |
|
1699 |
]. |
|
1700 |
||
1701 |
children do:[:aChild| aChild parent:self ]. |
|
1702 |
^ children |
|
1703 |
! |
|
1704 |
||
1705 |
icon |
|
1706 |
"returns the icon |
|
1707 |
" |
|
1708 |
^ icon |
|
1709 |
! |
|
1710 |
||
1711 |
icon:anIcon |
|
1712 |
"set the icon; if icon changed, a notification |
|
1713 |
is raised. |
|
1714 |
" |
|
1715 |
icon ~= anIcon ifTrue:[ |
|
1716 |
icon := anIcon. |
|
1717 |
self iconChanged |
|
1718 |
] |
|
1719 |
! |
|
1720 |
||
1721 |
label |
|
1722 |
"returns the label |
|
1723 |
" |
|
1724 |
^ label |
|
1725 |
||
1726 |
! |
|
1727 |
||
1728 |
label:aLabel |
|
1729 |
"set the label; if label changed, a notification |
|
1730 |
is raised. |
|
1731 |
" |
|
1732 |
label ~= aLabel ifTrue:[ |
|
1733 |
label := aLabel. |
|
1734 |
self changed. |
|
1735 |
] |
|
1736 |
||
1737 |
! |
|
1738 |
||
1739 |
setIcon:anIcon |
|
1740 |
"set the icon without any change notification |
|
1741 |
" |
|
1742 |
icon := anIcon |
|
1743 |
! |
|
1744 |
||
1745 |
setLabel:aLabel |
|
1746 |
"set the label without any change notification |
|
1747 |
" |
|
1748 |
label := aLabel |
|
1749 |
! |
|
1750 |
||
1751 |
setLabel:aLabel icon:anIcon |
|
1752 |
"set the label and icon without any change notification |
|
1753 |
" |
|
1754 |
label := aLabel. |
|
1755 |
icon := anIcon. |
|
1756 |
! ! |
|
1757 |
||
1758 |
!HierarchicalItem class methodsFor:'documentation'! |
|
1759 |
||
1760 |
version |
|
2201
aa74fa6137a5
make indicator dependent on hasIndicator and not hasChildren
ca
parents:
2193
diff
changeset
|
1761 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.40 2002-09-19 09:17:15 ca Exp $' |
1390 | 1762 |
! ! |