author | Claus Gittinger <cg@exept.de> |
Mon, 19 Nov 2001 16:28:39 +0100 | |
changeset 2056 | b34a774d3a2b |
parent 2015 | 5a83ee792cc3 |
child 2065 | 845bd5d2523c |
permissions | -rw-r--r-- |
444 | 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 |
" |
|
12 |
||
13 |
||
1813 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
444 | 16 |
SelectionInListView subclass:#SelectionInTreeView |
847 | 17 |
instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
18 |
showLines showLinesForRoot listOfNodes imageInset textInset |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
19 |
labelOffsetY lineMask itemClass lineColor computeResources |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
20 |
showRoot showDirectoryIndicator closeIndicator openIndicator |
1171 | 21 |
showDirectoryIndicatorForRoot imageOpened imageClosed imageItem |
22 |
discardMotionEvents registeredImages supportsExpandAll |
|
23 |
buildInArray drawVLinesFromLevel highlightMode editorWidget |
|
1202
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
24 |
editorIndex editValueFgColor validateExpandabilityBlock' |
1171 | 25 |
classVariableNames:'DefaultHilightMode SelectionInset' |
847 | 26 |
poolDictionaries:'' |
1233 | 27 |
category:'Views-Trees' |
444 | 28 |
! |
29 |
||
30 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
35 |
All Rights Reserved |
|
36 |
||
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
44 |
||
45 |
! |
|
46 |
||
47 |
documentation |
|
48 |
" |
|
49 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
50 |
lists and adds the functions to show/hide subtrees. |
|
456 | 51 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 52 |
|
1431 | 53 |
Notice: |
54 |
This class obsoletes SelectionInHierarchyView, which is no longer |
|
55 |
maintained but kept for backward compatibility. |
|
56 |
||
57 |
Notice2: |
|
58 |
Even for this class, an improved replacement now exists: |
|
59 |
HierarchicalListView. |
|
60 |
Please consider using that one. |
|
61 |
(however, this class is kept for backward compatibility). |
|
446 | 62 |
|
444 | 63 |
[see also:] |
456 | 64 |
SelectionInTree |
65 |
TreeItem |
|
444 | 66 |
SelectionInListView |
494 | 67 |
FileSelectionTree |
444 | 68 |
|
69 |
[author:] |
|
70 |
Claus Atzkern |
|
71 |
" |
|
72 |
! |
|
73 |
||
74 |
examples |
|
75 |
" |
|
76 |
shows the tree of smalltalk classes: |
|
77 |
[exBegin] |
|
514 | 78 |
|top sel| |
456 | 79 |
|
514 | 80 |
top := StandardSystemView new; extent:300@300. |
456 | 81 |
sel := SelectionInTreeView new. |
514 | 82 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
456 | 83 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
84 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
85 |
top open. |
|
86 |
[exEnd] |
|
87 |
||
88 |
||
485 | 89 |
|
456 | 90 |
same, including nil-subclasses (i.e. really all classes): |
91 |
[exBegin] |
|
514 | 92 |
|top sel| |
444 | 93 |
|
514 | 94 |
top := StandardSystemView new; extent:300@300. |
456 | 95 |
sel := SelectionInTreeView new. |
514 | 96 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:nil). |
456 | 97 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
685 | 98 |
sel lineColor:(Color red). |
456 | 99 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
100 |
top open. |
|
101 |
[exEnd] |
|
102 |
||
485 | 103 |
|
483 | 104 |
|
485 | 105 |
shows the tree of smalltalk classes; show directory indication and no |
106 |
lines. |
|
107 |
[exBegin] |
|
514 | 108 |
|top sel| |
483 | 109 |
|
514 | 110 |
top := StandardSystemView new; extent:300@300. |
483 | 111 |
sel := SelectionInTreeView new. |
485 | 112 |
sel showLines:false. |
113 |
sel showDirectoryIndicator:true. |
|
514 | 114 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
485 | 115 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 116 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
117 |
top open. |
|
485 | 118 |
[exEnd] |
119 |
" |
|
120 |
||
514 | 121 |
|
444 | 122 |
! ! |
123 |
||
124 |
!SelectionInTreeView class methodsFor:'constants'! |
|
125 |
||
494 | 126 |
minImageInset |
127 |
"returns minimum inset from directory indication to image |
|
471 | 128 |
" |
494 | 129 |
^ 6 |
490 | 130 |
|
131 |
||
132 |
! ! |
|
133 |
||
900 | 134 |
!SelectionInTreeView class methodsFor:'defaults'! |
135 |
||
1171 | 136 |
defaultModelClass |
137 |
"returns the default model |
|
138 |
" |
|
139 |
^ SelectionInTree |
|
140 |
! |
|
141 |
||
900 | 142 |
updateStyleCache |
143 |
"extract values from the styleSheet and cache them in class variables" |
|
144 |
||
145 |
<resource: #style (#'selection.highlightMode')> |
|
146 |
||
1171 | 147 |
SelectionInset := 4. |
900 | 148 |
DefaultHilightMode := StyleSheet at:'selection.highlightMode' default:#line. |
149 |
" |
|
150 |
self updateStyleCache |
|
151 |
" |
|
152 |
||
153 |
||
154 |
! ! |
|
155 |
||
811 | 156 |
!SelectionInTreeView class methodsFor:'resources'! |
490 | 157 |
|
158 |
closeIndicator |
|
1278 | 159 |
"returns a little [+] bitmap" |
160 |
||
1624 | 161 |
^ HierarchicalListView closeIndicator |
811 | 162 |
|
589 | 163 |
|
811 | 164 |
|
165 |
||
166 |
||
167 |
||
471 | 168 |
! |
169 |
||
444 | 170 |
imageClosed |
1278 | 171 |
"returns a closed file-directory bitmap" |
172 |
||
1624 | 173 |
^ HierarchicalListView collapsedIcon |
444 | 174 |
|
175 |
! |
|
176 |
||
177 |
imageItem |
|
1278 | 178 |
"returns a regular file bitmap" |
179 |
||
1624 | 180 |
^ HierarchicalListView emptyIcon |
444 | 181 |
|
811 | 182 |
|
444 | 183 |
|
811 | 184 |
|
185 |
||
444 | 186 |
! |
187 |
||
188 |
imageOpened |
|
1278 | 189 |
"returns an opened file-directory bitmap" |
190 |
||
1624 | 191 |
^ HierarchicalListView expandedIcon |
444 | 192 |
|
490 | 193 |
! |
194 |
||
195 |
openIndicator |
|
1278 | 196 |
"returns a little [-] bitmap" |
197 |
||
1624 | 198 |
^ HierarchicalListView openIndicator |
490 | 199 |
|
811 | 200 |
|
444 | 201 |
! ! |
202 |
||
203 |
!SelectionInTreeView methodsFor:'accessing'! |
|
204 |
||
900 | 205 |
highlightMode |
206 |
"get the mode how to draw a selected line: |
|
207 |
#line draw whole line selected |
|
208 |
#label draw label selected |
|
209 |
" |
|
210 |
^ highlightMode |
|
211 |
! |
|
212 |
||
213 |
highlightMode:aMode |
|
214 |
"set the mode how to draw a selected line: |
|
215 |
#line draw whole line selected |
|
216 |
#label draw label selected |
|
217 |
" |
|
218 |
|mode| |
|
219 |
||
220 |
(mode := aMode) == #label ifFalse:[ |
|
221 |
mode := #line |
|
222 |
]. |
|
223 |
||
224 |
mode ~~ highlightMode ifTrue:[ |
|
225 |
highlightMode := mode. |
|
226 |
||
227 |
shown ifTrue:[ |
|
228 |
self invalidate |
|
229 |
] |
|
230 |
] |
|
231 |
! |
|
232 |
||
1171 | 233 |
itemClass |
234 |
"returns current itemClass used |
|
235 |
" |
|
236 |
^ itemClass |
|
237 |
||
238 |
||
239 |
! |
|
240 |
||
241 |
itemClass:anItemClass |
|
242 |
"set itemClass to be used |
|
243 |
" |
|
244 |
||
245 |
(anItemClass notNil and:[anItemClass ~~ itemClass]) ifTrue:[ |
|
246 |
itemClass := anItemClass. |
|
247 |
computeResources := true. |
|
248 |
self refetchDeviceResources. |
|
249 |
]. |
|
250 |
||
251 |
! |
|
252 |
||
685 | 253 |
lineColor |
254 |
"returns user configured line color or nil |
|
255 |
" |
|
256 |
^ lineColor |
|
257 |
||
258 |
! |
|
259 |
||
260 |
lineColor:aColor |
|
261 |
"returns user configured line color or nil |
|
262 |
" |
|
263 |
|col| |
|
264 |
||
265 |
col := aColor = fgColor ifTrue:[nil] ifFalse:[aColor]. |
|
266 |
||
267 |
col = lineColor ifFalse:[ |
|
268 |
lineColor := col. |
|
269 |
||
270 |
shown ifTrue:[ |
|
1477 | 271 |
lineColor notNil ifTrue:[lineColor := lineColor onDevice:device]. |
685 | 272 |
self invalidate |
273 |
] |
|
274 |
] |
|
275 |
! |
|
276 |
||
490 | 277 |
nodeAtIndex:anIndex |
278 |
"returns node at an index or nil |
|
279 |
" |
|
785 | 280 |
(anIndex notNil and:[anIndex between:1 and:listOfNodes size]) ifTrue:[ |
490 | 281 |
^ listOfNodes at:anIndex |
282 |
]. |
|
283 |
^ nil |
|
284 |
! |
|
285 |
||
507 | 286 |
root |
287 |
"gets the root of the model; the first item into list. |
|
288 |
" |
|
289 |
^ self nodeAtIndex:1 |
|
290 |
! |
|
291 |
||
292 |
root:aRoot |
|
293 |
"sets the root of the model; the first item into list. |
|
294 |
" |
|
514 | 295 |
aRoot notNil ifTrue:[aRoot expand]. |
507 | 296 |
model root:aRoot |
297 |
! |
|
298 |
||
490 | 299 |
textInset |
300 |
"get the left inset of the text label |
|
301 |
" |
|
302 |
^ textInset |
|
303 |
! |
|
304 |
||
305 |
textInset:anInset |
|
306 |
"set the left inset of the text label |
|
307 |
" |
|
308 |
anInset ~~ textInset ifTrue:[ |
|
309 |
anInset >= 0 ifTrue:[ |
|
310 |
textInset := anInset. |
|
311 |
self invalidate |
|
312 |
] ifFalse:[ |
|
313 |
self error |
|
314 |
] |
|
315 |
]. |
|
316 |
! ! |
|
317 |
||
318 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
319 |
||
855 | 320 |
drawVLinesFromLevel |
321 |
"returns the level vertical lines are drawn from; |
|
322 |
starting at 1 up to n |
|
323 |
" |
|
324 |
^ drawVLinesFromLevel |
|
325 |
! |
|
326 |
||
327 |
drawVLinesFromLevel:aLevel |
|
328 |
"set the level vertical lines are drawn from; |
|
329 |
starting at 1 up to n |
|
330 |
" |
|
331 |
|lv| |
|
332 |
||
333 |
lv := (aLevel ? 1) max:1. |
|
334 |
||
335 |
lv ~~ drawVLinesFromLevel ifTrue:[ |
|
336 |
drawVLinesFromLevel := lv. |
|
337 |
self invalidate |
|
338 |
] |
|
339 |
! |
|
340 |
||
835 | 341 |
supportsExpandAll |
342 |
^ supportsExpandAll |
|
343 |
! |
|
344 |
||
345 |
supportsExpandAll:aBool |
|
346 |
||
347 |
supportsExpandAll := aBool |
|
348 |
! |
|
349 |
||
517 | 350 |
validateDoubleClickBlock |
1202
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
351 |
"return the conditionBlock; this block is evaluated before a doubleClick action |
517 | 352 |
on a node will be performed. In case of returning false, the doubleClick will |
353 |
not be handled. |
|
354 |
" |
|
355 |
^ validateDoubleClickBlock |
|
356 |
||
357 |
||
358 |
! |
|
359 |
||
360 |
validateDoubleClickBlock:aOneArgBlock |
|
361 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
362 |
on a node will be performed. In case of returning false, the doubleClick will |
|
363 |
not be handled. |
|
364 |
" |
|
365 |
validateDoubleClickBlock := aOneArgBlock |
|
366 |
||
367 |
||
1202
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
368 |
! |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
369 |
|
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
370 |
validateExpandabilityBlock |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
371 |
"return the expand conditionBlock; this block is evaluated before an expand due to |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
372 |
a doubleClick on a node will be performed. In case of returning false, |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
373 |
the node will not be expanded. |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
374 |
" |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
375 |
^ validateExpandabilityBlock |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
376 |
|
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
377 |
|
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
378 |
! |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
379 |
|
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
380 |
validateExpandabilityBlock:aOneArgBlock |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
381 |
"set the expand conditionBlock; this block is evaluated before an expand due to |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
382 |
a doubleClick on a node will be performed. In case of returning false, |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
383 |
the node will not be expanded. |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
384 |
" |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
385 |
validateExpandabilityBlock := aOneArgBlock |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
386 |
|
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
387 |
|
514 | 388 |
! ! |
389 |
||
390 |
!SelectionInTreeView methodsFor:'accessing-channels'! |
|
391 |
||
392 |
rootHolder |
|
393 |
"get the holder which keeps the hierarchical list entry or nil |
|
394 |
" |
|
395 |
^ rootHolder |
|
396 |
! |
|
397 |
||
398 |
rootHolder:aValueHolder |
|
399 |
"set the holder which keeps the hierarchical list entry or nil |
|
400 |
" |
|
401 |
rootHolder notNil ifTrue:[ |
|
402 |
rootHolder removeDependent:self |
|
403 |
]. |
|
855 | 404 |
|
514 | 405 |
(rootHolder := aValueHolder) notNil ifTrue:[ |
406 |
rootHolder addDependent:self. |
|
407 |
self rootFromModel. |
|
494 | 408 |
]. |
514 | 409 |
! |
410 |
||
411 |
selectionHolder |
|
412 |
"get the holder which keeps a list of selected items or nil |
|
413 |
" |
|
414 |
^ selectionHolder |
|
415 |
||
416 |
! |
|
417 |
||
418 |
selectionHolder:aHolder |
|
419 |
"set the holder which keeps a list of selected items or nil |
|
420 |
" |
|
421 |
selectionHolder notNil ifTrue:[ |
|
422 |
selectionHolder removeDependent:self |
|
423 |
]. |
|
424 |
||
425 |
(selectionHolder := aHolder) notNil ifTrue:[ |
|
426 |
selectionHolder addDependent:self. |
|
427 |
self selectionFromModel |
|
428 |
]. |
|
429 |
||
490 | 430 |
! ! |
431 |
||
432 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
433 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
434 |
imageClosed |
1278 | 435 |
"return the value of the instance variable 'imageClosed'. |
436 |
Thats the (default) bitmap image shown for closed folders |
|
437 |
(initialized to a file-directory bitmap)" |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
438 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
439 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
440 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
441 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
442 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
443 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
444 |
imageItem |
1278 | 445 |
"return the value of the instance variable 'imageItem'. |
446 |
Thats the (default) bitmap image shown for regular items |
|
447 |
(initialized to a plain-file bitmap)" |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
448 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
449 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
450 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
451 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
452 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
453 |
|
569 | 454 |
imageOnDevice:anImage |
846 | 455 |
"associate image to device and clear pixel mask (in case of realized); |
569 | 456 |
returns the new image. |
457 |
" |
|
458 |
|img| |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
459 |
|
846 | 460 |
img := anImage. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
461 |
img notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
462 |
img device ~~ device ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
463 |
img := img copy. |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
464 |
]. |
1477 | 465 |
img := img onDevice:device. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
466 |
img := img clearMaskedPixels. |
569 | 467 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
468 |
^ img |
846 | 469 |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
470 |
"Modified: / 12.8.1998 / 12:46:38 / cg" |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
471 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
472 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
473 |
imageOpened |
1278 | 474 |
"return the value of the instance variable 'imageOpened'. |
475 |
Thats the (default) bitmap image shown for opened folders |
|
476 |
(initialized to an open file-directory bitmap)" |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
477 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
478 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
479 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
480 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 481 |
! ! |
482 |
||
1275 | 483 |
!SelectionInTreeView methodsFor:'accessing-look'! |
484 |
||
485 |
showDirectoryIndicator |
|
486 |
"returns true if directories has an open/closed indicator |
|
487 |
" |
|
488 |
^ showDirectoryIndicator |
|
489 |
! |
|
490 |
||
491 |
showDirectoryIndicator:aState |
|
492 |
"set or clear open/closed indicator for directories |
|
493 |
" |
|
494 |
"show or hide lines |
|
495 |
" |
|
496 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
497 |
showDirectoryIndicator := aState. |
|
498 |
self recomputeDirectoryIndicator. |
|
499 |
self invalidate |
|
500 |
]. |
|
501 |
! |
|
502 |
||
503 |
showDirectoryIndicatorForRoot |
|
504 |
"returns true if root directory has an open/closed indicator if |
|
505 |
the common showDirectoryIndicator is enabled |
|
506 |
" |
|
507 |
^ showDirectoryIndicatorForRoot |
|
508 |
! |
|
509 |
||
510 |
showDirectoryIndicatorForRoot:aState |
|
511 |
"true if root directory has an open/closed indicator if |
|
512 |
the common showDirectoryIndicator is enabled |
|
513 |
" |
|
514 |
aState ~~ showDirectoryIndicatorForRoot ifTrue:[ |
|
515 |
showDirectoryIndicatorForRoot := aState. |
|
516 |
self recomputeDirectoryIndicator. |
|
517 |
self invalidate |
|
518 |
]. |
|
519 |
! |
|
520 |
||
521 |
showLines |
|
522 |
"returns true if lines are shown |
|
523 |
" |
|
524 |
^ showLines |
|
525 |
! |
|
526 |
||
527 |
showLines:aState |
|
528 |
"show or hide lines |
|
529 |
" |
|
530 |
aState ~~ showLines ifTrue:[ |
|
531 |
showLines := aState. |
|
532 |
self invalidate |
|
533 |
]. |
|
534 |
! |
|
535 |
||
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
536 |
showLinesForRoot |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
537 |
"returns true if root-lines are shown |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
538 |
" |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
539 |
^ showLinesForRoot |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
540 |
! |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
541 |
|
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
542 |
showLinesForRoot:aState |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
543 |
"show or hide lines for root(s) |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
544 |
" |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
545 |
aState ~~ showLinesForRoot ifTrue:[ |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
546 |
showLinesForRoot := aState. |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
547 |
self invalidate |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
548 |
]. |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
549 |
! |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
550 |
|
1275 | 551 |
showRoot |
552 |
"list with or without root |
|
553 |
" |
|
554 |
^ showRoot |
|
555 |
! |
|
556 |
||
557 |
showRoot:aState |
|
558 |
"list with or without root |
|
559 |
" |
|
560 |
showRoot ~~ aState ifTrue:[ |
|
561 |
model showRoot:(showRoot := aState). |
|
562 |
]. |
|
563 |
! ! |
|
564 |
||
514 | 565 |
!SelectionInTreeView methodsFor:'change & update'! |
566 |
||
855 | 567 |
modelChanged:what with:aPara |
568 |
"hierarchical list changed |
|
569 |
" |
|
570 |
|start size visLn h y0 y1 cY parent pvLv ndLv| |
|
571 |
||
572 |
aPara isNil ifTrue:[ |
|
573 |
what == #list ifTrue:[ self getListFromModel ] |
|
574 |
ifFalse:[ super update:what with:aPara from:model ]. |
|
575 |
^ self |
|
576 |
]. |
|
577 |
||
578 |
(what == #insertCollection: or:[what == #removeFrom:]) ifFalse:[ |
|
579 |
what == #at: ifTrue:[ ^ self redrawLine:aPara ]. |
|
580 |
what == #replace ifTrue:[ ^ self invalidateRepairNow:true ]. |
|
581 |
||
582 |
^ super update:what with:aPara from:model. |
|
583 |
]. |
|
584 |
list := self listFromModel. |
|
585 |
||
586 |
shown ifFalse:[ |
|
587 |
^ self contentsChanged |
|
588 |
]. |
|
589 |
(self sensor notNil and: [self sensor hasExposeEventFor:self]) ifTrue:[ "/ outstanding expose events |
|
590 |
self invalidateRepairNow:true. |
|
591 |
^ self contentsChanged |
|
592 |
]. |
|
593 |
||
594 |
start := aPara at:1. |
|
595 |
size := aPara at:2. |
|
596 |
parent := aPara at:3. |
|
597 |
||
860 | 598 |
what == #removeFrom: ifTrue:[ |
599 |
size := size - start + 1 |
|
600 |
]. |
|
601 |
||
855 | 602 |
start > 1 ifTrue:[ |
603 |
pvLv := (list at:start - 1) level. |
|
604 |
ndLv := parent level + 1. |
|
605 |
||
606 |
ndLv < pvLv ifTrue:[ |
|
607 |
what == #insertCollection: ifTrue:[ |
|
608 |
visLn := start + size. |
|
609 |
] ifFalse:[ |
|
610 |
visLn := start. |
|
611 |
]. |
|
612 |
||
613 |
(visLn > list size or:[(list at:visLn) level ~~ ndLv]) ifTrue:[ |
|
614 |
[(start := start - 1) ~~ 1] whileTrue:[ |
|
615 |
(list at:start) level <= ndLv ifTrue:[ |
|
616 |
self redrawFromLine:start. |
|
617 |
^ self contentsChanged. |
|
618 |
] |
|
619 |
]. |
|
620 |
self invalidateRepairNow:true. |
|
621 |
^ self contentsChanged |
|
622 |
] |
|
623 |
]. |
|
624 |
self redrawIconAndIndicatorAt:(start - 1) |
|
625 |
]. |
|
626 |
(visLn := self listLineToVisibleLine:start) isNil ifTrue:[ |
|
627 |
^ self contentsChanged |
|
628 |
]. |
|
629 |
||
630 |
h := size * fontHeight. |
|
631 |
y0 := self yOfVisibleLine:visLn. |
|
632 |
y1 := y0 + h. |
|
633 |
cY := height - y1 - 1. |
|
634 |
||
635 |
cY < 40 ifTrue:[ |
|
636 |
self redrawFromLine:start. |
|
637 |
] ifFalse:[ |
|
638 |
self catchExpose. |
|
639 |
||
640 |
what == #insertCollection: ifTrue:[ |
|
641 |
self copyFrom:self x:0 y:y0 toX:0 y:y1 width:width height:cY async:true. |
|
642 |
] ifFalse:[ |
|
643 |
self copyFrom:self x:0 y:y1 toX:0 y:y0 width:width height:cY async:true. |
|
644 |
y0 := y0 + cY. |
|
645 |
h := height - y0. |
|
646 |
]. |
|
647 |
self redrawX:0 y:y0 width:width height:h. |
|
648 |
self waitForExpose. |
|
649 |
]. |
|
650 |
device flush. |
|
651 |
self contentsChanged. |
|
652 |
! |
|
653 |
||
514 | 654 |
update:something with:aParameter from:aModel |
655 |
"one of my models changed its value |
|
785 | 656 |
" |
657 |
|idx| |
|
658 |
||
514 | 659 |
aModel == rootHolder ifTrue:[ |
660 |
^ self rootFromModel |
|
661 |
]. |
|
855 | 662 |
|
514 | 663 |
aModel == selectionHolder ifTrue:[ |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
664 |
^ self selectionFromModel |
514 | 665 |
]. |
666 |
||
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
667 |
aModel == model ifTrue:[ |
855 | 668 |
^ self modelChanged:something with:aParameter |
669 |
]. |
|
670 |
||
671 |
(aModel isKindOf:TreeItem) ifTrue:[ |
|
672 |
(something == #size or:[something == #children]) ifTrue:[ |
|
673 |
model recomputeList. |
|
674 |
^ self |
|
675 |
]. |
|
676 |
||
677 |
(idx := self indexOfNode:aModel) ~~ 0 ifTrue:[ |
|
678 |
something == #value ifTrue:[ |
|
679 |
^ self redrawLine:idx. |
|
785 | 680 |
]. |
811 | 681 |
|
855 | 682 |
something == #indication ifTrue:[ |
683 |
^ self redrawIndicatorLine:idx. |
|
811 | 684 |
]. |
1308 | 685 |
"/ assume that the nodes string has changed |
686 |
^ self redrawLine:idx. |
|
855 | 687 |
]. |
688 |
^ self |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
689 |
]. |
855 | 690 |
super update:something with:aParameter from:aModel. |
811 | 691 |
|
514 | 692 |
! ! |
693 |
||
444 | 694 |
!SelectionInTreeView methodsFor:'drawing'! |
695 |
||
481 | 696 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
697 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 698 |
|
699 |
! |
|
700 |
||
701 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 702 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 703 |
|
704 |
! |
|
705 |
||
706 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 707 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 708 |
|
709 |
! |
|
710 |
||
711 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 712 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 713 |
|
714 |
! |
|
715 |
||
716 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 717 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
718 |
||
444 | 719 |
! |
720 |
||
721 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 722 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 723 |
|
846 | 724 |
! |
725 |
||
726 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
727 |
self redrawX:0 |
|
728 |
y:(self yOfVisibleLine:startVisLineNr) |
|
729 |
width:width |
|
730 |
height:(endVisLineNr - startVisLineNr + 1 * fontHeight) |
|
731 |
||
732 |
||
848 | 733 |
! |
444 | 734 |
|
848 | 735 |
redrawIconAndIndicatorAt:aLnNr |
736 |
|visLineNr x0 x1 lv| |
|
481 | 737 |
|
769 | 738 |
shown ifTrue:[ |
848 | 739 |
visLineNr := self listLineToVisibleLine:aLnNr. |
740 |
visLineNr notNil ifTrue:[ |
|
741 |
lv := (listOfNodes at:aLnNr) level. |
|
742 |
x1 := (imageWidth + (self xOfFigureLevel:lv)) min:width. |
|
743 |
x0 := (self xOfFigureLevel:(lv - 1)) max:0. |
|
769 | 744 |
|
848 | 745 |
(x0 > width or:[x1 < 0]) ifFalse:[ |
746 |
self redrawX:x0 |
|
747 |
y:(self yOfVisibleLine:visLineNr) |
|
748 |
width:(x1 - x0) |
|
749 |
height:fontHeight |
|
750 |
] |
|
769 | 751 |
] |
848 | 752 |
]. |
769 | 753 |
! |
754 |
||
811 | 755 |
redrawIndicatorLine:aLineNr |
756 |
"redraw the directory indicator for a line |
|
757 |
" |
|
758 |
|node ext img visLn |
|
759 |
x "{ Class:SmallInteger }" |
|
760 |
y "{ Class:SmallInteger }" |
|
761 |
dX "{ Class:SmallInteger }" |
|
762 |
| |
|
763 |
||
764 |
( shown |
|
765 |
and:[showDirectoryIndicator |
|
766 |
and:[(visLn := self listLineToVisibleLine:aLineNr) notNil]] |
|
767 |
) ifFalse:[ |
|
768 |
^ self |
|
769 |
]. |
|
770 |
||
771 |
node := listOfNodes at:aLineNr. |
|
772 |
||
846 | 773 |
(node parent notNil or:[showDirectoryIndicatorForRoot]) ifFalse:[ |
811 | 774 |
^ self |
775 |
]. |
|
776 |
||
846 | 777 |
x := imageWidth // 2. |
778 |
x := x + (self xOfFigureLevel:(node level - 1)). |
|
811 | 779 |
|
780 |
"/ draw directory indicator |
|
781 |
||
782 |
img := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
1620
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
783 |
img notNil ifTrue:[ |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
784 |
ext := img extent // 2. |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
785 |
dX := ext x. |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
786 |
|
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
787 |
(x + dX > 0 and:[(x := x - dX) < (width - margin)]) ifTrue:[ |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
788 |
(self isInSelection:aLineNr) ifTrue:[ self paint:hilightFgColor on:hilightBgColor ] |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
789 |
ifFalse:[ self paint:fgColor on:bgColor ]. |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
790 |
|
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
791 |
y := (self yOfVisibleLine:visLn) + (fontHeight // 2) - 1. |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
792 |
self displayForm:img x:x y:(y - ext y) |
99124a1a1342
care for nil-image when drawing indicator line
Claus Gittinger <cg@exept.de>
parents:
1477
diff
changeset
|
793 |
]. |
811 | 794 |
]. |
795 |
||
796 |
||
797 |
||
900 | 798 |
! |
799 |
||
800 |
redrawVisibleLine:visLineNr |
|
801 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor |
|
802 |
! |
|
803 |
||
804 |
redrawVisibleLine:visLineNr from:startCol to:endCol |
|
805 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor |
|
848 | 806 |
! ! |
807 |
||
808 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
809 |
||
900 | 810 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
811 |
"redraw a visible line range with clearing the background |
|
848 | 812 |
" |
900 | 813 |
|y h| |
848 | 814 |
|
900 | 815 |
y := self yOfVisibleLine:startVisLineNr. |
816 |
h := endVisLineNr - startVisLineNr + 1 * fontHeight. |
|
817 |
||
818 |
y + h > height ifTrue:[ |
|
819 |
h := height - y |
|
820 |
]. |
|
821 |
self redrawX:0 y:y width:width height:h. |
|
848 | 822 |
! |
823 |
||
824 |
drawVHLinesX:x0 y:y0 toX:x1 start:start stop:stop |
|
825 |
"redraw from line to line without clearing the background |
|
826 |
" |
|
827 |
|node prevNode parent p1 p2 showVLines showHLine lv nxtPrnt |
|
1305
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
828 |
showRootNot isFirst |
848 | 829 |
|
830 |
x "{ Class:SmallInteger }" |
|
831 |
y "{ Class:SmallInteger }" |
|
832 |
||
833 |
yTop "{ Class:SmallInteger }" |
|
834 |
yBot "{ Class:SmallInteger }" |
|
835 |
yCtr "{ Class:SmallInteger }" |
|
836 |
||
837 |
begHLnY "{ Class:SmallInteger }" |
|
838 |
begHLnX "{ Class:SmallInteger }" |
|
839 |
endHLnX "{ Class:SmallInteger }" |
|
840 |
||
841 |
widthLvl "{ Class:SmallInteger }" |
|
842 |
offsHLnX "{ Class:SmallInteger }" |
|
843 |
||
844 |
level "{ Class:SmallInteger }" |
|
855 | 845 |
startLvI "{ Class:SmallInteger }" |
846 |
startLvX "{ Class:SmallInteger }" |
|
847 |
limitLvI "{ Class:SmallInteger }" |
|
848 |
limitLvX "{ Class:SmallInteger }" |
|
848 | 849 |
| |
1305
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
850 |
|
848 | 851 |
yBot := y0. |
852 |
yCtr := yBot - (fontHeight // 2). |
|
853 |
widthLvl := imageInset + imageWidth. |
|
854 |
offsHLnX := imageWidth // 2 + (self xOfFigureLevel:-1). |
|
855 |
||
856 |
parent := 4711. "/ to force a recompute |
|
857 |
prevNode := 4711. "/ to force a recomputation of the level |
|
858 |
||
859 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
860 |
self paint:lineColor on:bgColor. |
|
861 |
self mask:lineMask. |
|
862 |
begHLnY := y0. |
|
855 | 863 |
startLvI := self smallestLevelOfNodesBetween:start and:stop. |
864 |
startLvX := self xOfFigureLevel:startLvI. |
|
865 |
limitLvI := drawVLinesFromLevel + 1. |
|
866 |
limitLvX := limitLvI * widthLvl + offsHLnX. |
|
848 | 867 |
|
868 |
buildInArray atAllPut:0. |
|
869 |
||
870 |
start == 1 ifTrue:[ |
|
871 |
begHLnY := yCtr + fontHeight. |
|
872 |
]. |
|
1305
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
873 |
showRootNot := showRoot not. |
848 | 874 |
|
875 |
start to:stop do:[:anIndex| |
|
876 |
node := listOfNodes at:anIndex. |
|
877 |
yTop := yBot - 1. |
|
878 |
yBot := yBot + fontHeight. |
|
879 |
yCtr := yCtr + fontHeight. |
|
880 |
||
881 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
|
882 |
parent := nxtPrnt. |
|
883 |
||
884 |
prevNode == parent ifTrue:[ |
|
885 |
level := level + 1. |
|
886 |
begHLnX := endHLnX. |
|
887 |
] ifFalse:[ |
|
888 |
level := node level. |
|
1309 | 889 |
begHLnX := level * widthLvl + offsHLnX. |
848 | 890 |
]. |
891 |
||
1305
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
892 |
isFirst := parent isNil or:[(showRootNot and:[level == 2])]. |
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
893 |
endHLnX := begHLnX + widthLvl. |
855 | 894 |
showVLines := begHLnX >= x0 and:[level > drawVLinesFromLevel]. |
1305
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
895 |
showHLine := x0 < endHLnX and:[x1 > begHLnX]. |
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
896 |
|
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
897 |
(showHLine and:[isFirst]) ifTrue:[ |
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
898 |
showHLine := showDirectoryIndicatorForRoot and:[showDirectoryIndicator] |
c8f2fe1fac85
fix drawing horizontal lines for the root element(s)
Claus Gittinger <cg@exept.de>
parents:
1278
diff
changeset
|
899 |
] |
848 | 900 |
]. |
901 |
||
902 |
showHLine ifTrue:[ |
|
903 |
self displayLineFromX:begHLnX y:yCtr toX:endHLnX y:yCtr |
|
904 |
]. |
|
905 |
||
906 |
showVLines ifTrue:[ |
|
907 |
y := (parent basicLastChild == node) ifTrue:[yCtr] ifFalse:[yBot]. |
|
908 |
x := begHLnX. |
|
909 |
p2 := parent. |
|
910 |
lv := level - 1. |
|
911 |
self displayLineFromX:x y:begHLnY toX:x y:y. |
|
912 |
||
855 | 913 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[ |
848 | 914 |
(p1 basicLastChild ~~ p2 and:[x <= x1]) ifTrue:[ |
855 | 915 |
x >= startLvX ifTrue:[ |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
916 |
(isFirst not or:[showLinesForRoot]) ifTrue:[ |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
917 |
self displayLineFromX:x y:yTop toX:x y:yBot |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
918 |
] |
848 | 919 |
] ifFalse:[ |
920 |
buildInArray at:lv put:yBot |
|
921 |
]. |
|
922 |
]. |
|
923 |
lv := lv - 1. |
|
924 |
p2 := p1 |
|
925 |
] |
|
926 |
]. |
|
927 |
prevNode := node. |
|
928 |
begHLnY := yCtr. |
|
929 |
]. |
|
930 |
||
855 | 931 |
"/ |
932 |
"/ draw outstanding verical lines to left |
|
933 |
"/ |
|
934 |
x := limitLvX. |
|
935 |
y := (start ~~ 1) ifTrue:[y0] ifFalse:[y0 + (fontHeight // 2)]. |
|
848 | 936 |
|
855 | 937 |
limitLvI to:startLvI do:[:i| |
938 |
(yBot := buildInArray at:i) ~~ 0 ifTrue:[ |
|
939 |
self displayLineFromX:x y:y toX:x y:yBot |
|
940 |
]. |
|
941 |
x := x + widthLvl. |
|
848 | 942 |
]. |
943 |
self mask:nil. |
|
811 | 944 |
! |
945 |
||
900 | 946 |
drawVisibleLineSelected:visLineNr with:fg and:bg |
947 |
"redraw a single line as selected." |
|
948 |
||
949 |
(self visibleLineToListLine:visLineNr) isNil ifTrue:[ |
|
950 |
^ super drawVisibleLine:visLineNr with:fg and:bg |
|
951 |
]. |
|
952 |
self redrawX:0 |
|
953 |
y:(self yOfVisibleLine:visLineNr) |
|
954 |
width:width |
|
955 |
height:fontHeight |
|
956 |
! |
|
957 |
||
902 | 958 |
redrawElement:anIndex |
959 |
||
960 |
|vln x0 xT y| |
|
961 |
||
962 |
shown ifTrue:[ |
|
963 |
( highlightMode ~~ #label |
|
908 | 964 |
or:[(vln := self listLineToVisibleLine:anIndex) isNil |
965 |
or:[anIndex > listOfNodes size]] |
|
902 | 966 |
) ifTrue:[ |
967 |
super redrawElement:anIndex |
|
968 |
] ifFalse:[ |
|
969 |
y := self yOfVisibleLine:vln. |
|
970 |
xT := self xOfStringLevel:((listOfNodes at:anIndex) level). |
|
971 |
x0 := xT - textInset. |
|
972 |
self paint:bgColor. |
|
973 |
self fillRectangleX:x0 y:y width:(width - x0) height:fontHeight. |
|
974 |
self redrawLabelAt:xT y:y index:anIndex |
|
975 |
] |
|
976 |
] |
|
977 |
||
978 |
! |
|
979 |
||
900 | 980 |
redrawLabelAt:x y:yTop index:anIndex |
1171 | 981 |
|isSel y0 x0 w label node value xV wV| |
982 |
||
983 |
node := listOfNodes at:anIndex. |
|
984 |
label := node name. |
|
985 |
isSel := self isInSelection:anIndex. |
|
986 |
xV := 0. |
|
987 |
wV := 0. |
|
988 |
y0 := yTop + (fontHeight // 2) + labelOffsetY. |
|
989 |
||
990 |
(value := node printableEditValue) notNil ifTrue:[ |
|
991 |
xV := (self xOfValueNode:node) - SelectionInset |
|
992 |
]. |
|
900 | 993 |
|
994 |
highlightMode == #label ifTrue:[ |
|
995 |
x0 := x + 4. |
|
996 |
||
1171 | 997 |
isSel ifTrue:[ |
900 | 998 |
w := (label notNil ifTrue:[label widthOn:self] ifFalse:[60]) + 8. |
999 |
self paint:hilightBgColor. |
|
1000 |
self fillRectangleX:x y:yTop width:w height:fontHeight. |
|
1171 | 1001 |
|
1002 |
(value notNil and:[(editorWidget isNil or:[editorIndex ~~ anIndex])]) ifTrue:[ |
|
1003 |
wV := SelectionInset + SelectionInset + (value widthOn:self). |
|
1004 |
self fillRectangleX:xV y:yTop width:wV height:fontHeight. |
|
1005 |
] |
|
900 | 1006 |
] |
1007 |
] ifFalse:[ |
|
1008 |
x0 := x |
|
1009 |
]. |
|
1010 |
||
1011 |
label notNil ifTrue:[ |
|
1171 | 1012 |
isSel ifTrue:[self paint:hilightFgColor on:hilightBgColor] |
1013 |
ifFalse:[self paint:fgColor on:bgColor]. |
|
1014 |
||
1015 |
self displayOpaqueString:label x:x0 y:y0. |
|
1016 |
||
1017 |
value notNil ifTrue:[ |
|
1175 | 1018 |
isSel ifFalse:[ |
1019 |
self paint:editValueFgColor on:bgColor |
|
1020 |
]. |
|
1171 | 1021 |
self displayOpaqueString:value x:(xV + SelectionInset) y:y0 |
1022 |
]. |
|
1023 |
||
900 | 1024 |
]. |
1025 |
||
1171 | 1026 |
(isSel and:[highlightMode == #label]) ifTrue:[ |
1027 |
self redrawSelFrameAtX:x y:yTop toX:(x + w). |
|
1028 |
||
1029 |
wV ~~ 0 ifTrue:[ |
|
1030 |
self redrawSelFrameAtX:xV y:yTop toX:(xV + wV) |
|
1031 |
] |
|
900 | 1032 |
]. |
1033 |
||
1171 | 1034 |
|
900 | 1035 |
! |
1036 |
||
769 | 1037 |
redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop |
1038 |
"redraw from line to line without clearing the background |
|
1039 |
" |
|
848 | 1040 |
|node prevNode parent icon showIndc showIcon showText nxtPrnt |
846 | 1041 |
|
1042 |
end "{ Class:SmallInteger }" |
|
1043 |
||
1044 |
yBot "{ Class:SmallInteger }" |
|
1045 |
yCtr "{ Class:SmallInteger }" |
|
1046 |
||
848 | 1047 |
xIndc "{ Class:SmallInteger }" |
846 | 1048 |
xIcon "{ Class:SmallInteger }" |
1049 |
xText "{ Class:SmallInteger }" |
|
1050 |
||
1051 |
widthLvl "{ Class:SmallInteger }" |
|
1052 |
insetTxt "{ Class:SmallInteger }" |
|
848 | 1053 |
|
1054 |
offIndcX "{ Class:SmallInteger }" |
|
1055 |
offIndcY "{ Class:SmallInteger }" |
|
1056 |
offIconX "{ Class:SmallInteger }" |
|
769 | 1057 |
| |
848 | 1058 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
1059 |
^ self |
|
1060 |
]. |
|
846 | 1061 |
yBot := y0. |
1062 |
yCtr := yBot - (fontHeight // 2). |
|
1063 |
widthLvl := imageInset + imageWidth. |
|
1064 |
insetTxt := imageWidth + textInset. |
|
848 | 1065 |
offIconX := self xOfFigureLevel:0. |
1066 |
showIndc := false. |
|
846 | 1067 |
|
1068 |
showDirectoryIndicator ifTrue:[ |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1069 |
offIndcX := imageWidth // 2 - widthLvl. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1070 |
offIndcY := 0. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1071 |
openIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1072 |
icon := openIndicator extent // 2. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1073 |
offIndcX := offIndcX - icon x. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1074 |
offIndcY := icon y. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1075 |
] |
846 | 1076 |
]. |
785 | 1077 |
|
1078 |
showLines ifTrue:[ |
|
848 | 1079 |
self drawVHLinesX:x0 y:y0 toX:x1 start:start stop:end |
785 | 1080 |
]. |
485 | 1081 |
|
846 | 1082 |
parent := 4711. "/ to force a recompute |
1083 |
prevNode := 4711. "/ to force a recomputation of the level |
|
1084 |
||
1085 |
start to:end do:[:anIndex| |
|
1086 |
node := listOfNodes at:anIndex. |
|
1087 |
yBot := yBot + fontHeight. |
|
494 | 1088 |
yCtr := yCtr + fontHeight. |
485 | 1089 |
|
848 | 1090 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
1091 |
parent := nxtPrnt. |
|
1092 |
xIcon := prevNode == parent ifTrue:[xIcon + widthLvl] |
|
1093 |
ifFalse:[node level * widthLvl + offIconX]. |
|
481 | 1094 |
|
848 | 1095 |
xText := xIcon + insetTxt. |
1096 |
showIcon := xIcon < x1 and:[xText > x0]. |
|
1097 |
showText := xText < x1. |
|
769 | 1098 |
|
848 | 1099 |
showDirectoryIndicator ifTrue:[ |
1100 |
xIndc := xIcon + offIndcX. |
|
481 | 1101 |
|
848 | 1102 |
showIndc := ( (parent notNil or:[showDirectoryIndicatorForRoot]) |
1103 |
and:[(xIcon > x0 and:[xIndc < x1])] |
|
1104 |
) |
|
1105 |
] |
|
785 | 1106 |
]. |
481 | 1107 |
|
846 | 1108 |
(showIcon and:[(icon := self figureFor:node) notNil]) ifTrue:[ |
1109 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2)) |
|
770 | 1110 |
]. |
848 | 1111 |
|
846 | 1112 |
showText ifTrue:[ |
900 | 1113 |
self redrawLabelAt:xText y:(yBot - fontHeight) index:anIndex |
485 | 1114 |
]. |
848 | 1115 |
(showIndc and:[node showIndicator]) ifTrue:[ |
846 | 1116 |
icon := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
1091
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1117 |
icon notNil ifTrue:[ |
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1118 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY) |
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1119 |
] |
846 | 1120 |
]. |
1121 |
prevNode := node. |
|
769 | 1122 |
] |
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1123 |
|
1091
2e86163cfb17
care for non-existing icon image
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1124 |
"Modified: / 22.8.1998 / 12:56:50 / cg" |
792 | 1125 |
! |
1126 |
||
900 | 1127 |
redrawSelFrameAtX:x0 y:y0 toX:x1 |
1128 |
"redraw selection frame for a line |
|
792 | 1129 |
" |
900 | 1130 |
| |
792 | 1131 |
w "{ Class: SmallInteger }" |
1132 |
y "{ Class: SmallInteger }" |
|
1133 |
x "{ Class: SmallInteger }" |
|
1134 |
| |
|
1135 |
||
1136 |
hilightFrameColor notNil ifTrue:[ |
|
1137 |
hilightLevel == 0 ifTrue:[ |
|
1138 |
self paint:hilightFrameColor. |
|
1105
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1139 |
highlightMode == #line ifTrue:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1140 |
self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1141 |
y := y0 + fontHeight - 1. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1142 |
^self displayLineFromX:x0 y:y toX:x1 y:y. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1143 |
] ifFalse:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1144 |
^self displayRectangleX:x0 y:y0 width:x1 - x0 height:fontHeight |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1145 |
] |
792 | 1146 |
] |
1147 |
] ifFalse:[ |
|
1148 |
hilightStyle == #motif ifTrue:[ |
|
1149 |
self paint:bgColor. |
|
900 | 1150 |
y := y0 + 1. |
1105
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1151 |
highlightMode == #line ifTrue:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1152 |
self displayLineFromX:x0 y:y toX:x1 y:y. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1153 |
y := y0 + fontHeight - 2. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1154 |
self displayLineFromX:x0 y:y toX:x1 y:y. |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1155 |
] ifFalse:[ |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1156 |
self displayRectangleX:x0 + 1 y:y width:x1 - x0 - 2 height:fontHeight - 2 |
c79bb5824b74
draw closed frames around selections if highlightMode ~~ #line
tz
parents:
1091
diff
changeset
|
1157 |
] |
792 | 1158 |
] |
1159 |
]. |
|
1160 |
||
1161 |
hilightLevel ~~ 0 ifTrue:[ |
|
1162 |
"/ draw edge |
|
1163 |
||
900 | 1164 |
highlightMode == #line ifTrue:[ |
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1165 |
w := ((width - (2 * margin)) max:(self widthOfContents)) + viewOrigin x. |
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
1166 |
x := margin - viewOrigin x. |
900 | 1167 |
] ifFalse:[ |
1168 |
w := x1 - x0. |
|
1169 |
x := x0. |
|
1170 |
]. |
|
1171 |
self drawEdgesForX:x y:y0 width:w height:fontHeight level:hilightLevel. |
|
792 | 1172 |
] |
900 | 1173 |
! |
1174 |
||
1175 |
redrawX:x y:y width:w height:h |
|
1176 |
"a region must be redrawn" |
|
1177 |
||
1178 |
|savClip startLn sel |
|
1179 |
y0 "{ Class:SmallInteger }" |
|
1180 |
y1 "{ Class:SmallInteger }" |
|
1181 |
visStart "{ Class:SmallInteger }" |
|
1182 |
visEnd "{ Class:SmallInteger }" |
|
1183 |
stopLn "{ Class:SmallInteger }" |
|
1184 |
maxY "{ Class:SmallInteger }" |
|
1185 |
maxX "{ Class:SmallInteger }" |
|
1186 |
dltLine "{ Class:SmallInteger }" |
|
1187 |
startY "{ Class:SmallInteger }"| |
|
1188 |
||
1189 |
shown ifFalse:[^ self]. |
|
1190 |
||
1191 |
visStart := self visibleLineOfY:(y + 1). |
|
1192 |
startLn := self visibleLineToAbsoluteLine:visStart. |
|
1193 |
||
1194 |
self paint:bgColor. |
|
1195 |
self fillRectangleX:x y:y width:w height:h. |
|
1196 |
startLn isNil ifTrue:[ ^ self ]. |
|
1197 |
||
1198 |
sel := nil. |
|
1199 |
maxX := x + w. |
|
1200 |
maxY := y + h. |
|
1201 |
visEnd := self visibleLineOfY:maxY. |
|
1202 |
startY := self yOfVisibleLine:visStart. |
|
1203 |
dltLine := startLn - visStart. |
|
1204 |
stopLn := dltLine + visEnd. |
|
1205 |
savClip := clipRect. |
|
1206 |
||
1207 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
|
1208 |
||
1209 |
(highlightMode == #line and:[self hasSelection]) ifTrue:[ |
|
1210 |
"/ redraw the background for all selected lines in the invalid range |
|
1211 |
||
1212 |
self selectionDo:[:lnNr| |
|
1213 |
(lnNr between:startLn and:stopLn) ifTrue:[ |
|
1214 |
sel isNil ifTrue:[ |
|
1215 |
sel := OrderedCollection new. |
|
1216 |
self paint:hilightBgColor. |
|
1217 |
]. |
|
1218 |
sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)). |
|
1219 |
y1 := y0 + fontHeight min:maxY. |
|
1220 |
y0 := y0 max:y. |
|
1221 |
self fillRectangleX:x y:y0 width:w height:y1 - y0. |
|
1222 |
] |
|
1223 |
] |
|
1224 |
]. |
|
1225 |
self redrawLinesX:x y:startY toX:maxX start:startLn stop:stopLn. |
|
1226 |
||
1227 |
"/ draw selection frames |
|
1228 |
sel notNil ifTrue:[ |
|
1229 |
sel do:[:y0| self redrawSelFrameAtX:x y:y0 toX:maxX] |
|
1230 |
]. |
|
1231 |
||
1232 |
self clippingRectangle:savClip. |
|
444 | 1233 |
! ! |
1234 |
||
494 | 1235 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 1236 |
|
494 | 1237 |
detectNode:aOneArgBlock |
1238 |
"evaluate the argument, aBlock for each node in the list until |
|
1239 |
the block returns true; in this case return the node which caused |
|
1240 |
the true evaluation. If none node is detected, nil is returned. |
|
1241 |
" |
|
1242 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 1243 |
! |
1244 |
||
1245 |
selectedNodesDo:aOneArgBlock |
|
1246 |
"evaluate the block on each node selected |
|
1247 |
" |
|
1248 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 1249 |
! ! |
1250 |
||
569 | 1251 |
!SelectionInTreeView methodsFor:'event handling'! |
1252 |
||
639 | 1253 |
buttonMotion:buttonMask x:x y:y |
1254 |
"mouse-move while button was pressed - handle selection changes" |
|
1255 |
||
1256 |
discardMotionEvents ifFalse:[ |
|
1257 |
super buttonMotion:buttonMask x:x y:y |
|
1258 |
] |
|
1259 |
||
1260 |
||
1261 |
! |
|
1262 |
||
569 | 1263 |
buttonMultiPress:button x:x y:y |
1264 |
||
1265 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
1266 |
^ super buttonMultiPress:button x:x y:y |
|
1267 |
]. |
|
1268 |
"/ discard doubleClick on indicator |
|
1269 |
! |
|
1270 |
||
1271 |
buttonPress:button x:x y:y |
|
1171 | 1272 |
"handle button press event |
1273 |
" |
|
1268 | 1274 |
|node menu| |
1171 | 1275 |
|
1276 |
((button == 2) or:[button == #menu]) ifTrue:[ |
|
1277 |
( (node := self selectedNode) notNil |
|
1278 |
and:[(menu := node middleButtonMenu) notNil] |
|
1279 |
) ifTrue:[ |
|
1188 | 1280 |
menu isCollection ifTrue:[ |
1281 |
|appl| |
|
1282 |
||
1283 |
menu := Menu new fromLiteralArrayEncoding:menu. |
|
1284 |
||
1285 |
(appl := self application) notNil ifTrue:[ |
|
1286 |
menu findGuiResourcesIn:appl |
|
1287 |
]. |
|
2056
b34a774d3a2b
findGuiResources... now sets the receiver, if not yet set
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
1288 |
"/ menu receiver:appl. -- now done in findGuiResources ... |
1188 | 1289 |
]. |
1171 | 1290 |
menu startUp |
1291 |
] ifFalse:[ |
|
1292 |
super buttonPress:button x:x y:y |
|
1293 |
] |
|
1294 |
] ifFalse:[ |
|
1295 |
self handleSelectButtonAtX:x y:y. |
|
1296 |
||
1297 |
( editorWidget isNil |
|
1298 |
and:[(node := self selectedNode) notNil |
|
1299 |
and:[node canEdit |
|
1300 |
and:[x >= (self xOfValueNode:node)]]] |
|
1301 |
) ifTrue:[ |
|
1302 |
self openEditor |
|
1303 |
] |
|
1304 |
] |
|
1305 |
! |
|
1306 |
||
1307 |
buttonRelease:button x:x y:y |
|
1308 |
"stop any autoscroll" |
|
1309 |
||
1310 |
discardMotionEvents ifTrue:[ |
|
1311 |
clickPosition := nil. |
|
1312 |
discardMotionEvents := false. |
|
1313 |
]. |
|
1314 |
super buttonRelease:button x:x y:y |
|
1315 |
||
1316 |
! |
|
1317 |
||
1318 |
doubleClicked |
|
1319 |
"handle a double click; collapse or expand selected entry |
|
1320 |
in case of having children |
|
1321 |
" |
|
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1322 |
|node | |
1171 | 1323 |
|
1324 |
(node := self selectedNode) notNil ifTrue:[ |
|
1202
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1325 |
(validateDoubleClickBlock isNil |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1326 |
or:[(validateDoubleClickBlock value:node) ~~ false]) ifTrue:[ |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1327 |
(validateExpandabilityBlock isNil |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1328 |
or:[(validateExpandabilityBlock value:node) ~~ false]) ifTrue:[ |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1329 |
self selectedNodeExpand:(node isExpandable). |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1330 |
]. |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1331 |
node hasChildren ifFalse:[ |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1332 |
super doubleClicked |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1333 |
] |
1171 | 1334 |
] |
1335 |
] |
|
1336 |
||
1337 |
! |
|
1338 |
||
1339 |
handleSelectButtonAtX:x y:y |
|
1340 |
"handle a select button click |
|
569 | 1341 |
" |
1268 | 1342 |
|node lineNr sensor isExpd| |
569 | 1343 |
|
1171 | 1344 |
lineNr := self indicatiorLineForButton:#select atX:x y:y. |
569 | 1345 |
|
1346 |
lineNr == 0 ifTrue:[ |
|
1171 | 1347 |
^ super buttonPress:#select x:x y:y |
569 | 1348 |
]. |
1349 |
node := listOfNodes at:lineNr. |
|
1350 |
||
639 | 1351 |
discardMotionEvents := true. |
569 | 1352 |
dragIsActive := false. |
1353 |
clickPosition := nil. |
|
1354 |
||
639 | 1355 |
self hasSelection ifTrue:[ |
1356 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
1357 |
self selection:lineNr |
|
1358 |
] ifFalse:[ |
|
1359 |
self selection:nil |
|
569 | 1360 |
] |
1361 |
]. |
|
855 | 1362 |
|
1363 |
isExpd := node isExpandable. |
|
835 | 1364 |
|
855 | 1365 |
( supportsExpandAll |
1366 |
and:[(sensor := self sensor) notNil |
|
1367 |
and:[(sensor ctrlDown or:[sensor shiftDown])]] |
|
1368 |
) ifTrue:[ |
|
1369 |
isExpd ifTrue:[model doExpandAll:node] |
|
1370 |
ifFalse:[model doCollapseAll:node] |
|
835 | 1371 |
] ifFalse:[ |
855 | 1372 |
isExpd ifTrue:[model doExpand:node] |
1373 |
ifFalse:[model doCollapse:node]. |
|
835 | 1374 |
]. |
848 | 1375 |
|
639 | 1376 |
! |
1377 |
||
569 | 1378 |
indicatiorLineForButton:aButton atX:x y:y |
1379 |
"returns linenumber assigned to indicator at x/y or 0 |
|
1380 |
" |
|
1268 | 1381 |
|nr x0 node| |
569 | 1382 |
|
1383 |
( enabled |
|
1384 |
and:[showDirectoryIndicator |
|
1385 |
and:[aButton == 1 or:[aButton == #select]]] |
|
1386 |
) ifTrue:[ |
|
2014 | 1387 |
nr := self lineAtY:y. "/ self visibleLineToListLine:(self visibleLineOfY:y). |
569 | 1388 |
|
835 | 1389 |
nr notNil ifTrue:[ |
1390 |
node := listOfNodes at:nr. |
|
1391 |
node hasChildren ifTrue:[ |
|
1392 |
x0 := self xOfFigureLevel:(node level - 1). |
|
569 | 1393 |
|
835 | 1394 |
(x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[ |
1395 |
^ nr |
|
569 | 1396 |
] |
1397 |
] |
|
1398 |
] |
|
1399 |
]. |
|
1400 |
^ 0 |
|
756 | 1401 |
! |
1402 |
||
835 | 1403 |
isCtrlMetaAltOrShiftPressed |
1404 |
"returns true if CTRL, META, ALT or SHIFT is pressed |
|
1405 |
" |
|
1406 |
|sensor| |
|
1407 |
||
1408 |
(sensor := self sensor) notNil ifTrue:[ |
|
1409 |
^ ( sensor ctrlDown |
|
1410 |
or:[sensor altDown |
|
1411 |
or:[sensor shiftDown |
|
1412 |
or:[sensor metaDown]]] |
|
1413 |
) |
|
1414 |
]. |
|
1415 |
^ false |
|
1416 |
! |
|
1417 |
||
756 | 1418 |
key:key select:index x:x y:y |
1419 |
"select an entry by a keyboard action. This is treated like a doubleClick |
|
1420 |
on that entry. |
|
1421 |
Add on: In case that the entry is not selectable, scroll to the entry |
|
1422 |
" |
|
1423 |
(enabled and:[keyActionStyle notNil]) ifFalse:[ |
|
1424 |
^ self |
|
1425 |
]. |
|
1426 |
||
1427 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
1887
b47b3cb2515b
does not inherit #key:select:x:y:
Claus Gittinger <cg@exept.de>
parents:
1822
diff
changeset
|
1428 |
^ super keyPress:key x:x y:y |
b47b3cb2515b
does not inherit #key:select:x:y:
Claus Gittinger <cg@exept.de>
parents:
1822
diff
changeset
|
1429 |
"/ ^ super key:key select:index x:x y:y |
756 | 1430 |
]. |
1431 |
||
1432 |
keyActionStyle == #pass ifTrue:[ |
|
1433 |
^ self |
|
1434 |
]. |
|
1435 |
||
1436 |
self gotoLine:index |
|
785 | 1437 |
! |
1438 |
||
811 | 1439 |
keyPress:key x:x y:y |
1440 |
"handle keyboard input" |
|
1441 |
||
1442 |
<resource: #keyboard ( #CursorLeft #CursorRight ) > |
|
1443 |
||
1444 |
|idx node inc end| |
|
1445 |
||
1446 |
enabled ifFalse:[ |
|
1447 |
^ self |
|
1448 |
]. |
|
1449 |
||
1450 |
(key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
|
1451 |
(idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
|
1452 |
||
1453 |
(key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
|
1454 |
ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
|
1455 |
||
1456 |
[(idx := idx + inc) ~~ end] whileTrue:[ |
|
1457 |
node := listOfNodes at:idx. |
|
825 | 1458 |
node hasChildren ifTrue:[ |
811 | 1459 |
^ self key:key select:idx x:x y:y |
1460 |
] |
|
1461 |
]. |
|
1462 |
^ self |
|
1463 |
]. |
|
1464 |
^ super keyPress:key x:x y:y |
|
1465 |
||
1466 |
||
1467 |
||
1468 |
||
569 | 1469 |
! ! |
1470 |
||
1328 | 1471 |
!SelectionInTreeView methodsFor:'initialize / release'! |
444 | 1472 |
|
685 | 1473 |
create |
1474 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1475 |
lineMask := lineMask onDevice:device. |
685 | 1476 |
|
846 | 1477 |
lineColor := lineColor isNil ifTrue:[fgColor] |
1478 |
ifFalse:[lineColor onDevice:device]. |
|
1175 | 1479 |
|
1480 |
editValueFgColor := editValueFgColor onDevice:device. |
|
685 | 1481 |
! |
1482 |
||
514 | 1483 |
destroy |
1484 |
"remove dependencies |
|
1485 |
" |
|
811 | 1486 |
rootHolder removeDependent:self. |
1487 |
selectionHolder removeDependent:self. |
|
1488 |
||
1489 |
model notNil ifTrue:[ |
|
1490 |
model stopRunningTasks |
|
514 | 1491 |
]. |
1492 |
super destroy. |
|
1493 |
||
1494 |
! |
|
1495 |
||
785 | 1496 |
fetchDefaultImages |
1497 |
"returns a directory with default keys and images; could be |
|
1498 |
redefined by subclass. |
|
1499 |
" |
|
1171 | 1500 |
^ itemClass notNil ifTrue:[itemClass keysAndIcons] |
1501 |
ifFalse:[nil] |
|
785 | 1502 |
! |
1503 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1504 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1505 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1506 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1507 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1508 |
super fetchDeviceResources. |
478 | 1509 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1510 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1511 |
|
478 | 1512 |
fetchImageResources |
1513 |
"initialize heavily used device resources - to avoid rendering |
|
1514 |
images again and again later; returns maximum extent of the images used. |
|
1515 |
Could be redefined by subclass |
|
471 | 1516 |
" |
785 | 1517 |
|img x y keysAndIcons| |
494 | 1518 |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1519 |
x := y := 0. |
494 | 1520 |
imageOpened isNil ifTrue:[ |
846 | 1521 |
imageOpened := self imageOnDevice:(self class imageOpened) |
494 | 1522 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1523 |
imageOpened notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1524 |
x := x max:(imageOpened width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1525 |
y := y max:(imageOpened height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1526 |
]. |
444 | 1527 |
|
494 | 1528 |
imageClosed isNil ifTrue:[ |
569 | 1529 |
imageClosed := self imageOnDevice:(self class imageClosed) |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
1530 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1531 |
imageClosed notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1532 |
x := x max:(imageClosed width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1533 |
y := y max:(imageClosed height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1534 |
]. |
494 | 1535 |
|
1536 |
imageItem isNil ifTrue:[ |
|
569 | 1537 |
imageItem := self imageOnDevice:(self class imageItem) |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
1538 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1539 |
imageItem notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1540 |
x := x max:(imageItem width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1541 |
y := y max:(imageItem height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1542 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1543 |
|
785 | 1544 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1545 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1546 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
846 | 1547 |
registeredImages at:aKey put:(self imageOnDevice:anIcon) |
785 | 1548 |
] |
1549 |
] |
|
1550 |
]. |
|
1551 |
registeredImages keysAndValuesDo:[:k :img| |
|
1552 |
x := (img width) max:x. |
|
1553 |
y := (img height) max:y. |
|
1554 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1555 |
|
785 | 1556 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1557 |
x := (img width) max:x. |
|
1558 |
y := (img height) max:y. |
|
1559 |
]. |
|
1560 |
^ x @ y |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1561 |
|
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1562 |
"Modified: / 12.8.1998 / 12:45:53 / cg" |
444 | 1563 |
! |
1564 |
||
480 | 1565 |
getFontParameters |
546 | 1566 |
"save old computed height derived from images |
1567 |
" |
|
1568 |
|lineHeight| |
|
1569 |
||
1570 |
lineHeight := fontHeight ? 0. |
|
480 | 1571 |
super getFontParameters. |
569 | 1572 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1573 |
|
546 | 1574 |
lineHeight > fontHeight ifTrue:[ |
1575 |
fontHeight := lineHeight |
|
1576 |
]. |
|
685 | 1577 |
fontHeight odd ifTrue:[ |
1578 |
fontHeight := fontHeight + 1 |
|
1579 |
] |
|
480 | 1580 |
! |
1581 |
||
900 | 1582 |
initStyle |
1583 |
"setup viewStyle specifics" |
|
1584 |
||
1585 |
super initStyle. |
|
1171 | 1586 |
highlightMode := DefaultHilightMode ? #label. |
900 | 1587 |
|
1588 |
! |
|
1589 |
||
444 | 1590 |
initialize |
471 | 1591 |
"setup instance attributes |
1592 |
" |
|
444 | 1593 |
super initialize. |
1171 | 1594 |
|
1595 |
itemClass isNil ifTrue:[ |
|
1596 |
itemClass := TreeItem |
|
1597 |
]. |
|
1598 |
||
835 | 1599 |
supportsExpandAll := true. |
569 | 1600 |
self bitGravity:#NorthWest. |
773 | 1601 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1602 |
showDirectoryIndicator := discardMotionEvents := showLinesForRoot := false. |
1275 | 1603 |
leftMargin := 2. |
1604 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
|
773 | 1605 |
registeredImages := IdentityDictionary new. |
855 | 1606 |
drawVLinesFromLevel := 1. |
659 | 1607 |
textInset := 4. |
494 | 1608 |
imageInset := 0. "/ set during indication enabled |
1609 |
imageWidth := 8. "/ default: will change during startup |
|
848 | 1610 |
|
1611 |
buildInArray := Array new:50. "/ used for temporary calculation |
|
1612 |
"/ suppress garbage collection |
|
1613 |
||
514 | 1614 |
self model:nil. "/ creates a default model. |
1171 | 1615 |
highlightMode := #label. |
1175 | 1616 |
editValueFgColor := Color blue. |
478 | 1617 |
! |
1618 |
||
569 | 1619 |
realize |
1620 |
super realize. |
|
1621 |
self refetchDeviceResources. |
|
1622 |
! |
|
1623 |
||
811 | 1624 |
recomputeDirectoryIndicator |
1625 |
"setup attributes used by directory indicator |
|
1626 |
" |
|
1627 |
|x w| |
|
1628 |
||
1629 |
imageInset := 0. |
|
1630 |
||
1631 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1632 |
^ self |
|
1633 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1634 |
|
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1635 |
x := 0. |
811 | 1636 |
openIndicator isNil ifTrue:[ |
1637 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1638 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1639 |
openIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1640 |
x := openIndicator width |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1641 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1642 |
|
811 | 1643 |
closeIndicator isNil ifTrue:[ |
1644 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1645 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1646 |
closeIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1647 |
x := x max:(closeIndicator width) |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1648 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1649 |
|
811 | 1650 |
x := x // 2. |
1651 |
w := imageWidth // 2. |
|
1652 |
||
1653 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1654 |
imageInset := x - w. |
|
1655 |
]. |
|
1656 |
||
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1657 |
"Modified: / 13.8.1998 / 12:02:04 / cg" |
811 | 1658 |
! |
1659 |
||
478 | 1660 |
refetchDeviceResources |
1661 |
"reinitialize heavily used device resources - to avoid rendering |
|
1662 |
images again and again later |
|
1663 |
" |
|
551 | 1664 |
|extent| |
478 | 1665 |
|
569 | 1666 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1667 |
computeResources := false. |
1668 |
extent := self fetchImageResources. |
|
494 | 1669 |
|
546 | 1670 |
extent y >= fontHeight ifTrue:[ |
1671 |
fontHeight := 1 + extent y. |
|
494 | 1672 |
]. |
685 | 1673 |
fontHeight odd ifTrue:[ |
1674 |
fontHeight := fontHeight + 1 |
|
1675 |
]. |
|
846 | 1676 |
"/ round and not odd: because of line drawing |
685 | 1677 |
|
846 | 1678 |
imageWidth := (extent x) // 2. |
1679 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1]. |
|
1680 |
imageWidth := imageWidth * 2. |
|
1681 |
||
546 | 1682 |
self recomputeDirectoryIndicator. |
569 | 1683 |
self computeNumberOfLinesShown. |
546 | 1684 |
] |
444 | 1685 |
! ! |
1686 |
||
483 | 1687 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1688 |
|
1689 |
getListFromModel |
|
1690 |
"if I have a model, get my list from it using the listMessage. |
|
1691 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1692 |
" |
|
483 | 1693 |
super list:(self listFromModel) keepSelection:true |
1694 |
! |
|
444 | 1695 |
|
483 | 1696 |
listFromModel |
1697 |
"get list from model and return the new list. |
|
1698 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1699 |
" |
|
846 | 1700 |
|msg| |
838 | 1701 |
|
846 | 1702 |
widthOfWidestLine := nil. |
847 | 1703 |
list := listOfNodes := (msg := listMsg ? aspectMsg) notNil ifTrue:[model perform:msg] ifFalse:[#()]. |
1704 |
self refetchDeviceResources. |
|
846 | 1705 |
^ listOfNodes |
494 | 1706 |
! |
1707 |
||
1708 |
model:aModel |
|
514 | 1709 |
"check whether model is nil; than a default model is created |
1710 |
" |
|
855 | 1711 |
|model root| |
514 | 1712 |
|
811 | 1713 |
model notNil ifTrue:[ |
1714 |
model stopRunningTasks |
|
1715 |
]. |
|
1716 |
||
1171 | 1717 |
model := aModel ? (self class defaultModelClass new). |
1718 |
self itemClass:(model class defaultItemClass). |
|
855 | 1719 |
root := model root. |
1720 |
||
514 | 1721 |
model showRoot:showRoot. |
855 | 1722 |
|
1723 |
root notNil ifTrue:[ |
|
1724 |
root expand |
|
1725 |
]. |
|
514 | 1726 |
super model:model. |
855 | 1727 |
self getListFromModel |
811 | 1728 |
|
514 | 1729 |
! |
1730 |
||
1731 |
rootFromModel |
|
1732 |
"update hierarchical list from root model; 'rootHolder' |
|
1733 |
" |
|
1734 |
|root| |
|
1735 |
||
585 | 1736 |
root := rootHolder root. |
514 | 1737 |
|
1738 |
self root == root ifFalse:[ |
|
1739 |
self selection:nil. |
|
1740 |
self root:root. |
|
585 | 1741 |
]. |
514 | 1742 |
! |
1743 |
||
1744 |
selectionFromModel |
|
1745 |
"set the selection derived from the selectionHolder |
|
1746 |
" |
|
855 | 1747 |
|coll value size idx| |
514 | 1748 |
|
1214 | 1749 |
(value := selectionHolder value) isNil ifFalse:[ |
1750 |
(multipleSelectOk and:[value isCollection]) ifFalse:[ |
|
1751 |
^ self selectNode:value |
|
860 | 1752 |
]. |
1214 | 1753 |
|
1754 |
(size := value size) ~~ 0 ifTrue:[ |
|
1755 |
size == 1 ifTrue:[ |
|
1756 |
^ self selectNode:(value at:1) |
|
1757 |
]. |
|
1758 |
||
1759 |
model doMakeVisible:value. |
|
1760 |
||
1761 |
coll := OrderedCollection new:size. |
|
1762 |
||
1763 |
value do:[:el| |
|
1764 |
idx := el isNumber ifTrue:[el] ifFalse:[self indexOfNode:el]. |
|
1765 |
||
1766 |
idx ~~ 0 ifTrue:[ |
|
1767 |
coll add:idx |
|
1768 |
]. |
|
1769 |
]. |
|
1770 |
||
1771 |
coll isEmpty ifTrue:[ |
|
1772 |
coll := nil |
|
1773 |
]. |
|
1774 |
]. |
|
848 | 1775 |
]. |
1776 |
self selection:coll |
|
514 | 1777 |
! |
1778 |
||
1779 |
selectionToModel |
|
1780 |
"write selection to selection holder |
|
1781 |
" |
|
1782 |
|newSel oldSel| |
|
1783 |
||
1784 |
oldSel := selectionHolder value. |
|
1785 |
||
1786 |
multipleSelectOk ifFalse:[ |
|
1787 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1788 |
selectionHolder value:newSel |
|
1789 |
] |
|
1790 |
] ifTrue:[ |
|
1791 |
selection size == 0 ifTrue:[ |
|
1792 |
oldSel notNil ifTrue:[ |
|
1793 |
selectionHolder value:nil |
|
1794 |
] |
|
1795 |
] ifFalse:[ |
|
1796 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1797 |
||
1798 |
newSel size ~~ oldSel size ifTrue:[ |
|
1799 |
selectionHolder value:newSel. |
|
1800 |
] ifFalse:[ |
|
1801 |
newSel do:[:aNode| |
|
785 | 1802 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1803 |
^ selectionHolder value:newSel |
1804 |
] |
|
1805 |
] |
|
1806 |
] |
|
1807 |
] |
|
1808 |
] |
|
444 | 1809 |
! ! |
1810 |
||
490 | 1811 |
!SelectionInTreeView methodsFor:'private'! |
1812 |
||
1171 | 1813 |
closeEditor |
1814 |
"close the editor |
|
1815 |
" |
|
1816 |
editorWidget notNil ifTrue:[ |
|
1817 |
editorWidget destroy. |
|
1818 |
editorIndex := 0. |
|
1819 |
editorWidget := nil. |
|
1820 |
]. |
|
1821 |
||
1822 |
! |
|
1823 |
||
490 | 1824 |
list:aList keepSelection:keepSelection |
585 | 1825 |
"setup new list; keep selection dependent on the boolean state |
1826 |
keepSelection |
|
1827 |
" |
|
1268 | 1828 |
|list| |
490 | 1829 |
|
846 | 1830 |
list := (aList size == 0) ifTrue:[#()] ifFalse:[aList]. |
1831 |
super list:list keepSelection:keepSelection. |
|
1832 |
self refetchDeviceResources. |
|
490 | 1833 |
|
1171 | 1834 |
! |
1835 |
||
1836 |
openEditor |
|
1837 |
"open an editor on selection |
|
1838 |
" |
|
1175 | 1839 |
|node x0 x1 y0| |
1171 | 1840 |
|
1841 |
editorWidget notNil ifTrue:[ |
|
1842 |
^ self |
|
1843 |
]. |
|
1844 |
editorIndex := self selectedIndex. |
|
1845 |
||
1846 |
( (node := listOfNodes at:editorIndex ifAbsent:nil) isNil |
|
1847 |
or:[(y0 := self listLineToVisibleLine:editorIndex) isNil |
|
1848 |
or:[(editorWidget := node editor) isNil]] |
|
1849 |
) ifTrue:[ |
|
1850 |
^ self |
|
1851 |
]. |
|
1175 | 1852 |
editorWidget withAllSubViewsDo:[:v| v font:font ]. |
1853 |
||
1171 | 1854 |
y0 := self yOfVisibleLine:y0. |
1855 |
x0 := self xOfValueNode:node. |
|
1856 |
x1 := (editorWidget preferredExtent x) max:50. |
|
1857 |
x1 := (x0 + x1) min:(self width - 5). |
|
1858 |
||
1859 |
editorWidget geometryLayout:(Rectangle left:x0 right:x1 top:y0 bottom:y0 + fontHeight). |
|
1860 |
||
1861 |
self addComponent:editorWidget. |
|
1862 |
editorWidget realize. |
|
1863 |
self paint:bgColor. |
|
1864 |
||
1865 |
self fillRectangleX:(x0 - SelectionInset) |
|
1866 |
y:y0 |
|
1867 |
width:SelectionInset + SelectionInset + (x1 - x0) |
|
1868 |
height:fontHeight. |
|
1869 |
||
1870 |
||
1871 |
||
1872 |
||
1873 |
||
811 | 1874 |
! ! |
1875 |
||
1876 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1877 |
|
811 | 1878 |
collectionOfDragObjects |
1879 |
"returns collection of dragable objects assigned to selection |
|
1880 |
Here, by default, a collection of text-dragObjects is generated; |
|
1881 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1882 |
to convert as appropriate." |
|
1883 |
||
1884 |
|collection converted selection dLbl dObj node| |
|
1885 |
||
1886 |
selection := self selectionAsCollection. |
|
1887 |
||
1888 |
collection := selection collect:[:nr| |
|
1889 |
node := listOfNodes at:nr. |
|
1890 |
dObj := self dragObjectForNode:node. |
|
1891 |
dObj theObject:(node contents). |
|
846 | 1892 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
811 | 1893 |
dObj displayObject:dLbl. |
1894 |
dObj |
|
1895 |
]. |
|
1896 |
||
1897 |
dragObjectConverter notNil ifTrue:[ |
|
1898 |
converted := OrderedCollection new. |
|
1899 |
collection keysAndValuesDo:[:nr :obj | |
|
1900 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
846 | 1901 |
node := listOfNodes at:nr. |
1902 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
|
811 | 1903 |
converted displayObject:dLbl. |
1904 |
converted add:dObj |
|
1905 |
] |
|
1906 |
]. |
|
1907 |
collection := converted |
|
1908 |
]. |
|
1909 |
^ collection. |
|
1910 |
||
1911 |
||
569 | 1912 |
|
1913 |
! |
|
1914 |
||
811 | 1915 |
dragObjectForNode:aNode |
1916 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1917 |
" |
811 | 1918 |
^ DropObject new:aNode. |
546 | 1919 |
|
811 | 1920 |
|
1921 |
! |
|
546 | 1922 |
|
811 | 1923 |
startDragX:x y:y |
1924 |
"start drag |
|
1925 |
" |
|
1926 |
dragIsActive := true. |
|
546 | 1927 |
|
811 | 1928 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1929 |
from:self |
|
1930 |
atEnd:endDragAction |
|
546 | 1931 |
|
1932 |
||
490 | 1933 |
! ! |
1934 |
||
468 | 1935 |
!SelectionInTreeView methodsFor:'private queries'! |
1936 |
||
1937 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1938 |
"return the length (in characters) of the longest line in a line-range |
|
1939 |
" |
|
846 | 1940 |
^ self widthOfContents // fontWidth + 1 |
468 | 1941 |
! |
1942 |
||
848 | 1943 |
smallestLevelOfNodesBetween:start and:stop |
1944 |
"returns the smallest level of the nodes in a line range |
|
1945 |
" |
|
1946 |
|prevNode currParent nextParent |
|
1947 |
||
1948 |
lvl "{ Class:SmallInteger }" |
|
1949 |
min "{ Class:SmallInteger }" |
|
1950 |
end "{ Class:SmallInteger }" |
|
1951 |
beg "{ Class:SmallInteger }" |
|
1952 |
| |
|
1953 |
||
1954 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
|
1955 |
^ 0 |
|
1956 |
]. |
|
1957 |
||
1958 |
prevNode := listOfNodes at:start. |
|
1959 |
currParent := prevNode parent. |
|
1960 |
||
1961 |
currParent isNil ifTrue:[ |
|
1962 |
^ 1 |
|
1963 |
]. |
|
1964 |
||
1965 |
(min := prevNode level) == 2 ifTrue:[ |
|
1966 |
^ min |
|
1967 |
]. |
|
1968 |
beg := start + 1. |
|
1969 |
||
1970 |
listOfNodes from:beg to:end do:[:currNode| |
|
1971 |
(nextParent := currNode parent) == currParent ifFalse:[ |
|
1972 |
(currParent := nextParent) == prevNode ifFalse:[ |
|
1973 |
(lvl := currNode level) == 2 ifTrue:[ |
|
1974 |
^ 2 |
|
1975 |
]. |
|
1976 |
min := min min:lvl |
|
1977 |
] |
|
1978 |
]. |
|
1979 |
prevNode := currNode |
|
1980 |
]. |
|
1981 |
^ min |
|
1982 |
||
1983 |
||
1984 |
||
1985 |
||
1986 |
! |
|
1987 |
||
468 | 1988 |
widthOfContents |
1989 |
"return the width of the contents in pixels |
|
1990 |
- used for scrollbar interface" |
|
1991 |
||
846 | 1992 |
listOfNodes isNil ifTrue:[^ 0]. |
468 | 1993 |
|
1994 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
846 | 1995 |
widthOfWidestLine := self widthOfLongestLine |
468 | 1996 |
]. |
1997 |
^ widthOfWidestLine + (leftMargin * 2) |
|
1998 |
||
1999 |
! |
|
2000 |
||
846 | 2001 |
widthOfLongestLine |
2002 |
"return the width of the longest line in pixels |
|
468 | 2003 |
" |
848 | 2004 |
|parent pItem p |
846 | 2005 |
startX "{ Class: SmallInteger }" |
2006 |
deltaX "{ Class: SmallInteger }" |
|
838 | 2007 |
level "{ Class: SmallInteger }" |
2008 |
width "{ Class: SmallInteger }" |
|
2009 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 2010 |
|
848 | 2011 |
buildInArray atAllPut:0. |
846 | 2012 |
parent := nil. |
2013 |
maxSz := 1. |
|
838 | 2014 |
level := 1. |
846 | 2015 |
|
2016 |
listOfNodes do:[:anItem| |
|
848 | 2017 |
(p := anItem parent) ~~ parent ifTrue:[ |
2018 |
buildInArray at:level put:maxSz. |
|
846 | 2019 |
|
848 | 2020 |
(parent := p) == pItem ifTrue:[level := level + 1] |
2021 |
ifFalse:[level := anItem level]. |
|
2022 |
||
2023 |
maxSz := buildInArray at:level. |
|
846 | 2024 |
]. |
2025 |
pItem := anItem. |
|
2026 |
maxSz := maxSz max:(anItem name size). |
|
2027 |
]. |
|
848 | 2028 |
buildInArray at:level put:maxSz. |
468 | 2029 |
|
846 | 2030 |
startX := self xOfStringLevel:1. |
2031 |
deltaX := imageInset + imageWidth. |
|
2032 |
width := '1' widthOn:self. |
|
2033 |
maxSz := 0. |
|
468 | 2034 |
|
848 | 2035 |
buildInArray do:[:el| |
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2036 |
el == 0 ifTrue:[ ^ maxSz + viewOrigin x ]. |
846 | 2037 |
maxSz := maxSz max:(el * width + startX). |
2038 |
startX := startX + deltaX. |
|
468 | 2039 |
]. |
846 | 2040 |
! ! |
2041 |
||
2042 |
!SelectionInTreeView methodsFor:'private redefinitions'! |
|
2043 |
||
2044 |
expandTabs |
|
2045 |
"nothing to do |
|
2046 |
" |
|
838 | 2047 |
|
2048 |
||
468 | 2049 |
! |
2050 |
||
846 | 2051 |
list:aCollection expandTabs:expand scanForNonStrings:scan |
2052 |
||
2053 |
includesNonStrings := false. |
|
2054 |
self list:aCollection expandTabs:false scanForNonStrings:false includesNonStrings:false |
|
2055 |
! |
|
2056 |
||
468 | 2057 |
withoutRedrawAt:anIndex put:aString |
1813 | 2058 |
"change a line without redisplay and WITHOUT any sizeChange notifications. |
2059 |
Somewhat dangerous, since scrollBars will not be informed about contents-changes. |
|
2060 |
Use only if multiple lines are to be changed, and a sizeChanged is invoked by some other |
|
2061 |
means at the end." |
|
468 | 2062 |
|
2063 |
|width| |
|
2064 |
||
2065 |
width := widthOfWidestLine. |
|
2066 |
widthOfWidestLine := nil. |
|
2067 |
super withoutRedrawAt:anIndex put:aString. |
|
846 | 2068 |
widthOfWidestLine := width. |
468 | 2069 |
|
846 | 2070 |
(widthOfWidestLine notNil and:[aString size ~~ 0]) ifTrue:[ |
2071 |
width := self xOfStringNode:(listOfNodes at:anIndex) |
|
2072 |
+ (aString widthOn:self) |
|
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2073 |
+ viewOrigin x. |
846 | 2074 |
|
838 | 2075 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 2076 |
]. |
2077 |
! ! |
|
2078 |
||
483 | 2079 |
!SelectionInTreeView methodsFor:'queries'! |
2080 |
||
2081 |
figureFor:aNode |
|
1278 | 2082 |
"return a (bitmap) figure for a node" |
2083 |
||
785 | 2084 |
|icon img| |
2085 |
||
1278 | 2086 |
"/ the item may provide an icon |
2087 |
"/ (it knows for itself if its open or closed) |
|
2088 |
||
785 | 2089 |
(icon := aNode icon) notNil ifTrue:[ |
2090 |
img := registeredImages at:icon ifAbsent:nil. |
|
2091 |
img notNil ifTrue:[ |
|
2092 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2093 |
]. |
785 | 2094 |
icon isImage ifTrue:[ |
846 | 2095 |
img := self imageOnDevice:icon. |
785 | 2096 |
registeredImages at:icon put:img. |
1278 | 2097 |
^ img |
785 | 2098 |
] |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2099 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2100 |
|
1278 | 2101 |
"/ ok, node did not return an icon - use default. |
2102 |
||
846 | 2103 |
aNode hasChildren ifFalse:[ |
1278 | 2104 |
"/ regular |
2105 |
^ imageItem |
|
846 | 2106 |
]. |
1278 | 2107 |
"/ folder |
846 | 2108 |
^ aNode hidden ifTrue:[imageClosed] ifFalse:[imageOpened] |
785 | 2109 |
|
483 | 2110 |
! |
2111 |
||
2112 |
indexOfNode:aNode |
|
2113 |
"returns index of a node |
|
2114 |
" |
|
785 | 2115 |
^ listOfNodes identityIndexOf:aNode |
483 | 2116 |
! |
2117 |
||
494 | 2118 |
xOfFigureLevel:aLevel |
2119 |
"origin x where to draw the icon |
|
2120 |
" |
|
785 | 2121 |
|l "{ Class:SmallInteger }"| |
494 | 2122 |
|
785 | 2123 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 2124 |
|
659 | 2125 |
showDirectoryIndicator ifFalse:[ |
2126 |
l := l - 1 |
|
2127 |
] ifTrue:[ |
|
2128 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
2129 |
l := l - 1 |
|
2130 |
] |
|
2131 |
]. |
|
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2132 |
^ (l * (imageInset + imageWidth)) + imageInset - viewOrigin x + leftMargin |
494 | 2133 |
! |
2134 |
||
483 | 2135 |
xOfFigureNode:aNode |
2136 |
"origin x where to draw the icon |
|
2137 |
" |
|
494 | 2138 |
^ self xOfFigureLevel:(aNode level) |
2139 |
! |
|
490 | 2140 |
|
494 | 2141 |
xOfStringLevel:aLevel |
2142 |
"origin x where to draw the text( label ) |
|
2143 |
" |
|
2144 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 2145 |
|
2146 |
! |
|
2147 |
||
2148 |
xOfStringNode:aNode |
|
2149 |
"origin x where to draw the text( label ) |
|
2150 |
" |
|
494 | 2151 |
^ self xOfStringLevel:(aNode level) |
483 | 2152 |
|
1171 | 2153 |
! |
2154 |
||
2155 |
xOfValueNode:aNode |
|
2156 |
"returns the left x position of the start of the value |
|
2157 |
" |
|
2158 |
|p x| |
|
2159 |
||
2160 |
p := aNode parent. |
|
2161 |
||
2162 |
x := p notNil ifTrue:[30 + (p childrenWidthOn:self)] |
|
2163 |
ifFalse:[0]. |
|
2164 |
||
2165 |
^ x + (self xOfStringNode:aNode) |
|
2166 |
||
483 | 2167 |
! ! |
2168 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2169 |
!SelectionInTreeView methodsFor:'scrolling'! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2170 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2171 |
needScrollToMakeLine:aListLineNr |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2172 |
"redefined to scroll whenever line is not in top half" |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2173 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2174 |
(aListLineNr >= firstLineShown) ifTrue:[ |
1162 | 2175 |
(aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[ |
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2176 |
^ false |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2177 |
] |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2178 |
]. |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2179 |
^ true |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2180 |
|
1171 | 2181 |
! |
2182 |
||
2183 |
originChanged:delta |
|
2184 |
"sent after scrolling - have to update origin of editor |
|
2185 |
" |
|
2186 |
super originChanged:delta. |
|
2187 |
||
2188 |
editorWidget notNil ifTrue:[ |
|
2189 |
editorWidget origin:(editorWidget origin - delta) |
|
2190 |
] |
|
2191 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2192 |
! ! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2193 |
|
444 | 2194 |
!SelectionInTreeView methodsFor:'selection'! |
2195 |
||
468 | 2196 |
selectNode:aNode |
2197 |
"change selection to a node |
|
2198 |
" |
|
855 | 2199 |
|index| |
848 | 2200 |
|
860 | 2201 |
(index := aNode) notNil ifTrue:[ |
2202 |
index isNumber ifFalse:[ |
|
2203 |
(index := self indexOfNode:aNode) == 0 ifTrue:[ |
|
2204 |
model doMakeVisible:aNode. |
|
2205 |
index := self indexOfNode:aNode. |
|
2206 |
] |
|
855 | 2207 |
]. |
848 | 2208 |
index == 0 ifTrue:[ |
855 | 2209 |
index := nil |
848 | 2210 |
] |
2211 |
]. |
|
2212 |
self selection:index |
|
468 | 2213 |
|
2214 |
||
2215 |
! |
|
2216 |
||
1972 | 2217 |
selectNodes:aCollectionOfNodes |
2218 |
|selIndexCollection| |
|
2219 |
||
2220 |
selIndexCollection := aCollectionOfNodes collect:[:eachNode | listOfNodes identityIndexOf:eachNode]. |
|
2221 |
selIndexCollection := selIndexCollection reject:[:eachIndex | eachIndex == 0]. |
|
2222 |
self selection:selIndexCollection. |
|
2223 |
||
2224 |
"/ first := true. |
|
2225 |
"/ aCollectionOfNodes do:[:eachNode | |
|
2226 |
"/ first ifTrue:[ |
|
2227 |
"/ self selectNode:eachNode. |
|
2228 |
"/ first := false. |
|
2229 |
"/ ] ifFalse:[ |
|
2230 |
"/ self selectedNodeAdd:eachNode |
|
2231 |
"/ ] |
|
2232 |
"/ ]. |
|
2233 |
"/ |
|
2234 |
! |
|
2235 |
||
456 | 2236 |
selectedIndex |
2237 |
"get single selected index or 0 |
|
2238 |
" |
|
483 | 2239 |
selection size == 1 ifTrue:[^ selection first]. |
2240 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 2241 |
^ 0 |
444 | 2242 |
! |
2243 |
||
2244 |
selectedNode |
|
2245 |
"get the single selected node or nil |
|
2246 |
" |
|
456 | 2247 |
|idx| |
2248 |
||
2249 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
2250 |
^ listOfNodes at:idx |
|
444 | 2251 |
]. |
2252 |
^ nil |
|
514 | 2253 |
! |
2254 |
||
1972 | 2255 |
selectedNodes |
2256 |
"get a collection of selected nodes |
|
2257 |
" |
|
2258 |
|selIndexCollection| |
|
2259 |
||
2260 |
(selIndexCollection := self selection) size == 0 ifTrue:[^ #() ]. |
|
2261 |
^ selIndexCollection collect:[:eachIndex | listOfNodes at:eachIndex]. |
|
2262 |
! |
|
2263 |
||
514 | 2264 |
selectionChangedFrom:oldSelection |
2265 |
"update selectionHolder if not nil |
|
2266 |
" |
|
1171 | 2267 |
self closeEditor. |
514 | 2268 |
|
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2269 |
"/ first change my selectionHolders value ... |
514 | 2270 |
selectionHolder notNil ifTrue:[ |
2271 |
self selectionToModel. |
|
2272 |
]. |
|
2273 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2274 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2275 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2276 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2277 |
|
1171 | 2278 |
! |
2279 |
||
2280 |
setSelection:aSelection |
|
2281 |
"if no selection exists, close the editor |
|
2282 |
" |
|
2283 |
(aSelection isNil or:[aSelection == 0]) ifTrue:[ |
|
2284 |
self closeEditor |
|
2285 |
]. |
|
2286 |
super setSelection:aSelection |
|
2287 |
||
2288 |
||
444 | 2289 |
! ! |
2290 |
||
855 | 2291 |
!SelectionInTreeView methodsFor:'selection actions'! |
507 | 2292 |
|
2293 |
selectedNodeAdd:something |
|
2294 |
"add a node or collection of nodes after selected node |
|
2295 |
" |
|
2296 |
|node| |
|
2297 |
||
2298 |
something notNil ifTrue:[ |
|
2299 |
(node := self selectedNode) notNil ifTrue:[ |
|
2300 |
node parent notNil ifTrue:[ |
|
2301 |
node isCollapsable ifTrue:[ |
|
2302 |
model add:something beforeIndex:1 below:node |
|
2303 |
] ifFalse:[ |
|
2304 |
model add:something after:node |
|
2305 |
] |
|
2306 |
] ifFalse:[ |
|
2307 |
model add:something beforeIndex:1 below:(self root) |
|
2308 |
] |
|
2309 |
] |
|
2310 |
] |
|
2311 |
||
2312 |
! |
|
2313 |
||
2314 |
selectedNodeBecomeChildOfNext |
|
1972 | 2315 |
"make the selected node a child of the next node |
507 | 2316 |
" |
2317 |
|idx node cprt nprt| |
|
2318 |
||
2319 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2320 |
idx := cprt indexOfChild:node. |
|
2321 |
||
2322 |
idx == cprt children size ifFalse:[ |
|
2323 |
nprt := cprt childAt:(idx + 1). |
|
2324 |
||
2325 |
nprt notNil ifTrue:[ |
|
855 | 2326 |
self setSelection:nil. |
2327 |
model remove:node. |
|
507 | 2328 |
model add:node beforeIndex:1 below:nprt. |
2329 |
self selectNode:node. |
|
2330 |
] |
|
2331 |
] |
|
2332 |
] |
|
2333 |
! |
|
2334 |
||
1972 | 2335 |
selectedNodeBecomeChildOfPrevious |
2336 |
"make the selected node a child of the previous node |
|
2337 |
" |
|
2338 |
|idx node cprt nprt| |
|
2339 |
||
2340 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2341 |
idx := cprt indexOfChild:node. |
|
2342 |
||
2343 |
idx == cprt children size ifFalse:[ |
|
2344 |
nprt := cprt childAt:(idx - 1). |
|
2345 |
||
2346 |
nprt notNil ifTrue:[ |
|
2347 |
self setSelection:nil. |
|
2348 |
model remove:node. |
|
2349 |
model add:node below:nprt. |
|
2350 |
self selectNode:node. |
|
2351 |
] |
|
2352 |
] |
|
2353 |
] |
|
2354 |
! |
|
2355 |
||
507 | 2356 |
selectedNodeBecomeSisterOfParent |
2357 |
"become node a sister of its current parent |
|
2358 |
" |
|
2359 |
|node cprt nprt| |
|
2360 |
||
2361 |
( (node := self selectedNode) isNil |
|
2362 |
or:[(cprt := node parent) isNil |
|
2363 |
or:[(nprt := cprt parent) isNil]] |
|
2364 |
) ifFalse:[ |
|
855 | 2365 |
self setSelection:nil. |
2366 |
model remove:node. |
|
507 | 2367 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
855 | 2368 |
self selectNode:node. |
507 | 2369 |
] |
2370 |
||
2371 |
! |
|
2372 |
||
2373 |
selectedNodeChangeSequenceOrder:anOffset |
|
2374 |
"move child 'anOffset' forward or backward in list of children |
|
2375 |
" |
|
2376 |
|idx node size parent| |
|
2377 |
||
2378 |
( (node := self selectedNode) notNil |
|
2379 |
and:[(parent := node parent) notNil |
|
2380 |
and:[(size := parent children size) > 1]] |
|
2381 |
) ifTrue:[ |
|
2382 |
idx := parent indexOfChild:node. |
|
855 | 2383 |
self setSelection:nil. |
2384 |
model remove:node. |
|
507 | 2385 |
|
2386 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
2387 |
idx := size |
|
2388 |
] ifFalse:[ |
|
2389 |
idx > size ifTrue:[idx := 1] |
|
2390 |
]. |
|
2391 |
model add:node beforeIndex:idx below:parent. |
|
2392 |
self selectNode:node. |
|
2393 |
] |
|
2394 |
! |
|
2395 |
||
2396 |
selectedNodeExpand:doExpand |
|
2397 |
"collapse or expand selected node |
|
2398 |
" |
|
855 | 2399 |
|node| |
507 | 2400 |
|
855 | 2401 |
(node := self selectedNode) notNil ifTrue:[ |
2402 |
doExpand ifTrue:[model doExpand:node] |
|
2403 |
ifFalse:[model doCollapse:node] |
|
2404 |
] |
|
507 | 2405 |
! |
2406 |
||
1972 | 2407 |
selectedNodesBecomeChildrenOfNext |
2408 |
"make the selected nodes children of the next node |
|
2409 |
" |
|
2410 |
|indices maxIndex nodes parent newParent| |
|
2411 |
||
2412 |
nodes := self selectedNodes. |
|
2413 |
nodes size == 0 ifTrue:[^ self]. |
|
2414 |
||
2415 |
indices := nodes collect:[:eachNode | listOfNodes identityIndexOf:eachNode]. |
|
2416 |
maxIndex := indices max. |
|
2417 |
||
2418 |
newParent := listOfNodes at:(maxIndex + 1) ifAbsent:nil. |
|
2419 |
newParent isNil ifTrue:[^ self]. |
|
2420 |
||
2421 |
indices sortWith:nodes. |
|
2422 |
||
2423 |
nodes reverseDo:[:eachNodeToMove | |
|
2424 |
model remove:eachNodeToMove. |
|
2425 |
model add:eachNodeToMove beforeIndex:1 below:newParent. |
|
2426 |
]. |
|
2427 |
self selectNodes:nodes. |
|
2428 |
! |
|
2429 |
||
2430 |
selectedNodesBecomeSistersOfParent |
|
2431 |
"move selected nodes up (out of their parent to their grandparent). |
|
2432 |
I.e. nodes become sisters of their current parent |
|
2433 |
" |
|
2434 |
|nodes parent grandParent indices| |
|
2435 |
||
2436 |
nodes := self selectedNodes. |
|
2437 |
nodes size == 0 ifTrue:[^ self]. |
|
2438 |
||
2439 |
"/ common parent ? |
|
2440 |
parent := nodes first parent. |
|
2441 |
(nodes conform:[:eachNode | eachNode parent == parent]) ifFalse:[^ self]. |
|
2442 |
||
2443 |
"/ is there a grandparent ? |
|
2444 |
grandParent := parent parent. |
|
2445 |
grandParent isNil ifTrue:[^ self]. |
|
2446 |
||
2447 |
self setSelection:nil. |
|
2448 |
indices := nodes collect:[:eachNode | listOfNodes identityIndexOf:eachNode]. |
|
2449 |
indices sortWith:nodes. |
|
2450 |
||
2451 |
nodes reverseDo:[:eachNodeToMove | |
|
2452 |
model remove:eachNodeToMove. |
|
2453 |
model add:eachNodeToMove afterIndex:(grandParent indexOfChild:parent) below:grandParent. |
|
2454 |
]. |
|
2455 |
self selectNodes:nodes. |
|
2456 |
! |
|
2457 |
||
507 | 2458 |
selectedNodesRemove |
2459 |
"remove selected nodes |
|
2460 |
" |
|
855 | 2461 |
|selection| |
2462 |
||
2463 |
selection := self selection. |
|
507 | 2464 |
self selection:nil. |
855 | 2465 |
model remove:selection. |
507 | 2466 |
! ! |
2467 |
||
444 | 2468 |
!SelectionInTreeView class methodsFor:'documentation'! |
2469 |
||
2470 |
version |
|
2056
b34a774d3a2b
findGuiResources... now sets the receiver, if not yet set
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
2471 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.96 2001-11-19 15:28:39 cg Exp $' |
444 | 2472 |
! ! |