author | Claus Gittinger <cg@exept.de> |
Thu, 22 Aug 2002 18:53:28 +0200 | |
changeset 2156 | e16dc409ecf2 |
parent 2065 | 845bd5d2523c |
child 2333 | eeff6439157e |
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 |
||
2065
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1450 |
"/ cg: its nicer to expand/collaps on these keys |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1451 |
key == #CursorRight ifTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1452 |
(node := self selectedNode) notNil ifTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1453 |
model doExpand:node. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1454 |
^ self. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1455 |
]. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1456 |
]. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1457 |
key == #CursorLeft ifTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1458 |
(node := self selectedNode) notNil ifTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1459 |
model doCollapse:node. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1460 |
^ self. |
811 | 1461 |
]. |
1462 |
]. |
|
2065
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1463 |
|
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1464 |
"/ search fwd/bwd for a node with children |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1465 |
|
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1466 |
"/ (key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1467 |
"/ (idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1468 |
"/ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1469 |
"/ (key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1470 |
"/ ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1471 |
"/ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1472 |
"/ [(idx := idx + inc) ~~ end] whileTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1473 |
"/ node := listOfNodes at:idx. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1474 |
"/ node hasChildren ifTrue:[ |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1475 |
"/ ^ self key:key select:idx x:x y:y |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1476 |
"/ ] |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1477 |
"/ ]. |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1478 |
"/ ^ self |
845bd5d2523c
crsrLeft/right behavior changed
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
1479 |
"/ ]. |
811 | 1480 |
^ super keyPress:key x:x y:y |
569 | 1481 |
! ! |
1482 |
||
1328 | 1483 |
!SelectionInTreeView methodsFor:'initialize / release'! |
444 | 1484 |
|
685 | 1485 |
create |
1486 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1487 |
lineMask := lineMask onDevice:device. |
685 | 1488 |
|
846 | 1489 |
lineColor := lineColor isNil ifTrue:[fgColor] |
1490 |
ifFalse:[lineColor onDevice:device]. |
|
1175 | 1491 |
|
1492 |
editValueFgColor := editValueFgColor onDevice:device. |
|
685 | 1493 |
! |
1494 |
||
785 | 1495 |
fetchDefaultImages |
1496 |
"returns a directory with default keys and images; could be |
|
1497 |
redefined by subclass. |
|
1498 |
" |
|
1171 | 1499 |
^ itemClass notNil ifTrue:[itemClass keysAndIcons] |
1500 |
ifFalse:[nil] |
|
785 | 1501 |
! |
1502 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1503 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1504 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1505 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1506 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1507 |
super fetchDeviceResources. |
478 | 1508 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1509 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1510 |
|
478 | 1511 |
fetchImageResources |
1512 |
"initialize heavily used device resources - to avoid rendering |
|
1513 |
images again and again later; returns maximum extent of the images used. |
|
1514 |
Could be redefined by subclass |
|
471 | 1515 |
" |
785 | 1516 |
|img x y keysAndIcons| |
494 | 1517 |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1518 |
x := y := 0. |
494 | 1519 |
imageOpened isNil ifTrue:[ |
846 | 1520 |
imageOpened := self imageOnDevice:(self class imageOpened) |
494 | 1521 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1522 |
imageOpened notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1523 |
x := x max:(imageOpened width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1524 |
y := y max:(imageOpened height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1525 |
]. |
444 | 1526 |
|
494 | 1527 |
imageClosed isNil ifTrue:[ |
569 | 1528 |
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
|
1529 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1530 |
imageClosed notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1531 |
x := x max:(imageClosed width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1532 |
y := y max:(imageClosed height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1533 |
]. |
494 | 1534 |
|
1535 |
imageItem isNil ifTrue:[ |
|
569 | 1536 |
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
|
1537 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1538 |
imageItem notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1539 |
x := x max:(imageItem width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1540 |
y := y max:(imageItem height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1541 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1542 |
|
785 | 1543 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1544 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1545 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
846 | 1546 |
registeredImages at:aKey put:(self imageOnDevice:anIcon) |
785 | 1547 |
] |
1548 |
] |
|
1549 |
]. |
|
1550 |
registeredImages keysAndValuesDo:[:k :img| |
|
1551 |
x := (img width) max:x. |
|
1552 |
y := (img height) max:y. |
|
1553 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1554 |
|
785 | 1555 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1556 |
x := (img width) max:x. |
|
1557 |
y := (img height) max:y. |
|
1558 |
]. |
|
1559 |
^ x @ y |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1560 |
|
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1561 |
"Modified: / 12.8.1998 / 12:45:53 / cg" |
444 | 1562 |
! |
1563 |
||
480 | 1564 |
getFontParameters |
546 | 1565 |
"save old computed height derived from images |
1566 |
" |
|
1567 |
|lineHeight| |
|
1568 |
||
1569 |
lineHeight := fontHeight ? 0. |
|
480 | 1570 |
super getFontParameters. |
569 | 1571 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1572 |
|
546 | 1573 |
lineHeight > fontHeight ifTrue:[ |
1574 |
fontHeight := lineHeight |
|
1575 |
]. |
|
685 | 1576 |
fontHeight odd ifTrue:[ |
1577 |
fontHeight := fontHeight + 1 |
|
1578 |
] |
|
480 | 1579 |
! |
1580 |
||
900 | 1581 |
initStyle |
1582 |
"setup viewStyle specifics" |
|
1583 |
||
1584 |
super initStyle. |
|
1171 | 1585 |
highlightMode := DefaultHilightMode ? #label. |
900 | 1586 |
|
1587 |
! |
|
1588 |
||
444 | 1589 |
initialize |
471 | 1590 |
"setup instance attributes |
1591 |
" |
|
444 | 1592 |
super initialize. |
1171 | 1593 |
|
1594 |
itemClass isNil ifTrue:[ |
|
1595 |
itemClass := TreeItem |
|
1596 |
]. |
|
1597 |
||
835 | 1598 |
supportsExpandAll := true. |
569 | 1599 |
self bitGravity:#NorthWest. |
773 | 1600 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1601 |
showDirectoryIndicator := discardMotionEvents := showLinesForRoot := false. |
1275 | 1602 |
leftMargin := 2. |
1603 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
|
773 | 1604 |
registeredImages := IdentityDictionary new. |
855 | 1605 |
drawVLinesFromLevel := 1. |
659 | 1606 |
textInset := 4. |
494 | 1607 |
imageInset := 0. "/ set during indication enabled |
1608 |
imageWidth := 8. "/ default: will change during startup |
|
848 | 1609 |
|
1610 |
buildInArray := Array new:50. "/ used for temporary calculation |
|
1611 |
"/ suppress garbage collection |
|
1612 |
||
514 | 1613 |
self model:nil. "/ creates a default model. |
1171 | 1614 |
highlightMode := #label. |
1175 | 1615 |
editValueFgColor := Color blue. |
478 | 1616 |
! |
1617 |
||
569 | 1618 |
realize |
1619 |
super realize. |
|
1620 |
self refetchDeviceResources. |
|
1621 |
! |
|
1622 |
||
811 | 1623 |
recomputeDirectoryIndicator |
1624 |
"setup attributes used by directory indicator |
|
1625 |
" |
|
1626 |
|x w| |
|
1627 |
||
1628 |
imageInset := 0. |
|
1629 |
||
1630 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1631 |
^ self |
|
1632 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1633 |
|
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1634 |
x := 0. |
811 | 1635 |
openIndicator isNil ifTrue:[ |
1636 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1637 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1638 |
openIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1639 |
x := openIndicator width |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1640 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1641 |
|
811 | 1642 |
closeIndicator isNil ifTrue:[ |
1643 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1644 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1645 |
closeIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1646 |
x := x max:(closeIndicator width) |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1647 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1648 |
|
811 | 1649 |
x := x // 2. |
1650 |
w := imageWidth // 2. |
|
1651 |
||
1652 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1653 |
imageInset := x - w. |
|
1654 |
]. |
|
1655 |
||
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1656 |
"Modified: / 13.8.1998 / 12:02:04 / cg" |
811 | 1657 |
! |
1658 |
||
478 | 1659 |
refetchDeviceResources |
1660 |
"reinitialize heavily used device resources - to avoid rendering |
|
1661 |
images again and again later |
|
1662 |
" |
|
551 | 1663 |
|extent| |
478 | 1664 |
|
569 | 1665 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1666 |
computeResources := false. |
1667 |
extent := self fetchImageResources. |
|
494 | 1668 |
|
546 | 1669 |
extent y >= fontHeight ifTrue:[ |
1670 |
fontHeight := 1 + extent y. |
|
494 | 1671 |
]. |
685 | 1672 |
fontHeight odd ifTrue:[ |
1673 |
fontHeight := fontHeight + 1 |
|
1674 |
]. |
|
846 | 1675 |
"/ round and not odd: because of line drawing |
685 | 1676 |
|
846 | 1677 |
imageWidth := (extent x) // 2. |
1678 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1]. |
|
1679 |
imageWidth := imageWidth * 2. |
|
1680 |
||
546 | 1681 |
self recomputeDirectoryIndicator. |
569 | 1682 |
self computeNumberOfLinesShown. |
546 | 1683 |
] |
2156 | 1684 |
! |
1685 |
||
1686 |
release |
|
1687 |
"remove dependencies |
|
1688 |
" |
|
1689 |
rootHolder removeDependent:self. |
|
1690 |
selectionHolder removeDependent:self. |
|
1691 |
||
1692 |
model notNil ifTrue:[ |
|
1693 |
model stopRunningTasks |
|
1694 |
]. |
|
1695 |
super release. |
|
444 | 1696 |
! ! |
1697 |
||
483 | 1698 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1699 |
|
1700 |
getListFromModel |
|
1701 |
"if I have a model, get my list from it using the listMessage. |
|
1702 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1703 |
" |
|
483 | 1704 |
super list:(self listFromModel) keepSelection:true |
1705 |
! |
|
444 | 1706 |
|
483 | 1707 |
listFromModel |
1708 |
"get list from model and return the new list. |
|
1709 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1710 |
" |
|
846 | 1711 |
|msg| |
838 | 1712 |
|
846 | 1713 |
widthOfWidestLine := nil. |
847 | 1714 |
list := listOfNodes := (msg := listMsg ? aspectMsg) notNil ifTrue:[model perform:msg] ifFalse:[#()]. |
1715 |
self refetchDeviceResources. |
|
846 | 1716 |
^ listOfNodes |
494 | 1717 |
! |
1718 |
||
1719 |
model:aModel |
|
514 | 1720 |
"check whether model is nil; than a default model is created |
1721 |
" |
|
855 | 1722 |
|model root| |
514 | 1723 |
|
811 | 1724 |
model notNil ifTrue:[ |
1725 |
model stopRunningTasks |
|
1726 |
]. |
|
1727 |
||
1171 | 1728 |
model := aModel ? (self class defaultModelClass new). |
1729 |
self itemClass:(model class defaultItemClass). |
|
855 | 1730 |
root := model root. |
1731 |
||
514 | 1732 |
model showRoot:showRoot. |
855 | 1733 |
|
1734 |
root notNil ifTrue:[ |
|
1735 |
root expand |
|
1736 |
]. |
|
514 | 1737 |
super model:model. |
855 | 1738 |
self getListFromModel |
811 | 1739 |
|
514 | 1740 |
! |
1741 |
||
1742 |
rootFromModel |
|
1743 |
"update hierarchical list from root model; 'rootHolder' |
|
1744 |
" |
|
1745 |
|root| |
|
1746 |
||
585 | 1747 |
root := rootHolder root. |
514 | 1748 |
|
1749 |
self root == root ifFalse:[ |
|
1750 |
self selection:nil. |
|
1751 |
self root:root. |
|
585 | 1752 |
]. |
514 | 1753 |
! |
1754 |
||
1755 |
selectionFromModel |
|
1756 |
"set the selection derived from the selectionHolder |
|
1757 |
" |
|
855 | 1758 |
|coll value size idx| |
514 | 1759 |
|
1214 | 1760 |
(value := selectionHolder value) isNil ifFalse:[ |
1761 |
(multipleSelectOk and:[value isCollection]) ifFalse:[ |
|
1762 |
^ self selectNode:value |
|
860 | 1763 |
]. |
1214 | 1764 |
|
1765 |
(size := value size) ~~ 0 ifTrue:[ |
|
1766 |
size == 1 ifTrue:[ |
|
1767 |
^ self selectNode:(value at:1) |
|
1768 |
]. |
|
1769 |
||
1770 |
model doMakeVisible:value. |
|
1771 |
||
1772 |
coll := OrderedCollection new:size. |
|
1773 |
||
1774 |
value do:[:el| |
|
1775 |
idx := el isNumber ifTrue:[el] ifFalse:[self indexOfNode:el]. |
|
1776 |
||
1777 |
idx ~~ 0 ifTrue:[ |
|
1778 |
coll add:idx |
|
1779 |
]. |
|
1780 |
]. |
|
1781 |
||
1782 |
coll isEmpty ifTrue:[ |
|
1783 |
coll := nil |
|
1784 |
]. |
|
1785 |
]. |
|
848 | 1786 |
]. |
1787 |
self selection:coll |
|
514 | 1788 |
! |
1789 |
||
1790 |
selectionToModel |
|
1791 |
"write selection to selection holder |
|
1792 |
" |
|
1793 |
|newSel oldSel| |
|
1794 |
||
1795 |
oldSel := selectionHolder value. |
|
1796 |
||
1797 |
multipleSelectOk ifFalse:[ |
|
1798 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1799 |
selectionHolder value:newSel |
|
1800 |
] |
|
1801 |
] ifTrue:[ |
|
1802 |
selection size == 0 ifTrue:[ |
|
1803 |
oldSel notNil ifTrue:[ |
|
1804 |
selectionHolder value:nil |
|
1805 |
] |
|
1806 |
] ifFalse:[ |
|
1807 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1808 |
||
1809 |
newSel size ~~ oldSel size ifTrue:[ |
|
1810 |
selectionHolder value:newSel. |
|
1811 |
] ifFalse:[ |
|
1812 |
newSel do:[:aNode| |
|
785 | 1813 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1814 |
^ selectionHolder value:newSel |
1815 |
] |
|
1816 |
] |
|
1817 |
] |
|
1818 |
] |
|
1819 |
] |
|
444 | 1820 |
! ! |
1821 |
||
490 | 1822 |
!SelectionInTreeView methodsFor:'private'! |
1823 |
||
1171 | 1824 |
closeEditor |
1825 |
"close the editor |
|
1826 |
" |
|
1827 |
editorWidget notNil ifTrue:[ |
|
1828 |
editorWidget destroy. |
|
1829 |
editorIndex := 0. |
|
1830 |
editorWidget := nil. |
|
1831 |
]. |
|
1832 |
||
1833 |
! |
|
1834 |
||
490 | 1835 |
list:aList keepSelection:keepSelection |
585 | 1836 |
"setup new list; keep selection dependent on the boolean state |
1837 |
keepSelection |
|
1838 |
" |
|
1268 | 1839 |
|list| |
490 | 1840 |
|
846 | 1841 |
list := (aList size == 0) ifTrue:[#()] ifFalse:[aList]. |
1842 |
super list:list keepSelection:keepSelection. |
|
1843 |
self refetchDeviceResources. |
|
490 | 1844 |
|
1171 | 1845 |
! |
1846 |
||
1847 |
openEditor |
|
1848 |
"open an editor on selection |
|
1849 |
" |
|
1175 | 1850 |
|node x0 x1 y0| |
1171 | 1851 |
|
1852 |
editorWidget notNil ifTrue:[ |
|
1853 |
^ self |
|
1854 |
]. |
|
1855 |
editorIndex := self selectedIndex. |
|
1856 |
||
1857 |
( (node := listOfNodes at:editorIndex ifAbsent:nil) isNil |
|
1858 |
or:[(y0 := self listLineToVisibleLine:editorIndex) isNil |
|
1859 |
or:[(editorWidget := node editor) isNil]] |
|
1860 |
) ifTrue:[ |
|
1861 |
^ self |
|
1862 |
]. |
|
1175 | 1863 |
editorWidget withAllSubViewsDo:[:v| v font:font ]. |
1864 |
||
1171 | 1865 |
y0 := self yOfVisibleLine:y0. |
1866 |
x0 := self xOfValueNode:node. |
|
1867 |
x1 := (editorWidget preferredExtent x) max:50. |
|
1868 |
x1 := (x0 + x1) min:(self width - 5). |
|
1869 |
||
1870 |
editorWidget geometryLayout:(Rectangle left:x0 right:x1 top:y0 bottom:y0 + fontHeight). |
|
1871 |
||
1872 |
self addComponent:editorWidget. |
|
1873 |
editorWidget realize. |
|
1874 |
self paint:bgColor. |
|
1875 |
||
1876 |
self fillRectangleX:(x0 - SelectionInset) |
|
1877 |
y:y0 |
|
1878 |
width:SelectionInset + SelectionInset + (x1 - x0) |
|
1879 |
height:fontHeight. |
|
1880 |
||
1881 |
||
1882 |
||
1883 |
||
1884 |
||
811 | 1885 |
! ! |
1886 |
||
1887 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1888 |
|
811 | 1889 |
collectionOfDragObjects |
1890 |
"returns collection of dragable objects assigned to selection |
|
1891 |
Here, by default, a collection of text-dragObjects is generated; |
|
1892 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1893 |
to convert as appropriate." |
|
1894 |
||
1895 |
|collection converted selection dLbl dObj node| |
|
1896 |
||
1897 |
selection := self selectionAsCollection. |
|
1898 |
||
1899 |
collection := selection collect:[:nr| |
|
1900 |
node := listOfNodes at:nr. |
|
1901 |
dObj := self dragObjectForNode:node. |
|
1902 |
dObj theObject:(node contents). |
|
846 | 1903 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
811 | 1904 |
dObj displayObject:dLbl. |
1905 |
dObj |
|
1906 |
]. |
|
1907 |
||
1908 |
dragObjectConverter notNil ifTrue:[ |
|
1909 |
converted := OrderedCollection new. |
|
1910 |
collection keysAndValuesDo:[:nr :obj | |
|
1911 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
846 | 1912 |
node := listOfNodes at:nr. |
1913 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
|
811 | 1914 |
converted displayObject:dLbl. |
1915 |
converted add:dObj |
|
1916 |
] |
|
1917 |
]. |
|
1918 |
collection := converted |
|
1919 |
]. |
|
1920 |
^ collection. |
|
1921 |
||
1922 |
||
569 | 1923 |
|
1924 |
! |
|
1925 |
||
811 | 1926 |
dragObjectForNode:aNode |
1927 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1928 |
" |
811 | 1929 |
^ DropObject new:aNode. |
546 | 1930 |
|
811 | 1931 |
|
1932 |
! |
|
546 | 1933 |
|
811 | 1934 |
startDragX:x y:y |
1935 |
"start drag |
|
1936 |
" |
|
1937 |
dragIsActive := true. |
|
546 | 1938 |
|
811 | 1939 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1940 |
from:self |
|
1941 |
atEnd:endDragAction |
|
546 | 1942 |
|
1943 |
||
490 | 1944 |
! ! |
1945 |
||
468 | 1946 |
!SelectionInTreeView methodsFor:'private queries'! |
1947 |
||
1948 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1949 |
"return the length (in characters) of the longest line in a line-range |
|
1950 |
" |
|
846 | 1951 |
^ self widthOfContents // fontWidth + 1 |
468 | 1952 |
! |
1953 |
||
848 | 1954 |
smallestLevelOfNodesBetween:start and:stop |
1955 |
"returns the smallest level of the nodes in a line range |
|
1956 |
" |
|
1957 |
|prevNode currParent nextParent |
|
1958 |
||
1959 |
lvl "{ Class:SmallInteger }" |
|
1960 |
min "{ Class:SmallInteger }" |
|
1961 |
end "{ Class:SmallInteger }" |
|
1962 |
beg "{ Class:SmallInteger }" |
|
1963 |
| |
|
1964 |
||
1965 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
|
1966 |
^ 0 |
|
1967 |
]. |
|
1968 |
||
1969 |
prevNode := listOfNodes at:start. |
|
1970 |
currParent := prevNode parent. |
|
1971 |
||
1972 |
currParent isNil ifTrue:[ |
|
1973 |
^ 1 |
|
1974 |
]. |
|
1975 |
||
1976 |
(min := prevNode level) == 2 ifTrue:[ |
|
1977 |
^ min |
|
1978 |
]. |
|
1979 |
beg := start + 1. |
|
1980 |
||
1981 |
listOfNodes from:beg to:end do:[:currNode| |
|
1982 |
(nextParent := currNode parent) == currParent ifFalse:[ |
|
1983 |
(currParent := nextParent) == prevNode ifFalse:[ |
|
1984 |
(lvl := currNode level) == 2 ifTrue:[ |
|
1985 |
^ 2 |
|
1986 |
]. |
|
1987 |
min := min min:lvl |
|
1988 |
] |
|
1989 |
]. |
|
1990 |
prevNode := currNode |
|
1991 |
]. |
|
1992 |
^ min |
|
1993 |
||
1994 |
||
1995 |
||
1996 |
||
1997 |
! |
|
1998 |
||
468 | 1999 |
widthOfContents |
2000 |
"return the width of the contents in pixels |
|
2001 |
- used for scrollbar interface" |
|
2002 |
||
846 | 2003 |
listOfNodes isNil ifTrue:[^ 0]. |
468 | 2004 |
|
2005 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
846 | 2006 |
widthOfWidestLine := self widthOfLongestLine |
468 | 2007 |
]. |
2008 |
^ widthOfWidestLine + (leftMargin * 2) |
|
2009 |
||
2010 |
! |
|
2011 |
||
846 | 2012 |
widthOfLongestLine |
2013 |
"return the width of the longest line in pixels |
|
468 | 2014 |
" |
848 | 2015 |
|parent pItem p |
846 | 2016 |
startX "{ Class: SmallInteger }" |
2017 |
deltaX "{ Class: SmallInteger }" |
|
838 | 2018 |
level "{ Class: SmallInteger }" |
2019 |
width "{ Class: SmallInteger }" |
|
2020 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 2021 |
|
848 | 2022 |
buildInArray atAllPut:0. |
846 | 2023 |
parent := nil. |
2024 |
maxSz := 1. |
|
838 | 2025 |
level := 1. |
846 | 2026 |
|
2027 |
listOfNodes do:[:anItem| |
|
848 | 2028 |
(p := anItem parent) ~~ parent ifTrue:[ |
2029 |
buildInArray at:level put:maxSz. |
|
846 | 2030 |
|
848 | 2031 |
(parent := p) == pItem ifTrue:[level := level + 1] |
2032 |
ifFalse:[level := anItem level]. |
|
2033 |
||
2034 |
maxSz := buildInArray at:level. |
|
846 | 2035 |
]. |
2036 |
pItem := anItem. |
|
2037 |
maxSz := maxSz max:(anItem name size). |
|
2038 |
]. |
|
848 | 2039 |
buildInArray at:level put:maxSz. |
468 | 2040 |
|
846 | 2041 |
startX := self xOfStringLevel:1. |
2042 |
deltaX := imageInset + imageWidth. |
|
2043 |
width := '1' widthOn:self. |
|
2044 |
maxSz := 0. |
|
468 | 2045 |
|
848 | 2046 |
buildInArray do:[:el| |
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2047 |
el == 0 ifTrue:[ ^ maxSz + viewOrigin x ]. |
846 | 2048 |
maxSz := maxSz max:(el * width + startX). |
2049 |
startX := startX + deltaX. |
|
468 | 2050 |
]. |
846 | 2051 |
! ! |
2052 |
||
2053 |
!SelectionInTreeView methodsFor:'private redefinitions'! |
|
2054 |
||
2055 |
expandTabs |
|
2056 |
"nothing to do |
|
2057 |
" |
|
838 | 2058 |
|
2059 |
||
468 | 2060 |
! |
2061 |
||
846 | 2062 |
list:aCollection expandTabs:expand scanForNonStrings:scan |
2063 |
||
2064 |
includesNonStrings := false. |
|
2065 |
self list:aCollection expandTabs:false scanForNonStrings:false includesNonStrings:false |
|
2066 |
! |
|
2067 |
||
468 | 2068 |
withoutRedrawAt:anIndex put:aString |
1813 | 2069 |
"change a line without redisplay and WITHOUT any sizeChange notifications. |
2070 |
Somewhat dangerous, since scrollBars will not be informed about contents-changes. |
|
2071 |
Use only if multiple lines are to be changed, and a sizeChanged is invoked by some other |
|
2072 |
means at the end." |
|
468 | 2073 |
|
2074 |
|width| |
|
2075 |
||
2076 |
width := widthOfWidestLine. |
|
2077 |
widthOfWidestLine := nil. |
|
2078 |
super withoutRedrawAt:anIndex put:aString. |
|
846 | 2079 |
widthOfWidestLine := width. |
468 | 2080 |
|
846 | 2081 |
(widthOfWidestLine notNil and:[aString size ~~ 0]) ifTrue:[ |
2082 |
width := self xOfStringNode:(listOfNodes at:anIndex) |
|
2083 |
+ (aString widthOn:self) |
|
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2084 |
+ viewOrigin x. |
846 | 2085 |
|
838 | 2086 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 2087 |
]. |
2088 |
! ! |
|
2089 |
||
483 | 2090 |
!SelectionInTreeView methodsFor:'queries'! |
2091 |
||
2092 |
figureFor:aNode |
|
1278 | 2093 |
"return a (bitmap) figure for a node" |
2094 |
||
785 | 2095 |
|icon img| |
2096 |
||
1278 | 2097 |
"/ the item may provide an icon |
2098 |
"/ (it knows for itself if its open or closed) |
|
2099 |
||
785 | 2100 |
(icon := aNode icon) notNil ifTrue:[ |
2101 |
img := registeredImages at:icon ifAbsent:nil. |
|
2102 |
img notNil ifTrue:[ |
|
2103 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2104 |
]. |
785 | 2105 |
icon isImage ifTrue:[ |
846 | 2106 |
img := self imageOnDevice:icon. |
785 | 2107 |
registeredImages at:icon put:img. |
1278 | 2108 |
^ img |
785 | 2109 |
] |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2110 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2111 |
|
1278 | 2112 |
"/ ok, node did not return an icon - use default. |
2113 |
||
846 | 2114 |
aNode hasChildren ifFalse:[ |
1278 | 2115 |
"/ regular |
2116 |
^ imageItem |
|
846 | 2117 |
]. |
1278 | 2118 |
"/ folder |
846 | 2119 |
^ aNode hidden ifTrue:[imageClosed] ifFalse:[imageOpened] |
785 | 2120 |
|
483 | 2121 |
! |
2122 |
||
2123 |
indexOfNode:aNode |
|
2124 |
"returns index of a node |
|
2125 |
" |
|
785 | 2126 |
^ listOfNodes identityIndexOf:aNode |
483 | 2127 |
! |
2128 |
||
494 | 2129 |
xOfFigureLevel:aLevel |
2130 |
"origin x where to draw the icon |
|
2131 |
" |
|
785 | 2132 |
|l "{ Class:SmallInteger }"| |
494 | 2133 |
|
785 | 2134 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 2135 |
|
659 | 2136 |
showDirectoryIndicator ifFalse:[ |
2137 |
l := l - 1 |
|
2138 |
] ifTrue:[ |
|
2139 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
2140 |
l := l - 1 |
|
2141 |
] |
|
2142 |
]. |
|
2015
5a83ee792cc3
eliminated accesses to leftOffset
Claus Gittinger <cg@exept.de>
parents:
2014
diff
changeset
|
2143 |
^ (l * (imageInset + imageWidth)) + imageInset - viewOrigin x + leftMargin |
494 | 2144 |
! |
2145 |
||
483 | 2146 |
xOfFigureNode:aNode |
2147 |
"origin x where to draw the icon |
|
2148 |
" |
|
494 | 2149 |
^ self xOfFigureLevel:(aNode level) |
2150 |
! |
|
490 | 2151 |
|
494 | 2152 |
xOfStringLevel:aLevel |
2153 |
"origin x where to draw the text( label ) |
|
2154 |
" |
|
2155 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 2156 |
|
2157 |
! |
|
2158 |
||
2159 |
xOfStringNode:aNode |
|
2160 |
"origin x where to draw the text( label ) |
|
2161 |
" |
|
494 | 2162 |
^ self xOfStringLevel:(aNode level) |
483 | 2163 |
|
1171 | 2164 |
! |
2165 |
||
2166 |
xOfValueNode:aNode |
|
2167 |
"returns the left x position of the start of the value |
|
2168 |
" |
|
2169 |
|p x| |
|
2170 |
||
2171 |
p := aNode parent. |
|
2172 |
||
2173 |
x := p notNil ifTrue:[30 + (p childrenWidthOn:self)] |
|
2174 |
ifFalse:[0]. |
|
2175 |
||
2176 |
^ x + (self xOfStringNode:aNode) |
|
2177 |
||
483 | 2178 |
! ! |
2179 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2180 |
!SelectionInTreeView methodsFor:'scrolling'! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2181 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2182 |
needScrollToMakeLine:aListLineNr |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2183 |
"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
|
2184 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2185 |
(aListLineNr >= firstLineShown) ifTrue:[ |
1162 | 2186 |
(aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[ |
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2187 |
^ false |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2188 |
] |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2189 |
]. |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2190 |
^ true |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2191 |
|
1171 | 2192 |
! |
2193 |
||
2194 |
originChanged:delta |
|
2195 |
"sent after scrolling - have to update origin of editor |
|
2196 |
" |
|
2197 |
super originChanged:delta. |
|
2198 |
||
2199 |
editorWidget notNil ifTrue:[ |
|
2200 |
editorWidget origin:(editorWidget origin - delta) |
|
2201 |
] |
|
2202 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2203 |
! ! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2204 |
|
444 | 2205 |
!SelectionInTreeView methodsFor:'selection'! |
2206 |
||
468 | 2207 |
selectNode:aNode |
2208 |
"change selection to a node |
|
2209 |
" |
|
855 | 2210 |
|index| |
848 | 2211 |
|
860 | 2212 |
(index := aNode) notNil ifTrue:[ |
2213 |
index isNumber ifFalse:[ |
|
2214 |
(index := self indexOfNode:aNode) == 0 ifTrue:[ |
|
2215 |
model doMakeVisible:aNode. |
|
2216 |
index := self indexOfNode:aNode. |
|
2217 |
] |
|
855 | 2218 |
]. |
848 | 2219 |
index == 0 ifTrue:[ |
855 | 2220 |
index := nil |
848 | 2221 |
] |
2222 |
]. |
|
2223 |
self selection:index |
|
468 | 2224 |
|
2225 |
||
2226 |
! |
|
2227 |
||
1972 | 2228 |
selectNodes:aCollectionOfNodes |
2229 |
|selIndexCollection| |
|
2230 |
||
2231 |
selIndexCollection := aCollectionOfNodes collect:[:eachNode | listOfNodes identityIndexOf:eachNode]. |
|
2232 |
selIndexCollection := selIndexCollection reject:[:eachIndex | eachIndex == 0]. |
|
2233 |
self selection:selIndexCollection. |
|
2234 |
||
2235 |
"/ first := true. |
|
2236 |
"/ aCollectionOfNodes do:[:eachNode | |
|
2237 |
"/ first ifTrue:[ |
|
2238 |
"/ self selectNode:eachNode. |
|
2239 |
"/ first := false. |
|
2240 |
"/ ] ifFalse:[ |
|
2241 |
"/ self selectedNodeAdd:eachNode |
|
2242 |
"/ ] |
|
2243 |
"/ ]. |
|
2244 |
"/ |
|
2245 |
! |
|
2246 |
||
456 | 2247 |
selectedIndex |
2248 |
"get single selected index or 0 |
|
2249 |
" |
|
483 | 2250 |
selection size == 1 ifTrue:[^ selection first]. |
2251 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 2252 |
^ 0 |
444 | 2253 |
! |
2254 |
||
2255 |
selectedNode |
|
2256 |
"get the single selected node or nil |
|
2257 |
" |
|
456 | 2258 |
|idx| |
2259 |
||
2260 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
2261 |
^ listOfNodes at:idx |
|
444 | 2262 |
]. |
2263 |
^ nil |
|
514 | 2264 |
! |
2265 |
||
1972 | 2266 |
selectedNodes |
2267 |
"get a collection of selected nodes |
|
2268 |
" |
|
2269 |
|selIndexCollection| |
|
2270 |
||
2271 |
(selIndexCollection := self selection) size == 0 ifTrue:[^ #() ]. |
|
2272 |
^ selIndexCollection collect:[:eachIndex | listOfNodes at:eachIndex]. |
|
2273 |
! |
|
2274 |
||
514 | 2275 |
selectionChangedFrom:oldSelection |
2276 |
"update selectionHolder if not nil |
|
2277 |
" |
|
1171 | 2278 |
self closeEditor. |
514 | 2279 |
|
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2280 |
"/ first change my selectionHolders value ... |
514 | 2281 |
selectionHolder notNil ifTrue:[ |
2282 |
self selectionToModel. |
|
2283 |
]. |
|
2284 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2285 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2286 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2287 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2288 |
|
1171 | 2289 |
! |
2290 |
||
2291 |
setSelection:aSelection |
|
2292 |
"if no selection exists, close the editor |
|
2293 |
" |
|
2294 |
(aSelection isNil or:[aSelection == 0]) ifTrue:[ |
|
2295 |
self closeEditor |
|
2296 |
]. |
|
2297 |
super setSelection:aSelection |
|
2298 |
||
2299 |
||
444 | 2300 |
! ! |
2301 |
||
855 | 2302 |
!SelectionInTreeView methodsFor:'selection actions'! |
507 | 2303 |
|
2304 |
selectedNodeAdd:something |
|
2305 |
"add a node or collection of nodes after selected node |
|
2306 |
" |
|
2307 |
|node| |
|
2308 |
||
2309 |
something notNil ifTrue:[ |
|
2310 |
(node := self selectedNode) notNil ifTrue:[ |
|
2311 |
node parent notNil ifTrue:[ |
|
2312 |
node isCollapsable ifTrue:[ |
|
2313 |
model add:something beforeIndex:1 below:node |
|
2314 |
] ifFalse:[ |
|
2315 |
model add:something after:node |
|
2316 |
] |
|
2317 |
] ifFalse:[ |
|
2318 |
model add:something beforeIndex:1 below:(self root) |
|
2319 |
] |
|
2320 |
] |
|
2321 |
] |
|
2322 |
||
2323 |
! |
|
2324 |
||
2325 |
selectedNodeBecomeChildOfNext |
|
1972 | 2326 |
"make the selected node a child of the next node |
507 | 2327 |
" |
2328 |
|idx node cprt nprt| |
|
2329 |
||
2330 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2331 |
idx := cprt indexOfChild:node. |
|
2332 |
||
2333 |
idx == cprt children size ifFalse:[ |
|
2334 |
nprt := cprt childAt:(idx + 1). |
|
2335 |
||
2336 |
nprt notNil ifTrue:[ |
|
855 | 2337 |
self setSelection:nil. |
2338 |
model remove:node. |
|
507 | 2339 |
model add:node beforeIndex:1 below:nprt. |
2340 |
self selectNode:node. |
|
2341 |
] |
|
2342 |
] |
|
2343 |
] |
|
2344 |
! |
|
2345 |
||
1972 | 2346 |
selectedNodeBecomeChildOfPrevious |
2347 |
"make the selected node a child of the previous node |
|
2348 |
" |
|
2349 |
|idx node cprt nprt| |
|
2350 |
||
2351 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2352 |
idx := cprt indexOfChild:node. |
|
2353 |
||
2354 |
idx == cprt children size ifFalse:[ |
|
2355 |
nprt := cprt childAt:(idx - 1). |
|
2356 |
||
2357 |
nprt notNil ifTrue:[ |
|
2358 |
self setSelection:nil. |
|
2359 |
model remove:node. |
|
2360 |
model add:node below:nprt. |
|
2361 |
self selectNode:node. |
|
2362 |
] |
|
2363 |
] |
|
2364 |
] |
|
2365 |
! |
|
2366 |
||
507 | 2367 |
selectedNodeBecomeSisterOfParent |
2368 |
"become node a sister of its current parent |
|
2369 |
" |
|
2370 |
|node cprt nprt| |
|
2371 |
||
2372 |
( (node := self selectedNode) isNil |
|
2373 |
or:[(cprt := node parent) isNil |
|
2374 |
or:[(nprt := cprt parent) isNil]] |
|
2375 |
) ifFalse:[ |
|
855 | 2376 |
self setSelection:nil. |
2377 |
model remove:node. |
|
507 | 2378 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
855 | 2379 |
self selectNode:node. |
507 | 2380 |
] |
2381 |
||
2382 |
! |
|
2383 |
||
2384 |
selectedNodeChangeSequenceOrder:anOffset |
|
2385 |
"move child 'anOffset' forward or backward in list of children |
|
2386 |
" |
|
2387 |
|idx node size parent| |
|
2388 |
||
2389 |
( (node := self selectedNode) notNil |
|
2390 |
and:[(parent := node parent) notNil |
|
2391 |
and:[(size := parent children size) > 1]] |
|
2392 |
) ifTrue:[ |
|
2393 |
idx := parent indexOfChild:node. |
|
855 | 2394 |
self setSelection:nil. |
2395 |
model remove:node. |
|
507 | 2396 |
|
2397 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
2398 |
idx := size |
|
2399 |
] ifFalse:[ |
|
2400 |
idx > size ifTrue:[idx := 1] |
|
2401 |
]. |
|
2402 |
model add:node beforeIndex:idx below:parent. |
|
2403 |
self selectNode:node. |
|
2404 |
] |
|
2405 |
! |
|
2406 |
||
2407 |
selectedNodeExpand:doExpand |
|
2408 |
"collapse or expand selected node |
|
2409 |
" |
|
855 | 2410 |
|node| |
507 | 2411 |
|
855 | 2412 |
(node := self selectedNode) notNil ifTrue:[ |
2413 |
doExpand ifTrue:[model doExpand:node] |
|
2414 |
ifFalse:[model doCollapse:node] |
|
2415 |
] |
|
507 | 2416 |
! |
2417 |
||
1972 | 2418 |
selectedNodesBecomeChildrenOfNext |
2419 |
"make the selected nodes children of the next node |
|
2420 |
" |
|
2421 |
|indices maxIndex nodes parent newParent| |
|
2422 |
||
2423 |
nodes := self selectedNodes. |
|
2424 |
nodes size == 0 ifTrue:[^ self]. |
|
2425 |
||
2426 |
indices := nodes collect:[:eachNode | listOfNodes identityIndexOf:eachNode]. |
|
2427 |
maxIndex := indices max. |
|
2428 |
||
2429 |
newParent := listOfNodes at:(maxIndex + 1) ifAbsent:nil. |
|
2430 |
newParent isNil ifTrue:[^ self]. |
|
2431 |
||
2432 |
indices sortWith:nodes. |
|
2433 |
||
2434 |
nodes reverseDo:[:eachNodeToMove | |
|
2435 |
model remove:eachNodeToMove. |
|
2436 |
model add:eachNodeToMove beforeIndex:1 below:newParent. |
|
2437 |
]. |
|
2438 |
self selectNodes:nodes. |
|
2439 |
! |
|
2440 |
||
2441 |
selectedNodesBecomeSistersOfParent |
|
2442 |
"move selected nodes up (out of their parent to their grandparent). |
|
2443 |
I.e. nodes become sisters of their current parent |
|
2444 |
" |
|
2445 |
|nodes parent grandParent indices| |
|
2446 |
||
2447 |
nodes := self selectedNodes. |
|
2448 |
nodes size == 0 ifTrue:[^ self]. |
|
2449 |
||
2450 |
"/ common parent ? |
|
2451 |
parent := nodes first parent. |
|
2452 |
(nodes conform:[:eachNode | eachNode parent == parent]) ifFalse:[^ self]. |
|
2453 |
||
2454 |
"/ is there a grandparent ? |
|
2455 |
grandParent := parent parent. |
|
2456 |
grandParent isNil ifTrue:[^ self]. |
|
2457 |
||
2458 |
self setSelection:nil. |
|
2459 |
indices := nodes collect:[:eachNode | listOfNodes identityIndexOf:eachNode]. |
|
2460 |
indices sortWith:nodes. |
|
2461 |
||
2462 |
nodes reverseDo:[:eachNodeToMove | |
|
2463 |
model remove:eachNodeToMove. |
|
2464 |
model add:eachNodeToMove afterIndex:(grandParent indexOfChild:parent) below:grandParent. |
|
2465 |
]. |
|
2466 |
self selectNodes:nodes. |
|
2467 |
! |
|
2468 |
||
507 | 2469 |
selectedNodesRemove |
2470 |
"remove selected nodes |
|
2471 |
" |
|
855 | 2472 |
|selection| |
2473 |
||
2474 |
selection := self selection. |
|
507 | 2475 |
self selection:nil. |
855 | 2476 |
model remove:selection. |
507 | 2477 |
! ! |
2478 |
||
444 | 2479 |
!SelectionInTreeView class methodsFor:'documentation'! |
2480 |
||
2481 |
version |
|
2156 | 2482 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.98 2002-08-22 16:52:32 cg Exp $' |
444 | 2483 |
! ! |