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