author | Jan Vrany <jan.vrany@labware.com> |
Fri, 02 Sep 2022 11:25:39 +0100 | |
branch | jv |
changeset 6261 | 9b7eb7159d29 |
parent 4941 | bd6fab9e6d8f |
child 5452 | f7c0a99ef04d |
permissions | -rw-r--r-- |
458 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
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 |
" |
|
1818 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
4941 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
458 | 16 |
Model subclass:#SelectionInTree |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
17 |
instanceVariableNames:'root list selection showRoot contentsAction labelAction |
811 | 18 |
childrenAction iconAction indicatorList indicatorTask accessLock' |
458 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Support-Models' |
|
22 |
! |
|
23 |
||
24 |
!SelectionInTree class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
list and selection holder for hierarchical list structures. Used |
|
1189 | 45 |
to buildup file-trees, class trees etc. |
458 | 46 |
|
47 |
Especially suited for use with SelectionInTreeView. |
|
48 |
||
1189 | 49 |
Notice: this class replaces SelectionInHierarchy, which provides |
50 |
similar (but less sphisticated) functionality. |
|
51 |
||
458 | 52 |
[See also:] |
53 |
TreeItem |
|
54 |
SelectionInTreeView |
|
55 |
||
56 |
[Author:] |
|
57 |
W. Olberding |
|
58 |
Claus Atzkern |
|
59 |
" |
|
60 |
! ! |
|
61 |
||
811 | 62 |
!SelectionInTree class methodsFor:'instance creation'! |
63 |
||
64 |
new |
|
2840 | 65 |
^ self basicNew initialize |
811 | 66 |
! ! |
67 |
||
1174 | 68 |
!SelectionInTree class methodsFor:'defaults'! |
69 |
||
70 |
defaultItemClass |
|
71 |
"returns the default item class or nil (the default) |
|
72 |
" |
|
73 |
^ nil |
|
74 |
||
75 |
||
76 |
||
77 |
! ! |
|
78 |
||
458 | 79 |
!SelectionInTree methodsFor:'accessing'! |
80 |
||
81 |
list |
|
1189 | 82 |
"get the list of currently shown objects |
458 | 83 |
" |
84 |
^ list |
|
85 |
! |
|
86 |
||
87 |
root |
|
88 |
"get the root node |
|
89 |
" |
|
90 |
^ root |
|
91 |
! |
|
92 |
||
509 | 93 |
root:aRoot |
94 |
"set a new root |
|
458 | 95 |
" |
1176 | 96 |
|tree| |
97 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
98 |
root notNil ifTrue: [ |
1176 | 99 |
tree := root tree. |
100 |
root tree:nil. |
|
101 |
] ifFalse:[ |
|
102 |
tree := self |
|
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
103 |
]. |
811 | 104 |
self stopRunningTasks. |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
105 |
|
515 | 106 |
(root := aRoot) notNil ifTrue:[ |
1176 | 107 |
root tree:tree. |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
108 |
root parent:nil. |
857 | 109 |
]. |
1189 | 110 |
self recomputeList |
860 | 111 |
! |
112 |
||
113 |
value |
|
114 |
^ list |
|
496 | 115 |
! ! |
491 | 116 |
|
2697 | 117 |
!SelectionInTree methodsFor:'accessing hierarchy new'! |
118 |
||
119 |
doMakeVisible:something |
|
120 |
"make an item or list of items to become visible |
|
121 |
" |
|
122 |
|anchor parent| |
|
123 |
||
124 |
self each:something do:[:anItem| |
|
125 |
parent := anItem. |
|
126 |
anchor := nil. |
|
127 |
||
128 |
parent notNil ifTrue:[ |
|
129 |
[(parent := parent parent) notNil] whileTrue:[ |
|
130 |
parent hidden ifTrue:[ |
|
131 |
anchor notNil ifTrue:[ anchor expand ]. |
|
132 |
anchor := parent. |
|
133 |
] |
|
134 |
]. |
|
135 |
anchor notNil ifTrue:[ |
|
136 |
self expandItem:anchor do:[anchor expand] |
|
137 |
] |
|
138 |
]. |
|
139 |
] |
|
140 |
! ! |
|
141 |
||
1818 | 142 |
!SelectionInTree methodsFor:'accessing-behavior'! |
496 | 143 |
|
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
144 |
childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
145 |
"get children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
146 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
147 |
^childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
148 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
149 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
150 |
childrenAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
151 |
"set children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
152 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
153 |
childrenAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
154 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
155 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
156 |
contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
157 |
"get contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
158 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
159 |
^contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
160 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
161 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
162 |
contentsAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
163 |
"set contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
164 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
165 |
contentsAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
166 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
167 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
168 |
iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
169 |
"get icon action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
170 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
171 |
^iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
172 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
173 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
174 |
iconAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
175 |
"set icon action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
176 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
177 |
iconAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
178 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
179 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
180 |
labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
181 |
"get label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
182 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
183 |
^labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
184 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
185 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
186 |
labelAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
187 |
"set label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
188 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
189 |
labelAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
190 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
191 |
|
496 | 192 |
showRoot |
193 |
"list with or without root |
|
194 |
" |
|
195 |
^ showRoot |
|
491 | 196 |
! |
197 |
||
496 | 198 |
showRoot:aState |
199 |
"list with or without root |
|
491 | 200 |
" |
496 | 201 |
aState ~~ showRoot ifTrue:[ |
202 |
showRoot := aState. |
|
491 | 203 |
|
496 | 204 |
root notNil ifTrue:[ |
857 | 205 |
aState ifTrue:[ |
206 |
list addFirst:root. |
|
207 |
self changed:#insertCollection: with:(Array with:1 with:1 with:nil). |
|
208 |
] ifFalse:[ |
|
209 |
list removeFirst. |
|
210 |
self changed:#removeFrom: with:(Array with:1 with:1 with:nil). |
|
211 |
]. |
|
491 | 212 |
]. |
213 |
]. |
|
458 | 214 |
! ! |
215 |
||
1818 | 216 |
!SelectionInTree methodsFor:'accessing-hierarchy'! |
458 | 217 |
|
218 |
collapse:something |
|
219 |
"collapse a node or collection of nodes |
|
220 |
" |
|
857 | 221 |
|listChanged| |
222 |
||
223 |
listChanged := false. |
|
458 | 224 |
|
225 |
self each:something do:[:aNode| |
|
226 |
aNode isCollapsable ifTrue:[ |
|
227 |
aNode collapse. |
|
857 | 228 |
listChanged := true |
458 | 229 |
] |
230 |
]. |
|
857 | 231 |
listChanged ifTrue:[ |
232 |
self listFromRoot. |
|
233 |
self changed:#list. |
|
234 |
] |
|
235 |
||
458 | 236 |
! |
237 |
||
509 | 238 |
expand |
239 |
"expand the root |
|
240 |
" |
|
241 |
self expand:root |
|
242 |
! |
|
243 |
||
458 | 244 |
expand:something |
245 |
"expand a node or collection of nodes |
|
246 |
" |
|
857 | 247 |
|listChanged| |
248 |
||
249 |
listChanged := false. |
|
458 | 250 |
|
251 |
self each:something do:[:aNode| |
|
252 |
aNode isExpandable ifTrue:[ |
|
253 |
aNode expand. |
|
857 | 254 |
listChanged := true |
458 | 255 |
] |
256 |
]. |
|
857 | 257 |
listChanged ifTrue:[ |
258 |
self listFromRoot. |
|
259 |
self changed:#list. |
|
260 |
] |
|
261 |
! ! |
|
262 |
||
1818 | 263 |
!SelectionInTree methodsFor:'accessing-hierarchy new'! |
857 | 264 |
|
265 |
doCollapse:something |
|
266 |
"collapse all children under an item or a sequence of items; |
|
267 |
if the list changed, notifications are raised |
|
268 |
" |
|
269 |
self each:something do:[:anItem| |
|
270 |
self collapseItem:anItem do:[ anItem collapse ] |
|
271 |
] |
|
272 |
! |
|
273 |
||
274 |
doCollapseAll:something |
|
275 |
"collapse all children and subChildren under an item or sequence of items; |
|
276 |
if the list changed, notifications are raised |
|
277 |
" |
|
278 |
self each:something do:[:anItem| |
|
279 |
self collapseItem:anItem do:[ anItem collapseAll ] |
|
280 |
] |
|
281 |
! |
|
282 |
||
283 |
doExpand:something |
|
284 |
"expand all children under an item or collection of items; |
|
285 |
if the list changed, notifications are raised |
|
286 |
" |
|
287 |
self each:something do:[:anItem| |
|
288 |
self expandItem:anItem do:[anItem expand] |
|
289 |
] |
|
290 |
! |
|
291 |
||
292 |
doExpandAll:something |
|
293 |
"expand all children and subChildren under an item or sequence of items; |
|
294 |
if the list changed, notifications are raised |
|
295 |
" |
|
296 |
self each:something do:[:anItem| |
|
297 |
self expandItem:anItem do:[anItem expandAll] |
|
298 |
] |
|
458 | 299 |
! ! |
300 |
||
301 |
!SelectionInTree methodsFor:'adding & removing'! |
|
302 |
||
303 |
add:something after:aChild |
|
304 |
"add a node or collection of nodes to parent after a child |
|
305 |
" |
|
306 |
"add a node or collection of nodes to after a child |
|
307 |
" |
|
857 | 308 |
|p| |
309 |
||
310 |
(aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[ |
|
311 |
self add:something afterIndex:(p indexOfChild:aChild) below:p |
|
458 | 312 |
] |
857 | 313 |
|
458 | 314 |
! |
315 |
||
316 |
add:something afterIndex:anIndex below:aParent |
|
317 |
"add a node or collection of nodes to parent after an index |
|
318 |
" |
|
857 | 319 |
self add:something beforeIndex:(anIndex + 1) below:aParent |
458 | 320 |
! |
321 |
||
322 |
add:something before:aChild |
|
323 |
"add a node or collection of nodes to before a child |
|
324 |
" |
|
857 | 325 |
|p| |
326 |
||
327 |
(aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[ |
|
328 |
self add:something beforeIndex:(p indexOfChild:aChild) below:p |
|
458 | 329 |
] |
330 |
! |
|
331 |
||
332 |
add:something beforeIndex:anIndex below:aParent |
|
1204 | 333 |
"add a node or collection of nodes to aParents children |
334 |
before anIndex (which is a child-index) |
|
458 | 335 |
" |
857 | 336 |
|children start index size pList| |
337 |
||
338 |
( aParent isNil |
|
339 |
or:[something isNil |
|
340 |
or:[(something isCollection and:[something isEmpty])]] |
|
341 |
) ifTrue:[ |
|
342 |
^ self |
|
343 |
]. |
|
344 |
||
345 |
(start := self indexOf:aParent) == 0 ifTrue:[ |
|
346 |
"/ |
|
347 |
"/ parent not visible; list not changed |
|
348 |
"/ |
|
1304 | 349 |
aParent == root ifFalse:[ |
350 |
aParent add:something beforeIndex:anIndex. |
|
351 |
^ self |
|
352 |
] |
|
353 |
] ifFalse:[ |
|
354 |
aParent shown ifFalse:[ |
|
355 |
aParent add:something beforeIndex:anIndex. |
|
356 |
self changed:#at: with:start. |
|
357 |
^ self |
|
358 |
] |
|
857 | 359 |
]. |
360 |
children := aParent children. |
|
361 |
||
362 |
(children isEmpty or:[anIndex <= 1]) ifTrue:[ |
|
363 |
index := 1. |
|
364 |
] ifFalse:[ |
|
365 |
size := children size. |
|
366 |
||
367 |
anIndex > size ifTrue:[ |
|
368 |
index := size + 1. |
|
369 |
start := aParent numberOfAllVisibleChildren + start. |
|
370 |
] ifFalse:[ |
|
371 |
index := anIndex. |
|
372 |
start := (self indexOf:(children at:index)) - 1. |
|
373 |
] |
|
374 |
]. |
|
375 |
aParent add:something beforeIndex:index. |
|
376 |
||
377 |
(start := start + 1) == 0 ifTrue:[ |
|
378 |
"/ |
|
379 |
"/ not visible |
|
380 |
"/ |
|
381 |
^ self |
|
382 |
]. |
|
383 |
pList := OrderedCollection new:2048. |
|
384 |
||
385 |
self each:something do:[:aNode| |
|
386 |
pList add:aNode. |
|
387 |
aNode addVisibleChildrenTo:pList |
|
388 |
]. |
|
389 |
pList isEmpty ifTrue:[ |
|
390 |
^ self |
|
391 |
]. |
|
392 |
list addAll:pList beforeIndex:start. |
|
393 |
||
394 |
self changed:#insertCollection: |
|
395 |
with:(Array with:start with:pList size with:aParent). |
|
458 | 396 |
|
397 |
! |
|
398 |
||
399 |
add:something below:aParent |
|
400 |
"add a node or collection of nodes to parent |
|
401 |
" |
|
857 | 402 |
aParent notNil ifTrue:[ |
403 |
self add:something beforeIndex:(aParent numberOfChildren + 1) below:aParent |
|
404 |
] |
|
458 | 405 |
! |
406 |
||
407 |
remove:something |
|
408 |
"remove a node or collection of nodes |
|
409 |
" |
|
1268 | 410 |
|node index loNums loItem start size parent stop| |
857 | 411 |
|
412 |
something isNil ifTrue:[ |
|
413 |
^ something |
|
414 |
]. |
|
415 |
loNums := SortedCollection new. |
|
416 |
||
417 |
self each:something do:[:el| |
|
418 |
node := el isNumber ifTrue:[list at:el ifAbsent:nil] |
|
419 |
ifFalse:[el]. |
|
420 |
||
421 |
node notNil ifTrue:[ |
|
422 |
self stopIndicatorValidationFor:node. |
|
458 | 423 |
|
857 | 424 |
node parent isNil ifTrue:[ |
425 |
"/ remove all including root |
|
426 |
node == root ifTrue:[ self root:nil ]. |
|
427 |
^ something |
|
428 |
]. |
|
429 |
index := self indexOf:node. |
|
811 | 430 |
|
857 | 431 |
index == 0 ifTrue:[ |
432 |
"/ not visible |
|
433 |
node parent removeChild:node |
|
434 |
] ifFalse:[ |
|
435 |
loNums add:index |
|
436 |
]. |
|
458 | 437 |
] |
438 |
]. |
|
857 | 439 |
|
440 |
loNums isEmpty ifTrue:[ |
|
441 |
"/ nothing visible changed |
|
442 |
^ something |
|
443 |
]. |
|
444 |
loItem := OrderedCollection new. |
|
445 |
loNums do:[:i| loItem add:(list at:i)]. |
|
446 |
||
447 |
loItem do:[:aNode| |
|
448 |
start := self indexOf:aNode. |
|
449 |
||
450 |
start ~~ 0 ifTrue:[ |
|
451 |
parent := aNode parent. |
|
452 |
size := 1 + aNode numberOfAllVisibleChildren. |
|
860 | 453 |
stop := start + size - 1. |
857 | 454 |
parent remove:aNode. |
860 | 455 |
list removeFromIndex:start toIndex:stop. |
811 | 456 |
|
857 | 457 |
self changed:#removeFrom: |
860 | 458 |
with:(Array with:start with:stop with:parent). |
857 | 459 |
] |
460 |
]. |
|
461 |
^ something |
|
462 |
! |
|
463 |
||
464 |
removeAllOtherThanRoot |
|
465 |
"remove all other than the root |
|
466 |
" |
|
467 |
|listChanged| |
|
468 |
||
469 |
root notNil ifTrue:[ |
|
470 |
listChanged := root isCollapsable. |
|
471 |
root children:(OrderedCollection new). |
|
472 |
||
473 |
listChanged ifTrue:[ |
|
474 |
self listFromRoot. |
|
475 |
self changed:#list |
|
476 |
] |
|
477 |
] |
|
458 | 478 |
! |
479 |
||
480 |
removeIndex:something |
|
481 |
"remove a node at index or collection of indexed nodes |
|
482 |
" |
|
857 | 483 |
self remove:something |
458 | 484 |
! |
485 |
||
486 |
removeSelection |
|
487 |
"remove selected nodes |
|
488 |
" |
|
857 | 489 |
|sel| |
490 |
||
491 |
sel := self selectionIndex. |
|
492 |
self selectionIndex:nil. |
|
493 |
self remove:sel. |
|
1209 | 494 |
! |
495 |
||
496 |
replaceNode:aNode with:aNewNode |
|
497 |
"replace a node by a new node; if the new node is nil, the node and its |
|
498 |
children are removed. Otherwise the children are taken over to the new |
|
499 |
node. |
|
500 |
" |
|
501 |
|parent index children| |
|
502 |
||
503 |
(aNode isNil or:[aNode == aNewNode]) ifTrue:[ |
|
504 |
^ self |
|
505 |
]. |
|
506 |
||
507 |
aNewNode isNil ifTrue:[ |
|
508 |
^ self remove:aNode |
|
509 |
]. |
|
510 |
self stopIndicatorValidationFor:aNode. |
|
511 |
||
512 |
aNewNode children:(aNode children). |
|
513 |
aNode children:nil. |
|
514 |
||
515 |
aNode == root ifTrue:[ |
|
516 |
aNewNode tree:(aNode tree). |
|
517 |
aNewNode parent:nil. |
|
518 |
root := aNewNode. |
|
519 |
] ifFalse:[ |
|
520 |
parent := aNode parent. |
|
521 |
aNewNode tree:nil. |
|
522 |
aNewNode parent:parent. |
|
523 |
children := parent children. |
|
524 |
index := children identityIndexOf:aNode. |
|
525 |
children at:index put:aNewNode. |
|
526 |
]. |
|
527 |
||
528 |
aNode tree:nil. |
|
529 |
aNode parent:nil. |
|
530 |
||
531 |
(index := self indexOf:aNode) ~~ 0 ifTrue:[ |
|
532 |
list at:index put:aNewNode. |
|
533 |
self changed:#at: with:index |
|
534 |
]. |
|
458 | 535 |
! ! |
536 |
||
758 | 537 |
!SelectionInTree methodsFor:'change & update'! |
538 |
||
539 |
invalidate |
|
540 |
"called; something changed what requires a redraw but no recomputation. |
|
541 |
for example a name |
|
542 |
" |
|
543 |
self dependents do:[:aDependent| |
|
544 |
aDependent isView ifTrue:[ aDependent invalidate ] |
|
545 |
]. |
|
546 |
||
547 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
548 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
549 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
550 |
update:something with:aParameter from:aModel |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
551 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
552 |
self dependents do:[:aDependent| |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
553 |
aDependent update:something with:aParameter from:aModel |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
554 |
] |
758 | 555 |
! ! |
556 |
||
458 | 557 |
!SelectionInTree methodsFor:'enumerating'! |
558 |
||
559 |
each:something do:aBlock |
|
560 |
"evaluate a block for something or in case of a collection for each |
|
561 |
element in the collection |
|
562 |
" |
|
563 |
something notNil ifTrue:[ |
|
564 |
something isCollection ifTrue:[something do:[:el|aBlock value:el]] |
|
565 |
ifFalse:[aBlock value:something] |
|
566 |
] |
|
567 |
||
568 |
! ! |
|
569 |
||
496 | 570 |
!SelectionInTree methodsFor:'initialization'! |
571 |
||
572 |
initialize |
|
811 | 573 |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
574 |
showRoot := true. |
811 | 575 |
indicatorList := OrderedCollection new. |
576 |
accessLock := Semaphore forMutualExclusion. |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
577 |
list := List new. |
496 | 578 |
! ! |
579 |
||
458 | 580 |
!SelectionInTree methodsFor:'private'! |
581 |
||
582 |
recomputeList |
|
583 |
"Travers the tree and build a new list." |
|
584 |
||
857 | 585 |
self listFromRoot. |
586 |
self changed:#list. |
|
587 |
! ! |
|
588 |
||
2494 | 589 |
!SelectionInTree methodsFor:'private-hierarchy'! |
857 | 590 |
|
591 |
collapseItem:anItem do:collapseBlock |
|
592 |
"collapse all children under an item; raise a notification if |
|
593 |
the list changed |
|
594 |
" |
|
595 |
|start stop size| |
|
596 |
||
597 |
anItem isCollapsable ifFalse:[ |
|
598 |
^ self |
|
599 |
]. |
|
600 |
||
601 |
(start := self indexOf:anItem) == 0 ifTrue:[ |
|
602 |
"/ |
|
603 |
"/ item not visible |
|
604 |
"/ |
|
605 |
collapseBlock value. |
|
606 |
] ifFalse:[ |
|
607 |
size := anItem numberOfAllVisibleChildren. |
|
608 |
collapseBlock value. |
|
609 |
||
610 |
size == 0 ifTrue:[ |
|
611 |
"/ |
|
612 |
"/ no children before; list not changed |
|
613 |
"/ |
|
614 |
self changed:#at: with:start |
|
615 |
] ifFalse:[ |
|
616 |
stop := start + size. |
|
617 |
start := start + 1. |
|
618 |
list removeFromIndex:start toIndex:stop. |
|
860 | 619 |
self changed:#removeFrom: with:(Array with:start with:stop with:anItem). |
857 | 620 |
] |
621 |
] |
|
622 |
! |
|
623 |
||
624 |
expandItem:anItem do:expandBlock |
|
625 |
"expand all children under an item; raise a notification if |
|
626 |
the list changed |
|
627 |
" |
|
628 |
|start size pList| |
|
629 |
||
630 |
anItem isExpandable ifFalse:[ |
|
631 |
^ self |
|
632 |
]. |
|
633 |
expandBlock value. |
|
634 |
||
635 |
(start := self indexOf:anItem) ~~ 0 ifTrue:[ |
|
636 |
anItem addVisibleChildrenTo:(pList := OrderedCollection new:2048). |
|
637 |
||
638 |
(size := pList size) ~~ 0 ifTrue:[ |
|
639 |
start := 1 + start. |
|
640 |
list addAll:pList beforeIndex:start. |
|
641 |
||
642 |
self changed:#insertCollection: |
|
643 |
with:(Array with:start with:size with:anItem). |
|
644 |
] ifFalse:[ |
|
645 |
self changed:#at: with:start |
|
646 |
] |
|
647 |
] |
|
648 |
! |
|
649 |
||
650 |
listFromRoot |
|
1204 | 651 |
"Traverse the tree and build a new list; |
857 | 652 |
no change notification is raised |
653 |
" |
|
842 | 654 |
list clearContents. |
458 | 655 |
|
656 |
root notNil ifTrue:[ |
|
857 | 657 |
showRoot ifTrue:[ list add:root ]. |
658 |
root addVisibleChildrenTo:list |
|
659 |
] |
|
660 |
||
661 |
! ! |
|
662 |
||
663 |
!SelectionInTree methodsFor:'queries'! |
|
664 |
||
665 |
indexOf:anItem |
|
666 |
"returns the index of an item or 0 |
|
667 |
" |
|
668 |
^ anItem notNil ifTrue:[list identityIndexOf:anItem] |
|
669 |
ifFalse:[0] |
|
458 | 670 |
! ! |
671 |
||
849 | 672 |
!SelectionInTree methodsFor:'searching'! |
673 |
||
1550 | 674 |
detectFirstItem:aOneArgBlock |
675 |
"detect an item the evaluation of the block returns true. |
|
676 |
The argument to the block is the item. |
|
677 |
This recursively enumerates the tree for the first item for which |
|
678 |
the block returns true. |
|
679 |
" |
|
680 |
root notNil ifTrue:[ |
|
681 |
^ root detectFirstChild:aOneArgBlock |
|
682 |
]. |
|
683 |
^ nil |
|
684 |
||
685 |
||
686 |
! |
|
687 |
||
849 | 688 |
detectItem:aOneArgBlock |
1553 | 689 |
"detect an item the evaluation of the block returns true. |
690 |
The argument to the block is the item. |
|
1550 | 691 |
This searches top-level items only. |
849 | 692 |
" |
693 |
root notNil ifTrue:[ |
|
694 |
^ root detectChild:aOneArgBlock |
|
695 |
]. |
|
696 |
^ nil |
|
697 |
||
698 |
||
699 |
! |
|
700 |
||
701 |
detectItem:aTwoArgBlock arguments:aListOfArgs |
|
1553 | 702 |
"detect an item the evaluation of the block returns true. |
703 |
The first argument to the block is the item, the second argument |
|
704 |
the value derived from the argument list at level. |
|
705 |
This recursively walks down the tree up to aListOfArgs size levels; |
|
706 |
i.e. if you pass (1 to:10) as aListOfArgs, the block will get the sub-level |
|
707 |
as second argument and stop the search after 10 levels. |
|
849 | 708 |
" |
1550 | 709 |
|
849 | 710 |
root notNil ifTrue:[ |
1553 | 711 |
^ root detectChild:aTwoArgBlock arguments:aListOfArgs |
849 | 712 |
]. |
713 |
^ nil |
|
714 |
||
715 |
||
716 |
! ! |
|
717 |
||
458 | 718 |
!SelectionInTree methodsFor:'selection'! |
719 |
||
1213 | 720 |
selectNode:aNode |
721 |
|index| |
|
722 |
||
723 |
(index := self indexOf:aNode) ~~ 0 ifTrue:[ |
|
724 |
self selectionIndex:index |
|
725 |
] |
|
726 |
! |
|
727 |
||
1234 | 728 |
selectNodes:aCollectionOfNodes |
729 |
| indices| |
|
730 |
||
4941 | 731 |
indices := aCollectionOfNodes |
732 |
collect:[:aNode | self indexOf:aNode] |
|
733 |
thenSelect:[:idx | idx ~~ 0]. |
|
1234 | 734 |
indices sort. |
735 |
self selectionIndex:indices |
|
736 |
||
737 |
"Created: / 6.3.1999 / 22:37:59 / cg" |
|
738 |
! |
|
739 |
||
906 | 740 |
selectedNode |
741 |
"returns selected node or nil |
|
742 |
" |
|
743 |
|nodes| |
|
744 |
(nodes := self selectedNodes) notNil ifTrue: [ |
|
745 |
^nodes first |
|
746 |
]. |
|
747 |
^nil |
|
748 |
||
749 |
||
750 |
! |
|
751 |
||
857 | 752 |
selectedNodes |
753 |
"returns list of selected nodes or nil |
|
754 |
" |
|
755 |
|node coll| |
|
756 |
||
757 |
selection isNil ifTrue:[ |
|
758 |
^ nil |
|
759 |
]. |
|
760 |
||
761 |
selection isCollection ifFalse:[ |
|
762 |
node := list at:selection ifAbsent:nil. |
|
763 |
^ node notNil ifTrue:[Array with:node] ifFalse:[nil] |
|
764 |
]. |
|
765 |
||
766 |
selection isEmpty ifTrue:[ |
|
767 |
^ nil |
|
768 |
]. |
|
769 |
||
770 |
coll := OrderedCollection new:(selection size). |
|
771 |
||
772 |
selection do:[:idx| |
|
773 |
(node := list at:idx ifAbsent:nil) notNil ifTrue:[ |
|
774 |
coll add:node |
|
775 |
] |
|
776 |
]. |
|
4275 | 777 |
^ coll asNilIfEmpty |
857 | 778 |
! |
779 |
||
2038 | 780 |
selectedNodesDo:aOneArgBlock |
781 |
"evaluate the block on eack node selected |
|
782 |
" |
|
783 |
|node| |
|
784 |
||
785 |
selection isNil ifTrue:[ |
|
786 |
^ nil |
|
787 |
]. |
|
788 |
||
789 |
selection isCollection ifFalse:[ |
|
790 |
node := list at:selection ifAbsent:nil. |
|
791 |
node notNil ifTrue:[ |
|
792 |
aOneArgBlock value:node |
|
793 |
]. |
|
794 |
^ self |
|
795 |
]. |
|
796 |
||
797 |
selection do:[:i| |
|
798 |
node := list at:i ifAbsent:nil. |
|
799 |
||
800 |
node notNil ifTrue:[ |
|
801 |
aOneArgBlock value:node |
|
802 |
]. |
|
803 |
]. |
|
804 |
! |
|
805 |
||
458 | 806 |
selection |
807 |
"get the selection or nil |
|
808 |
" |
|
809 |
^ self selectionIndex |
|
810 |
! |
|
811 |
||
812 |
selection:indexesOrNil |
|
3872
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
813 |
"set the selection" |
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
814 |
|
458 | 815 |
self selectionIndex:indexesOrNil |
816 |
! |
|
817 |
||
818 |
selectionIndex |
|
819 |
"get the selection or nil |
|
820 |
" |
|
821 |
^ selection |
|
822 |
! |
|
823 |
||
824 |
selectionIndex:indexesOrNil |
|
825 |
"set the selection |
|
826 |
" |
|
496 | 827 |
|oldSel| |
828 |
||
829 |
oldSel := selection. |
|
830 |
self setSelectionIndex:indexesOrNil. |
|
831 |
||
832 |
oldSel = selection ifFalse:[ |
|
2038 | 833 |
self changed:#selectionIndex. |
834 |
||
835 |
self selectedNodesDo:[:aNode| |
|
836 |
aNode changedSelected |
|
837 |
] |
|
496 | 838 |
] |
839 |
! |
|
840 |
||
841 |
setSelection:indexesOrNil |
|
842 |
"set the selection without raising a notification |
|
843 |
" |
|
844 |
self setSelectionIndex:indexesOrNil |
|
845 |
! |
|
846 |
||
847 |
setSelectionIndex:indexesOrNil |
|
848 |
"set the selection without raising a notification |
|
849 |
" |
|
458 | 850 |
|indexes| |
851 |
||
852 |
indexes := indexesOrNil. |
|
853 |
||
854 |
indexes size == 0 ifTrue:[ |
|
855 |
(indexes isCollection or:[indexes == 0]) ifTrue:[ |
|
856 |
indexes := nil |
|
857 |
] |
|
858 |
]. |
|
496 | 859 |
selection := indexes |
458 | 860 |
|
861 |
! ! |
|
862 |
||
811 | 863 |
!SelectionInTree methodsFor:'update indication task'! |
864 |
||
865 |
startIndicatorValidationFor:aNode |
|
866 |
"add a node to list of updating indications |
|
867 |
" |
|
868 |
|index| |
|
869 |
||
870 |
accessLock critical:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
871 |
|prio| |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
872 |
|
811 | 873 |
index := indicatorList identityIndexOf:aNode. |
874 |
||
875 |
index ~~ 0 ifTrue:[ |
|
876 |
indicatorList removeIndex:index. "/ reorganize list to be faster |
|
877 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
878 |
indicatorList addLast: "addFirst:" aNode. |
811 | 879 |
|
880 |
indicatorTask isNil ifTrue:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
881 |
prio := Processor activePriority. |
811 | 882 |
indicatorTask := [ |
883 |
[ self taskCycle ] whileTrue:[ Processor yield ] |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
884 |
] forkAt:(prio - 1). |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
885 |
indicatorTask priorityRange:(prio-1 to:prio). |
811 | 886 |
] |
887 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
888 |
|
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
889 |
"Modified: / 26.9.1998 / 15:20:44 / cg" |
811 | 890 |
! |
891 |
||
892 |
stopIndicatorValidationFor:aNodeOrList |
|
893 |
"remove a node or list of nodes from list of updating indications |
|
894 |
" |
|
895 |
accessLock critical:[ |
|
896 |
aNodeOrList isCollection ifTrue:[ |
|
897 |
aNodeOrList do:[:aNode| |
|
898 |
indicatorList removeIdentical:aNode ifAbsent:nil |
|
899 |
] |
|
900 |
] ifFalse:[ |
|
901 |
indicatorList removeIdentical:aNodeOrList ifAbsent:nil |
|
902 |
] |
|
903 |
] |
|
904 |
||
905 |
||
906 |
! |
|
907 |
||
908 |
stopRunningTasks |
|
909 |
"stop task |
|
910 |
" |
|
911 |
accessLock critical:[ indicatorList removeAll ] |
|
912 |
||
913 |
! |
|
914 |
||
915 |
taskCycle |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
916 |
"run one cycle fetching indicator state. |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
917 |
This is done in the background to avoid long startup |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
918 |
delays, in case the indicator information takes long to |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
919 |
gather (i.e. when reading directories)" |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
920 |
|
2038 | 921 |
|node flag| |
811 | 922 |
|
923 |
accessLock critical:[ |
|
924 |
indicatorList isEmpty ifTrue:[ "/ queue is empty; terminate task |
|
925 |
indicatorTask := nil. |
|
926 |
^ false |
|
927 |
]. |
|
928 |
node := indicatorList removeFirst. "/ run task on first node |
|
929 |
node hasValidIndicator ifTrue:[ "/ up to date |
|
930 |
^ true |
|
931 |
]. |
|
2038 | 932 |
node setShowIndicator:(node defaultShowSeparator). "/ disable registry |
811 | 933 |
]. |
934 |
||
2038 | 935 |
flag := DirectoryContents directoryNamed:(node fileName) detect:(node matchAction). |
936 |
node showIndicator:flag. |
|
811 | 937 |
^ true |
1145 | 938 |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
939 |
"Modified: / 26.9.1998 / 15:11:16 / cg" |
811 | 940 |
! ! |
941 |
||
458 | 942 |
!SelectionInTree class methodsFor:'documentation'! |
943 |
||
944 |
version |
|
4941 | 945 |
^ '$Header$' |
3872
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
946 |
! |
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
947 |
|
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
948 |
version_CVS |
4941 | 949 |
^ '$Header$' |
458 | 950 |
! ! |
4275 | 951 |