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