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