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