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