author | ca |
Wed, 02 Feb 2000 12:37:49 +0100 | |
changeset 1669 | 443680316aac |
parent 1650 | 9ac3cdd8572d |
child 1733 | 67c144581e63 |
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 |
||
1390 | 14 |
Object subclass:#HierarchicalItem |
1606 | 15 |
instanceVariableNames:'parent children isExpanded height width' |
1390 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
1430 | 18 |
category:'Views-Support' |
1390 | 19 |
! |
20 |
||
21 |
HierarchicalItem subclass:#Example |
|
22 |
instanceVariableNames:'label icon' |
|
23 |
classVariableNames:'PenguinIcon' |
|
24 |
poolDictionaries:'' |
|
25 |
privateIn:HierarchicalItem |
|
26 |
! |
|
27 |
||
28 |
!HierarchicalItem class methodsFor:'documentation'! |
|
29 |
||
1431 | 30 |
copyright |
31 |
" |
|
32 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
! |
|
44 |
||
1390 | 45 |
documentation |
46 |
" |
|
47 |
Hierarchical Items are mostly like Models, but the list of |
|
48 |
dependencies are kept by its HierarchicalList. |
|
49 |
The class is used to build up hierarchical trees. |
|
50 |
||
51 |
[Instance variables:] |
|
52 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
53 |
children <Collection or nil> list of children |
|
54 |
isExpanded <Boolean> indicates whether the item is |
|
55 |
expanded or collapsed |
|
56 |
||
57 |
[author:] |
|
58 |
Claus Atzkern |
|
59 |
||
60 |
[see also:] |
|
61 |
HierarchicalList |
|
62 |
HierarchicalListView |
|
63 |
" |
|
64 |
||
65 |
||
66 |
! ! |
|
67 |
||
68 |
!HierarchicalItem class methodsFor:'instance creation'! |
|
69 |
||
70 |
new |
|
71 |
^ (self basicNew) initialize |
|
72 |
! ! |
|
73 |
||
74 |
!HierarchicalItem methodsFor:'accessing'! |
|
75 |
||
76 |
level |
|
77 |
"returns the level starting with 1 |
|
78 |
" |
|
79 |
|parent |
|
80 |
level "{ Class:SmallInteger }" |
|
81 |
| |
|
82 |
level := 0. |
|
83 |
parent := self. |
|
84 |
||
85 |
[(parent := parent parentOrModel) notNil] whileTrue:[ |
|
86 |
level := level + 1 |
|
87 |
]. |
|
88 |
^ level |
|
89 |
||
90 |
! |
|
91 |
||
92 |
parent |
|
93 |
"returns the parent or nil |
|
94 |
" |
|
95 |
^ (parent notNil and:[parent isHierarchicalItem]) ifTrue:[parent] |
|
96 |
ifFalse:[nil] |
|
97 |
! |
|
98 |
||
99 |
parent:aParent |
|
100 |
"set the parent (or the model if the item is the root item) |
|
101 |
" |
|
102 |
parent := aParent |
|
103 |
||
104 |
! ! |
|
105 |
||
106 |
!HierarchicalItem methodsFor:'accessing children'! |
|
107 |
||
108 |
at:anIndex |
|
109 |
"returns the child under an index or nil |
|
110 |
" |
|
111 |
^ self children notNil ifTrue:[children at:anIndex ifAbsent:nil] |
|
112 |
ifFalse:[nil] |
|
113 |
! |
|
114 |
||
115 |
at:anIndex put:anItem |
|
116 |
"replace a child by a new item |
|
117 |
" |
|
118 |
|oldItem itemExpanded size| |
|
119 |
||
120 |
size := self children size. |
|
121 |
||
122 |
(anIndex between:1 and:size) ifFalse:[ |
|
123 |
^ self subscriptBoundsError |
|
124 |
]. |
|
125 |
||
126 |
anItem isNil ifTrue:[ |
|
127 |
^ self removeFromIndex:anIndex toIndex:anIndex. |
|
128 |
]. |
|
129 |
||
130 |
oldItem := children at:anIndex. |
|
131 |
oldItem collapse. |
|
132 |
itemExpanded := anItem isExpanded. |
|
133 |
anItem setExpanded:false. |
|
134 |
children at:anIndex put:anItem. |
|
135 |
self changed. |
|
136 |
||
137 |
itemExpanded ifTrue:[ |
|
138 |
anItem expand |
|
139 |
]. |
|
140 |
! |
|
141 |
||
142 |
children:aListOfChildren |
|
143 |
"set a new list of children |
|
144 |
" |
|
145 |
self removeAll. |
|
146 |
^ self addAll:aListOfChildren beforeIndex:1 |
|
147 |
! |
|
148 |
||
149 |
first |
|
150 |
"returns the first child |
|
151 |
" |
|
152 |
^ self at:1 |
|
153 |
! |
|
154 |
||
155 |
last |
|
156 |
"returns the last child |
|
157 |
" |
|
158 |
^ self at:(self children size) |
|
159 |
! ! |
|
160 |
||
161 |
!HierarchicalItem methodsFor:'accessing hierarchy'! |
|
162 |
||
163 |
collapse |
|
164 |
"hide children |
|
165 |
" |
|
166 |
|visChd model index| |
|
167 |
||
168 |
self canCollapse ifTrue:[ |
|
169 |
isExpanded := false. |
|
170 |
||
171 |
(index := self listIndex) notNil ifTrue:[ |
|
172 |
(visChd := children size) ~~ 0 ifTrue:[ |
|
173 |
children do:[:aChild| |
|
174 |
visChd := visChd + aChild numberOfVisibleChildren |
|
175 |
]. |
|
176 |
self model itemRemoveFromIndex:(index + 1) |
|
177 |
toIndex:(index + visChd). |
|
178 |
||
179 |
index ~~ 0 ifTrue:[ |
|
180 |
self hierarchyChanged |
|
181 |
] |
|
182 |
] |
|
183 |
] |
|
184 |
] |
|
185 |
! |
|
186 |
||
187 |
expand |
|
188 |
"expand children |
|
189 |
" |
|
190 |
|index list| |
|
191 |
||
192 |
self canExpand ifTrue:[ |
|
193 |
isExpanded := true. |
|
194 |
||
195 |
(index := self listIndex) notNil ifTrue:[ |
|
196 |
(children notNil or:[self children notNil]) ifTrue:[ |
|
197 |
children notEmpty ifTrue:[ |
|
198 |
list := OrderedCollection new:64. |
|
199 |
self addVisibleChildrenTo:list. |
|
200 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
201 |
]. |
|
202 |
index ~~ 0 ifTrue:[ |
|
203 |
self hierarchyChanged |
|
204 |
] |
|
205 |
] |
|
206 |
] |
|
207 |
] |
|
208 |
||
209 |
! |
|
210 |
||
1409 | 211 |
makeVisible |
212 |
"expand all my parents |
|
213 |
" |
|
214 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
|
215 |
parent expand. |
|
216 |
parent makeVisible |
|
217 |
]. |
|
218 |
! |
|
219 |
||
1390 | 220 |
recursiveCollapse |
221 |
"collapse children and sub-children |
|
222 |
**** must be expanded |
|
223 |
" |
|
224 |
|visChd index| |
|
225 |
||
226 |
self canCollapse ifTrue:[ |
|
227 |
(index := self listIndex) notNil ifTrue:[ |
|
228 |
(visChd := children size) ~~ 0 ifTrue:[ |
|
229 |
children do:[:aChild| |
|
230 |
visChd := visChd + aChild numberOfVisibleChildren |
|
231 |
] |
|
232 |
]. |
|
233 |
self recursiveSetCollapsed. |
|
234 |
||
235 |
visChd ~~ 0 ifTrue:[ |
|
236 |
self model itemRemoveFromIndex:(index + 1) |
|
237 |
toIndex:(index + visChd) |
|
238 |
]. |
|
239 |
index ~~ 0 ifTrue:[ |
|
240 |
self hierarchyChanged |
|
241 |
] |
|
242 |
] ifFalse:[ |
|
243 |
self recursiveSetCollapsed |
|
244 |
] |
|
245 |
] |
|
246 |
||
247 |
! |
|
248 |
||
249 |
recursiveExpand |
|
250 |
"expand children and sub-children |
|
251 |
**** must be collapsed |
|
252 |
" |
|
253 |
|model index list| |
|
254 |
||
255 |
self canExpand ifTrue:[ |
|
256 |
isExpanded := true. |
|
257 |
||
258 |
self children size ~~ 0 ifTrue:[ |
|
259 |
(index := self listIndex) isNil ifTrue:[ |
|
260 |
children do:[:aChild| aChild setExpanded:true ] |
|
261 |
] ifFalse:[ |
|
262 |
list := OrderedCollection new:512. |
|
263 |
self recursiveSetExpandedAndAddToList:list. |
|
264 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
265 |
||
266 |
index ~~ 0 ifTrue:[ |
|
267 |
self hierarchyChanged |
|
268 |
] |
|
269 |
] |
|
270 |
] |
|
271 |
] |
|
272 |
! |
|
273 |
||
274 |
recursiveToggleExpand |
|
275 |
"if the item is collapsed, the children and all sub-children |
|
276 |
are expanded otherwise collapsed |
|
277 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
278 |
(isExpanded == true) ifTrue:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
279 |
self recursiveCollapse |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
280 |
] ifFalse:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
281 |
self recursiveExpand |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
282 |
] |
1390 | 283 |
|
284 |
! |
|
285 |
||
286 |
toggleExpand |
|
287 |
"if the item is collapsed, the children are expanded |
|
288 |
otherwise collapsed |
|
289 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
290 |
(isExpanded == true) ifTrue:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
291 |
self collapse |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
292 |
] ifFalse:[ |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
293 |
self expand |
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
294 |
] |
1390 | 295 |
|
296 |
! ! |
|
297 |
||
298 |
!HierarchicalItem methodsFor:'accessing mvc'! |
|
299 |
||
300 |
application |
|
301 |
"returns the responsible application or nil |
|
302 |
" |
|
303 |
|model| |
|
304 |
||
305 |
(model := self model) notNil ifTrue:[ |
|
306 |
^ model application |
|
307 |
]. |
|
308 |
^ nil |
|
309 |
! |
|
310 |
||
311 |
applicationsDo:aOneArgBlock |
|
312 |
"evaluate the block on each dependent application |
|
313 |
" |
|
314 |
|model| |
|
315 |
||
316 |
(model := self model) notNil ifTrue:[ |
|
317 |
model applicationsDo:aOneArgBlock |
|
318 |
] |
|
319 |
||
320 |
! |
|
321 |
||
322 |
model |
|
323 |
"returns the hierachicalList model or nil |
|
324 |
" |
|
325 |
|p model| |
|
326 |
||
327 |
model := self. |
|
328 |
[(p := model parentOrModel) notNil] whileTrue:[model := p]. |
|
329 |
^ model isHierarchicalItem ifFalse:[model] ifTrue:[nil] |
|
330 |
! ! |
|
331 |
||
332 |
!HierarchicalItem methodsFor:'adding & removing'! |
|
333 |
||
334 |
add:aChildItem |
|
335 |
"add a child at end |
|
336 |
" |
|
337 |
^ self add:aChildItem beforeIndex:(self children size + 1). |
|
338 |
||
339 |
! |
|
340 |
||
341 |
add:aChildItem after:aChild |
|
342 |
"add an item after an existing item |
|
343 |
" |
|
344 |
|index| |
|
345 |
||
1539 | 346 |
(index := self identityIndexOf:aChild) ~~ 0 ifTrue:[ |
1390 | 347 |
self subscriptBoundsError |
348 |
] ifFalse:[ |
|
349 |
self add:aChildItem beforeIndex:(index + 1) |
|
350 |
]. |
|
351 |
^ aChildItem |
|
352 |
! |
|
353 |
||
354 |
add:aChildItem afterIndex:anIndex |
|
355 |
"add an item after an index |
|
356 |
" |
|
357 |
^ self add:aChildItem beforeIndex:(anIndex + 1). |
|
358 |
! |
|
359 |
||
360 |
add:aChildItem before:aChild |
|
361 |
"add an item before an existing item |
|
362 |
" |
|
363 |
|index| |
|
364 |
||
365 |
(index := self identityIndexOf:aChild) ~~ 0 ifTrue:[ |
|
366 |
^ self add:aChildItem beforeIndex:index |
|
367 |
]. |
|
368 |
self subscriptBoundsError |
|
369 |
! |
|
370 |
||
371 |
add:aChildItem beforeIndex:anIndex |
|
372 |
"add an item before an index |
|
373 |
" |
|
374 |
aChildItem notNil ifTrue:[ |
|
375 |
self addAll:(Array with:aChildItem) beforeIndex:anIndex |
|
376 |
]. |
|
377 |
^ aChildItem |
|
378 |
! |
|
379 |
||
1488 | 380 |
add:aChild sortBlock:aBlock |
381 |
"add a child sorted |
|
382 |
" |
|
383 |
(aBlock notNil and:[children size ~~ 0]) ifTrue:[ |
|
384 |
children keysAndValuesDo:[:index :child| |
|
385 |
(aBlock value:aChild value:child) ifTrue:[ |
|
386 |
^ self add:aChild beforeIndex:index |
|
387 |
] |
|
388 |
] |
|
389 |
]. |
|
390 |
^ self add:aChild |
|
391 |
! |
|
392 |
||
1390 | 393 |
addAll:aList |
394 |
"add children at the end |
|
395 |
" |
|
396 |
^ self addAll:aList beforeIndex:(self children size + 1) |
|
397 |
! |
|
398 |
||
1650 | 399 |
addAll:aList before:aChild |
400 |
"add an item before an existing item |
|
401 |
" |
|
402 |
|index| |
|
403 |
||
404 |
(index := self identityIndexOf:aChild) ~~ 0 ifTrue:[ |
|
405 |
^ self addAll:aList beforeIndex:index |
|
406 |
]. |
|
407 |
self subscriptBoundsError |
|
408 |
! |
|
409 |
||
1390 | 410 |
addAll:aList beforeIndex:anIndex |
411 |
"add children before an index |
|
412 |
" |
|
1602 | 413 |
|coll model notify index size| |
1390 | 414 |
|
415 |
(aList isNil or:[aList isEmpty]) ifTrue:[ |
|
416 |
^ aList |
|
417 |
]. |
|
418 |
size := self children size. |
|
419 |
||
420 |
anIndex == 1 ifTrue:[ |
|
421 |
notify := self |
|
422 |
] ifFalse:[ |
|
423 |
anIndex > size ifTrue:[ |
|
424 |
anIndex > (1 + size) ifTrue:[ |
|
425 |
^ self subscriptBoundsError |
|
426 |
]. |
|
427 |
notify := self at:size |
|
428 |
] ifFalse:[ |
|
429 |
notify := nil |
|
430 |
] |
|
431 |
]. |
|
1669 | 432 |
children isArray ifTrue:[ |
433 |
children := children asOrderedCollection |
|
434 |
]. |
|
1390 | 435 |
|
436 |
size == 0 ifTrue:[ |
|
437 |
children := OrderedCollection new |
|
438 |
]. |
|
439 |
aList do:[:anItem| anItem parent:self ]. |
|
440 |
children addAll:aList beforeIndex:anIndex. |
|
441 |
||
442 |
(model := self model) isNil ifTrue:[ |
|
443 |
^ aList |
|
444 |
]. |
|
445 |
||
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
446 |
(isExpanded == true) ifFalse:[ |
1390 | 447 |
notify notNil ifTrue:[ |
448 |
notify changed |
|
449 |
]. |
|
450 |
^ aList |
|
451 |
]. |
|
452 |
(index := self listIndex) isNil ifTrue:[ |
|
453 |
^ aList |
|
454 |
]. |
|
455 |
||
456 |
children from:1 to:(anIndex - 1) do:[:anItem| |
|
457 |
index := 1 + index + anItem numberOfVisibleChildren |
|
458 |
]. |
|
459 |
coll := OrderedCollection new. |
|
460 |
||
461 |
aList do:[:anItem| |
|
462 |
coll add:anItem. |
|
463 |
anItem addVisibleChildrenTo:coll. |
|
464 |
]. |
|
465 |
model itemAddAll:coll beforeIndex:(index + 1). |
|
466 |
||
467 |
notify notNil ifTrue:[ |
|
468 |
notify changed |
|
469 |
]. |
|
470 |
^ aList |
|
471 |
! |
|
472 |
||
1489 | 473 |
addAll:aList sortBlock:aBlock |
474 |
"add children sorted |
|
475 |
" |
|
476 |
aList notNil ifTrue:[ |
|
477 |
aBlock isNil ifTrue:[ |
|
478 |
^ self addAll:aList |
|
479 |
]. |
|
480 |
aList do:[:el|self add:el sortBlock:aBlock] |
|
481 |
]. |
|
482 |
^ aList |
|
483 |
! |
|
484 |
||
1390 | 485 |
addAllFirst:aCollectionOfItems |
486 |
"add children at the beginning |
|
487 |
" |
|
488 |
^ self addAll:aCollectionOfItems beforeIndex:1 |
|
489 |
! |
|
490 |
||
491 |
addAllLast:aCollectionOfItems |
|
492 |
"add children at the end |
|
493 |
" |
|
494 |
^ self addAll:aCollectionOfItems |
|
495 |
! |
|
496 |
||
497 |
addFirst:aChildItem |
|
498 |
"add a child at begin |
|
499 |
" |
|
500 |
^ self add:aChildItem beforeIndex:1. |
|
501 |
||
502 |
! |
|
503 |
||
504 |
addLast:anItem |
|
505 |
"add a child at end |
|
506 |
" |
|
507 |
^ self add:anItem |
|
508 |
! |
|
509 |
||
510 |
remove:aChild |
|
511 |
"remove a child |
|
512 |
" |
|
513 |
self removeIndex:(self identityIndexOf:aChild) |
|
514 |
||
515 |
! |
|
516 |
||
517 |
removeAll |
|
518 |
"remove all children |
|
519 |
" |
|
520 |
|size| |
|
521 |
||
522 |
(size := self children size) ~~ 0 ifTrue:[ |
|
523 |
self removeFromIndex:1 toIndex:size |
|
524 |
] |
|
525 |
! |
|
526 |
||
1489 | 527 |
removeAll:aList |
528 |
"remove all children in the collection |
|
529 |
" |
|
530 |
|index| |
|
531 |
||
532 |
aList size ~~ 0 ifTrue:[ |
|
533 |
aList do:[:el| |
|
534 |
index := self identityIndexOf:el. |
|
535 |
index ~~ 0 ifTrue:[ |
|
536 |
self removeIndex:index |
|
537 |
] |
|
538 |
] |
|
539 |
] |
|
540 |
! |
|
541 |
||
1390 | 542 |
removeFromIndex:startIndex toIndex:stopIndex |
543 |
"remove the children from startIndex up to and including |
|
544 |
the child under stopIndex. |
|
545 |
" |
|
546 |
|model notify |
|
547 |
index "{ Class:SmallInteger }" |
|
548 |
start "{ Class:SmallInteger }" |
|
549 |
stop "{ Class:SmallInteger }" |
|
550 |
size "{ Class:SmallInteger }" |
|
551 |
| |
|
552 |
size := self children size. |
|
553 |
stop := stopIndex. |
|
554 |
start := startIndex. |
|
555 |
||
556 |
(stop <= size and:[start between:1 and:stop]) ifFalse:[ |
|
557 |
^ self subscriptBoundsError |
|
558 |
]. |
|
559 |
start == 1 ifTrue:[ |
|
560 |
notify := self |
|
561 |
] ifFalse:[ |
|
562 |
stop == size ifTrue:[ |
|
563 |
notify := self at:(start - 1) |
|
564 |
] ifFalse:[ |
|
565 |
notify := nil |
|
566 |
] |
|
567 |
]. |
|
568 |
||
569 |
(model := self model) notNil ifTrue:[ |
|
570 |
index := model identityIndexOf:(children at:start). |
|
571 |
size := stop - start + 1. |
|
572 |
] ifFalse:[ |
|
573 |
index := 0 |
|
574 |
]. |
|
1669 | 575 |
|
1390 | 576 |
children from:start to:stop do:[:aChild| |
577 |
index ~~ 0 ifTrue:[ |
|
578 |
size := size + aChild numberOfVisibleChildren |
|
579 |
]. |
|
580 |
aChild parent:nil |
|
581 |
]. |
|
582 |
children removeFromIndex:start toIndex:stop. |
|
583 |
||
584 |
index ~~ 0 ifTrue:[ |
|
585 |
model itemRemoveFromIndex:index toIndex:(index + size - 1) |
|
586 |
]. |
|
587 |
notify notNil ifTrue:[ |
|
588 |
notify changed |
|
589 |
]. |
|
590 |
! |
|
591 |
||
592 |
removeIndex:anIndex |
|
593 |
"remove the child at an index |
|
594 |
" |
|
595 |
anIndex > 0 ifTrue:[ |
|
596 |
self removeFromIndex:anIndex toIndex:anIndex |
|
597 |
] |
|
598 |
! ! |
|
599 |
||
600 |
!HierarchicalItem methodsFor:'change & update'! |
|
601 |
||
602 |
changed |
|
603 |
"the item changed; raise change notification |
|
604 |
" |
|
605 |
self changed:nil with:nil |
|
606 |
! |
|
607 |
||
608 |
changed:aParameter |
|
609 |
"the item changed; raise change notification |
|
610 |
" |
|
611 |
self changed:aParameter with:nil |
|
612 |
||
613 |
! |
|
614 |
||
1606 | 615 |
changed:what with:anArgument |
1390 | 616 |
"the item changed; raise change notification |
617 |
" |
|
618 |
|model| |
|
619 |
||
1606 | 620 |
(what ~~ #hierarchy and:[what ~~ #icon]) ifTrue:[ |
621 |
width := nil |
|
622 |
]. |
|
1390 | 623 |
|
1606 | 624 |
(model := self model) notNil ifTrue:[ |
625 |
model itemChanged:what with:anArgument from:self |
|
1390 | 626 |
]. |
1606 | 627 |
super changed:what with:anArgument |
1390 | 628 |
! |
629 |
||
630 |
hierarchyChanged |
|
631 |
"hierarchy changed; optimize redrawing |
|
632 |
" |
|
633 |
self changed:#hierarchy with:nil |
|
634 |
! |
|
635 |
||
636 |
iconChanged |
|
637 |
"icon changed; optimize redrawing |
|
638 |
" |
|
639 |
self changed:#icon with:nil |
|
640 |
! ! |
|
641 |
||
642 |
!HierarchicalItem methodsFor:'enumerating'! |
|
643 |
||
644 |
do:aOneArgBlock |
|
645 |
"evaluate a block on each child |
|
646 |
" |
|
647 |
self children notNil ifTrue:[ children do:aOneArgBlock ] |
|
648 |
||
649 |
! |
|
650 |
||
651 |
from:startIndex do:aOneArgBlock |
|
652 |
"evaluate a block on each child starting with the |
|
653 |
child at startIndex to the end. |
|
654 |
" |
|
655 |
self from:startIndex to:self size do:aOneArgBlock |
|
656 |
! |
|
657 |
||
658 |
from:startIndex to:endIndex do:aOneArgBlock |
|
659 |
"evaluate a block on each child starting with the |
|
660 |
child at startIndex to the endIndex. |
|
661 |
" |
|
662 |
self children notNil ifTrue:[ |
|
663 |
children from:startIndex to:endIndex do:aOneArgBlock |
|
664 |
] |
|
665 |
||
666 |
! |
|
667 |
||
668 |
from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
669 |
"evaluate a block on each child starting with the |
|
670 |
child at endIndex to the startIndex. |
|
671 |
" |
|
672 |
self children notNil ifTrue:[ |
|
673 |
children from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
674 |
] |
|
675 |
||
676 |
! |
|
677 |
||
678 |
recursiveDo:aOneArgBlock |
|
679 |
"evaluate a block on each item and all the sub-items |
|
680 |
" |
|
681 |
self do:[:aChild| |
|
682 |
aOneArgBlock value:aChild. |
|
683 |
aChild recursiveDo:aOneArgBlock |
|
684 |
]. |
|
685 |
||
686 |
! |
|
687 |
||
688 |
reverseDo:aOneArgBlock |
|
689 |
"evaluate a block on each child |
|
690 |
procesing children in reverse direction |
|
691 |
" |
|
692 |
self children notNil ifTrue:[ children reverseDo:aOneArgBlock ] |
|
693 |
||
694 |
! ! |
|
695 |
||
696 |
!HierarchicalItem methodsFor:'initialization'! |
|
697 |
||
698 |
initialize |
|
699 |
isExpanded := false |
|
700 |
! ! |
|
701 |
||
702 |
!HierarchicalItem methodsFor:'private'! |
|
703 |
||
704 |
addVisibleChildrenTo:aList |
|
705 |
"add all visible children and sub-children to the list |
|
706 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
707 |
isExpanded == true ifTrue:[ |
1390 | 708 |
(children notNil or:[self children notNil]) ifTrue:[ |
709 |
children do:[:aChild| |
|
710 |
aList add:aChild. |
|
711 |
aChild addVisibleChildrenTo:aList |
|
712 |
] |
|
713 |
] |
|
714 |
] |
|
715 |
||
716 |
||
717 |
||
718 |
||
719 |
||
720 |
! |
|
721 |
||
722 |
listIndex |
|
723 |
"returns the visible index or nil; for a none visible root |
|
724 |
0 is returned |
|
725 |
" |
|
726 |
|index model| |
|
727 |
||
728 |
(model := self model) notNil ifTrue:[ |
|
729 |
index := model identityIndexOf:self. |
|
730 |
||
731 |
(index ~~ 0 or:[parent == model]) ifTrue:[ |
|
732 |
^ index |
|
733 |
] |
|
734 |
]. |
|
735 |
^ nil |
|
736 |
! |
|
737 |
||
738 |
numberOfVisibleChildren |
|
739 |
"returns number of all visible children including subchildren |
|
740 |
" |
|
741 |
|size "{ Class: SmallInteger }" |
|
742 |
| |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
743 |
(isExpanded == true) ifTrue:[ |
1390 | 744 |
(children notNil or:[self children notNil]) ifTrue:[ |
745 |
(size := children size) ~~ 0 ifTrue:[ |
|
746 |
children do:[:el| size := size + el numberOfVisibleChildren ]. |
|
747 |
^ size |
|
748 |
] |
|
749 |
] |
|
750 |
]. |
|
751 |
^ 0 |
|
752 |
||
753 |
||
754 |
||
755 |
||
756 |
! |
|
757 |
||
758 |
parentOrModel |
|
759 |
"returns the parent without checking for item or model |
|
760 |
" |
|
761 |
^ parent |
|
762 |
! |
|
763 |
||
764 |
setExpanded:aBoolean |
|
765 |
"set expanded flag without any computation or notification |
|
766 |
" |
|
767 |
isExpanded := aBoolean |
|
768 |
! ! |
|
769 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
770 |
!HierarchicalItem methodsFor:'private displaying'! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
771 |
|
1606 | 772 |
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
|
773 |
"display the label at x@y |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
774 |
" |
1606 | 775 |
|y0 hF| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
776 |
|
1606 | 777 |
lH ~~ 0 ifTrue:[ |
778 |
y0 := y - (lH + 1 - h // 2). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
779 |
|
1606 | 780 |
aLabel isImageOrForm ifTrue:[ |
781 |
^ aLabel displayOn:aGC x:x y:y0 |
|
782 |
]. |
|
783 |
y0 := y0 + (aGC font ascent). |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
784 |
|
1606 | 785 |
aLabel isString ifFalse:[ |
786 |
^ aLabel displayOn:aGC x:x y:y0 |
|
787 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
788 |
|
1606 | 789 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
790 |
^ aLabel displayOn:aGC x:x y:y0 |
|
791 |
]. |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
792 |
|
1606 | 793 |
hF := aGC font height. |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
794 |
|
1606 | 795 |
aLabel asCollectionOfLines do:[:el| |
796 |
el displayOn:aGC x:x y:y0. |
|
797 |
y0 := y0 + hF |
|
798 |
] |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
799 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
800 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
801 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
802 |
heightOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
803 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
804 |
" |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
805 |
|h| |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
806 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
807 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
808 |
^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
809 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
810 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
811 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
812 |
h := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
813 |
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
|
814 |
^ h |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
815 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
816 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
817 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
818 |
^ h * (aGC font height) |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
819 |
! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
820 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
821 |
widthOf:aLabel on:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
822 |
"returns the height of the label or 0 |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
823 |
" |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
824 |
|w| |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
825 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
826 |
aLabel isSequenceable ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
827 |
^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0] |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
828 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
829 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
830 |
aLabel isString ifFalse:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
831 |
w := -5. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
832 |
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
|
833 |
^ w |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
834 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
835 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
836 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
837 |
^ aLabel widthOn:aGC |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
838 |
]. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
839 |
|
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
840 |
w := 0. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
841 |
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
|
842 |
^ w |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
843 |
! ! |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
844 |
|
1390 | 845 |
!HierarchicalItem methodsFor:'private hierarchy'! |
846 |
||
847 |
recursiveSetCollapsed |
|
848 |
"collapse all children and sub-children without notifications |
|
849 |
" |
|
850 |
isExpanded := false. |
|
851 |
||
852 |
children notNil ifTrue:[ |
|
853 |
children do:[:aChild| aChild recursiveSetCollapsed ] |
|
854 |
] |
|
855 |
! |
|
856 |
||
857 |
recursiveSetExpandedAndAddToList:aList |
|
858 |
"expand all children and sub-children without notifications; |
|
859 |
add children to list |
|
860 |
" |
|
861 |
isExpanded := true. |
|
862 |
||
863 |
(children notNil or:[self children notNil]) ifTrue:[ |
|
864 |
children do:[:aChild| |
|
865 |
aList add:aChild. |
|
866 |
aChild recursiveSetExpandedAndAddToList:aList. |
|
867 |
] |
|
868 |
] |
|
869 |
||
870 |
! ! |
|
871 |
||
872 |
!HierarchicalItem methodsFor:'protocol accessing'! |
|
873 |
||
874 |
children |
|
875 |
"returns list of children |
|
876 |
*** to optimize:redefine by subClass |
|
877 |
" |
|
878 |
|model| |
|
879 |
||
880 |
children isNil ifTrue:[ |
|
881 |
(model := self model) notNil ifTrue:[ |
|
1486 | 882 |
children := model childrenFor:self |
1390 | 883 |
]. |
884 |
]. |
|
885 |
^ children |
|
886 |
! |
|
887 |
||
888 |
icon |
|
889 |
"returns the icon or nil; |
|
890 |
*** to optimize:redefine by subClass |
|
891 |
" |
|
892 |
|model| |
|
893 |
||
894 |
(model := self model) notNil ifTrue:[ |
|
895 |
^ model iconFor:self |
|
896 |
]. |
|
897 |
^ nil |
|
898 |
! |
|
899 |
||
900 |
label |
|
901 |
"returns the label displayed on aGC; |
|
902 |
*** to optimize:redefine by subClass |
|
903 |
" |
|
904 |
|model| |
|
905 |
||
906 |
(model := self model) notNil ifTrue:[ |
|
907 |
^ model labelFor:self |
|
908 |
]. |
|
909 |
^ nil |
|
910 |
||
911 |
! |
|
912 |
||
913 |
middleButtonMenu |
|
914 |
"returns the middleButtonMenu or nil if no menu is defined |
|
915 |
" |
|
916 |
|model| |
|
917 |
||
918 |
(model := self model) notNil ifTrue:[ |
|
919 |
^ model middleButtonMenuFor:self |
|
920 |
]. |
|
921 |
^ nil |
|
922 |
! ! |
|
923 |
||
924 |
!HierarchicalItem methodsFor:'protocol displaying'! |
|
925 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1489
diff
changeset
|
926 |
displayOn:aGC x:x y:y h:h |
1390 | 927 |
"draw the receiver in the graphicsContext, aGC. |
928 |
" |
|
929 |
|label |
|
1398 | 930 |
x0 "{ Class:SmallInteger }" |
1390 | 931 |
| |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
932 |
(label := self label) isNil ifTrue:[^ self]. |
1398 | 933 |
|
934 |
(label isSequenceable and:[label isString not]) ifFalse:[ |
|
1606 | 935 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h |
1398 | 936 |
]. |
937 |
||
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
938 |
x0 := x. |
1398 | 939 |
label do:[:el| |
940 |
el notNil ifTrue:[ |
|
1606 | 941 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h. |
1398 | 942 |
x0 := x0 + 5 + (el widthOn:aGC). |
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
943 |
]. |
1390 | 944 |
] |
945 |
! |
|
946 |
||
947 |
heightOn:aGC |
|
948 |
"return the width of the receiver, if it is to be displayed on aGC |
|
949 |
" |
|
1606 | 950 |
height isNil ifTrue:[ |
951 |
height := self heightOf:(self label) on:aGC |
|
952 |
]. |
|
953 |
^ height |
|
1390 | 954 |
! |
955 |
||
956 |
widthOn:aGC |
|
957 |
"return the width of the receiver, if it is to be displayed on aGC |
|
958 |
" |
|
1606 | 959 |
width isNil ifTrue:[ |
960 |
width := self widthOf:(self label) on:aGC |
|
961 |
]. |
|
962 |
^ width |
|
963 |
||
1390 | 964 |
! ! |
965 |
||
966 |
!HierarchicalItem methodsFor:'protocol monitoring'! |
|
967 |
||
968 |
monitoringCycle |
|
969 |
"called all 'n' seconds by the model, if the monitoring |
|
970 |
cycle is enabled. The item can perform some checks, .. |
|
971 |
**** can be redefined by subclass to perform some actions |
|
972 |
" |
|
973 |
! ! |
|
974 |
||
975 |
!HierarchicalItem methodsFor:'protocol queries'! |
|
976 |
||
1571 | 977 |
drawHorizontalLineUpToText |
978 |
"draw the horizizontal line for the selected item up to the text |
|
979 |
or on default to the start of the the vertical line; only used by |
|
980 |
the hierarchical view |
|
981 |
" |
|
982 |
^ false |
|
983 |
! |
|
984 |
||
1390 | 985 |
hasChildren |
986 |
"checks whether the item has a list of children; the list must not |
|
987 |
be loaded yet( ex. FileDirectory ). |
|
988 |
*** to optimize:redefine by subClass |
|
989 |
" |
|
990 |
^ children notNil ifTrue:[children notEmpty] |
|
991 |
ifFalse:[self children size ~~ 0] |
|
992 |
! |
|
993 |
||
994 |
string |
|
995 |
"access the printable string used for steping through a list |
|
996 |
searching for an entry starting with a character. |
|
997 |
*** to optimize:redefine by subClass |
|
998 |
" |
|
1398 | 999 |
|label| |
1000 |
||
1001 |
(label := self label) notNil ifTrue:[ |
|
1002 |
label isString ifTrue:[ ^ label string ]. |
|
1003 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
1004 |
||
1005 |
label isSequenceable ifFalse:[ |
|
1006 |
^ label perform:#string ifNotUnderstood:nil |
|
1007 |
]. |
|
1008 |
||
1009 |
label do:[:el||s| |
|
1010 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
1011 |
s := el perform:#string ifNotUnderstood:nil. |
|
1012 |
s notNil ifTrue:[^ s]. |
|
1013 |
] |
|
1014 |
] |
|
1015 |
]. |
|
1016 |
^ nil |
|
1017 |
||
1390 | 1018 |
|
1019 |
! ! |
|
1020 |
||
1021 |
!HierarchicalItem methodsFor:'queries'! |
|
1022 |
||
1023 |
canCollapse |
|
1024 |
"called before collapsing the item |
|
1025 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1026 |
^ (isExpanded == true) |
1390 | 1027 |
! |
1028 |
||
1029 |
canExpand |
|
1030 |
"called before expanding the item |
|
1031 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1032 |
^ (isExpanded == true) not and:[self hasChildren] |
1390 | 1033 |
! |
1034 |
||
1035 |
isExpanded |
|
1036 |
"return true if item is expanded |
|
1037 |
" |
|
1598
33202082065d
care for uninitialized isExpanded
Claus Gittinger <cg@exept.de>
parents:
1571
diff
changeset
|
1038 |
^ (isExpanded == true) |
1390 | 1039 |
! |
1040 |
||
1041 |
isHierarchicalItem |
|
1042 |
"used to decide if the parent is a hierarchical item |
|
1043 |
or the model |
|
1044 |
" |
|
1045 |
^ true |
|
1046 |
! |
|
1047 |
||
1650 | 1048 |
isSelectable |
1049 |
"returns true if the item is selectable otherwise false |
|
1050 |
" |
|
1051 |
^ true |
|
1052 |
! |
|
1053 |
||
1390 | 1054 |
size |
1055 |
"return the number of children |
|
1056 |
" |
|
1057 |
^ children notNil ifTrue:[children size] |
|
1058 |
ifFalse:[self children size] |
|
1059 |
! ! |
|
1060 |
||
1061 |
!HierarchicalItem methodsFor:'searching'! |
|
1062 |
||
1063 |
detect:aOneArgBlock |
|
1064 |
"find the first child, for which evaluation of the block returns |
|
1065 |
true; if none does so, report an error |
|
1066 |
" |
|
1067 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
|
1068 |
||
1069 |
! |
|
1070 |
||
1071 |
detect:aOneArgBlock ifNone:anExceptionBlock |
|
1072 |
"find the first child, for which evaluation of the block returns |
|
1073 |
true; if none does so, return the evaluation of anExceptionBlock |
|
1074 |
" |
|
1075 |
self children notNil ifTrue:[ |
|
1076 |
^ children detect:aOneArgBlock ifNone:anExceptionBlock |
|
1077 |
]. |
|
1078 |
^ anExceptionBlock value |
|
1079 |
||
1080 |
||
1081 |
! |
|
1082 |
||
1083 |
identityIndexOf:aChild |
|
1084 |
"return the index of aChild or 0 if not found. Compare using == |
|
1085 |
" |
|
1086 |
self children notNil ifTrue:[ |
|
1087 |
^ children identityIndexOf:aChild |
|
1088 |
]. |
|
1089 |
^ 0 |
|
1090 |
! |
|
1091 |
||
1092 |
identityIndexOf:aChild startingAt:startIndex |
|
1093 |
"return the index of aChild, starting search at startIndex. |
|
1094 |
Compare using ==; return 0 if not found |
|
1095 |
" |
|
1096 |
self children notNil ifTrue:[ |
|
1097 |
^ children identityIndexOf:aChild startingAt:startIndex |
|
1098 |
]. |
|
1099 |
^ 0 |
|
1489 | 1100 |
! |
1101 |
||
1102 |
recursiveDetect:aOneArgBlock |
|
1103 |
"recursive find the first child, for which evaluation |
|
1104 |
of the block returns true; if none nil is returned |
|
1105 |
" |
|
1106 |
|child| |
|
1107 |
||
1108 |
self children notNil ifTrue:[ |
|
1109 |
children do:[:aChild| |
|
1110 |
(aOneArgBlock value:aChild) ifTrue:[ |
|
1111 |
^ aChild |
|
1112 |
]. |
|
1113 |
||
1114 |
(child := aChild recursiveDetect:aOneArgBlock) notNil ifTrue:[ |
|
1115 |
^ child |
|
1116 |
] |
|
1117 |
] |
|
1118 |
]. |
|
1119 |
^ nil |
|
1390 | 1120 |
! ! |
1121 |
||
1122 |
!HierarchicalItem::Example class methodsFor:'instance creation'! |
|
1123 |
||
1124 |
labeled:aLabel |
|
1125 |
^ self new setLabel:aLabel |
|
1126 |
||
1127 |
||
1128 |
! |
|
1129 |
||
1130 |
labeled:aLabel icon:anIcon |
|
1131 |
^ self new setLabel:aLabel icon:anIcon |
|
1132 |
||
1133 |
||
1134 |
! ! |
|
1135 |
||
1136 |
!HierarchicalItem::Example class methodsFor:'resources'! |
|
1137 |
||
1138 |
iconForLevel:aLevel |
|
1139 |
"returns an icon |
|
1140 |
" |
|
1141 |
aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ]. |
|
1142 |
aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ]. |
|
1143 |
aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ]. |
|
1144 |
||
1145 |
^ nil |
|
1146 |
||
1147 |
! |
|
1148 |
||
1149 |
penguinIcon |
|
1150 |
PenguinIcon isNil ifTrue:[ |
|
1151 |
PenguinIcon := Image fromFile:'bitmaps/xpmBitmaps/misc_logos/linux_penguin.xpm'. |
|
1152 |
]. |
|
1153 |
^ PenguinIcon |
|
1154 |
! ! |
|
1155 |
||
1156 |
!HierarchicalItem::Example methodsFor:'accessing'! |
|
1157 |
||
1158 |
children |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1159 |
|lvl lbl txt image img icon tmp| |
1390 | 1160 |
|
1161 |
children notNil ifTrue:[ |
|
1162 |
^ children |
|
1163 |
]. |
|
1164 |
||
1165 |
(lvl := self level) == 5 ifTrue:[ |
|
1166 |
children := #(). |
|
1167 |
^ children |
|
1168 |
]. |
|
1169 |
icon := self class iconForLevel:(lvl + 1). |
|
1170 |
children := OrderedCollection new. |
|
1171 |
||
1172 |
lvl < 4 ifTrue:[ |
|
1173 |
txt := (lvl + 1) printString, ' ['. |
|
1174 |
img := NewLauncher saveImageIcon. |
|
1175 |
||
1176 |
1 to:5 do:[:i| |
|
1177 |
(i == 2 or:[i == 3]) ifTrue:[ |
|
1178 |
lbl := img |
|
1179 |
] ifFalse:[ |
|
1180 |
i == 4 ifTrue:[ |
|
1540
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1181 |
tmp := #( 'penguin' 'and' 'text') asStringCollection asString. |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1182 |
lbl := Array with:(self class penguinIcon) |
3fab5658652a
support carrige return in labels
Claus Gittinger <cg@exept.de>
parents:
1539
diff
changeset
|
1183 |
with:tmp. |
1390 | 1184 |
] ifFalse:[ |
1185 |
lbl := txt, (i printString), ']' |
|
1186 |
] |
|
1187 |
]. |
|
1188 |
children add:(self class labeled:lbl icon:icon) |
|
1189 |
]. |
|
1190 |
] ifFalse:[ |
|
1191 |
image := ResourceSelectionBrowser iconPrivateClass. |
|
1192 |
txt := LabelAndIcon icon:image string:'Text'. |
|
1193 |
img := Icon copyIcon. |
|
1194 |
||
1195 |
1 to:5 do:[:i| |
|
1196 |
lbl := i odd ifTrue:[txt] ifFalse:[img]. |
|
1398 | 1197 |
lbl := Array with:lbl with:'test' with:img. |
1390 | 1198 |
children add:(self class labeled:lbl icon:icon). |
1199 |
] |
|
1200 |
]. |
|
1201 |
||
1202 |
children do:[:aChild| aChild parent:self ]. |
|
1203 |
^ children |
|
1204 |
! |
|
1205 |
||
1206 |
icon |
|
1207 |
"returns the icon |
|
1208 |
" |
|
1209 |
^ icon |
|
1210 |
! |
|
1211 |
||
1212 |
icon:anIcon |
|
1213 |
"set the icon; if icon changed, a notification |
|
1214 |
is raised. |
|
1215 |
" |
|
1216 |
icon ~= anIcon ifTrue:[ |
|
1217 |
icon := anIcon. |
|
1218 |
self iconChanged |
|
1219 |
] |
|
1220 |
! |
|
1221 |
||
1222 |
label |
|
1223 |
"returns the label |
|
1224 |
" |
|
1225 |
^ label |
|
1226 |
||
1227 |
! |
|
1228 |
||
1229 |
label:aLabel |
|
1230 |
"set the label; if label changed, a notification |
|
1231 |
is raised. |
|
1232 |
" |
|
1233 |
label ~= aLabel ifTrue:[ |
|
1234 |
label := aLabel. |
|
1235 |
self changed. |
|
1236 |
] |
|
1237 |
||
1238 |
! |
|
1239 |
||
1240 |
setIcon:anIcon |
|
1241 |
"set the icon without any change notification |
|
1242 |
" |
|
1243 |
icon := anIcon |
|
1244 |
! |
|
1245 |
||
1246 |
setLabel:aLabel |
|
1247 |
"set the label without any change notification |
|
1248 |
" |
|
1249 |
label := aLabel |
|
1250 |
! |
|
1251 |
||
1252 |
setLabel:aLabel icon:anIcon |
|
1253 |
"set the label and icon without any change notification |
|
1254 |
" |
|
1255 |
label := aLabel. |
|
1256 |
icon := anIcon. |
|
1257 |
! ! |
|
1258 |
||
1259 |
!HierarchicalItem class methodsFor:'documentation'! |
|
1260 |
||
1261 |
version |
|
1669 | 1262 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalItem.st,v 1.19 2000-02-02 11:37:49 ca Exp $' |
1390 | 1263 |
! ! |