author | sr |
Fri, 13 Dec 2019 14:08:49 +0100 | |
changeset 6195 | bd5eb047338b |
parent 6193 | b50c38f9dbdb |
child 6228 | 8a02146c43d3 |
permissions | -rw-r--r-- |
6009 | 1 |
"{ Encoding: utf8 }" |
2 |
||
4733 | 3 |
" |
4 |
COPYRIGHT (c) 1999/2015 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
14 |
"{ Package: 'stx:libwidg2' }" |
|
15 |
||
16 |
"{ NameSpace: Smalltalk }" |
|
17 |
||
18 |
Object subclass:#AbstractHierarchicalItem |
|
19 |
instanceVariableNames:'parent children' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Views-Support' |
|
23 |
! |
|
24 |
||
25 |
!AbstractHierarchicalItem class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1999/2015 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
Hierarchical Items are mostly like Models, but the list of |
|
44 |
dependencies are kept by its HierarchicalList. |
|
45 |
The class is used to build up hierarchical trees. |
|
46 |
||
47 |
2015 update: |
|
48 |
the original HierarchicalItem has been refactored into this abstract class, |
|
49 |
which provides all the mechanisms, but leaves the concrete representation |
|
50 |
of some slots open. |
|
51 |
These are: |
|
52 |
- if and how the geometry information (width + height) are cached, |
|
53 |
- if and how the expanded-state is remembered. |
|
54 |
- if and how the underlying model is fetched |
|
55 |
||
56 |
The old class used private slots for the first three (width-height-isExpanded), |
|
57 |
but did not keep a reference to the model. This leads to a very poor performance, |
|
58 |
as many algorithms degenerated to O(n log(n)) or even O(n^2) time behavior, |
|
59 |
as the model was fetched by walking along the parent chain - sometimes for every item |
|
60 |
in a long list. |
|
61 |
||
62 |
The old class is still around and may be used for small trees, |
|
63 |
but we recommend rewriting applications to use the new CompactHierarchicalItem |
|
64 |
class, which behaves the same on the outside, but uses clever tricks to be both more |
|
65 |
space efficient (saving 2 slots) and time efficient (caching the model). |
|
4749
13a7e6db823b
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4746
diff
changeset
|
66 |
For this, make sure that the subclass does not access the instvars isExpanded, width and height |
13a7e6db823b
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4746
diff
changeset
|
67 |
directly, but uses the getters isExpanded, width and height and the setters setExpanded:, width: and height: |
4733 | 68 |
|
69 |
[Instance variables:] |
|
70 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
71 |
children <Collection or nil> list of children |
|
72 |
||
73 |
[author:] |
|
5740 | 74 |
Claus Atzkern |
4733 | 75 |
Claus Gittinger (redesign and refactoring) |
76 |
||
77 |
[see also:] |
|
78 |
HierarchicalItem (the old item class) |
|
79 |
HierarchicalList (typical model) |
|
80 |
HierarchicalListView (typical user of me) |
|
81 |
" |
|
82 |
! ! |
|
83 |
||
84 |
!AbstractHierarchicalItem class methodsFor:'instance creation'! |
|
85 |
||
86 |
new |
|
87 |
^ (self basicNew) initialize |
|
88 |
! |
|
89 |
||
90 |
parent:aParent |
|
91 |
|item| |
|
92 |
||
93 |
item := self new. |
|
94 |
item parent:aParent. |
|
95 |
^ item |
|
96 |
! ! |
|
97 |
||
98 |
!AbstractHierarchicalItem class methodsFor:'protocol'! |
|
99 |
||
100 |
doResetExtentOnChange |
|
101 |
"true: the extent of the item is reset if a change |
|
102 |
notification is raised from the item. the default is true |
|
103 |
" |
|
104 |
^ true |
|
105 |
! ! |
|
106 |
||
5461 | 107 |
!AbstractHierarchicalItem class methodsFor:'queries'! |
108 |
||
109 |
isAbstract |
|
110 |
"Return if this class is an abstract class. |
|
111 |
True is returned here for myself only; false for subclasses. |
|
112 |
Abstract subclasses must redefine this again." |
|
113 |
||
114 |
^ self == AbstractHierarchicalItem. |
|
115 |
! ! |
|
116 |
||
4733 | 117 |
!AbstractHierarchicalItem methodsFor:'accessing'! |
118 |
||
119 |
getChildren |
|
5996 | 120 |
"returns the children as they are present (or not); |
121 |
not going to the model, and especially not creating autocreated children..." |
|
4733 | 122 |
|
123 |
^ children |
|
5996 | 124 |
|
125 |
"Modified (comment): / 12-02-2019 / 17:41:06 / Claus Gittinger" |
|
4733 | 126 |
! |
127 |
||
128 |
level |
|
129 |
"returns the level starting with 0 for the root" |
|
130 |
||
131 |
|item level| |
|
132 |
||
133 |
item := self. |
|
134 |
level := 0. |
|
135 |
||
136 |
[ (item := item parentOrModel) notNil] whileTrue:[ |
|
137 |
level := level + 1. |
|
5739 | 138 |
level > 10000 ifTrue:[ |
139 |
self halt:'possibly recursive item hierarchy'. |
|
140 |
^ self. |
|
4733 | 141 |
]. |
142 |
]. |
|
143 |
^ level |
|
144 |
||
145 |
"Modified: / 09-07-2010 / 08:56:27 / cg" |
|
146 |
! |
|
147 |
||
6000 | 148 |
nextSibling |
149 |
"returns the next child of my parent or nil" |
|
150 |
||
151 |
|siblings myIndex| |
|
152 |
||
153 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
|
154 |
siblings := parent getChildren. |
|
155 |
myIndex := siblings identityIndexOf:self. |
|
156 |
myIndex ~~ 0 ifTrue:[ |
|
157 |
^ siblings at:myIndex+1 ifAbsent:nil |
|
158 |
]. |
|
159 |
]. |
|
160 |
^ nil |
|
161 |
||
162 |
"Created: / 13-02-2019 / 15:17:39 / Claus Gittinger" |
|
163 |
! |
|
164 |
||
4733 | 165 |
parent |
166 |
"returns the parent or nil" |
|
167 |
||
5865 | 168 |
|p| |
5870 | 169 |
|
170 |
p := parent. |
|
171 |
^ (p notNil and:[p isHierarchicalItem]) |
|
5865 | 172 |
ifTrue:[p] |
4733 | 173 |
ifFalse:[nil] |
5865 | 174 |
|
5870 | 175 |
"Modified: / 01-08-2018 / 10:18:37 / Claus Gittinger" |
176 |
"Modified: / 01-08-2018 / 16:15:07 / Stefan Vogel" |
|
4733 | 177 |
! |
178 |
||
179 |
parent:aParent |
|
180 |
"set the parent (or the model if the item is the root item)" |
|
181 |
||
182 |
parent := aParent |
|
183 |
! |
|
184 |
||
6000 | 185 |
previousSibling |
186 |
"returns the previous child of my parent or nil" |
|
187 |
||
188 |
|siblings myIndex| |
|
189 |
||
190 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
|
191 |
siblings := parent getChildren. |
|
192 |
myIndex := siblings identityIndexOf:self. |
|
193 |
myIndex ~~ 0 ifTrue:[ |
|
194 |
^ siblings at:myIndex-1 ifAbsent:nil |
|
195 |
]. |
|
196 |
]. |
|
197 |
^ nil |
|
198 |
||
199 |
"Created: / 13-02-2019 / 15:17:57 / Claus Gittinger" |
|
200 |
! |
|
201 |
||
4733 | 202 |
rootItem |
203 |
"returns the root item" |
|
204 |
||
205 |
parent isHierarchicalItem ifTrue:[ |
|
206 |
^ parent rootItem |
|
207 |
]. |
|
208 |
^ self |
|
209 |
! ! |
|
210 |
||
211 |
!AbstractHierarchicalItem methodsFor:'accessing-children'! |
|
212 |
||
213 |
at:anIndex |
|
214 |
"return the child at anIndex if valid; |
|
215 |
if the index is invalid, nil is returned" |
|
216 |
||
217 |
^ self at:anIndex ifAbsent:nil |
|
218 |
! |
|
219 |
||
220 |
at:anIndex ifAbsent:exceptionBlock |
|
221 |
"return the child at anIndex if valid; if the index is |
|
222 |
invalid, the result of evaluating the exceptionBlock is returned." |
|
223 |
||
224 |
|list| |
|
225 |
||
226 |
(list := self children) notNil ifTrue:[ |
|
227 |
^ list at:anIndex ifAbsent:exceptionBlock |
|
228 |
]. |
|
229 |
^ exceptionBlock value |
|
230 |
! |
|
231 |
||
232 |
at:anIndex put:anItem |
|
233 |
"replace a child by a new item. return anItem (sigh)" |
|
234 |
||
235 |
|children oldItem visIndex model expFlag| |
|
236 |
||
237 |
anItem isNil ifTrue:[ |
|
238 |
self removeFromIndex:anIndex toIndex:anIndex. |
|
239 |
^ nil |
|
240 |
]. |
|
241 |
anItem parent:self. |
|
242 |
||
243 |
(model := self model) isNil ifTrue:[ |
|
244 |
self children at:anIndex put:anItem. |
|
245 |
^ anItem |
|
246 |
]. |
|
247 |
||
5840 | 248 |
model synchronized:[ |
4733 | 249 |
children := self children. |
250 |
oldItem := children at:anIndex. |
|
251 |
||
252 |
oldItem isExpanded ifTrue:[ |
|
253 |
oldItem collapse |
|
254 |
]. |
|
255 |
visIndex := model identityIndexOf:oldItem. |
|
256 |
expFlag := anItem isExpanded. |
|
257 |
anItem setExpanded:false. |
|
258 |
||
259 |
children at:anIndex put:anItem. |
|
260 |
||
261 |
visIndex ~~ 0 ifTrue:[ |
|
262 |
model at:visIndex put:anItem. |
|
263 |
]. |
|
264 |
self changed:#redraw. |
|
265 |
expFlag ifTrue:[ anItem expand ]. |
|
266 |
]. |
|
267 |
^ anItem |
|
5840 | 268 |
|
269 |
"Modified: / 28-07-2018 / 15:51:06 / Claus Gittinger" |
|
4733 | 270 |
! |
271 |
||
272 |
children:aListOfChildren |
|
273 |
"set a new list of children" |
|
274 |
||
5840 | 275 |
self synchronized:[ |
4733 | 276 |
self removeAll. |
5994 | 277 |
self addAll:aListOfChildren beforeIndex:1. |
4733 | 278 |
]. |
279 |
^ aListOfChildren |
|
5840 | 280 |
|
5994 | 281 |
"Modified: / 06-02-2019 / 15:59:15 / Claus Gittinger" |
4733 | 282 |
! |
283 |
||
284 |
first |
|
285 |
"returns the first child |
|
286 |
" |
|
287 |
^ self at:1 |
|
288 |
! |
|
289 |
||
290 |
last |
|
291 |
"returns the last child" |
|
292 |
||
293 |
^ self at:(self size) |
|
294 |
! |
|
295 |
||
296 |
second |
|
297 |
"returns the second child" |
|
298 |
||
299 |
^ self at:2 |
|
300 |
! ! |
|
301 |
||
302 |
!AbstractHierarchicalItem methodsFor:'accessing-hierarchy'! |
|
303 |
||
304 |
collapse |
|
305 |
"hide all my subitems" |
|
306 |
||
307 |
self canCollapse ifTrue:[ |
|
5840 | 308 |
self synchronized:[ |
5996 | 309 |
|overAllNrOfVisibleChildren nrOfVisibleChildren index| |
310 |
||
311 |
overAllNrOfVisibleChildren := self numberOfVisibleChildren. |
|
312 |
||
313 |
self setExpanded:false. |
|
314 |
||
4733 | 315 |
(index := self listIndex) notNil ifTrue:[ |
5996 | 316 |
"/ do not call self size or self children, |
317 |
"/ as this might autocreate children !!!! |
|
318 |
(nrOfVisibleChildren := children size) ~~ 0 ifTrue:[ |
|
319 |
children do:[:el| |
|
320 |
nrOfVisibleChildren := nrOfVisibleChildren + el numberOfVisibleChildren |
|
4733 | 321 |
]. |
5996 | 322 |
self assert:(nrOfVisibleChildren = overAllNrOfVisibleChildren). |
323 |
self model itemRemoveFromIndex:(index + 1) toIndex:(index + nrOfVisibleChildren). |
|
4733 | 324 |
]. |
325 |
index ~~ 0 ifTrue:[self hierarchyChanged]. |
|
326 |
] |
|
327 |
] |
|
328 |
] |
|
5840 | 329 |
|
5996 | 330 |
"Modified: / 12-02-2019 / 18:53:55 / Claus Gittinger" |
4733 | 331 |
! |
332 |
||
333 |
enforcedExpand |
|
334 |
"expand children - even if there are no children, |
|
335 |
the item is initially expanded (but this might be undone later, |
|
336 |
when we know that no children are there" |
|
337 |
||
338 |
self expand:true |
|
339 |
! |
|
340 |
||
341 |
expand |
|
342 |
"expand children - but only if there are children |
|
343 |
(i.e. this cannot be used before the childInfo is valid; |
|
344 |
aka not before the updateTask came along this item)" |
|
345 |
||
346 |
self expand:false |
|
347 |
! |
|
348 |
||
349 |
expand:enforced |
|
350 |
"expand children" |
|
351 |
||
352 |
"/ test whether the item already is expanded; #canExpand could be redefined |
|
353 |
"/ without checking whether the node is expanded (happens already) !! |
|
354 |
||
355 |
self isExpanded ifTrue:[ ^ self ]. |
|
356 |
(enforced not and:[self canExpand not]) ifTrue:[ ^ self ]. |
|
357 |
||
5840 | 358 |
self synchronized:[ |
5720 | 359 |
|index list| |
360 |
||
6010 | 361 |
self isExpanded ifFalse:[ |
362 |
(index := self listIndex) notNil ifTrue:[ |
|
363 |
"/ must set expand-flag to false, otherwise change notifications |
|
364 |
"/ are raised during lazy auto creation (to the list). |
|
365 |
self setExpanded:false. |
|
366 |
list := self children. |
|
367 |
list notEmptyOrNil ifTrue:[ |
|
368 |
self setExpanded:true. |
|
369 |
list := OrderedCollection new. |
|
370 |
self addVisibleChildrenTo:list. |
|
371 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
372 |
]. |
|
373 |
index ~~ 0 ifTrue:[self hierarchyChanged]. |
|
374 |
] ifFalse:[ |
|
375 |
self setExpanded:true |
|
376 |
] |
|
377 |
]. |
|
4733 | 378 |
]. |
5720 | 379 |
|
380 |
"Modified: / 08-03-2018 / 21:06:13 / stefan" |
|
6010 | 381 |
"Modified: / 20-02-2019 / 00:23:49 / Claus Gittinger" |
4733 | 382 |
! |
383 |
||
5728 | 384 |
expandLevels:numLevels |
385 |
"expand children numLevels down" |
|
386 |
||
387 |
numLevels == 0 ifTrue:[^ self]. |
|
388 |
self children do:[:each | |
|
389 |
each expand. |
|
390 |
each expandLevels:(numLevels - 1). |
|
391 |
]. |
|
392 |
! |
|
393 |
||
394 |
expandLevels:numLevels max:maxNumExpandedHolder |
|
395 |
"expand children numLevels down" |
|
396 |
||
5998 | 397 |
|childrenToExpand| |
398 |
||
5728 | 399 |
numLevels == 0 ifTrue:[^ self]. |
400 |
maxNumExpandedHolder value <= 0 ifTrue:[^ self]. |
|
401 |
||
5998 | 402 |
childrenToExpand := self children. |
403 |
childrenToExpand do:[:each | |
|
5728 | 404 |
each expand. |
405 |
]. |
|
406 |
||
5998 | 407 |
maxNumExpandedHolder value:(maxNumExpandedHolder value - childrenToExpand size). |
408 |
childrenToExpand do:[:each | |
|
5728 | 409 |
each expandLevels:(numLevels - 1) max:maxNumExpandedHolder. |
410 |
]. |
|
5998 | 411 |
|
412 |
"Modified: / 13-02-2019 / 12:33:40 / Claus Gittinger" |
|
5728 | 413 |
! |
414 |
||
5992 | 415 |
expandWithoutUpdate |
416 |
"in case expand is redefined to do any update |
|
417 |
(as in guiBrowser's applicationTreeItem), |
|
418 |
this can be used to expand without updating" |
|
419 |
||
420 |
self expand |
|
421 |
||
422 |
"Created: / 02-02-2019 / 19:59:55 / Claus Gittinger" |
|
423 |
"Modified (comment): / 03-02-2019 / 01:28:33 / Claus Gittinger" |
|
424 |
! |
|
425 |
||
5623 | 426 |
labelPath |
427 |
"return my label-path as an ordered collection of individual labels" |
|
428 |
||
429 |
^ ({self} , self allParents) reverse collect:#label |
|
430 |
||
431 |
"Created: / 16-10-2017 / 13:09:10 / cg" |
|
432 |
"Modified: / 16-10-2017 / 14:16:46 / cg" |
|
433 |
! |
|
434 |
||
4733 | 435 |
makeVisible |
436 |
"expand all my parents" |
|
437 |
||
438 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
|
5840 | 439 |
self synchronized:[ |
4733 | 440 |
parent makeVisible. |
441 |
parent expand. |
|
442 |
] |
|
443 |
]. |
|
5840 | 444 |
|
445 |
"Modified: / 28-07-2018 / 15:47:52 / Claus Gittinger" |
|
4733 | 446 |
! |
447 |
||
448 |
recursiveCollapse |
|
5998 | 449 |
"collapse item and recursively all sub items" |
450 |
||
451 |
self canCollapse ifFalse:[^ self]. |
|
5999 | 452 |
|
453 |
"/ self checkConsistency. |
|
5840 | 454 |
self synchronized:[ |
5996 | 455 |
|nrOfVisibleChildren index| |
5840 | 456 |
|
457 |
self canCollapse ifTrue:[ |
|
4733 | 458 |
(index := self listIndex) notNil ifTrue:[ |
5996 | 459 |
"/ do not call self size or self children here; |
460 |
"/ otherwise, lazy children would be autocreated !!!! |
|
5998 | 461 |
nrOfVisibleChildren := self numberOfVisibleChildren. |
5996 | 462 |
self recursiveSetCollapsedHelper. |
463 |
||
464 |
nrOfVisibleChildren ~~ 0 ifTrue:[ |
|
5998 | 465 |
self model removeFromIndex:(index + 1) toIndex:(index + nrOfVisibleChildren) |
4733 | 466 |
]. |
467 |
index ~~ 0 ifTrue:[ |
|
468 |
self hierarchyChanged |
|
469 |
] |
|
470 |
] ifFalse:[ |
|
5998 | 471 |
"/ not visible |
5996 | 472 |
self recursiveSetCollapsedHelper |
4733 | 473 |
] |
474 |
] |
|
5998 | 475 |
]. |
5999 | 476 |
"/ self checkConsistency. |
477 |
||
478 |
"Modified: / 13-02-2019 / 12:59:40 / Claus Gittinger" |
|
4733 | 479 |
! |
480 |
||
481 |
recursiveExpand |
|
5998 | 482 |
"expand children and sub-children; |
483 |
WARNING: refetches children. |
|
5870 | 484 |
Precondition: must be collapsed" |
485 |
||
6142 | 486 |
"/ true ifTrue:[ ^ self __recursiveExpand ]. |
487 |
||
6193 | 488 |
(self isExpanded not and:[self canRecursiveExpand]) ifFalse:[ ^ self ]. |
6142 | 489 |
|
490 |
self synchronized:[ | index | |
|
491 |
index := self listIndex. |
|
6193 | 492 |
"/ matilk: why check this again? |
493 |
(index notNil and:[self isExpanded not and:[self canRecursiveExpand]]) ifTrue:[ | action mdlist | |
|
6142 | 494 |
mdlist := OrderedCollection with:self. |
495 |
||
496 |
[ mdlist notEmpty ] whileTrue:[ | toExpand | |
|
497 |
toExpand := mdlist removeFirst. |
|
5996 | 498 |
toExpand setExpanded:true. |
6142 | 499 |
|
500 |
toExpand do:[: eachChild | |
|
6193 | 501 |
(eachChild isExpanded or:[eachChild canRecursiveExpand]) |
6142 | 502 |
ifTrue: [ mdlist add:eachChild ] |
503 |
ifFalse:[ eachChild setExpanded:false ]. |
|
4733 | 504 |
]. |
6142 | 505 |
]. |
506 |
mdlist := OrderedCollection new: 100. |
|
507 |
action := [: el | mdlist add: el. el isExpanded ifTrue:[ el do: action ]. ]. |
|
508 |
action value: self. |
|
509 |
mdlist removeFirst. |
|
510 |
self model itemAddAll:mdlist afterIndex: index. |
|
511 |
self hierarchyChanged. |
|
512 |
]. |
|
4733 | 513 |
]. |
6193 | 514 |
|
515 |
"Modified: / 11-12-2019 / 12:58:20 / Maren Tilk" |
|
4733 | 516 |
! |
517 |
||
518 |
recursiveToggleExpand |
|
519 |
"if the item is collapsed, the item and all its sub-items |
|
520 |
are expanded otherwise collapsed" |
|
521 |
||
522 |
self isExpanded ifTrue:[ |
|
523 |
self recursiveCollapse |
|
524 |
] ifFalse:[ |
|
525 |
self recursiveExpand |
|
526 |
] |
|
527 |
! |
|
528 |
||
529 |
toggleExpand |
|
530 |
"if the item is collapsed, the item is expanded otherwise collapsed" |
|
531 |
||
532 |
self isExpanded ifTrue:[ |
|
533 |
self collapse |
|
534 |
] ifFalse:[ |
|
535 |
self expand |
|
536 |
]. |
|
537 |
! ! |
|
538 |
||
539 |
!AbstractHierarchicalItem methodsFor:'accessing-mvc'! |
|
540 |
||
541 |
application |
|
542 |
"returns the responsible application or nil" |
|
543 |
||
544 |
|model| |
|
545 |
||
546 |
(model := self model) notNil ifTrue:[ |
|
547 |
^ model application |
|
548 |
]. |
|
549 |
^ nil |
|
550 |
! |
|
551 |
||
552 |
applicationsDo:aOneArgBlock |
|
553 |
"evaluate the block for each dependent application" |
|
554 |
||
555 |
|model| |
|
556 |
||
557 |
(model := self model) notNil ifTrue:[ |
|
558 |
model applicationsDo:aOneArgBlock |
|
559 |
] |
|
560 |
! |
|
561 |
||
5840 | 562 |
fetchModel |
4733 | 563 |
"returns the hierachicalList model or nil. |
564 |
This is a stupid implementation here, in that the top-item's parent is assumed to |
|
565 |
be the model of the tree, and that is returned. |
|
566 |
This saves a slot in every node, but makes some algorithms O(n*log n) or even O(n^2). |
|
567 |
So be aware of the performance penalty" |
|
568 |
||
569 |
|item next| |
|
570 |
||
571 |
item := self. |
|
572 |
[ (next := item parentOrModel) notNil ] whileTrue:[ |
|
573 |
item := next. |
|
574 |
]. |
|
575 |
||
576 |
item isHierarchicalItem ifFalse:[^ item]. |
|
577 |
^ nil |
|
5840 | 578 |
! |
579 |
||
580 |
model |
|
581 |
"returns the hierachicalList model or nil. |
|
582 |
This uses fetchModel, which has a stupid implementation here, |
|
583 |
in that the top-item's parent is assumed to be the model of the tree, and that is returned. |
|
584 |
This saves a slot in every node, but makes some algorithms O(n*log n) or even O(n^2). |
|
585 |
So be aware of the performance penalty or redefined fetchModel" |
|
586 |
||
587 |
^ self fetchModel |
|
588 |
||
589 |
"Modified (comment): / 28-07-2018 / 13:30:24 / Claus Gittinger" |
|
4733 | 590 |
! ! |
591 |
||
592 |
!AbstractHierarchicalItem methodsFor:'adding & removing'! |
|
593 |
||
594 |
add:aChildItem |
|
595 |
"add a child at end" |
|
596 |
||
5857 | 597 |
^ self synchronized:[ |
5840 | 598 |
self add:aChildItem beforeIndex:(self children size + 1). |
599 |
]. |
|
600 |
||
601 |
"Modified: / 28-07-2018 / 13:35:08 / Claus Gittinger" |
|
5857 | 602 |
"Modified: / 29-07-2018 / 20:23:01 / Stefan Vogel" |
4733 | 603 |
! |
604 |
||
605 |
add:aChildItem after:aChild |
|
606 |
"add an item after an existing item" |
|
607 |
||
5857 | 608 |
^ self synchronized:[ |
609 |
|index| |
|
610 |
||
5840 | 611 |
index := self identityIndexOf:aChild. |
612 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
|
613 |
||
614 |
self add:aChildItem beforeIndex:(index + 1). |
|
615 |
]. |
|
616 |
||
617 |
"Modified: / 28-07-2018 / 13:35:18 / Claus Gittinger" |
|
5857 | 618 |
"Modified: / 29-07-2018 / 20:23:26 / Stefan Vogel" |
4733 | 619 |
! |
620 |
||
621 |
add:aChildItem afterIndex:anIndex |
|
622 |
"add an item after an index" |
|
623 |
||
5857 | 624 |
^ self add:aChildItem beforeIndex:(anIndex + 1). |
5840 | 625 |
|
626 |
"Modified: / 28-07-2018 / 13:37:32 / Claus Gittinger" |
|
5857 | 627 |
"Modified: / 29-07-2018 / 20:23:39 / Stefan Vogel" |
4733 | 628 |
! |
629 |
||
630 |
add:aChildItem before:aChild |
|
631 |
"add an item before an existing item" |
|
632 |
||
5857 | 633 |
^ self synchronized:[ |
5840 | 634 |
|index| |
635 |
||
636 |
index := self identityIndexOf:aChild. |
|
637 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
|
638 |
||
639 |
self add:aChildItem beforeIndex:index. |
|
640 |
]. |
|
641 |
||
642 |
"Modified: / 28-07-2018 / 13:35:47 / Claus Gittinger" |
|
5857 | 643 |
"Modified: / 29-07-2018 / 20:22:28 / Stefan Vogel" |
4733 | 644 |
! |
645 |
||
646 |
add:aChildItem beforeIndex:anIndex |
|
647 |
"add an item before an index" |
|
648 |
||
649 |
aChildItem notNil ifTrue:[ |
|
650 |
self addAll:(Array with:aChildItem) beforeIndex:anIndex |
|
651 |
]. |
|
5857 | 652 |
^ aChildItem. |
5840 | 653 |
|
654 |
"Modified: / 28-07-2018 / 13:35:01 / Claus Gittinger" |
|
5857 | 655 |
"Modified: / 29-07-2018 / 20:24:07 / Stefan Vogel" |
4733 | 656 |
! |
657 |
||
658 |
add:aChild sortBlock:aBlock |
|
659 |
"add a child sorted" |
|
660 |
||
5857 | 661 |
^ self synchronized:[ |
4733 | 662 |
self basicAdd:aChild sortBlock:aBlock |
663 |
]. |
|
5840 | 664 |
|
665 |
"Modified: / 28-07-2018 / 13:37:12 / Claus Gittinger" |
|
5857 | 666 |
"Modified: / 29-07-2018 / 20:24:31 / Stefan Vogel" |
4733 | 667 |
! |
668 |
||
669 |
addAll:aList |
|
6121 | 670 |
"add children at the end. |
671 |
Returns the argument, aList" |
|
4733 | 672 |
|
5857 | 673 |
^ self synchronized:[ |
5840 | 674 |
self addAll:aList beforeIndex:(self children size + 1) |
675 |
] |
|
676 |
||
677 |
"Modified: / 28-07-2018 / 13:37:25 / Claus Gittinger" |
|
5857 | 678 |
"Modified: / 29-07-2018 / 20:25:09 / Stefan Vogel" |
4733 | 679 |
! |
680 |
||
681 |
addAll:aList before:aChild |
|
682 |
"add an item before an existing item" |
|
683 |
||
5857 | 684 |
^ self synchronized:[ |
5840 | 685 |
|index| |
686 |
||
687 |
index := self identityIndexOf:aChild. |
|
688 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
|
689 |
||
690 |
self addAll:aList beforeIndex:index |
|
691 |
]. |
|
692 |
||
693 |
"Modified: / 28-07-2018 / 13:37:53 / Claus Gittinger" |
|
5857 | 694 |
"Modified: / 29-07-2018 / 20:25:18 / Stefan Vogel" |
4733 | 695 |
! |
696 |
||
697 |
addAll:aList beforeIndex:anIndex |
|
698 |
"add children before an index" |
|
699 |
||
5857 | 700 |
aList notEmptyOrNil ifTrue:[ |
5840 | 701 |
self synchronized:[ |
4733 | 702 |
self basicAddAll:aList beforeIndex:anIndex |
703 |
] |
|
704 |
]. |
|
705 |
^ aList |
|
5840 | 706 |
|
707 |
"Modified: / 28-07-2018 / 13:38:02 / Claus Gittinger" |
|
5857 | 708 |
"Modified: / 29-07-2018 / 20:25:38 / Stefan Vogel" |
4733 | 709 |
! |
710 |
||
711 |
addAll:aList sortBlock:aBlock |
|
712 |
"add children sorted" |
|
713 |
||
5857 | 714 |
aList notEmptyOrNil ifTrue:[ ^ aList ]. |
4733 | 715 |
|
716 |
aBlock isNil ifTrue:[ |
|
717 |
self addAll:aList. |
|
718 |
] ifFalse:[ |
|
5840 | 719 |
self synchronized:[ |
4733 | 720 |
aList do:[:el| self basicAdd:el sortBlock:aBlock ] |
721 |
] |
|
722 |
]. |
|
5857 | 723 |
^ aList |
5840 | 724 |
|
725 |
"Modified: / 28-07-2018 / 13:38:14 / Claus Gittinger" |
|
5857 | 726 |
"Modified: / 29-07-2018 / 20:26:24 / Stefan Vogel" |
4733 | 727 |
! |
728 |
||
729 |
addAllFirst:aCollectionOfItems |
|
730 |
"add children at the beginning" |
|
731 |
||
5857 | 732 |
^ self addAll:aCollectionOfItems beforeIndex:1 |
5840 | 733 |
|
734 |
"Modified: / 28-07-2018 / 13:38:24 / Claus Gittinger" |
|
5857 | 735 |
"Modified: / 29-07-2018 / 20:26:47 / Stefan Vogel" |
4733 | 736 |
! |
737 |
||
738 |
addAllLast:aCollectionOfItems |
|
739 |
"add children at the end" |
|
740 |
||
5857 | 741 |
^ self addAll:aCollectionOfItems |
5840 | 742 |
|
743 |
"Modified: / 28-07-2018 / 13:38:32 / Claus Gittinger" |
|
5857 | 744 |
"Modified: / 29-07-2018 / 20:26:55 / Stefan Vogel" |
4733 | 745 |
! |
746 |
||
747 |
addFirst:aChildItem |
|
748 |
"add a child at the beginning" |
|
749 |
||
5857 | 750 |
^ self add:aChildItem beforeIndex:1. |
5840 | 751 |
|
752 |
"Modified: / 28-07-2018 / 13:38:47 / Claus Gittinger" |
|
5857 | 753 |
"Modified: / 29-07-2018 / 20:27:01 / Stefan Vogel" |
4733 | 754 |
! |
755 |
||
756 |
addLast:anItem |
|
757 |
"add a child at the end" |
|
758 |
||
5857 | 759 |
^ self add:anItem |
5840 | 760 |
|
761 |
"Modified: / 28-07-2018 / 13:38:52 / Claus Gittinger" |
|
5857 | 762 |
"Modified: / 29-07-2018 / 20:27:09 / Stefan Vogel" |
4733 | 763 |
! |
764 |
||
765 |
remove |
|
766 |
"remove the item" |
|
767 |
||
768 |
parent notNil ifTrue:[ "check whether parent exists" |
|
769 |
parent isHierarchicalItem ifTrue:[parent remove:self] "parent is HierarchicalItem" |
|
770 |
ifFalse:[parent root:nil] "parent is HierarchicalList" |
|
771 |
]. |
|
5857 | 772 |
|
773 |
"Modified: / 29-07-2018 / 20:31:18 / Stefan Vogel" |
|
4733 | 774 |
! |
775 |
||
776 |
remove:aChild |
|
777 |
"remove a child" |
|
778 |
||
5840 | 779 |
self synchronized:[ |
780 |
self removeIndex:(self identityIndexOf:aChild) |
|
781 |
]. |
|
782 |
||
783 |
"Modified: / 28-07-2018 / 13:39:47 / Claus Gittinger" |
|
5857 | 784 |
"Modified: / 29-07-2018 / 20:40:47 / Stefan Vogel" |
4733 | 785 |
! |
786 |
||
787 |
removeAll |
|
5840 | 788 |
"remove all children. |
789 |
Returns the receiver." |
|
790 |
||
791 |
self synchronized:[ |
|
792 |
|size| |
|
793 |
||
794 |
(size := children size) ~~ 0 ifTrue:[ |
|
795 |
self removeFromIndex:1 toIndex:size |
|
796 |
] |
|
4733 | 797 |
] |
5840 | 798 |
|
799 |
"Modified (comment): / 28-07-2018 / 13:44:24 / Claus Gittinger" |
|
4733 | 800 |
! |
801 |
||
802 |
removeAll:aList |
|
6095 | 803 |
"remove all items in aList from my children. |
5840 | 804 |
Returns the receiver." |
4733 | 805 |
|
806 |
aList size ~~ 0 ifTrue:[ |
|
5840 | 807 |
self synchronized:[ |
4733 | 808 |
aList do:[:el| |
5840 | 809 |
|index| |
810 |
||
4733 | 811 |
(index := self identityIndexOf:el) ~~ 0 ifTrue:[ |
812 |
self removeIndex:index |
|
813 |
] |
|
814 |
] |
|
815 |
] |
|
816 |
]. |
|
5840 | 817 |
|
5857 | 818 |
"Modified: / 29-07-2018 / 20:39:01 / Stefan Vogel" |
6095 | 819 |
"Modified (comment): / 23-07-2019 / 17:56:03 / Claus Gittinger" |
4733 | 820 |
! |
821 |
||
822 |
removeAllIdentical:aList |
|
823 |
"remove all children in the collection" |
|
824 |
||
5840 | 825 |
^ self removeAll:aList. |
4733 | 826 |
|
827 |
"Created: / 20-09-2010 / 09:43:06 / sr" |
|
5840 | 828 |
"Modified: / 28-07-2018 / 13:41:48 / Claus Gittinger" |
4733 | 829 |
! |
830 |
||
831 |
removeFromIndex:startIndex |
|
5840 | 832 |
"remove the children from startIndex up to end of children. |
833 |
Returns the receiver." |
|
834 |
||
835 |
self synchronized:[ |
|
836 |
self removeFromIndex:startIndex toIndex:(children size) |
|
837 |
]. |
|
838 |
||
839 |
"Modified: / 28-07-2018 / 13:44:07 / Claus Gittinger" |
|
4733 | 840 |
! |
841 |
||
842 |
removeFromIndex:startIndex toIndex:stopIndex |
|
843 |
"remove the children from startIndex up to and including |
|
844 |
the child under stopIndex. |
|
845 |
Returns the receiver." |
|
846 |
||
5840 | 847 |
self synchronized:[ |
5870 | 848 |
|nrOfChildren| |
5840 | 849 |
|
850 |
nrOfChildren := children size. |
|
851 |
||
852 |
(startIndex <= stopIndex and:[startIndex <= nrOfChildren]) ifTrue:[ |
|
5870 | 853 |
self basicRemoveFromIndex:startIndex toIndex:(stopIndex min:nrOfChildren) |
5840 | 854 |
]. |
5870 | 855 |
(children isEmptyOrNil and:[self clearExpandedWhenLastChildWasRemoved]) ifTrue:[ |
856 |
self setExpanded:false. |
|
5840 | 857 |
]. |
4733 | 858 |
]. |
859 |
||
5840 | 860 |
"Modified: / 28-07-2018 / 13:45:07 / Claus Gittinger" |
5870 | 861 |
"Modified: / 02-08-2018 / 15:51:19 / Stefan Vogel" |
4733 | 862 |
! |
863 |
||
864 |
removeIndex:anIndex |
|
6073 | 865 |
"remove the child at an index. |
866 |
Returns the receiver" |
|
4733 | 867 |
|
868 |
anIndex > 0 ifTrue:[ |
|
869 |
self removeFromIndex:anIndex toIndex:anIndex |
|
870 |
] |
|
6073 | 871 |
|
872 |
"Modified (comment): / 24-06-2019 / 12:47:27 / Claus Gittinger" |
|
4733 | 873 |
! ! |
874 |
||
875 |
!AbstractHierarchicalItem methodsFor:'basic adding & removing'! |
|
876 |
||
5870 | 877 |
basicAdd:aChild sortBlock:aBlockOrNil |
5840 | 878 |
"add a child sorted. |
879 |
Not synchronized - should only be called internally |
|
880 |
within a synchronized region." |
|
4733 | 881 |
|
882 |
|size list| |
|
883 |
||
884 |
size := children size. |
|
885 |
list := Array with:aChild. |
|
886 |
||
5870 | 887 |
(aBlockOrNil notNil and:[size ~~ 0]) ifTrue:[ |
4733 | 888 |
children keysAndValuesDo:[:i :el| |
5870 | 889 |
(aBlockOrNil value:aChild value:el) ifTrue:[ |
4733 | 890 |
self basicAddAll:list beforeIndex:i. |
891 |
^ aChild |
|
892 |
] |
|
893 |
] |
|
894 |
]. |
|
5870 | 895 |
|
896 |
"insert at the end" |
|
4733 | 897 |
self basicAddAll:list beforeIndex:(size + 1). |
898 |
^ aChild. |
|
5840 | 899 |
|
900 |
"Modified (comment): / 28-07-2018 / 13:46:12 / Claus Gittinger" |
|
5870 | 901 |
"Modified (comment): / 01-08-2018 / 16:07:16 / Stefan Vogel" |
4733 | 902 |
! |
903 |
||
904 |
basicAddAll:aList beforeIndex:anIndex |
|
5840 | 905 |
"add children before an index. |
906 |
Not synchronized - should only be called internally |
|
907 |
within a synchronized region." |
|
4733 | 908 |
|
5994 | 909 |
|coll model notify index oldSize| |
910 |
||
911 |
oldSize := children size. |
|
4733 | 912 |
|
913 |
anIndex == 1 ifTrue:[ |
|
914 |
notify := self |
|
915 |
] ifFalse:[ |
|
5994 | 916 |
anIndex > oldSize ifTrue:[ |
917 |
anIndex > (1 + oldSize) ifTrue:[ |
|
4733 | 918 |
^ self subscriptBoundsError:index |
919 |
]. |
|
5994 | 920 |
notify := self at:oldSize |
4733 | 921 |
] ifFalse:[ |
922 |
notify := nil |
|
923 |
] |
|
924 |
]. |
|
5870 | 925 |
|
926 |
aList do:[:eachItem| eachItem parent:self ]. |
|
927 |
||
5994 | 928 |
oldSize == 0 ifTrue:[ |
5993 | 929 |
self setChildren:(OrderedCollection withAll:aList). |
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
930 |
] ifFalse:[ |
5870 | 931 |
children isArray ifTrue:[ |
5993 | 932 |
self setChildren:(children asOrderedCollection) |
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
933 |
]. |
5870 | 934 |
children addAll:aList beforeIndex:anIndex. |
4733 | 935 |
]. |
5993 | 936 |
|
4733 | 937 |
(model := self model) isNil ifTrue:[ |
938 |
^ aList |
|
939 |
]. |
|
940 |
||
941 |
self isExpanded ifFalse:[ |
|
942 |
notify notNil ifTrue:[ |
|
943 |
notify changed |
|
944 |
]. |
|
945 |
^ aList |
|
946 |
]. |
|
947 |
(index := self listIndex) isNil ifTrue:[ |
|
948 |
^ aList |
|
949 |
]. |
|
950 |
||
951 |
children from:1 to:(anIndex - 1) do:[:anItem| |
|
952 |
index := 1 + index + anItem numberOfVisibleChildren |
|
953 |
]. |
|
5857 | 954 |
|
4733 | 955 |
coll := OrderedCollection new. |
956 |
aList do:[:anItem| |
|
957 |
coll add:anItem. |
|
958 |
anItem addVisibleChildrenTo:coll. |
|
959 |
]. |
|
960 |
model itemAddAll:coll beforeIndex:(index + 1). |
|
961 |
||
962 |
notify notNil ifTrue:[ |
|
963 |
notify changed |
|
964 |
]. |
|
965 |
^ aList |
|
5840 | 966 |
|
5870 | 967 |
"Modified: / 01-08-2018 / 15:31:54 / Stefan Vogel" |
968 |
"Modified (format): / 02-08-2018 / 15:52:16 / Stefan Vogel" |
|
5993 | 969 |
"Modified: / 03-02-2019 / 19:32:25 / Claus Gittinger" |
5994 | 970 |
"Modified (format): / 06-02-2019 / 15:58:41 / Claus Gittinger" |
4733 | 971 |
! |
972 |
||
973 |
basicRemoveFromIndex:startIndex toIndex:stopIndex |
|
974 |
"remove the children from startIndex up to and including |
|
5840 | 975 |
the child under stopIndex. |
976 |
Not synchronized - should only be called internally |
|
977 |
within a synchronized region." |
|
4733 | 978 |
|
979 |
|model notify |
|
980 |
index "{ Class:SmallInteger }" |
|
981 |
start "{ Class:SmallInteger }" |
|
982 |
stop "{ Class:SmallInteger }" |
|
983 |
size "{ Class:SmallInteger }" |
|
984 |
| |
|
985 |
size := self children size. |
|
986 |
stop := stopIndex. |
|
987 |
start := startIndex. |
|
988 |
||
989 |
(stop <= size and:[start between:1 and:stop]) ifFalse:[ |
|
990 |
^ self subscriptBoundsError:index |
|
991 |
]. |
|
992 |
start == 1 ifTrue:[ |
|
993 |
notify := self |
|
994 |
] ifFalse:[ |
|
995 |
stop == size ifTrue:[ |
|
996 |
notify := self at:(start - 1) |
|
997 |
] ifFalse:[ |
|
998 |
notify := nil |
|
999 |
] |
|
1000 |
]. |
|
1001 |
||
1002 |
(model := self model) notNil ifTrue:[ |
|
1003 |
index := model identityIndexOf:(children at:start). |
|
1004 |
size := stop - start + 1. |
|
1005 |
] ifFalse:[ |
|
1006 |
index := 0 |
|
1007 |
]. |
|
1008 |
||
1009 |
children from:start to:stop do:[:aChild| |
|
1010 |
index ~~ 0 ifTrue:[ |
|
1011 |
size := size + aChild numberOfVisibleChildren |
|
1012 |
]. |
|
1013 |
aChild parent:nil |
|
1014 |
]. |
|
1015 |
children removeFromIndex:start toIndex:stop. |
|
1016 |
||
1017 |
index ~~ 0 ifTrue:[ |
|
1018 |
model itemRemoveFromIndex:index toIndex:(index + size - 1) |
|
1019 |
]. |
|
1020 |
notify notNil ifTrue:[ |
|
1021 |
notify changed |
|
1022 |
]. |
|
5840 | 1023 |
|
1024 |
"Modified (format): / 28-07-2018 / 13:46:41 / Claus Gittinger" |
|
4733 | 1025 |
! ! |
1026 |
||
1027 |
!AbstractHierarchicalItem methodsFor:'change & update'! |
|
1028 |
||
1029 |
changed:what with:anArgument |
|
1030 |
"the item changed; raise change notification |
|
1031 |
#icon icon is modified; height and width are unchanged |
|
1032 |
#hierarchy collapsed/expanded; height and width are unchanged |
|
1033 |
#redraw redraw but height and width are unchanged |
|
1034 |
....... all others: the height and width are reset |
|
1035 |
" |
|
5886 | 1036 |
|
4733 | 1037 |
|model| |
1038 |
||
5860 | 1039 |
(what ~~ #redraw |
1040 |
and:[what ~~ #hierarchy |
|
1041 |
and:[what ~~ #icon |
|
1042 |
and:[self class doResetExtentOnChange]]]) ifTrue:[ |
|
1043 |
self makeWidthAndHeightUnknown |
|
1044 |
]. |
|
1045 |
||
5886 | 1046 |
(model := self model) notNil ifTrue:[ |
1047 |
self synchronized:[ |
|
5860 | 1048 |
model itemChanged:what with:anArgument from:self. |
4733 | 1049 |
]. |
1050 |
]. |
|
1051 |
super changed:what with:anArgument |
|
1052 |
||
1053 |
"Modified: / 24-11-2010 / 17:21:20 / cg" |
|
5861 | 1054 |
"Modified: / 30-07-2018 / 15:58:18 / Stefan Vogel" |
5886 | 1055 |
"Modified (format): / 15-08-2018 / 12:37:03 / Claus Gittinger" |
4733 | 1056 |
! |
1057 |
||
1058 |
childrenOrderChanged |
|
1059 |
"called if the order of the children changed by a user |
|
1060 |
operation. Update the model and raise a change notification for |
|
1061 |
each item which has changed its position |
|
1062 |
triggered by the user operation !!" |
|
1063 |
||
1064 |
|model visStart list| |
|
1065 |
||
1066 |
self isExpanded ifFalse:[ ^ self ]. "/ not expanded |
|
1067 |
children size > 1 ifFalse:[ ^ self ]. |
|
1068 |
||
1069 |
model := self model. |
|
1070 |
model isNil ifTrue:[^ self]. "/ no model |
|
1071 |
||
1072 |
visStart := model identityIndexOf:self. |
|
1073 |
visStart == 0 ifTrue:[ |
|
1074 |
model root ~~ self ifTrue:[ ^ self ]. |
|
5840 | 1075 |
"/ I'am the root but switched of by setting #showRoot to false |
4733 | 1076 |
]. |
1077 |
||
5840 | 1078 |
self synchronized:[ |
4733 | 1079 |
list := OrderedCollection new. |
1080 |
self addVisibleChildrenTo:list. |
|
1081 |
||
1082 |
list do:[:el| |
|
1083 |
visStart := visStart + 1. |
|
1084 |
||
1085 |
(model at:visStart ifAbsent:el) ~~ el ifTrue:[ |
|
1086 |
model at:visStart put:el |
|
1087 |
]. |
|
1088 |
] |
|
1089 |
]. |
|
5840 | 1090 |
|
1091 |
"Modified (format): / 28-07-2018 / 13:47:27 / Claus Gittinger" |
|
4733 | 1092 |
! |
1093 |
||
1094 |
fontChanged |
|
1095 |
"called if the font has changed. |
|
1096 |
Clear the precomputed width and height" |
|
1097 |
||
1098 |
self makeWidthAndHeightUnknown. |
|
1099 |
||
5870 | 1100 |
children notNil ifTrue:[ |
4733 | 1101 |
children do:[:el| el fontChanged]. |
1102 |
]. |
|
5870 | 1103 |
|
1104 |
"Modified: / 02-08-2018 / 15:53:52 / Stefan Vogel" |
|
4733 | 1105 |
! |
1106 |
||
1107 |
hierarchyChanged |
|
1108 |
"hierarchy changed; optimize redrawing" |
|
1109 |
||
1110 |
self changed:#hierarchy with:nil |
|
1111 |
! |
|
1112 |
||
1113 |
iconChanged |
|
1114 |
"icon changed; optimize redrawing" |
|
1115 |
||
1116 |
self changed:#icon with:nil |
|
1117 |
! |
|
1118 |
||
5886 | 1119 |
invalidate |
1120 |
"force redrawing of me" |
|
1121 |
||
1122 |
self changed:#redraw with:nil |
|
1123 |
||
1124 |
"Created: / 15-08-2018 / 12:38:48 / Claus Gittinger" |
|
1125 |
! |
|
1126 |
||
4733 | 1127 |
labelChanged |
1128 |
"called if the label has changed. |
|
5887 | 1129 |
Clear the precomputed width and height, and invalidate" |
4733 | 1130 |
|
1131 |
self makeWidthAndHeightUnknown. |
|
5887 | 1132 |
self invalidate |
4733 | 1133 |
|
1134 |
"Created: / 17-01-2011 / 17:43:42 / cg" |
|
5887 | 1135 |
"Modified: / 15-08-2018 / 12:43:20 / Claus Gittinger" |
4733 | 1136 |
! ! |
1137 |
||
1138 |
!AbstractHierarchicalItem methodsFor:'enumerating'! |
|
1139 |
||
5623 | 1140 |
allExpandedItemsDo:aBlock |
1141 |
"recursively enumerate all expanded nodes |
|
1142 |
(depth first; parent before children)" |
|
1143 |
||
1144 |
self recursiveDo:[:each | |
|
1145 |
each isExpanded ifTrue:[ |
|
1146 |
aBlock value:each. |
|
1147 |
]. |
|
1148 |
]. |
|
1149 |
||
1150 |
"Created: / 16-10-2017 / 14:19:00 / cg" |
|
1151 |
! |
|
1152 |
||
4733 | 1153 |
collect:aBlock |
5363 | 1154 |
"for each child in the receiver (non recursive), evaluate the argument, aBlock |
4733 | 1155 |
and return a new collection with the results" |
1156 |
||
1157 |
|coll| |
|
1158 |
||
1159 |
coll := OrderedCollection new. |
|
1160 |
self do:[:el| coll add:(aBlock value:el) ]. |
|
1161 |
^ coll |
|
5363 | 1162 |
|
1163 |
"Modified (comment): / 25-11-2016 / 08:42:19 / cg" |
|
4733 | 1164 |
! |
1165 |
||
1166 |
contains:aBlock |
|
5363 | 1167 |
"evaluate aOneArgBlock for each of the receiver's children (non recursive). |
4733 | 1168 |
Return true and skip remaining elements, if aBlock ever returns true, |
1169 |
otherwise return false" |
|
1170 |
||
1171 |
self do:[:el | (aBlock value:el) ifTrue:[^ true] ]. |
|
1172 |
^ false |
|
5362 | 1173 |
|
5363 | 1174 |
"Modified (comment): / 25-11-2016 / 08:43:31 / cg" |
4733 | 1175 |
! |
1176 |
||
1177 |
do:aOneArgBlock |
|
5363 | 1178 |
"evaluate a block for each child (non recursive)" |
4733 | 1179 |
|
1180 |
self from:1 to:nil do:aOneArgBlock |
|
5363 | 1181 |
|
1182 |
"Modified (comment): / 25-11-2016 / 08:43:36 / cg" |
|
4733 | 1183 |
! |
1184 |
||
1185 |
from:startIndex do:aOneArgBlock |
|
1186 |
"evaluate a block on each child starting with the |
|
5362 | 1187 |
child at startIndex to the end." |
1188 |
||
4733 | 1189 |
self from:startIndex to:nil do:aOneArgBlock |
5362 | 1190 |
|
1191 |
"Modified (comment): / 25-11-2016 / 07:45:55 / cg" |
|
4733 | 1192 |
! |
1193 |
||
1194 |
from:startIndex reverseDo:aOneArgBlock |
|
5363 | 1195 |
"evaluate a block on each child (non recursive) starting at end to the startIndex" |
5362 | 1196 |
|
4733 | 1197 |
self from:startIndex to:nil reverseDo:aOneArgBlock |
5362 | 1198 |
|
5363 | 1199 |
"Modified (comment): / 25-11-2016 / 08:43:42 / cg" |
4733 | 1200 |
! |
1201 |
||
1202 |
from:startIndex to:endIndex do:aOneArgBlock |
|
5996 | 1203 |
"WARNING: may fetch lazy children |
1204 |
evaluate a block on each child (non recursive), |
|
5870 | 1205 |
starting with the child at startIndex to the endIndex (last index if nil). |
6121 | 1206 |
Answer the value of the block executed on the last element. |
1207 |
cg: this is stupid: everyoe else in the world returns the receiver from do:-like messages, |
|
1208 |
and noone seems to need this last result (afaik). |
|
1209 |
Also: other enumeration methods found here don't do that (see from:to:reverseDo:) |
|
1210 |
So this ought to be changed." |
|
5870 | 1211 |
|
1212 |
^ self synchronized:[ |
|
1213 |
self nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
4733 | 1214 |
]. |
5363 | 1215 |
|
1216 |
"Modified (comment): / 25-11-2016 / 08:43:51 / cg" |
|
5840 | 1217 |
"Modified: / 28-07-2018 / 13:48:49 / Claus Gittinger" |
5870 | 1218 |
"Modified: / 02-08-2018 / 16:04:04 / Stefan Vogel" |
5996 | 1219 |
"Modified (comment): / 12-02-2019 / 18:49:58 / Claus Gittinger" |
4733 | 1220 |
! |
1221 |
||
6193 | 1222 |
from:startIndex to:endIndex doOnCachedChildren:aOneArgBlock |
1223 |
"WARNING: This uses only the children, that are already known, i.e. it does |
|
1224 |
NOT fetch lazy children, but uses the list cached in the instance variable. |
|
1225 |
Evaluate a block on each child (non recursive), |
|
1226 |
starting with the child at startIndex to the endIndex (last index if nil). |
|
1227 |
Answer the value of the block executed on the last element. |
|
1228 |
cg: this is stupid: everyoe else in the world returns the receiver from do:-like messages, |
|
1229 |
and noone seems to need this last result (afaik). |
|
1230 |
Also: other enumeration methods found here don't do that (see from:to:reverseDo:) |
|
1231 |
So this ought to be changed." |
|
1232 |
||
1233 |
^ self synchronized:[ |
|
1234 |
self nonCriticalFrom:startIndex to:endIndex doOnCachedChildren:aOneArgBlock |
|
1235 |
]. |
|
1236 |
||
1237 |
"Created: / 11-12-2019 / 10:28:55 / Maren Tilk" |
|
1238 |
! |
|
1239 |
||
4733 | 1240 |
from:startIndex to:endIndex reverseDo:aOneArgBlock |
5996 | 1241 |
"WARNING: may fetch lazy children |
1242 |
evaluate a block on each child (non recursive), |
|
5363 | 1243 |
starting with the child at endIndex to the startIndex." |
4733 | 1244 |
|
5840 | 1245 |
self synchronized:[ |
1246 |
self size >= startIndex ifTrue:[ |
|
1247 |
self nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
|
1248 |
]. |
|
4733 | 1249 |
]. |
5363 | 1250 |
|
1251 |
"Modified (comment): / 25-11-2016 / 08:43:58 / cg" |
|
5840 | 1252 |
"Modified: / 28-07-2018 / 13:49:17 / Claus Gittinger" |
5996 | 1253 |
"Modified (comment): / 12-02-2019 / 18:50:04 / Claus Gittinger" |
4733 | 1254 |
! |
1255 |
||
1256 |
keysAndValuesDo:aTwoArgBlock |
|
5363 | 1257 |
"evaluate the argument, aBlock for every child (non recursive), |
4733 | 1258 |
passing both index and element as arguments." |
1259 |
||
5840 | 1260 |
|key| |
4733 | 1261 |
|
1262 |
key := 1. |
|
1263 |
||
1264 |
self do:[:el| |
|
5840 | 1265 |
el value:key value:el. |
4733 | 1266 |
key := key + 1. |
1267 |
]. |
|
5363 | 1268 |
|
1269 |
"Modified (comment): / 25-11-2016 / 08:44:03 / cg" |
|
5840 | 1270 |
"Modified: / 28-07-2018 / 13:49:35 / Claus Gittinger" |
4733 | 1271 |
! |
1272 |
||
1273 |
keysAndValuesReverseDo:aTwoArgBlock |
|
5996 | 1274 |
"WARNING: may fetch lazy children |
1275 |
evaluate the argument, aBlock in reverse order for every child (non recursive), |
|
5362 | 1276 |
passing both index and element as arguments." |
4733 | 1277 |
|
5840 | 1278 |
self synchronized:[ |
1279 |
self size == 0 ifFalse:[ |
|
1280 |
self nonCriticalKeysAndValuesReverseDo:aTwoArgBlock |
|
1281 |
]. |
|
4733 | 1282 |
]. |
5362 | 1283 |
|
5363 | 1284 |
"Modified (comment): / 25-11-2016 / 08:44:06 / cg" |
5840 | 1285 |
"Modified: / 28-07-2018 / 13:50:14 / Claus Gittinger" |
5996 | 1286 |
"Modified (comment): / 12-02-2019 / 18:50:08 / Claus Gittinger" |
4733 | 1287 |
! |
1288 |
||
1289 |
recursiveCollect:aBlock |
|
1290 |
"for each child in the receiver, evaluate the argument, aBlock |
|
5363 | 1291 |
and return a new collection with the results. |
1292 |
Warning: this only enumerates already visible child elements |
|
1293 |
i.e. any collapsed items are not visited." |
|
4733 | 1294 |
|
1295 |
|coll| |
|
1296 |
||
1297 |
coll := OrderedCollection new. |
|
1298 |
self recursiveDo:[:el| coll add:(aBlock value:el) ]. |
|
1299 |
^ coll |
|
5363 | 1300 |
|
1301 |
"Modified (comment): / 25-11-2016 / 08:43:20 / cg" |
|
4733 | 1302 |
! |
1303 |
||
1304 |
recursiveDo:aOneArgBlock |
|
5996 | 1305 |
"WARNING: may fetch lazy children |
1306 |
evaluate a block on each item and all the sub-items. |
|
5363 | 1307 |
Warning: this only enumerates already visible child elements |
1308 |
i.e. any collapsed items are not visited." |
|
4733 | 1309 |
|
5840 | 1310 |
self do:[:aChild| "/ notice: do does it synchronized |
4733 | 1311 |
aOneArgBlock value:aChild. |
1312 |
aChild nonCriticalRecursiveDo:aOneArgBlock |
|
1313 |
]. |
|
5363 | 1314 |
|
1315 |
"Modified (comment): / 25-11-2016 / 08:43:04 / cg" |
|
5996 | 1316 |
"Modified (comment): / 12-02-2019 / 18:51:21 / Claus Gittinger" |
4733 | 1317 |
! |
1318 |
||
6047 | 1319 |
recursiveDo:aOneArgBlock skipIf:elementCheck skipChildrenIf:childrenCheck |
6159 | 1320 |
"Do recursive, but skip an element and its subtree, |
1321 |
if elementCheck evaluates to true for the element. |
|
1322 |
Also do not go on with the recursion for the children |
|
1323 |
of an element if childrenCheck evalueates to true |
|
1324 |
for the element. |
|
1325 |
WARNING: may fetch lazy children |
|
6047 | 1326 |
evaluate a block on each item and all the sub-items. |
1327 |
Warning: this only enumerates already visible child elements |
|
1328 |
i.e. any collapsed items are not visited." |
|
1329 |
||
1330 |
self do:[:aChild| "/ notice: do does it synchronized |
|
1331 |
(elementCheck value:aChild) ifFalse:[ |
|
1332 |
aOneArgBlock value:aChild. |
|
1333 |
]. |
|
1334 |
(childrenCheck value:aChild) ifFalse:[ |
|
6159 | 1335 |
aChild recursiveDo:aOneArgBlock skipIf:elementCheck skipChildrenIf:childrenCheck |
6047 | 1336 |
]. |
1337 |
]. |
|
1338 |
||
1339 |
"Created: / 07-05-2019 / 13:12:53 / Claus Gittinger" |
|
6159 | 1340 |
"Modified: / 30-09-2019 / 12:01:04 / Maren" |
1341 |
"Modified (comment): / 30-09-2019 / 18:02:46 / Maren" |
|
6047 | 1342 |
! |
1343 |
||
6193 | 1344 |
recursiveDoOnCachedChildren:aOneArgBlock |
1345 |
"WARNING: This uses only the children, that are already known, i.e. it does |
|
1346 |
NOT fetch lazy children, but uses the list cached in the instance variable. |
|
1347 |
Evaluate a block on each item and all the sub-items. |
|
1348 |
Warning: this only enumerates already visible child elements |
|
1349 |
i.e. any collapsed items are not visited." |
|
1350 |
||
1351 |
self from:1 to:nil doOnCachedChildren:[:aChild| "/ notice: do does it synchronized |
|
1352 |
aOneArgBlock value:aChild. |
|
1353 |
aChild nonCriticalRecursiveDoOnCachedChildren:aOneArgBlock |
|
1354 |
]. |
|
1355 |
||
1356 |
"Created: / 11-12-2019 / 10:32:19 / Maren Tilk" |
|
1357 |
! |
|
1358 |
||
4733 | 1359 |
recursiveReverseDo:aOneArgBlock |
5996 | 1360 |
"WARNING: may fetch lazy children |
1361 |
evaluate a block on each item and all the sub-items; |
|
5363 | 1362 |
proccesing children in reverse direction. |
1363 |
Warning: this only enumerates already visible child elements |
|
1364 |
i.e. any collapsed items are not visited." |
|
4733 | 1365 |
|
5840 | 1366 |
self reverseDo:[:aChild| "/ notice: reverseDo does it synchronized |
4733 | 1367 |
aChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
1368 |
aOneArgBlock value:aChild. |
|
1369 |
]. |
|
5363 | 1370 |
|
1371 |
"Modified (comment): / 25-11-2016 / 08:43:09 / cg" |
|
5996 | 1372 |
"Modified (comment): / 12-02-2019 / 18:51:09 / Claus Gittinger" |
4733 | 1373 |
! |
1374 |
||
1375 |
recursiveSelect:aBlock |
|
5362 | 1376 |
"return a new collection with all children and subChildren from the receiver, |
5363 | 1377 |
for which the argument aBlock evaluates to true. |
1378 |
Warning: this only enumerates already visible child elements |
|
1379 |
i.e. any collapsed items are not visited." |
|
4733 | 1380 |
|
1381 |
|coll| |
|
1382 |
||
1383 |
coll := OrderedCollection new. |
|
1384 |
self recursiveDo:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
|
1385 |
^ coll |
|
5362 | 1386 |
|
5363 | 1387 |
"Modified (comment): / 25-11-2016 / 08:43:12 / cg" |
4733 | 1388 |
! |
1389 |
||
1390 |
reverseDo:aOneArgBlock |
|
5363 | 1391 |
"evaluate a block on each child (non recursive) in reverse direction" |
4733 | 1392 |
|
1393 |
self from:1 reverseDo:aOneArgBlock |
|
5363 | 1394 |
|
1395 |
"Modified (comment): / 25-11-2016 / 08:44:12 / cg" |
|
4733 | 1396 |
! |
1397 |
||
1398 |
select:aBlock |
|
5363 | 1399 |
"return a new collection with all items from the receiver (non recursive), |
1400 |
for which the argument aBlock evaluates to true." |
|
4733 | 1401 |
|
1402 |
|coll| |
|
1403 |
||
1404 |
coll := OrderedCollection new. |
|
1405 |
self do:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
|
1406 |
^ coll |
|
5363 | 1407 |
|
1408 |
"Modified (comment): / 25-11-2016 / 08:44:20 / cg" |
|
4733 | 1409 |
! |
1410 |
||
1411 |
withAllDo:aOneArgBlock |
|
5996 | 1412 |
"WARNING: may fetch lazy children |
1413 |
recursively evaluate aOneArgBlock on each item and subitem including self" |
|
4733 | 1414 |
|
1415 |
aOneArgBlock value:self. |
|
1416 |
||
5840 | 1417 |
self do:[:el| "/ do does it synchronized |
4733 | 1418 |
aOneArgBlock value:el. |
1419 |
el nonCriticalRecursiveDo:aOneArgBlock. |
|
1420 |
]. |
|
5363 | 1421 |
|
1422 |
"Modified (comment): / 25-11-2016 / 08:44:49 / cg" |
|
5996 | 1423 |
"Modified (comment): / 12-02-2019 / 18:50:40 / Claus Gittinger" |
4733 | 1424 |
! ! |
1425 |
||
1426 |
!AbstractHierarchicalItem methodsFor:'enumerating parents'! |
|
1427 |
||
5623 | 1428 |
allParents |
5925 | 1429 |
"return a collection of all parents (bottom to top, ie. in parent, grandparent, ... order)" |
5623 | 1430 |
|
1431 |
|parents| |
|
1432 |
||
1433 |
parents := OrderedCollection new. |
|
1434 |
self parentsDo:[:p | parents add:p]. |
|
1435 |
^ parents. |
|
1436 |
||
1437 |
"Created: / 16-10-2017 / 13:08:45 / cg" |
|
1438 |
! |
|
1439 |
||
4733 | 1440 |
parentsDetect:aBlock |
5925 | 1441 |
"find the first parent (bottom to top), for which evaluation of the block returns |
4733 | 1442 |
true; if none does so, report an error" |
1443 |
||
1444 |
^ self parentsDetect:aBlock ifNone:[self errorNotFound] |
|
1445 |
! |
|
1446 |
||
1447 |
parentsDetect:aBlock ifNone:anExceptionBlock |
|
5925 | 1448 |
"find the first parent (bottom to top), for which evaluation of the block returns |
4733 | 1449 |
true; if none does so, return the evaluation of anExceptionBlock" |
1450 |
||
5925 | 1451 |
self parentsDo:[:prnt | |
1452 |
(aBlock value:prnt) ifTrue:[^ prnt] |
|
4733 | 1453 |
]. |
1454 |
^ anExceptionBlock value |
|
5840 | 1455 |
|
1456 |
"Modified: / 28-07-2018 / 13:51:06 / Claus Gittinger" |
|
4733 | 1457 |
! |
1458 |
||
1459 |
parentsDo:aBlock |
|
5925 | 1460 |
"evaluate a block for each parent (bottom to top)" |
4733 | 1461 |
|
1462 |
|prnt| |
|
1463 |
||
1464 |
prnt := self. |
|
1465 |
||
5840 | 1466 |
self synchronized:[ |
4733 | 1467 |
[(prnt := prnt parent) notNil and:[prnt isHierarchicalItem]] whileTrue:[ |
1468 |
aBlock value:prnt |
|
1469 |
] |
|
1470 |
]. |
|
5840 | 1471 |
|
1472 |
"Modified: / 28-07-2018 / 13:51:22 / Claus Gittinger" |
|
4733 | 1473 |
! ! |
1474 |
||
1475 |
!AbstractHierarchicalItem methodsFor:'initialization'! |
|
1476 |
||
1477 |
initialize |
|
1478 |
self setExpanded:false |
|
1479 |
! ! |
|
1480 |
||
1481 |
!AbstractHierarchicalItem methodsFor:'private'! |
|
1482 |
||
1483 |
addVisibleChildrenTo:aList |
|
1484 |
"add all visible children and sub-children to the list" |
|
1485 |
||
1486 |
self isExpanded ifFalse:[^ self]. |
|
1487 |
||
5840 | 1488 |
self from:1 to:nil do:[:el| |
4733 | 1489 |
aList add:el. |
5996 | 1490 |
el isExpanded ifTrue:[ |
1491 |
el addVisibleChildrenTo:aList. |
|
1492 |
]. |
|
4733 | 1493 |
]. |
5840 | 1494 |
|
5996 | 1495 |
"Modified: / 12-02-2019 / 19:00:25 / Claus Gittinger" |
4733 | 1496 |
! |
1497 |
||
5998 | 1498 |
checkConsistency |
1499 |
|allChildrenDo idx expectedIndex| |
|
1500 |
||
1501 |
allChildrenDo := |
|
1502 |
[:item :action | |
|
1503 |
action value:item. |
|
1504 |
(item getChildren ? #()) do:[:subItem | |
|
1505 |
allChildrenDo value:subItem value:action |
|
1506 |
]. |
|
1507 |
]. |
|
1508 |
||
1509 |
idx := self listIndex. |
|
1510 |
self isExpanded ifFalse:[ |
|
1511 |
(self getChildren ? #()) do:[:eachChild | |
|
1512 |
allChildrenDo value:eachChild value:[:subItem | |
|
1513 |
self assert:(subItem listIndex isNil). |
|
1514 |
]. |
|
1515 |
]. |
|
1516 |
^ self. |
|
1517 |
]. |
|
1518 |
||
1519 |
expectedIndex := idx+1. |
|
1520 |
self getChildren do:[:eachChild | |
|
1521 |
self assert:(eachChild listIndex == expectedIndex). |
|
1522 |
expectedIndex := expectedIndex + 1 + eachChild numberOfVisibleChildren. |
|
1523 |
]. |
|
1524 |
||
1525 |
"Created: / 13-02-2019 / 12:31:24 / Claus Gittinger" |
|
1526 |
! |
|
1527 |
||
4733 | 1528 |
clearExpandedWhenLastChildWasRemoved |
5712 | 1529 |
"https://expeccoalm.exept.de/D227397 |
1530 |
Do not set #isExpanded to false just because #children is empty (may children appear 'again' later). |
|
1531 |
Do modify #isExpanded ONLY when a user presses the expand/collapse toggle, otherwise #isExpanded should be persistent. |
|
1532 |
||
1533 |
The user's preference if the item is expanded or collapsed should be kept, |
|
1534 |
regardless if there are chilren or not (even regardless anything else). |
|
1535 |
All other related things, like the drawing in case for #isExpanded is true and children is empty, |
|
1536 |
has to be solved within the drawing (or within any feature requesting this information)" |
|
1537 |
||
1538 |
^ false |
|
4733 | 1539 |
! |
1540 |
||
1541 |
criticalDo:aBlock |
|
5996 | 1542 |
<resource: #obsolete> |
5840 | 1543 |
self synchronized:aBlock |
5834 | 1544 |
|
1545 |
"Modified: / 23-07-2018 / 13:25:11 / Stefan Vogel" |
|
5840 | 1546 |
"Modified: / 28-07-2018 / 15:51:23 / Claus Gittinger" |
4733 | 1547 |
! |
1548 |
||
1549 |
listIndex |
|
5998 | 1550 |
"returns the index in the full list or nil; |
1551 |
for a non-visible root, 0 is returned" |
|
4733 | 1552 |
|
1553 |
|index model| |
|
1554 |
||
1555 |
(model := self model) notNil ifTrue:[ |
|
1556 |
index := model identityIndexOf:self. |
|
1557 |
||
1558 |
(index ~~ 0 or:[parent == model]) ifTrue:[ |
|
1559 |
^ index |
|
1560 |
] |
|
1561 |
]. |
|
1562 |
^ nil |
|
5998 | 1563 |
|
1564 |
"Modified (comment): / 13-02-2019 / 11:34:56 / Claus Gittinger" |
|
4733 | 1565 |
! |
1566 |
||
1567 |
numberOfVisibleChildren |
|
5996 | 1568 |
"returns the number of all visible children including subchildren, |
5998 | 1569 |
but excluding myself. |
1570 |
PseudoRecursive to avoid recursionError for very deep hierarchies." |
|
1571 |
||
1572 |
|count todo toCount itsChildren| |
|
4733 | 1573 |
|
1574 |
self isExpanded ifFalse:[^ 0]. |
|
5840 | 1575 |
|
1576 |
count := 0. |
|
5996 | 1577 |
todo := OrderedCollection with:self. |
1578 |
[todo notEmpty] whileTrue:[ |
|
1579 |
toCount := todo removeFirst. |
|
5998 | 1580 |
|
1581 |
itsChildren := toCount getChildren. |
|
6008 | 1582 |
itsChildren notNil ifTrue:[ |
1583 |
count := count + itsChildren size. |
|
1584 |
itsChildren do:[:each | |
|
1585 |
each isExpanded ifTrue:[ |
|
1586 |
todo add:each |
|
1587 |
]. |
|
5996 | 1588 |
]. |
6008 | 1589 |
]. |
4733 | 1590 |
]. |
5840 | 1591 |
^ count |
1592 |
||
6008 | 1593 |
"Modified: / 18-02-2019 / 18:36:17 / Claus Gittinger" |
4733 | 1594 |
! |
1595 |
||
1596 |
parentOrModel |
|
1597 |
"returns the parent without checking for item or model" |
|
1598 |
||
1599 |
^ parent |
|
5840 | 1600 |
! |
1601 |
||
5993 | 1602 |
setChildren:aCollectionOfChildrenOrNil |
5994 | 1603 |
children := aCollectionOfChildrenOrNil. |
1604 |
||
1605 |
Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ |
|
1606 |
children notNil ifTrue:[ |
|
1607 |
self assert:(children conform:[:each | each parent == self]). |
|
1608 |
]. |
|
1609 |
]. |
|
5993 | 1610 |
|
1611 |
"Created: / 03-02-2019 / 19:22:26 / Claus Gittinger" |
|
5994 | 1612 |
"Modified: / 06-02-2019 / 16:00:51 / Claus Gittinger" |
5993 | 1613 |
! |
1614 |
||
5840 | 1615 |
synchronized:aBlock |
6064 | 1616 |
"evaluate aBlock synchronized, i.e. use a monitor for this object; |
1617 |
return the value from aBlock" |
|
1618 |
||
5840 | 1619 |
|model| |
1620 |
||
1621 |
(model := self model) notNil ifTrue:[ |
|
5857 | 1622 |
^ model synchronized:aBlock |
5840 | 1623 |
] ifFalse:[ |
5977 | 1624 |
"/ self breakPoint:#cg. "/ should not happen |
5857 | 1625 |
^ aBlock value |
5840 | 1626 |
] |
1627 |
||
1628 |
"Created: / 28-07-2018 / 13:58:54 / Claus Gittinger" |
|
5857 | 1629 |
"Modified: / 29-07-2018 / 21:02:22 / Stefan Vogel" |
5977 | 1630 |
"Modified: / 21-12-2018 / 20:01:54 / Claus Gittinger" |
6064 | 1631 |
"Modified (comment): / 07-06-2019 / 13:51:36 / Claus Gittinger" |
4733 | 1632 |
! ! |
1633 |
||
1634 |
!AbstractHierarchicalItem methodsFor:'private-displaying'! |
|
1635 |
||
1636 |
displayLabel:aLabel h:lH on:aGC x:x y:y h:h |
|
1637 |
<resource: #obsolete> |
|
1638 |
||
1639 |
"display the label at x@y" |
|
1640 |
||
1641 |
"/ obsolete - left in for backward compatibility |
|
1642 |
self displayLabel:aLabel h:lH on:aGC x:x y:y h:h isHighlightedAsSelected:false |
|
1643 |
! |
|
1644 |
||
1645 |
displayLabel:aLabel h:lH on:aGC x:x y:y h:h isHighlightedAsSelected:isHighlightedAsSelected |
|
1646 |
"display the label at x@y" |
|
1647 |
||
4758
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1648 |
|y0| |
4733 | 1649 |
|
1650 |
lH ~~ 0 ifTrue:[ |
|
1651 |
y0 := y - ((lH + 1 - h) // 2). |
|
1652 |
y0 := y0 + (aLabel ascentOn:aGC). |
|
1653 |
||
1654 |
(aLabel isString not |
|
5821 | 1655 |
or:[(aLabel includes:(Character cr)) not]) ifTrue:[ |
4758
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1656 |
|labelShown| |
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1657 |
|
4733 | 1658 |
labelShown := aLabel. |
1659 |
isHighlightedAsSelected ifTrue:[ |
|
1660 |
(aLabel isText and:[aLabel hasChangeOfEmphasis]) ifTrue:[ |
|
1661 |
labelShown := Text string:aLabel string emphasisCollection:aLabel emphasis asArray. |
|
1662 |
labelShown emphasisAllRemove:#color. |
|
1663 |
]. |
|
1664 |
]. |
|
5821 | 1665 |
labelShown displayOn:aGC x:x y:y0. |
1666 |
^ self. |
|
4733 | 1667 |
]. |
1668 |
||
4758
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1669 |
aLabel asCollectionOfLines do:[:el| |
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1670 |
|labelShown| |
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1671 |
|
4733 | 1672 |
labelShown := el. |
1673 |
isHighlightedAsSelected ifTrue:[ |
|
1674 |
(el isText and:[el hasChangeOfEmphasis]) ifTrue:[ |
|
1675 |
labelShown := Text string:el string emphasisCollection:el emphasis asArray. |
|
1676 |
labelShown emphasisAllRemove:#color. |
|
1677 |
]. |
|
1678 |
]. |
|
1679 |
labelShown displayOn:aGC x:x y:y0. |
|
1680 |
y0 := y0 + (el heightOn:aGC) |
|
1681 |
] |
|
1682 |
]. |
|
1683 |
! |
|
1684 |
||
1685 |
heightOf:aLabel on:aGC |
|
1686 |
"returns the height of the label or 0" |
|
1687 |
||
1688 |
|h| |
|
1689 |
||
1690 |
aLabel isSequenceable ifFalse:[ |
|
6144 | 1691 |
aLabel isNil ifTrue:[^ 0]. |
1692 |
^ aLabel heightOn:aGC |
|
4733 | 1693 |
]. |
1694 |
||
1695 |
aLabel isString ifFalse:[ |
|
1696 |
h := 0. |
|
6144 | 1697 |
aLabel do:[:el | h := h max:(self heightOf:el on:aGC)]. |
4746
25341fd92e38
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4733
diff
changeset
|
1698 |
^ h |
4733 | 1699 |
]. |
1700 |
||
1701 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
|
1702 |
^ h * (aGC font height) |
|
1703 |
! |
|
1704 |
||
1705 |
widthOf:aLabel on:aGC |
|
6144 | 1706 |
"returns the width of the label or 0" |
4733 | 1707 |
|
1708 |
|w| |
|
1709 |
||
1710 |
aLabel isSequenceable ifFalse:[ |
|
6144 | 1711 |
aLabel isNil ifTrue:[^ 0]. |
1712 |
^ aLabel widthOn:aGC |
|
4733 | 1713 |
]. |
1714 |
||
1715 |
aLabel isString ifFalse:[ |
|
1716 |
w := -5. |
|
6144 | 1717 |
aLabel do:[:el| w := w + 5 + (self widthOf:el on:aGC)]. |
4733 | 1718 |
^ w |
1719 |
]. |
|
1720 |
||
1721 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
|
1722 |
^ aLabel widthOn:aGC |
|
1723 |
]. |
|
1724 |
||
1725 |
w := 0. |
|
6144 | 1726 |
aLabel asCollectionOfLines do:[:el | w := w max:(el widthOn:aGC)]. |
4733 | 1727 |
^ w |
1728 |
! ! |
|
1729 |
||
1730 |
!AbstractHierarchicalItem methodsFor:'private-enumerating'! |
|
1731 |
||
1732 |
nonCriticalDo:aOneArgBlock |
|
6026 | 1733 |
"WARNING: may fetch lazy children (i.e. calls #children) |
5996 | 1734 |
evaluate a block noncritical for each child. |
5840 | 1735 |
Not synchronized - should only be called internally |
1736 |
within a synchronized region." |
|
4733 | 1737 |
|
1738 |
^ self nonCriticalFrom:1 to:nil do:aOneArgBlock |
|
5840 | 1739 |
|
6026 | 1740 |
"Modified (comment): / 05-03-2019 / 09:37:32 / Claus Gittinger" |
4733 | 1741 |
! |
1742 |
||
1743 |
nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
6026 | 1744 |
"WARNING: may fetch lazy children (i.e. calls #children) |
5996 | 1745 |
evaluate a block noncritical for each child starting with the |
6026 | 1746 |
child at startIndex to the endIndex (if nil: to end of list). |
1747 |
Returns the value of the last block's evaluation. |
|
5840 | 1748 |
Not synchronized - should only be called internally |
5870 | 1749 |
within a synchronized region. |
1750 |
Answer the value of the block executed on the last element." |
|
4733 | 1751 |
|
1752 |
|list size resp| |
|
1753 |
||
1754 |
list := self children. |
|
1755 |
size := list size. |
|
1756 |
||
1757 |
startIndex > size ifTrue:[^ nil]. |
|
1758 |
resp := nil. |
|
1759 |
||
1760 |
endIndex notNil ifTrue:[ |
|
1761 |
size := size min:endIndex |
|
1762 |
]. |
|
1763 |
startIndex to:size do:[:i| |
|
1764 |
|item| |
|
1765 |
||
1766 |
item := list at:i ifAbsent:nil. |
|
5996 | 1767 |
item isNil ifTrue:[self halt:'oops - lost child item?'. ^ resp]. |
4733 | 1768 |
resp := aOneArgBlock value:item. |
1769 |
]. |
|
1770 |
^ resp |
|
5840 | 1771 |
|
5870 | 1772 |
"Modified (comment): / 02-08-2018 / 16:02:13 / Stefan Vogel" |
5996 | 1773 |
"Modified: / 12-02-2019 / 16:55:20 / Claus Gittinger" |
6026 | 1774 |
"Modified (comment): / 05-03-2019 / 09:37:28 / Claus Gittinger" |
4733 | 1775 |
! |
1776 |
||
6193 | 1777 |
nonCriticalFrom:startIndex to:endIndex doOnCachedChildren:aOneArgBlock |
1778 |
<resource: #todo> |
|
1779 |
"WARNING: This uses only the children, that are already known, i.e. it does |
|
1780 |
NOT fetch lazy children, but uses the list cached in the instance variable. |
|
1781 |
Evaluate a block noncritical for each child starting with the |
|
1782 |
child at startIndex to the endIndex (if nil: to end of list). |
|
1783 |
Returns the value of the last block's evaluation. |
|
1784 |
Not synchronized - should only be called internally |
|
1785 |
within a synchronized region. |
|
1786 |
Answer the value of the block executed on the last element." |
|
1787 |
||
1788 |
"/ TODO method is a copy of #nonCriticalFrom:to:do: |
|
1789 |
|list size resp| |
|
1790 |
||
1791 |
list := children ? #(). |
|
1792 |
size := list size. |
|
1793 |
||
1794 |
startIndex > size ifTrue:[^ nil]. |
|
1795 |
resp := nil. |
|
1796 |
||
1797 |
endIndex notNil ifTrue:[ |
|
1798 |
size := size min:endIndex |
|
1799 |
]. |
|
1800 |
startIndex to:size do:[:i| |
|
1801 |
|item| |
|
1802 |
||
1803 |
item := list at:i ifAbsent:nil. |
|
1804 |
item isNil ifTrue:[self halt:'oops - lost child item?'. ^ resp]. |
|
1805 |
resp := aOneArgBlock value:item. |
|
1806 |
]. |
|
1807 |
^ resp |
|
1808 |
||
1809 |
"Created: / 11-12-2019 / 10:17:39 / Maren Tilk" |
|
1810 |
"Modified (comment): / 11-12-2019 / 14:59:39 / Maren Tilk" |
|
1811 |
! |
|
1812 |
||
6026 | 1813 |
nonCriticalFrom:startIndex to:endIndexArg reverseDo:aOneArgBlock |
1814 |
"WARNING: may fetch lazy children (i.e. calls #children) |
|
5996 | 1815 |
evaluate a block non critical for each child starting with the |
6026 | 1816 |
child at endIndex (if nil: from the end of list) down to to startIndex. |
1817 |
Returns the value of the last block's evaluation. |
|
5840 | 1818 |
Not synchronized - should only be called internally |
1819 |
within a synchronized region." |
|
4733 | 1820 |
|
6026 | 1821 |
|list endIndex resp| |
4733 | 1822 |
|
1823 |
list := self children. |
|
6026 | 1824 |
endIndex := list size. |
4733 | 1825 |
resp := nil. |
1826 |
||
6026 | 1827 |
endIndexArg notNil ifTrue:[ |
1828 |
endIndex := endIndex min:endIndexArg |
|
4733 | 1829 |
]. |
6026 | 1830 |
endIndex to:startIndex by:-1 do:[:i| |
4733 | 1831 |
|item| |
1832 |
||
1833 |
item := list at:i ifAbsent:nil. |
|
1834 |
item isNil ifTrue:[^ resp]. |
|
1835 |
resp := aOneArgBlock value:item. |
|
1836 |
]. |
|
1837 |
^ resp |
|
5840 | 1838 |
|
6026 | 1839 |
"Modified (comment): / 05-03-2019 / 09:40:33 / Claus Gittinger" |
4733 | 1840 |
! |
1841 |
||
1842 |
nonCriticalKeysAndValuesReverseDo:aOneArgBlock |
|
6026 | 1843 |
"WARNING: may fetch lazy children (i.e. calls #children) |
5996 | 1844 |
evaluate the argument, aBlock in reverse order for every |
5840 | 1845 |
child, passing both index and element as arguments. |
1846 |
Not synchronized - should only be called internally |
|
1847 |
within a synchronized region." |
|
4733 | 1848 |
|
1849 |
|list size resp| |
|
1850 |
||
1851 |
list := self children. |
|
1852 |
size := list size. |
|
1853 |
resp := nil. |
|
1854 |
||
1855 |
size to:1 by:-1 do:[:i| |
|
1856 |
|item| |
|
1857 |
||
1858 |
item := list at:i ifAbsent:nil. |
|
1859 |
item isNil ifTrue:[^ resp]. |
|
1860 |
resp := aOneArgBlock value:i value:item. |
|
1861 |
]. |
|
1862 |
^ resp |
|
5840 | 1863 |
|
6026 | 1864 |
"Modified (comment): / 05-03-2019 / 09:37:35 / Claus Gittinger" |
4733 | 1865 |
! |
1866 |
||
1867 |
nonCriticalRecursiveDo:aOneArgBlock |
|
6026 | 1868 |
"WARNING: may fetch lazy children (i.e. calls #children) |
5996 | 1869 |
evaluate the block non critical for each item and all the sub-items. |
5840 | 1870 |
Not synchronized - should only be called internally |
1871 |
within a synchronized region." |
|
4733 | 1872 |
|
1873 |
self nonCriticalFrom:1 to:nil do:[:eachChild| |
|
1874 |
aOneArgBlock value:eachChild. |
|
1875 |
eachChild nonCriticalRecursiveDo:aOneArgBlock |
|
1876 |
]. |
|
5840 | 1877 |
|
6026 | 1878 |
"Modified (comment): / 05-03-2019 / 09:37:48 / Claus Gittinger" |
4733 | 1879 |
! |
1880 |
||
6193 | 1881 |
nonCriticalRecursiveDoOnCachedChildren:aOneArgBlock |
1882 |
"WARNING: This uses only the children, that are already known, i.e. it does |
|
1883 |
NOT call #children, but uses the list cached in the instance variable. |
|
1884 |
Not synchronized - should only be called internally |
|
1885 |
within a synchronized region." |
|
1886 |
||
1887 |
self nonCriticalFrom:1 to:nil doOnCachedChildren:[:eachChild| |
|
1888 |
aOneArgBlock value:eachChild. |
|
1889 |
eachChild nonCriticalRecursiveDoOnCachedChildren:aOneArgBlock |
|
1890 |
]. |
|
1891 |
||
1892 |
"Created: / 11-12-2019 / 10:38:58 / Maren Tilk" |
|
1893 |
! |
|
1894 |
||
4733 | 1895 |
nonCriticalRecursiveReverseDo:aOneArgBlock |
6026 | 1896 |
"WARNING: may fetch lazy children (i.e. calls #children) |
5996 | 1897 |
evaluate the block non critical for each item and all the sub-items; |
5840 | 1898 |
proccesing children in reverse direction. |
1899 |
Not synchronized - should only be called internally |
|
1900 |
within a synchronized region." |
|
4733 | 1901 |
|
1902 |
self nonCriticalFrom:1 to:nil reverseDo:[:eachChild| |
|
1903 |
eachChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
|
1904 |
aOneArgBlock value:eachChild. |
|
1905 |
]. |
|
5840 | 1906 |
|
6026 | 1907 |
"Modified (comment): / 05-03-2019 / 09:37:52 / Claus Gittinger" |
4733 | 1908 |
! |
1909 |
||
1910 |
nonCriticalRecursiveSort:aSortBlock |
|
6026 | 1911 |
"recursively sort children using aSortBlock. |
1912 |
Does NOT fetch children (via #children), but sort the ones which are already present. |
|
5840 | 1913 |
Not synchronized - should only be called internally |
1914 |
within a synchronized region." |
|
4733 | 1915 |
|
1916 |
|unsorted sorted| |
|
1917 |
||
1918 |
unsorted := children. |
|
1919 |
||
1920 |
unsorted size ~~ 0 ifTrue:[ |
|
1921 |
sorted := unsorted sort:aSortBlock. |
|
1922 |
sorted do:[:el| el nonCriticalRecursiveSort:aSortBlock ]. |
|
5993 | 1923 |
self setChildren:sorted. |
4733 | 1924 |
]. |
5840 | 1925 |
|
5993 | 1926 |
"Modified: / 03-02-2019 / 19:24:03 / Claus Gittinger" |
6026 | 1927 |
"Modified (comment): / 05-03-2019 / 09:39:57 / Claus Gittinger" |
4733 | 1928 |
! ! |
1929 |
||
1930 |
!AbstractHierarchicalItem methodsFor:'private-hierarchy'! |
|
1931 |
||
1932 |
recursiveSetCollapsed |
|
5996 | 1933 |
<resource: #obsolete> |
4733 | 1934 |
"collapse all children and sub-children without notifications" |
1935 |
||
5840 | 1936 |
self synchronized:[ |
4733 | 1937 |
self recursiveSetCollapsedHelper |
1938 |
] |
|
5840 | 1939 |
|
1940 |
"Modified: / 28-07-2018 / 13:56:58 / Claus Gittinger" |
|
4733 | 1941 |
! |
1942 |
||
1943 |
recursiveSetCollapsedHelper |
|
1944 |
"private helper. |
|
1945 |
collapse all children and sub-children without notifications. |
|
5840 | 1946 |
Helper; not synchronized - should only be called internally |
5998 | 1947 |
within a synchronized region. |
1948 |
PseudoRecursive to avoid recursionError with deep hierarchies." |
|
4733 | 1949 |
|
5996 | 1950 |
|todo toCollapse| |
5998 | 1951 |
|
1952 |
self canRecursiveCollapse ifFalse:[^ self]. |
|
5996 | 1953 |
|
1954 |
todo := OrderedCollection with:self. |
|
1955 |
[todo notEmpty] whileTrue:[ |
|
1956 |
"/ do not call self size or self children; |
|
1957 |
"/ otherwise, children might will be autocreated !!!! |
|
1958 |
toCollapse := todo removeFirst. |
|
5998 | 1959 |
|
5996 | 1960 |
toCollapse setExpanded:false. |
6009 | 1961 |
(toCollapse getChildren ? #()) do:[:eachChild | |
5996 | 1962 |
eachChild canRecursiveCollapse ifTrue:[ |
1963 |
todo add:eachChild |
|
1964 |
]. |
|
5870 | 1965 |
] |
1966 |
]. |
|
5840 | 1967 |
|
5870 | 1968 |
"Modified: / 02-08-2018 / 16:07:35 / Stefan Vogel" |
6009 | 1969 |
"Modified: / 18-02-2019 / 18:37:49 / Claus Gittinger" |
4733 | 1970 |
! |
1971 |
||
1972 |
recursiveSetExpandedAndAddToList:aList |
|
5996 | 1973 |
<resource: #obsolete> |
4733 | 1974 |
"expand all children and sub-children without notifications; |
1975 |
add children to list" |
|
1976 |
||
5840 | 1977 |
self synchronized:[ |
4733 | 1978 |
self recursiveSetExpandedAndAddToListHelper:aList |
1979 |
]. |
|
5840 | 1980 |
|
1981 |
"Modified: / 28-07-2018 / 13:59:52 / Claus Gittinger" |
|
4733 | 1982 |
! |
1983 |
||
1984 |
recursiveSetExpandedAndAddToListHelper:aList |
|
1985 |
"private helper. |
|
1986 |
expand all children and sub-children without notifications; adds children to aList |
|
5840 | 1987 |
Helper; not synchronized - should only be called internally |
1988 |
within a synchronized region." |
|
4733 | 1989 |
|
5996 | 1990 |
|toDo work toExpand indexToAddAfter| |
1991 |
||
1992 |
toDo := OrderedCollection with:(self -> aList size). |
|
5925 | 1993 |
[ toDo notEmpty ] whileTrue:[ |
5996 | 1994 |
work := toDo removeFirst. |
1995 |
toExpand := work key. |
|
1996 |
indexToAddAfter := work value. |
|
5925 | 1997 |
toExpand setExpanded:true. |
5996 | 1998 |
(children := toExpand children) size > 0 ifTrue:[ |
1999 |
aList addAll:children afterIndex:indexToAddAfter. |
|
2000 |
children doWithIndex:[:eachChild :index | |
|
2001 |
eachChild canRecursiveExpand ifTrue:[ |
|
2002 |
toDo add:(eachChild -> (indexToAddAfter+index)) |
|
2003 |
]. |
|
5925 | 2004 |
]. |
4733 | 2005 |
]. |
2006 |
]. |
|
5840 | 2007 |
|
5996 | 2008 |
"Modified: / 12-02-2019 / 17:08:48 / Claus Gittinger" |
4733 | 2009 |
! ! |
2010 |
||
2011 |
!AbstractHierarchicalItem methodsFor:'private-to be redefined'! |
|
2012 |
||
4751
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
2013 |
fetchChildren |
6019 | 2014 |
"should return the list of children via the model. |
2015 |
The default here is to return nil (no children). |
|
2016 |
*** redefine in subClass" |
|
2017 |
||
4751
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
2018 |
^ nil |
6019 | 2019 |
|
2020 |
"Modified (comment): / 01-03-2019 / 19:53:38 / Claus Gittinger" |
|
4751
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
2021 |
! |
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
2022 |
|
4733 | 2023 |
heightOn:aGC |
2024 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
2025 |
||
2026 |
self subclassResponsibility. |
|
2027 |
||
2028 |
"/ could in theory compute it for every draw operation; |
|
2029 |
"/ in practice, this is not a good idea, as it could make drawing very slow |
|
2030 |
"/ (unless that info can be easily computed) |
|
2031 |
||
2032 |
"/ so we force programmers to think about that issue and redefine this method |
|
2033 |
"/ as required. If compuation is really cheap, it can be redefined as: |
|
2034 |
"/ ^ self heightOf:(self label) on:aGC |
|
2035 |
! |
|
2036 |
||
2037 |
isExpanded |
|
2038 |
"returns true if the item is expanded" |
|
2039 |
||
2040 |
self subclassResponsibility |
|
2041 |
! |
|
2042 |
||
2043 |
makeWidthAndHeightUnknown |
|
2044 |
"invalidate any cached with/height information" |
|
2045 |
||
2046 |
"see comments in widthOn/heightOn" |
|
2047 |
self subclassResponsibility |
|
2048 |
! |
|
2049 |
||
2050 |
setExpanded:aBoolean |
|
2051 |
"set expanded flag without any computation or notification. |
|
2052 |
It is left to the subclasses responsibility, where this expanded state is stored; |
|
2053 |
could be in the model (as a list of expanded items), in the item itself (as boolean flag), |
|
2054 |
or somewhere else. |
|
2055 |
For huge trees, it may make sense to not store the expanded flag in a slot |
|
2056 |
(in order to save space). See CompactHierarchicalItem as a clever example of how it can be |
|
2057 |
stored without ANY additional space requirements." |
|
2058 |
||
2059 |
self subclassResponsibility |
|
2060 |
! |
|
2061 |
||
2062 |
widthOn:aGC |
|
2063 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
2064 |
||
2065 |
self subclassResponsibility. |
|
2066 |
||
2067 |
"/ could in theory compute it for every draw operation; |
|
2068 |
"/ in practice, this is not a good idea, as it could make drawing very slow |
|
2069 |
"/ (unless that info can be easily computed) |
|
2070 |
||
2071 |
"/ so we force programmers to think about that issue and redefine this method |
|
2072 |
"/ as required. If compuation is really cheap, it can be redefined as: |
|
2073 |
"/ ^ self widthOf:(self label) on:aGC |
|
2074 |
! ! |
|
2075 |
||
2076 |
!AbstractHierarchicalItem methodsFor:'protocol-accessing'! |
|
2077 |
||
2078 |
children |
|
2079 |
"returns a list of children. When first asked, the list is fetched, if it was |
|
5116 | 2080 |
built lazily. |
4733 | 2081 |
*** to optimize: either redefine this or fetchChildren by subClass" |
2082 |
||
2083 |
children isNil ifTrue:[ |
|
5993 | 2084 |
self setChildren:(self fetchChildren) |
4733 | 2085 |
]. |
2086 |
^ children |
|
5993 | 2087 |
|
2088 |
"Modified: / 03-02-2019 / 19:23:55 / Claus Gittinger" |
|
4733 | 2089 |
! |
2090 |
||
2091 |
icon |
|
2092 |
"returns the icon or nil; |
|
2093 |
*** to optimize:redefine by subClass" |
|
2094 |
||
2095 |
|model| |
|
2096 |
||
2097 |
(model := self model) notNil ifTrue:[ |
|
2098 |
^ model iconFor:self |
|
2099 |
]. |
|
2100 |
^ nil |
|
2101 |
! |
|
2102 |
||
2103 |
label |
|
2104 |
"returns the label displayed on aGC; |
|
2105 |
*** to optimize:redefine by subClass" |
|
2106 |
||
2107 |
|model| |
|
2108 |
||
2109 |
(model := self model) notNil ifTrue:[ |
|
2110 |
^ model labelFor:self |
|
2111 |
]. |
|
2112 |
^ nil |
|
2113 |
! |
|
2114 |
||
2115 |
middleButtonMenu |
|
2116 |
"returns the items middleButtonMenu or nil if no menu is defined. |
|
2117 |
If nil is returned, the view is asked for a menu." |
|
2118 |
||
2119 |
<resource: #programMenu> |
|
2120 |
||
2121 |
|model| |
|
2122 |
||
2123 |
(model := self model) notNil ifTrue:[ |
|
2124 |
^ model middleButtonMenuFor:self |
|
2125 |
]. |
|
2126 |
^ nil |
|
2127 |
! |
|
2128 |
||
2129 |
recursiveSortChildren:aSortBlock |
|
5840 | 2130 |
self synchronized:[ |
2131 |
|children| |
|
2132 |
||
2133 |
(children := self children) notEmptyOrNil ifTrue:[ |
|
4733 | 2134 |
children sort:aSortBlock. |
2135 |
children do:[:aChild| aChild recursiveSortChildren:aSortBlock ] |
|
2136 |
] |
|
2137 |
]. |
|
5840 | 2138 |
|
2139 |
"Modified: / 28-07-2018 / 14:01:15 / Claus Gittinger" |
|
4733 | 2140 |
! |
2141 |
||
2142 |
sortChildren:aSortBlock |
|
2143 |
"sort the children inplace using the 2-arg block sortBlock for comparison" |
|
2144 |
||
2145 |
<resource: #obsolete> |
|
2146 |
self obsoleteMethodWarning:'use #sort:'. |
|
2147 |
self sort:aSortBlock. |
|
2148 |
! ! |
|
2149 |
||
2150 |
!AbstractHierarchicalItem methodsFor:'protocol-displaying'! |
|
2151 |
||
2152 |
displayIcon:anIcon atX:x y:y on:aGC |
|
2153 |
"called to draw the icon - can be redefined to manipulate the icon" |
|
2154 |
||
2155 |
anIcon displayOn:aGC x:x y:y. |
|
2156 |
! |
|
2157 |
||
2158 |
displayOn:aGC x:x y:y h:h |
|
2159 |
<resource: #obsolete> |
|
2160 |
"draw the receiver in the graphicsContext, aGC" |
|
2161 |
||
2162 |
"/ obsolete - left here for backward compatibility |
|
2163 |
self displayOn:aGC x:x y:y h:h isHighlightedAsSelected:false |
|
2164 |
! |
|
2165 |
||
2166 |
displayOn:aGC x:x y:y h:h isHighlightedAsSelected:isHighlightedAsSelected |
|
2167 |
"draw the receiver in the graphicsContext, aGC" |
|
2168 |
||
2169 |
|label |
|
2170 |
x0 "{ Class:SmallInteger }"| |
|
2171 |
||
2172 |
label := self label. |
|
2173 |
label isNil ifTrue:[^ self]. |
|
2174 |
||
5325 | 2175 |
label isNonByteCollection ifFalse:[ |
4733 | 2176 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h isHighlightedAsSelected:isHighlightedAsSelected |
2177 |
]. |
|
2178 |
||
2179 |
x0 := x. |
|
2180 |
label do:[:el| |
|
2181 |
el notNil ifTrue:[ |
|
2182 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h isHighlightedAsSelected:isHighlightedAsSelected. |
|
2183 |
x0 := x0 + 5 + (el widthOn:aGC). |
|
2184 |
]. |
|
2185 |
] |
|
2186 |
! ! |
|
2187 |
||
2188 |
!AbstractHierarchicalItem methodsFor:'protocol-event processing'! |
|
2189 |
||
2190 |
processButtonPress:button visibleX:visX visibleY: visY on: view |
|
2191 |
"A mouse button was pressed on myself. The visX/visY coordinates |
|
2192 |
are relative to the viewOrigin. |
|
2193 |
||
2194 |
If this method returns TRUE, the other method |
|
2195 |
#processButtonPress:x:y:on: IS NOT CALLED !!!!!! |
|
2196 |
" |
|
2197 |
||
2198 |
^false |
|
2199 |
||
2200 |
"Created: / 18-04-2013 / 09:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2201 |
"Modified (comment): / 18-04-2013 / 11:04:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2202 |
! |
|
2203 |
||
2204 |
processButtonPress:button x:x y:y |
|
2205 |
"a mouse button was pressed in my label. |
|
2206 |
Return true, if the event is eaten (ignored by the gc). |
|
2207 |
By default, false is returned (should be handled by the gc)." |
|
2208 |
||
2209 |
^ false |
|
2210 |
! |
|
2211 |
||
2212 |
processButtonPress:button x:x y:y on:aGC |
|
2213 |
"a mouse button was pressed in my label. |
|
2214 |
Return true, if the event is eaten (ignored by the gc). |
|
2215 |
By default, false is returned (should be handled by the gc)." |
|
2216 |
||
2217 |
^ self processButtonPress:button x:x y:y |
|
2218 |
! |
|
2219 |
||
2220 |
processButtonPressOnIcon:button on:aGC |
|
2221 |
"a mouse button was pressed in my icon. |
|
2222 |
Return true, if the event is eaten (ignored by the gc). |
|
2223 |
By default, false is returned (should be handled by the gc)." |
|
2224 |
||
2225 |
^ false |
|
2226 |
! ! |
|
2227 |
||
2228 |
!AbstractHierarchicalItem methodsFor:'protocol-monitoring'! |
|
2229 |
||
2230 |
monitoringCycle |
|
2231 |
"called every 'n' seconds by the model, if the monitoring |
|
2232 |
cycle is enabled. The item can perform some checks, .. |
|
2233 |
**** can be redefined by subclass to perform some actions |
|
2234 |
" |
|
2235 |
! ! |
|
2236 |
||
2237 |
!AbstractHierarchicalItem methodsFor:'protocol-queries'! |
|
2238 |
||
2239 |
canCollapse |
|
2240 |
"called before collapsing the item; can be redefined |
|
2241 |
by subclass to omit the collapse operation" |
|
2242 |
||
2243 |
^ self isExpanded |
|
2244 |
! |
|
2245 |
||
2246 |
canExpand |
|
2247 |
"called before expanding the item; can be redefined |
|
2248 |
by subclass to omit the expand operation" |
|
2249 |
||
2250 |
^ self hasChildren |
|
2251 |
! |
|
2252 |
||
2253 |
canRecursiveCollapse |
|
2254 |
"called before collapsing the item; can be redefined |
|
5998 | 2255 |
by subclass to omit the collapse operation. |
2256 |
Q: why is there an extra canRecursiveCollapse (i.e. not always using canCollapse)?" |
|
4733 | 2257 |
|
2258 |
^ self canCollapse |
|
5998 | 2259 |
|
2260 |
"Modified (comment): / 13-02-2019 / 12:14:03 / Claus Gittinger" |
|
4733 | 2261 |
! |
2262 |
||
2263 |
canRecursiveExpand |
|
6056 | 2264 |
"called before recursive expanding the item; |
2265 |
can be redefined by subclass to omit the expand operation" |
|
4733 | 2266 |
|
2267 |
^ self canExpand |
|
6056 | 2268 |
|
2269 |
"Modified (comment): / 27-05-2019 / 18:27:01 / Claus Gittinger" |
|
4733 | 2270 |
! |
2271 |
||
2272 |
drawHorizontalLineUpToText |
|
5802 | 2273 |
"draw the horizontal line for the selected item up to the text |
2274 |
or (by default) to the start of the vertical line; |
|
2275 |
only used by the hierarchical view |
|
4733 | 2276 |
" |
2277 |
^ false |
|
5802 | 2278 |
|
2279 |
"Modified (comment): / 12-06-2018 / 10:41:54 / Claus Gittinger" |
|
4733 | 2280 |
! |
2281 |
||
2282 |
hasChildren |
|
5991 | 2283 |
"checks whether the item has children; |
2284 |
here the children are fetched, and thus this may take some time. |
|
2285 |
*** to optimize: redefine in subClass (example: FileDirectory)" |
|
4733 | 2286 |
|
5720 | 2287 |
^ self children notEmptyOrNil |
2288 |
||
2289 |
"Modified: / 08-03-2018 / 19:37:45 / stefan" |
|
5991 | 2290 |
"Modified (comment): / 02-02-2019 / 14:51:59 / Claus Gittinger" |
4733 | 2291 |
! |
2292 |
||
2293 |
hasIndicator |
|
2294 |
"on default the indicator is drawn if the item has children" |
|
2295 |
||
2296 |
^ self hasChildren |
|
2297 |
! |
|
2298 |
||
2299 |
isSelectable |
|
2300 |
"returns true if the item is selectable. Can be redefined in subclasses" |
|
2301 |
||
2302 |
^ true |
|
2303 |
! |
|
2304 |
||
2305 |
string |
|
2306 |
"access the printable string used for stepping through a list |
|
2307 |
searching for an entry starting with a character. |
|
2308 |
*** to optimize:redefine by subClass" |
|
2309 |
||
2310 |
|label| |
|
2311 |
||
2312 |
(label := self label) notNil ifTrue:[ |
|
2313 |
label isString ifTrue:[ ^ label string ]. |
|
2314 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
2315 |
||
2316 |
label isSequenceable ifFalse:[ |
|
2317 |
^ label perform:#string ifNotUnderstood:nil |
|
2318 |
]. |
|
2319 |
||
2320 |
label do:[:el||s| |
|
2321 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
2322 |
s := el perform:#string ifNotUnderstood:nil. |
|
2323 |
s notNil ifTrue:[^ s]. |
|
2324 |
] |
|
2325 |
] |
|
2326 |
]. |
|
2327 |
^ nil |
|
2328 |
! ! |
|
2329 |
||
2330 |
!AbstractHierarchicalItem methodsFor:'queries'! |
|
2331 |
||
2332 |
isChildOf:anItem |
|
5884 | 2333 |
"returns true if the item is a child (or grandchild or ...) of anItem" |
4733 | 2334 |
|
5840 | 2335 |
self synchronized:[ |
2336 |
|item| |
|
2337 |
||
2338 |
item := self. |
|
2339 |
||
2340 |
[anItem ~~ item] whileTrue:[ |
|
2341 |
((item := item parent) notNil and:[item isHierarchicalItem]) ifFalse:[ |
|
2342 |
^ false |
|
2343 |
] |
|
2344 |
]. |
|
4733 | 2345 |
]. |
2346 |
^ true |
|
5840 | 2347 |
|
2348 |
"Modified: / 28-07-2018 / 14:02:32 / Claus Gittinger" |
|
5884 | 2349 |
"Modified (comment): / 12-08-2018 / 12:49:16 / Claus Gittinger" |
4733 | 2350 |
! |
2351 |
||
2352 |
isCollapsed |
|
2353 |
"returns true if the item is collapsed" |
|
2354 |
||
2355 |
^ self isExpanded not |
|
2356 |
! |
|
2357 |
||
2358 |
isDirectoryItem |
|
2359 |
^ false |
|
2360 |
||
2361 |
"Created: / 23-06-2006 / 12:47:05 / fm" |
|
2362 |
"Modified: / 23-02-2007 / 12:04:23 / User" |
|
2363 |
! |
|
2364 |
||
2365 |
isHierarchicalItem |
|
2366 |
"used to decide if the parent is a hierarchical item or the model" |
|
2367 |
||
2368 |
^ true |
|
2369 |
! |
|
2370 |
||
2371 |
isRealChildOf:anItem |
|
2372 |
"returns true if the item is a child of anItem" |
|
2373 |
||
5840 | 2374 |
self synchronized:[ |
2375 |
|item| |
|
2376 |
item := self parent. |
|
2377 |
||
2378 |
[item notNil] whileTrue:[ |
|
2379 |
item == anItem ifTrue:[^ true]. |
|
2380 |
item := item parent. |
|
2381 |
]. |
|
4733 | 2382 |
]. |
2383 |
^ false |
|
5840 | 2384 |
|
2385 |
"Modified: / 28-07-2018 / 14:03:22 / Claus Gittinger" |
|
4733 | 2386 |
! |
2387 |
||
2388 |
isRootItem |
|
2389 |
"returns true if the item is the root item" |
|
2390 |
||
2391 |
^ parent isHierarchicalItem not |
|
2392 |
! |
|
2393 |
||
2394 |
size |
|
2395 |
"return the number of children" |
|
2396 |
||
2397 |
^ self children size |
|
2398 |
! ! |
|
2399 |
||
2400 |
!AbstractHierarchicalItem methodsFor:'searching'! |
|
2401 |
||
2402 |
detect:aOneArgBlock |
|
5363 | 2403 |
"find the first child (not recursive), for which evaluation of the block returns |
4733 | 2404 |
true; if none does so, report an error" |
2405 |
||
2406 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
|
5363 | 2407 |
|
2408 |
"Modified (comment): / 25-11-2016 / 08:40:16 / cg" |
|
4733 | 2409 |
! |
2410 |
||
2411 |
detect:aOneArgBlock ifNone:exceptionValue |
|
5363 | 2412 |
"find the first child (not recursive), for which evaluation of the block returns |
4733 | 2413 |
true; if none does so, return the value of anExceptionValue" |
2414 |
||
2415 |
self do:[:el| |
|
2416 |
(aOneArgBlock value:el) ifTrue:[^ el] |
|
2417 |
]. |
|
2418 |
^ exceptionValue value |
|
5363 | 2419 |
|
2420 |
"Modified (comment): / 25-11-2016 / 08:40:18 / cg" |
|
4733 | 2421 |
! |
2422 |
||
2423 |
detectLast:aOneArgBlock |
|
5363 | 2424 |
"find the last child (not recursive), for which evaluation of the block returns |
4733 | 2425 |
true; if none does so, an exception is raised" |
2426 |
||
2427 |
^ self detectLast:aOneArgBlock ifNone:[self errorNotFound] |
|
5363 | 2428 |
|
2429 |
"Modified (comment): / 25-11-2016 / 08:40:21 / cg" |
|
4733 | 2430 |
! |
2431 |
||
2432 |
detectLast:aOneArgBlock ifNone:anExceptionValue |
|
5363 | 2433 |
"find the last child (not recursive), for which evaluation of the block returns |
4733 | 2434 |
true; if none does so, return the value of anExceptionValue" |
2435 |
||
2436 |
self reverseDo:[:el| (aOneArgBlock value:el) ifTrue:[^ el] ]. |
|
2437 |
^ anExceptionValue value |
|
5363 | 2438 |
|
2439 |
"Modified (comment): / 25-11-2016 / 08:40:23 / cg" |
|
4733 | 2440 |
! |
2441 |
||
5624 | 2442 |
findChildByLabelPath:aLabelPath |
2443 |
"recursivly find the child by its label path. |
|
2444 |
A label path is an ordered collection (or array) of strings, |
|
2445 |
which are the labels of items (i.e. as retrived by labelPath)." |
|
2446 |
||
2447 |
|restPath searchedLabel childSearched| |
|
2448 |
||
2449 |
childSearched := self. |
|
2450 |
restPath := aLabelPath. |
|
2451 |
||
2452 |
[ |
|
2453 |
|subChild| |
|
2454 |
||
2455 |
restPath isEmptyOrNil ifTrue:[^ childSearched]. |
|
2456 |
||
2457 |
searchedLabel := restPath first string. |
|
2458 |
||
2459 |
subChild := childSearched detect:[:eachSubChild | eachSubChild label string = searchedLabel] ifNone:nil. |
|
2460 |
subChild isNil ifTrue:[^ nil]. |
|
2461 |
||
2462 |
childSearched := subChild. |
|
2463 |
restPath := restPath from:2. |
|
2464 |
] loop. |
|
2465 |
||
2466 |
"Created: / 16-10-2017 / 14:30:11 / cg" |
|
2467 |
! |
|
2468 |
||
4733 | 2469 |
findFirst:aOneArgBlock |
5363 | 2470 |
"find the first child (not recursive), for which evaluation of the argument, aOneArgBlock |
4733 | 2471 |
returns true; return its index or 0 if none detected." |
2472 |
||
2473 |
||
2474 |
self keysAndValuesDo:[:i :el| (aOneArgBlock value:el) ifTrue:[^ i] ]. |
|
2475 |
^ 0 |
|
5363 | 2476 |
|
2477 |
"Modified (comment): / 25-11-2016 / 08:40:25 / cg" |
|
4733 | 2478 |
! |
2479 |
||
5363 | 2480 |
findLast:aOneArgBlock |
2481 |
"find the last child (not recursive), for which evaluation of the argument, aOneArgBlock |
|
4733 | 2482 |
returns true; return its index or 0 if none detected." |
2483 |
||
5363 | 2484 |
self keysAndValuesReverseDo:[:i :el| (aOneArgBlock value:el) ifTrue:[^ i] ]. |
4733 | 2485 |
^ 0 |
5363 | 2486 |
|
2487 |
"Modified (format): / 25-11-2016 / 08:40:33 / cg" |
|
4733 | 2488 |
! |
2489 |
||
5864 | 2490 |
findNextInTreeForWhich:aBlock |
2491 |
"does a breadth-first search in the tree starting at the receiver |
|
2492 |
i.e. first goes down recursively, then up to the next child of the parent |
|
2493 |
(doing a recursive search there), |
|
2494 |
up until all of the top item's children have been visited. |
|
2495 |
Returns the found item or nil." |
|
2496 |
||
2497 |
|item nextItem itemsParent| |
|
2498 |
||
2499 |
item := self. |
|
2500 |
[item notNil] whileTrue:[ |
|
2501 |
item recursiveDo:[:eachChild | |
|
2502 |
(aBlock value:eachChild) ifTrue:[ |
|
2503 |
^ eachChild. |
|
2504 |
]. |
|
2505 |
]. |
|
2506 |
||
2507 |
itemsParent := item parent. |
|
2508 |
nextItem := nil. |
|
2509 |
||
2510 |
[ |
|
2511 |
|idx siblings| |
|
2512 |
||
2513 |
itemsParent isNil ifTrue:[ |
|
2514 |
^ nil |
|
2515 |
]. |
|
2516 |
siblings := itemsParent children. |
|
2517 |
idx := siblings identityIndexOf:item. |
|
2518 |
nextItem := siblings at:idx+1 ifAbsent:nil. |
|
2519 |
nextItem isNil ifTrue:[ |
|
2520 |
item := itemsParent. |
|
2521 |
itemsParent := itemsParent parent. |
|
2522 |
]. |
|
2523 |
] doWhile:[ nextItem isNil ]. |
|
2524 |
||
2525 |
item := nextItem. |
|
2526 |
(aBlock value:item) ifTrue:[ |
|
2527 |
^ item. |
|
2528 |
]. |
|
2529 |
]. |
|
2530 |
^ nil |
|
2531 |
||
2532 |
"Created: / 31-07-2018 / 09:01:11 / Claus Gittinger" |
|
2533 |
! |
|
2534 |
||
5885 | 2535 |
findPreviousInTreeForWhich:aBlock |
2536 |
"does a breadth-first search in the tree starting at the receiver |
|
2537 |
i.e. first goes down recursively, then up to the next child of the parent |
|
2538 |
(doing a recursive search there), |
|
2539 |
up until all of the top item's children have been visited. |
|
2540 |
Returns the found item or nil." |
|
2541 |
||
2542 |
|item itemsParent idx siblings prevItem| |
|
2543 |
||
2544 |
item := self. |
|
2545 |
[item notNil] whileTrue:[ |
|
2546 |
"/ previous sibling |
|
2547 |
itemsParent := item parent. |
|
2548 |
itemsParent isNil ifTrue:[ |
|
2549 |
^ nil |
|
2550 |
]. |
|
2551 |
siblings := itemsParent children. |
|
2552 |
idx := siblings identityIndexOf:item. |
|
2553 |
idx <= 1 ifTrue:[ |
|
2554 |
"/ continue in parent |
|
2555 |
item := itemsParent. |
|
2556 |
] ifFalse:[ |
|
2557 |
prevItem := siblings at:idx-1 ifAbsent:nil. |
|
2558 |
"/ continue in prev sibling's last child |
|
2559 |
item := prevItem. |
|
2560 |
[item children notEmptyOrNil] whileTrue:[ |
|
2561 |
item := item children last. |
|
2562 |
] |
|
2563 |
]. |
|
2564 |
item isNil ifTrue:[^ nil]. |
|
2565 |
item isRootItem ifTrue:[^ nil]. |
|
2566 |
||
2567 |
(aBlock value:item) ifTrue:[ |
|
2568 |
^ item. |
|
2569 |
]. |
|
2570 |
]. |
|
2571 |
^ nil |
|
2572 |
||
2573 |
"Created: / 13-08-2018 / 10:59:12 / Claus Gittinger" |
|
2574 |
! |
|
2575 |
||
4733 | 2576 |
identityIndexOf:aChild |
2577 |
"return the index of aChild or 0 if not found. Compare using ==" |
|
2578 |
||
2579 |
^ self identityIndexOf:aChild startingAt:1 |
|
2580 |
! |
|
2581 |
||
2582 |
identityIndexOf:aChild startingAt:startIndex |
|
2583 |
"return the index of aChild, starting search at startIndex. |
|
2584 |
Compare using ==; return 0 if not found" |
|
2585 |
||
2586 |
|index| |
|
2587 |
||
2588 |
index := startIndex. |
|
2589 |
||
2590 |
self from:startIndex do:[:el| |
|
2591 |
el == aChild ifTrue:[^ index ]. |
|
2592 |
index := index + 1. |
|
2593 |
]. |
|
2594 |
^ 0 |
|
2595 |
! |
|
2596 |
||
2597 |
recursiveDetect:aOneArgBlock |
|
2598 |
"recursive find the first child, for which evaluation |
|
2599 |
of the block returns true; if none, nil is returned. |
|
2600 |
Warning: this only searches in already visible child elements |
|
2601 |
i.e. any collapsed items are not searched." |
|
2602 |
||
2603 |
self recursiveDo:[:aChild| |
|
2604 |
(aOneArgBlock value:aChild) ifTrue:[^ aChild] |
|
2605 |
]. |
|
2606 |
^ nil |
|
2607 |
! |
|
2608 |
||
6048 | 2609 |
recursiveDetect:aOneArgBlock skipIf:elementCheck skipChildrenIf:childrenCheck |
2610 |
"recursive find the first child, for which evaluation |
|
2611 |
of the block returns true; if none, nil is returned. |
|
2612 |
Warning: this only searches in already visible child elements |
|
2613 |
i.e. any collapsed items are not searched." |
|
2614 |
||
2615 |
self |
|
2616 |
recursiveDo:[:aChild| |
|
2617 |
(aOneArgBlock value:aChild) ifTrue:[^ aChild] |
|
2618 |
] |
|
2619 |
skipIf:elementCheck skipChildrenIf:childrenCheck. |
|
2620 |
^ nil |
|
2621 |
||
2622 |
"Created: / 07-05-2019 / 13:14:03 / Claus Gittinger" |
|
2623 |
! |
|
2624 |
||
4733 | 2625 |
recursiveDetectLast:aBlock |
5363 | 2626 |
"recursive find the last child, for which evaluation of the block returns true; |
2627 |
if none does so, nil is returned. |
|
2628 |
Warning: this only searches in already visible child elements |
|
2629 |
i.e. any collapsed items are not searched." |
|
4733 | 2630 |
|
2631 |
self recursiveReverseDo:[:aChild| |
|
2632 |
(aBlock value:aChild) ifTrue:[^ aChild]. |
|
2633 |
]. |
|
2634 |
^ nil |
|
5363 | 2635 |
|
2636 |
"Modified (comment): / 25-11-2016 / 08:41:42 / cg" |
|
4733 | 2637 |
! |
2638 |
||
2639 |
withAllDetect:aOneArgBlock |
|
5363 | 2640 |
"recursive find the first item including self, |
2641 |
for which evaluation of the block returns true; if none nil is returned. |
|
2642 |
Warning: this only searches in already visible child elements |
|
2643 |
i.e. any collapsed items are not searched." |
|
4733 | 2644 |
|
2645 |
(aOneArgBlock value:self) ifTrue:[^ self]. |
|
2646 |
||
2647 |
^ self recursiveDetect:aOneArgBlock |
|
5363 | 2648 |
|
2649 |
"Modified (comment): / 25-11-2016 / 08:41:53 / cg" |
|
4733 | 2650 |
! ! |
2651 |
||
2652 |
!AbstractHierarchicalItem methodsFor:'sorting & reordering'! |
|
2653 |
||
2654 |
recursiveSort:aSortBlock |
|
2655 |
"recursive sort the children inplace using the 2-arg block sortBlock for comparison" |
|
2656 |
||
5840 | 2657 |
children notEmptyOrNil ifTrue:[ |
2658 |
self synchronized:[ |
|
2659 |
"/ check again (asynchronous update was possible before) |
|
2660 |
children notEmptyOrNil ifTrue:[ |
|
2661 |
self nonCriticalRecursiveSort:aSortBlock. |
|
2662 |
self childrenOrderChanged. |
|
2663 |
] |
|
4733 | 2664 |
] |
2665 |
]. |
|
5840 | 2666 |
|
2667 |
"Modified (format): / 28-07-2018 / 15:46:06 / Claus Gittinger" |
|
4733 | 2668 |
! |
2669 |
||
2670 |
sort:aSortBlock |
|
2671 |
"sort the children inplace using the 2-arg block sortBlock for comparison" |
|
2672 |
||
2673 |
children notEmptyOrNil ifTrue: [ |
|
5840 | 2674 |
self synchronized:[ |
4733 | 2675 |
"/ check again (asynchronous update was possible before) |
2676 |
children notEmptyOrNil ifTrue: [ |
|
5993 | 2677 |
self setChildren:(children sort:aSortBlock). |
4733 | 2678 |
self childrenOrderChanged. |
2679 |
] |
|
2680 |
]. |
|
2681 |
] |
|
5840 | 2682 |
|
5993 | 2683 |
"Modified: / 03-02-2019 / 19:24:20 / Claus Gittinger" |
4733 | 2684 |
! ! |
2685 |
||
2686 |
!AbstractHierarchicalItem class methodsFor:'documentation'! |
|
2687 |
||
2688 |
version |
|
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
2689 |
^ '$Header$' |
4733 | 2690 |
! |
2691 |
||
2692 |
version_CVS |
|
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
2693 |
^ '$Header$' |
4733 | 2694 |
! ! |
2695 |