author | Claus Gittinger <cg@exept.de> |
Thu, 24 Aug 2000 21:12:23 +0200 | |
changeset 1822 | 911117459699 |
parent 1815 | a5f2bd36e179 |
child 1887 | b47b3cb2515b |
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:[ |
1165 |
w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset. |
|
1166 |
x := margin - leftOffset. |
|
1167 |
] ifFalse:[ |
|
1168 |
w := x1 - x0. |
|
1169 |
x := x0. |
|
1170 |
]. |
|
1171 |
self drawEdgesForX:x y:y0 width:w height:fontHeight level:hilightLevel. |
|
792 | 1172 |
] |
1173 |
||
1174 |
||
1175 |
||
900 | 1176 |
! |
1177 |
||
1178 |
redrawX:x y:y width:w height:h |
|
1179 |
"a region must be redrawn" |
|
1180 |
||
1181 |
|savClip startLn sel |
|
1182 |
y0 "{ Class:SmallInteger }" |
|
1183 |
y1 "{ Class:SmallInteger }" |
|
1184 |
visStart "{ Class:SmallInteger }" |
|
1185 |
visEnd "{ Class:SmallInteger }" |
|
1186 |
stopLn "{ Class:SmallInteger }" |
|
1187 |
maxY "{ Class:SmallInteger }" |
|
1188 |
maxX "{ Class:SmallInteger }" |
|
1189 |
dltLine "{ Class:SmallInteger }" |
|
1190 |
startY "{ Class:SmallInteger }"| |
|
1191 |
||
1192 |
shown ifFalse:[^ self]. |
|
1193 |
||
1194 |
visStart := self visibleLineOfY:(y + 1). |
|
1195 |
startLn := self visibleLineToAbsoluteLine:visStart. |
|
1196 |
||
1197 |
self paint:bgColor. |
|
1198 |
self fillRectangleX:x y:y width:w height:h. |
|
1199 |
startLn isNil ifTrue:[ ^ self ]. |
|
1200 |
||
1201 |
sel := nil. |
|
1202 |
maxX := x + w. |
|
1203 |
maxY := y + h. |
|
1204 |
visEnd := self visibleLineOfY:maxY. |
|
1205 |
startY := self yOfVisibleLine:visStart. |
|
1206 |
dltLine := startLn - visStart. |
|
1207 |
stopLn := dltLine + visEnd. |
|
1208 |
savClip := clipRect. |
|
1209 |
||
1210 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
|
1211 |
||
1212 |
(highlightMode == #line and:[self hasSelection]) ifTrue:[ |
|
1213 |
"/ redraw the background for all selected lines in the invalid range |
|
1214 |
||
1215 |
self selectionDo:[:lnNr| |
|
1216 |
(lnNr between:startLn and:stopLn) ifTrue:[ |
|
1217 |
sel isNil ifTrue:[ |
|
1218 |
sel := OrderedCollection new. |
|
1219 |
self paint:hilightBgColor. |
|
1220 |
]. |
|
1221 |
sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)). |
|
1222 |
y1 := y0 + fontHeight min:maxY. |
|
1223 |
y0 := y0 max:y. |
|
1224 |
self fillRectangleX:x y:y0 width:w height:y1 - y0. |
|
1225 |
] |
|
1226 |
] |
|
1227 |
]. |
|
1228 |
self redrawLinesX:x y:startY toX:maxX start:startLn stop:stopLn. |
|
1229 |
||
1230 |
"/ draw selection frames |
|
1231 |
sel notNil ifTrue:[ |
|
1232 |
sel do:[:y0| self redrawSelFrameAtX:x y:y0 toX:maxX] |
|
1233 |
]. |
|
1234 |
||
1235 |
self clippingRectangle:savClip. |
|
444 | 1236 |
! ! |
1237 |
||
494 | 1238 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 1239 |
|
494 | 1240 |
detectNode:aOneArgBlock |
1241 |
"evaluate the argument, aBlock for each node in the list until |
|
1242 |
the block returns true; in this case return the node which caused |
|
1243 |
the true evaluation. If none node is detected, nil is returned. |
|
1244 |
" |
|
1245 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 1246 |
! |
1247 |
||
1248 |
selectedNodesDo:aOneArgBlock |
|
1249 |
"evaluate the block on each node selected |
|
1250 |
" |
|
1251 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 1252 |
! ! |
1253 |
||
569 | 1254 |
!SelectionInTreeView methodsFor:'event handling'! |
1255 |
||
639 | 1256 |
buttonMotion:buttonMask x:x y:y |
1257 |
"mouse-move while button was pressed - handle selection changes" |
|
1258 |
||
1259 |
discardMotionEvents ifFalse:[ |
|
1260 |
super buttonMotion:buttonMask x:x y:y |
|
1261 |
] |
|
1262 |
||
1263 |
||
1264 |
! |
|
1265 |
||
569 | 1266 |
buttonMultiPress:button x:x y:y |
1267 |
||
1268 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
1269 |
^ super buttonMultiPress:button x:x y:y |
|
1270 |
]. |
|
1271 |
"/ discard doubleClick on indicator |
|
1272 |
! |
|
1273 |
||
1274 |
buttonPress:button x:x y:y |
|
1171 | 1275 |
"handle button press event |
1276 |
" |
|
1268 | 1277 |
|node menu| |
1171 | 1278 |
|
1279 |
((button == 2) or:[button == #menu]) ifTrue:[ |
|
1280 |
( (node := self selectedNode) notNil |
|
1281 |
and:[(menu := node middleButtonMenu) notNil] |
|
1282 |
) ifTrue:[ |
|
1188 | 1283 |
menu isCollection ifTrue:[ |
1284 |
|appl| |
|
1285 |
||
1286 |
menu := Menu new fromLiteralArrayEncoding:menu. |
|
1287 |
||
1288 |
(appl := self application) notNil ifTrue:[ |
|
1289 |
menu findGuiResourcesIn:appl |
|
1290 |
]. |
|
1291 |
menu receiver:appl. |
|
1292 |
]. |
|
1171 | 1293 |
menu startUp |
1294 |
] ifFalse:[ |
|
1295 |
super buttonPress:button x:x y:y |
|
1296 |
] |
|
1297 |
] ifFalse:[ |
|
1298 |
self handleSelectButtonAtX:x y:y. |
|
1299 |
||
1300 |
( editorWidget isNil |
|
1301 |
and:[(node := self selectedNode) notNil |
|
1302 |
and:[node canEdit |
|
1303 |
and:[x >= (self xOfValueNode:node)]]] |
|
1304 |
) ifTrue:[ |
|
1305 |
self openEditor |
|
1306 |
] |
|
1307 |
] |
|
1308 |
! |
|
1309 |
||
1310 |
buttonRelease:button x:x y:y |
|
1311 |
"stop any autoscroll" |
|
1312 |
||
1313 |
discardMotionEvents ifTrue:[ |
|
1314 |
clickPosition := nil. |
|
1315 |
discardMotionEvents := false. |
|
1316 |
]. |
|
1317 |
super buttonRelease:button x:x y:y |
|
1318 |
||
1319 |
! |
|
1320 |
||
1321 |
doubleClicked |
|
1322 |
"handle a double click; collapse or expand selected entry |
|
1323 |
in case of having children |
|
1324 |
" |
|
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1325 |
|node | |
1171 | 1326 |
|
1327 |
(node := self selectedNode) notNil ifTrue:[ |
|
1202
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1328 |
(validateDoubleClickBlock isNil |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1329 |
or:[(validateDoubleClickBlock value:node) ~~ false]) ifTrue:[ |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1330 |
(validateExpandabilityBlock isNil |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1331 |
or:[(validateExpandabilityBlock value:node) ~~ false]) ifTrue:[ |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1332 |
self selectedNodeExpand:(node isExpandable). |
b9a3beb20ca7
added an extra validateExpandability block,
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1333 |
]. |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1334 |
node hasChildren ifFalse:[ |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1335 |
super doubleClicked |
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1336 |
] |
1171 | 1337 |
] |
1338 |
] |
|
1339 |
||
1340 |
! |
|
1341 |
||
1342 |
handleSelectButtonAtX:x y:y |
|
1343 |
"handle a select button click |
|
569 | 1344 |
" |
1268 | 1345 |
|node lineNr sensor isExpd| |
569 | 1346 |
|
1171 | 1347 |
lineNr := self indicatiorLineForButton:#select atX:x y:y. |
569 | 1348 |
|
1349 |
lineNr == 0 ifTrue:[ |
|
1171 | 1350 |
^ super buttonPress:#select x:x y:y |
569 | 1351 |
]. |
1352 |
node := listOfNodes at:lineNr. |
|
1353 |
||
639 | 1354 |
discardMotionEvents := true. |
569 | 1355 |
dragIsActive := false. |
1356 |
clickPosition := nil. |
|
1357 |
||
639 | 1358 |
self hasSelection ifTrue:[ |
1359 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
1360 |
self selection:lineNr |
|
1361 |
] ifFalse:[ |
|
1362 |
self selection:nil |
|
569 | 1363 |
] |
1364 |
]. |
|
855 | 1365 |
|
1366 |
isExpd := node isExpandable. |
|
835 | 1367 |
|
855 | 1368 |
( supportsExpandAll |
1369 |
and:[(sensor := self sensor) notNil |
|
1370 |
and:[(sensor ctrlDown or:[sensor shiftDown])]] |
|
1371 |
) ifTrue:[ |
|
1372 |
isExpd ifTrue:[model doExpandAll:node] |
|
1373 |
ifFalse:[model doCollapseAll:node] |
|
835 | 1374 |
] ifFalse:[ |
855 | 1375 |
isExpd ifTrue:[model doExpand:node] |
1376 |
ifFalse:[model doCollapse:node]. |
|
835 | 1377 |
]. |
848 | 1378 |
|
639 | 1379 |
! |
1380 |
||
569 | 1381 |
indicatiorLineForButton:aButton atX:x y:y |
1382 |
"returns linenumber assigned to indicator at x/y or 0 |
|
1383 |
" |
|
1268 | 1384 |
|nr x0 node| |
569 | 1385 |
|
1386 |
( enabled |
|
1387 |
and:[showDirectoryIndicator |
|
1388 |
and:[aButton == 1 or:[aButton == #select]]] |
|
1389 |
) ifTrue:[ |
|
835 | 1390 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
569 | 1391 |
|
835 | 1392 |
nr notNil ifTrue:[ |
1393 |
node := listOfNodes at:nr. |
|
1394 |
node hasChildren ifTrue:[ |
|
1395 |
x0 := self xOfFigureLevel:(node level - 1). |
|
569 | 1396 |
|
835 | 1397 |
(x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[ |
1398 |
^ nr |
|
569 | 1399 |
] |
1400 |
] |
|
1401 |
] |
|
1402 |
]. |
|
1403 |
^ 0 |
|
756 | 1404 |
! |
1405 |
||
835 | 1406 |
isCtrlMetaAltOrShiftPressed |
1407 |
"returns true if CTRL, META, ALT or SHIFT is pressed |
|
1408 |
" |
|
1409 |
|sensor| |
|
1410 |
||
1411 |
(sensor := self sensor) notNil ifTrue:[ |
|
1412 |
^ ( sensor ctrlDown |
|
1413 |
or:[sensor altDown |
|
1414 |
or:[sensor shiftDown |
|
1415 |
or:[sensor metaDown]]] |
|
1416 |
) |
|
1417 |
]. |
|
1418 |
^ false |
|
1419 |
! |
|
1420 |
||
756 | 1421 |
key:key select:index x:x y:y |
1422 |
"select an entry by a keyboard action. This is treated like a doubleClick |
|
1423 |
on that entry. |
|
1424 |
Add on: In case that the entry is not selectable, scroll to the entry |
|
1425 |
" |
|
1426 |
(enabled and:[keyActionStyle notNil]) ifFalse:[ |
|
1427 |
^ self |
|
1428 |
]. |
|
1429 |
||
1430 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
780 | 1431 |
^ super key:key select:index x:x y:y |
756 | 1432 |
]. |
1433 |
||
1434 |
keyActionStyle == #pass ifTrue:[ |
|
1435 |
^ self |
|
1436 |
]. |
|
1437 |
||
1438 |
self gotoLine:index |
|
785 | 1439 |
! |
1440 |
||
811 | 1441 |
keyPress:key x:x y:y |
1442 |
"handle keyboard input" |
|
1443 |
||
1444 |
<resource: #keyboard ( #CursorLeft #CursorRight ) > |
|
1445 |
||
1446 |
|idx node inc end| |
|
1447 |
||
1448 |
enabled ifFalse:[ |
|
1449 |
^ self |
|
1450 |
]. |
|
1451 |
||
1452 |
(key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
|
1453 |
(idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
|
1454 |
||
1455 |
(key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
|
1456 |
ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
|
1457 |
||
1458 |
[(idx := idx + inc) ~~ end] whileTrue:[ |
|
1459 |
node := listOfNodes at:idx. |
|
825 | 1460 |
node hasChildren ifTrue:[ |
811 | 1461 |
^ self key:key select:idx x:x y:y |
1462 |
] |
|
1463 |
]. |
|
1464 |
^ self |
|
1465 |
]. |
|
1466 |
^ super keyPress:key x:x y:y |
|
1467 |
||
1468 |
||
1469 |
||
1470 |
||
569 | 1471 |
! ! |
1472 |
||
1328 | 1473 |
!SelectionInTreeView methodsFor:'initialize / release'! |
444 | 1474 |
|
685 | 1475 |
create |
1476 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1477 |
lineMask := lineMask onDevice:device. |
685 | 1478 |
|
846 | 1479 |
lineColor := lineColor isNil ifTrue:[fgColor] |
1480 |
ifFalse:[lineColor onDevice:device]. |
|
1175 | 1481 |
|
1482 |
editValueFgColor := editValueFgColor onDevice:device. |
|
685 | 1483 |
! |
1484 |
||
514 | 1485 |
destroy |
1486 |
"remove dependencies |
|
1487 |
" |
|
811 | 1488 |
rootHolder removeDependent:self. |
1489 |
selectionHolder removeDependent:self. |
|
1490 |
||
1491 |
model notNil ifTrue:[ |
|
1492 |
model stopRunningTasks |
|
514 | 1493 |
]. |
1494 |
super destroy. |
|
1495 |
||
1496 |
! |
|
1497 |
||
785 | 1498 |
fetchDefaultImages |
1499 |
"returns a directory with default keys and images; could be |
|
1500 |
redefined by subclass. |
|
1501 |
" |
|
1171 | 1502 |
^ itemClass notNil ifTrue:[itemClass keysAndIcons] |
1503 |
ifFalse:[nil] |
|
785 | 1504 |
! |
1505 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1506 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1507 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1508 |
images again and again later" |
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 |
super fetchDeviceResources. |
478 | 1511 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1512 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1513 |
|
478 | 1514 |
fetchImageResources |
1515 |
"initialize heavily used device resources - to avoid rendering |
|
1516 |
images again and again later; returns maximum extent of the images used. |
|
1517 |
Could be redefined by subclass |
|
471 | 1518 |
" |
785 | 1519 |
|img x y keysAndIcons| |
494 | 1520 |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1521 |
x := y := 0. |
494 | 1522 |
imageOpened isNil ifTrue:[ |
846 | 1523 |
imageOpened := self imageOnDevice:(self class imageOpened) |
494 | 1524 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1525 |
imageOpened notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1526 |
x := x max:(imageOpened width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1527 |
y := y max:(imageOpened height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1528 |
]. |
444 | 1529 |
|
494 | 1530 |
imageClosed isNil ifTrue:[ |
569 | 1531 |
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
|
1532 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1533 |
imageClosed notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1534 |
x := x max:(imageClosed width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1535 |
y := y max:(imageClosed height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1536 |
]. |
494 | 1537 |
|
1538 |
imageItem isNil ifTrue:[ |
|
569 | 1539 |
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
|
1540 |
]. |
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1541 |
imageItem notNil ifTrue:[ |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1542 |
x := x max:(imageItem width). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1543 |
y := y max:(imageItem height). |
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1544 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1545 |
|
785 | 1546 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1547 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1548 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
846 | 1549 |
registeredImages at:aKey put:(self imageOnDevice:anIcon) |
785 | 1550 |
] |
1551 |
] |
|
1552 |
]. |
|
1553 |
registeredImages keysAndValuesDo:[:k :img| |
|
1554 |
x := (img width) max:x. |
|
1555 |
y := (img height) max:y. |
|
1556 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1557 |
|
785 | 1558 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1559 |
x := (img width) max:x. |
|
1560 |
y := (img height) max:y. |
|
1561 |
]. |
|
1562 |
^ x @ y |
|
1070
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1563 |
|
856d037fe133
care for non-existing images.
Claus Gittinger <cg@exept.de>
parents:
1061
diff
changeset
|
1564 |
"Modified: / 12.8.1998 / 12:45:53 / cg" |
444 | 1565 |
! |
1566 |
||
480 | 1567 |
getFontParameters |
546 | 1568 |
"save old computed height derived from images |
1569 |
" |
|
1570 |
|lineHeight| |
|
1571 |
||
1572 |
lineHeight := fontHeight ? 0. |
|
480 | 1573 |
super getFontParameters. |
569 | 1574 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1575 |
|
546 | 1576 |
lineHeight > fontHeight ifTrue:[ |
1577 |
fontHeight := lineHeight |
|
1578 |
]. |
|
685 | 1579 |
fontHeight odd ifTrue:[ |
1580 |
fontHeight := fontHeight + 1 |
|
1581 |
] |
|
480 | 1582 |
! |
1583 |
||
900 | 1584 |
initStyle |
1585 |
"setup viewStyle specifics" |
|
1586 |
||
1587 |
super initStyle. |
|
1171 | 1588 |
highlightMode := DefaultHilightMode ? #label. |
900 | 1589 |
|
1590 |
! |
|
1591 |
||
444 | 1592 |
initialize |
471 | 1593 |
"setup instance attributes |
1594 |
" |
|
444 | 1595 |
super initialize. |
1171 | 1596 |
|
1597 |
itemClass isNil ifTrue:[ |
|
1598 |
itemClass := TreeItem |
|
1599 |
]. |
|
1600 |
||
835 | 1601 |
supportsExpandAll := true. |
569 | 1602 |
self bitGravity:#NorthWest. |
773 | 1603 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1815
a5f2bd36e179
double click on expandable item does not perform
Claus Gittinger <cg@exept.de>
parents:
1813
diff
changeset
|
1604 |
showDirectoryIndicator := discardMotionEvents := showLinesForRoot := false. |
1275 | 1605 |
leftMargin := 2. |
1606 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
|
773 | 1607 |
registeredImages := IdentityDictionary new. |
855 | 1608 |
drawVLinesFromLevel := 1. |
659 | 1609 |
textInset := 4. |
494 | 1610 |
imageInset := 0. "/ set during indication enabled |
1611 |
imageWidth := 8. "/ default: will change during startup |
|
848 | 1612 |
|
1613 |
buildInArray := Array new:50. "/ used for temporary calculation |
|
1614 |
"/ suppress garbage collection |
|
1615 |
||
514 | 1616 |
self model:nil. "/ creates a default model. |
1171 | 1617 |
highlightMode := #label. |
1175 | 1618 |
editValueFgColor := Color blue. |
478 | 1619 |
! |
1620 |
||
569 | 1621 |
realize |
1622 |
super realize. |
|
1623 |
self refetchDeviceResources. |
|
1624 |
! |
|
1625 |
||
811 | 1626 |
recomputeDirectoryIndicator |
1627 |
"setup attributes used by directory indicator |
|
1628 |
" |
|
1629 |
|x w| |
|
1630 |
||
1631 |
imageInset := 0. |
|
1632 |
||
1633 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1634 |
^ self |
|
1635 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1636 |
|
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1637 |
x := 0. |
811 | 1638 |
openIndicator isNil ifTrue:[ |
1639 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1640 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1641 |
openIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1642 |
x := openIndicator width |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1643 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1644 |
|
811 | 1645 |
closeIndicator isNil ifTrue:[ |
1646 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1647 |
]. |
|
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1648 |
closeIndicator notNil ifTrue:[ |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1649 |
x := x max:(closeIndicator width) |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1650 |
]. |
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1651 |
|
811 | 1652 |
x := x // 2. |
1653 |
w := imageWidth // 2. |
|
1654 |
||
1655 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1656 |
imageInset := x - w. |
|
1657 |
]. |
|
1658 |
||
1072
1888703adc18
care for non-existing open/close indicators.
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1659 |
"Modified: / 13.8.1998 / 12:02:04 / cg" |
811 | 1660 |
! |
1661 |
||
478 | 1662 |
refetchDeviceResources |
1663 |
"reinitialize heavily used device resources - to avoid rendering |
|
1664 |
images again and again later |
|
1665 |
" |
|
551 | 1666 |
|extent| |
478 | 1667 |
|
569 | 1668 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1669 |
computeResources := false. |
1670 |
extent := self fetchImageResources. |
|
494 | 1671 |
|
546 | 1672 |
extent y >= fontHeight ifTrue:[ |
1673 |
fontHeight := 1 + extent y. |
|
494 | 1674 |
]. |
685 | 1675 |
fontHeight odd ifTrue:[ |
1676 |
fontHeight := fontHeight + 1 |
|
1677 |
]. |
|
846 | 1678 |
"/ round and not odd: because of line drawing |
685 | 1679 |
|
846 | 1680 |
imageWidth := (extent x) // 2. |
1681 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1]. |
|
1682 |
imageWidth := imageWidth * 2. |
|
1683 |
||
546 | 1684 |
self recomputeDirectoryIndicator. |
569 | 1685 |
self computeNumberOfLinesShown. |
546 | 1686 |
] |
444 | 1687 |
! ! |
1688 |
||
483 | 1689 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1690 |
|
1691 |
getListFromModel |
|
1692 |
"if I have a model, get my list from it using the listMessage. |
|
1693 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1694 |
" |
|
483 | 1695 |
super list:(self listFromModel) keepSelection:true |
1696 |
! |
|
444 | 1697 |
|
483 | 1698 |
listFromModel |
1699 |
"get list from model and return the new list. |
|
1700 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1701 |
" |
|
846 | 1702 |
|msg| |
838 | 1703 |
|
846 | 1704 |
widthOfWidestLine := nil. |
847 | 1705 |
list := listOfNodes := (msg := listMsg ? aspectMsg) notNil ifTrue:[model perform:msg] ifFalse:[#()]. |
1706 |
self refetchDeviceResources. |
|
846 | 1707 |
^ listOfNodes |
494 | 1708 |
! |
1709 |
||
1710 |
model:aModel |
|
514 | 1711 |
"check whether model is nil; than a default model is created |
1712 |
" |
|
855 | 1713 |
|model root| |
514 | 1714 |
|
811 | 1715 |
model notNil ifTrue:[ |
1716 |
model stopRunningTasks |
|
1717 |
]. |
|
1718 |
||
1171 | 1719 |
model := aModel ? (self class defaultModelClass new). |
1720 |
self itemClass:(model class defaultItemClass). |
|
855 | 1721 |
root := model root. |
1722 |
||
514 | 1723 |
model showRoot:showRoot. |
855 | 1724 |
|
1725 |
root notNil ifTrue:[ |
|
1726 |
root expand |
|
1727 |
]. |
|
514 | 1728 |
super model:model. |
855 | 1729 |
self getListFromModel |
811 | 1730 |
|
514 | 1731 |
! |
1732 |
||
1733 |
rootFromModel |
|
1734 |
"update hierarchical list from root model; 'rootHolder' |
|
1735 |
" |
|
1736 |
|root| |
|
1737 |
||
585 | 1738 |
root := rootHolder root. |
514 | 1739 |
|
1740 |
self root == root ifFalse:[ |
|
1741 |
self selection:nil. |
|
1742 |
self root:root. |
|
585 | 1743 |
]. |
514 | 1744 |
! |
1745 |
||
1746 |
selectionFromModel |
|
1747 |
"set the selection derived from the selectionHolder |
|
1748 |
" |
|
855 | 1749 |
|coll value size idx| |
514 | 1750 |
|
1214 | 1751 |
(value := selectionHolder value) isNil ifFalse:[ |
1752 |
(multipleSelectOk and:[value isCollection]) ifFalse:[ |
|
1753 |
^ self selectNode:value |
|
860 | 1754 |
]. |
1214 | 1755 |
|
1756 |
(size := value size) ~~ 0 ifTrue:[ |
|
1757 |
size == 1 ifTrue:[ |
|
1758 |
^ self selectNode:(value at:1) |
|
1759 |
]. |
|
1760 |
||
1761 |
model doMakeVisible:value. |
|
1762 |
||
1763 |
coll := OrderedCollection new:size. |
|
1764 |
||
1765 |
value do:[:el| |
|
1766 |
idx := el isNumber ifTrue:[el] ifFalse:[self indexOfNode:el]. |
|
1767 |
||
1768 |
idx ~~ 0 ifTrue:[ |
|
1769 |
coll add:idx |
|
1770 |
]. |
|
1771 |
]. |
|
1772 |
||
1773 |
coll isEmpty ifTrue:[ |
|
1774 |
coll := nil |
|
1775 |
]. |
|
1776 |
]. |
|
848 | 1777 |
]. |
1778 |
self selection:coll |
|
514 | 1779 |
! |
1780 |
||
1781 |
selectionToModel |
|
1782 |
"write selection to selection holder |
|
1783 |
" |
|
1784 |
|newSel oldSel| |
|
1785 |
||
1786 |
oldSel := selectionHolder value. |
|
1787 |
||
1788 |
multipleSelectOk ifFalse:[ |
|
1789 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1790 |
selectionHolder value:newSel |
|
1791 |
] |
|
1792 |
] ifTrue:[ |
|
1793 |
selection size == 0 ifTrue:[ |
|
1794 |
oldSel notNil ifTrue:[ |
|
1795 |
selectionHolder value:nil |
|
1796 |
] |
|
1797 |
] ifFalse:[ |
|
1798 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1799 |
||
1800 |
newSel size ~~ oldSel size ifTrue:[ |
|
1801 |
selectionHolder value:newSel. |
|
1802 |
] ifFalse:[ |
|
1803 |
newSel do:[:aNode| |
|
785 | 1804 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1805 |
^ selectionHolder value:newSel |
1806 |
] |
|
1807 |
] |
|
1808 |
] |
|
1809 |
] |
|
1810 |
] |
|
444 | 1811 |
! ! |
1812 |
||
490 | 1813 |
!SelectionInTreeView methodsFor:'private'! |
1814 |
||
1171 | 1815 |
closeEditor |
1816 |
"close the editor |
|
1817 |
" |
|
1818 |
editorWidget notNil ifTrue:[ |
|
1819 |
editorWidget destroy. |
|
1820 |
editorIndex := 0. |
|
1821 |
editorWidget := nil. |
|
1822 |
]. |
|
1823 |
||
1824 |
! |
|
1825 |
||
490 | 1826 |
list:aList keepSelection:keepSelection |
585 | 1827 |
"setup new list; keep selection dependent on the boolean state |
1828 |
keepSelection |
|
1829 |
" |
|
1268 | 1830 |
|list| |
490 | 1831 |
|
846 | 1832 |
list := (aList size == 0) ifTrue:[#()] ifFalse:[aList]. |
1833 |
super list:list keepSelection:keepSelection. |
|
1834 |
self refetchDeviceResources. |
|
490 | 1835 |
|
1171 | 1836 |
! |
1837 |
||
1838 |
openEditor |
|
1839 |
"open an editor on selection |
|
1840 |
" |
|
1175 | 1841 |
|node x0 x1 y0| |
1171 | 1842 |
|
1843 |
editorWidget notNil ifTrue:[ |
|
1844 |
^ self |
|
1845 |
]. |
|
1846 |
editorIndex := self selectedIndex. |
|
1847 |
||
1848 |
( (node := listOfNodes at:editorIndex ifAbsent:nil) isNil |
|
1849 |
or:[(y0 := self listLineToVisibleLine:editorIndex) isNil |
|
1850 |
or:[(editorWidget := node editor) isNil]] |
|
1851 |
) ifTrue:[ |
|
1852 |
^ self |
|
1853 |
]. |
|
1175 | 1854 |
editorWidget withAllSubViewsDo:[:v| v font:font ]. |
1855 |
||
1171 | 1856 |
y0 := self yOfVisibleLine:y0. |
1857 |
x0 := self xOfValueNode:node. |
|
1858 |
x1 := (editorWidget preferredExtent x) max:50. |
|
1859 |
x1 := (x0 + x1) min:(self width - 5). |
|
1860 |
||
1861 |
editorWidget geometryLayout:(Rectangle left:x0 right:x1 top:y0 bottom:y0 + fontHeight). |
|
1862 |
||
1863 |
self addComponent:editorWidget. |
|
1864 |
editorWidget realize. |
|
1865 |
self paint:bgColor. |
|
1866 |
||
1867 |
self fillRectangleX:(x0 - SelectionInset) |
|
1868 |
y:y0 |
|
1869 |
width:SelectionInset + SelectionInset + (x1 - x0) |
|
1870 |
height:fontHeight. |
|
1871 |
||
1872 |
||
1873 |
||
1874 |
||
1875 |
||
811 | 1876 |
! ! |
1877 |
||
1878 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1879 |
|
811 | 1880 |
collectionOfDragObjects |
1881 |
"returns collection of dragable objects assigned to selection |
|
1882 |
Here, by default, a collection of text-dragObjects is generated; |
|
1883 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1884 |
to convert as appropriate." |
|
1885 |
||
1886 |
|collection converted selection dLbl dObj node| |
|
1887 |
||
1888 |
selection := self selectionAsCollection. |
|
1889 |
||
1890 |
collection := selection collect:[:nr| |
|
1891 |
node := listOfNodes at:nr. |
|
1892 |
dObj := self dragObjectForNode:node. |
|
1893 |
dObj theObject:(node contents). |
|
846 | 1894 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
811 | 1895 |
dObj displayObject:dLbl. |
1896 |
dObj |
|
1897 |
]. |
|
1898 |
||
1899 |
dragObjectConverter notNil ifTrue:[ |
|
1900 |
converted := OrderedCollection new. |
|
1901 |
collection keysAndValuesDo:[:nr :obj | |
|
1902 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
846 | 1903 |
node := listOfNodes at:nr. |
1904 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
|
811 | 1905 |
converted displayObject:dLbl. |
1906 |
converted add:dObj |
|
1907 |
] |
|
1908 |
]. |
|
1909 |
collection := converted |
|
1910 |
]. |
|
1911 |
^ collection. |
|
1912 |
||
1913 |
||
569 | 1914 |
|
1915 |
! |
|
1916 |
||
811 | 1917 |
dragObjectForNode:aNode |
1918 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1919 |
" |
811 | 1920 |
^ DropObject new:aNode. |
546 | 1921 |
|
811 | 1922 |
|
1923 |
! |
|
546 | 1924 |
|
811 | 1925 |
startDragX:x y:y |
1926 |
"start drag |
|
1927 |
" |
|
1928 |
dragIsActive := true. |
|
546 | 1929 |
|
811 | 1930 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1931 |
from:self |
|
1932 |
atEnd:endDragAction |
|
546 | 1933 |
|
1934 |
||
490 | 1935 |
! ! |
1936 |
||
468 | 1937 |
!SelectionInTreeView methodsFor:'private queries'! |
1938 |
||
1939 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1940 |
"return the length (in characters) of the longest line in a line-range |
|
1941 |
" |
|
846 | 1942 |
^ self widthOfContents // fontWidth + 1 |
468 | 1943 |
! |
1944 |
||
848 | 1945 |
smallestLevelOfNodesBetween:start and:stop |
1946 |
"returns the smallest level of the nodes in a line range |
|
1947 |
" |
|
1948 |
|prevNode currParent nextParent |
|
1949 |
||
1950 |
lvl "{ Class:SmallInteger }" |
|
1951 |
min "{ Class:SmallInteger }" |
|
1952 |
end "{ Class:SmallInteger }" |
|
1953 |
beg "{ Class:SmallInteger }" |
|
1954 |
| |
|
1955 |
||
1956 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
|
1957 |
^ 0 |
|
1958 |
]. |
|
1959 |
||
1960 |
prevNode := listOfNodes at:start. |
|
1961 |
currParent := prevNode parent. |
|
1962 |
||
1963 |
currParent isNil ifTrue:[ |
|
1964 |
^ 1 |
|
1965 |
]. |
|
1966 |
||
1967 |
(min := prevNode level) == 2 ifTrue:[ |
|
1968 |
^ min |
|
1969 |
]. |
|
1970 |
beg := start + 1. |
|
1971 |
||
1972 |
listOfNodes from:beg to:end do:[:currNode| |
|
1973 |
(nextParent := currNode parent) == currParent ifFalse:[ |
|
1974 |
(currParent := nextParent) == prevNode ifFalse:[ |
|
1975 |
(lvl := currNode level) == 2 ifTrue:[ |
|
1976 |
^ 2 |
|
1977 |
]. |
|
1978 |
min := min min:lvl |
|
1979 |
] |
|
1980 |
]. |
|
1981 |
prevNode := currNode |
|
1982 |
]. |
|
1983 |
^ min |
|
1984 |
||
1985 |
||
1986 |
||
1987 |
||
1988 |
! |
|
1989 |
||
468 | 1990 |
widthOfContents |
1991 |
"return the width of the contents in pixels |
|
1992 |
- used for scrollbar interface" |
|
1993 |
||
846 | 1994 |
listOfNodes isNil ifTrue:[^ 0]. |
468 | 1995 |
|
1996 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
846 | 1997 |
widthOfWidestLine := self widthOfLongestLine |
468 | 1998 |
]. |
1999 |
^ widthOfWidestLine + (leftMargin * 2) |
|
2000 |
||
2001 |
! |
|
2002 |
||
846 | 2003 |
widthOfLongestLine |
2004 |
"return the width of the longest line in pixels |
|
468 | 2005 |
" |
848 | 2006 |
|parent pItem p |
846 | 2007 |
startX "{ Class: SmallInteger }" |
2008 |
deltaX "{ Class: SmallInteger }" |
|
838 | 2009 |
level "{ Class: SmallInteger }" |
2010 |
width "{ Class: SmallInteger }" |
|
2011 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 2012 |
|
848 | 2013 |
buildInArray atAllPut:0. |
846 | 2014 |
parent := nil. |
2015 |
maxSz := 1. |
|
838 | 2016 |
level := 1. |
846 | 2017 |
|
2018 |
listOfNodes do:[:anItem| |
|
848 | 2019 |
(p := anItem parent) ~~ parent ifTrue:[ |
2020 |
buildInArray at:level put:maxSz. |
|
846 | 2021 |
|
848 | 2022 |
(parent := p) == pItem ifTrue:[level := level + 1] |
2023 |
ifFalse:[level := anItem level]. |
|
2024 |
||
2025 |
maxSz := buildInArray at:level. |
|
846 | 2026 |
]. |
2027 |
pItem := anItem. |
|
2028 |
maxSz := maxSz max:(anItem name size). |
|
2029 |
]. |
|
848 | 2030 |
buildInArray at:level put:maxSz. |
468 | 2031 |
|
846 | 2032 |
startX := self xOfStringLevel:1. |
2033 |
deltaX := imageInset + imageWidth. |
|
2034 |
width := '1' widthOn:self. |
|
2035 |
maxSz := 0. |
|
468 | 2036 |
|
848 | 2037 |
buildInArray do:[:el| |
846 | 2038 |
el == 0 ifTrue:[ ^ maxSz + leftOffset ]. |
2039 |
maxSz := maxSz max:(el * width + startX). |
|
2040 |
startX := startX + deltaX. |
|
468 | 2041 |
]. |
846 | 2042 |
! ! |
2043 |
||
2044 |
!SelectionInTreeView methodsFor:'private redefinitions'! |
|
2045 |
||
2046 |
expandTabs |
|
2047 |
"nothing to do |
|
2048 |
" |
|
838 | 2049 |
|
2050 |
||
468 | 2051 |
! |
2052 |
||
846 | 2053 |
list:aCollection expandTabs:expand scanForNonStrings:scan |
2054 |
||
2055 |
includesNonStrings := false. |
|
2056 |
self list:aCollection expandTabs:false scanForNonStrings:false includesNonStrings:false |
|
2057 |
! |
|
2058 |
||
468 | 2059 |
withoutRedrawAt:anIndex put:aString |
1813 | 2060 |
"change a line without redisplay and WITHOUT any sizeChange notifications. |
2061 |
Somewhat dangerous, since scrollBars will not be informed about contents-changes. |
|
2062 |
Use only if multiple lines are to be changed, and a sizeChanged is invoked by some other |
|
2063 |
means at the end." |
|
468 | 2064 |
|
2065 |
|width| |
|
2066 |
||
2067 |
width := widthOfWidestLine. |
|
2068 |
widthOfWidestLine := nil. |
|
2069 |
super withoutRedrawAt:anIndex put:aString. |
|
846 | 2070 |
widthOfWidestLine := width. |
468 | 2071 |
|
846 | 2072 |
(widthOfWidestLine notNil and:[aString size ~~ 0]) ifTrue:[ |
2073 |
width := self xOfStringNode:(listOfNodes at:anIndex) |
|
2074 |
+ (aString widthOn:self) |
|
2075 |
+ leftOffset. |
|
2076 |
||
838 | 2077 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 2078 |
]. |
2079 |
! ! |
|
2080 |
||
483 | 2081 |
!SelectionInTreeView methodsFor:'queries'! |
2082 |
||
2083 |
figureFor:aNode |
|
1278 | 2084 |
"return a (bitmap) figure for a node" |
2085 |
||
785 | 2086 |
|icon img| |
2087 |
||
1278 | 2088 |
"/ the item may provide an icon |
2089 |
"/ (it knows for itself if its open or closed) |
|
2090 |
||
785 | 2091 |
(icon := aNode icon) notNil ifTrue:[ |
2092 |
img := registeredImages at:icon ifAbsent:nil. |
|
2093 |
img notNil ifTrue:[ |
|
2094 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2095 |
]. |
785 | 2096 |
icon isImage ifTrue:[ |
846 | 2097 |
img := self imageOnDevice:icon. |
785 | 2098 |
registeredImages at:icon put:img. |
1278 | 2099 |
^ img |
785 | 2100 |
] |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2101 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
2102 |
|
1278 | 2103 |
"/ ok, node did not return an icon - use default. |
2104 |
||
846 | 2105 |
aNode hasChildren ifFalse:[ |
1278 | 2106 |
"/ regular |
2107 |
^ imageItem |
|
846 | 2108 |
]. |
1278 | 2109 |
"/ folder |
846 | 2110 |
^ aNode hidden ifTrue:[imageClosed] ifFalse:[imageOpened] |
785 | 2111 |
|
483 | 2112 |
! |
2113 |
||
2114 |
indexOfNode:aNode |
|
2115 |
"returns index of a node |
|
2116 |
" |
|
785 | 2117 |
^ listOfNodes identityIndexOf:aNode |
483 | 2118 |
! |
2119 |
||
494 | 2120 |
xOfFigureLevel:aLevel |
2121 |
"origin x where to draw the icon |
|
2122 |
" |
|
785 | 2123 |
|l "{ Class:SmallInteger }"| |
494 | 2124 |
|
785 | 2125 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 2126 |
|
659 | 2127 |
showDirectoryIndicator ifFalse:[ |
2128 |
l := l - 1 |
|
2129 |
] ifTrue:[ |
|
2130 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
2131 |
l := l - 1 |
|
2132 |
] |
|
2133 |
]. |
|
494 | 2134 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
2135 |
||
2136 |
! |
|
2137 |
||
483 | 2138 |
xOfFigureNode:aNode |
2139 |
"origin x where to draw the icon |
|
2140 |
" |
|
494 | 2141 |
^ self xOfFigureLevel:(aNode level) |
2142 |
! |
|
490 | 2143 |
|
494 | 2144 |
xOfStringLevel:aLevel |
2145 |
"origin x where to draw the text( label ) |
|
2146 |
" |
|
2147 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 2148 |
|
2149 |
! |
|
2150 |
||
2151 |
xOfStringNode:aNode |
|
2152 |
"origin x where to draw the text( label ) |
|
2153 |
" |
|
494 | 2154 |
^ self xOfStringLevel:(aNode level) |
483 | 2155 |
|
1171 | 2156 |
! |
2157 |
||
2158 |
xOfValueNode:aNode |
|
2159 |
"returns the left x position of the start of the value |
|
2160 |
" |
|
2161 |
|p x| |
|
2162 |
||
2163 |
p := aNode parent. |
|
2164 |
||
2165 |
x := p notNil ifTrue:[30 + (p childrenWidthOn:self)] |
|
2166 |
ifFalse:[0]. |
|
2167 |
||
2168 |
^ x + (self xOfStringNode:aNode) |
|
2169 |
||
483 | 2170 |
! ! |
2171 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2172 |
!SelectionInTreeView methodsFor:'scrolling'! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2173 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2174 |
needScrollToMakeLine:aListLineNr |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2175 |
"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
|
2176 |
|
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2177 |
(aListLineNr >= firstLineShown) ifTrue:[ |
1162 | 2178 |
(aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[ |
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2179 |
^ false |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2180 |
] |
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 |
^ true |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2183 |
|
1171 | 2184 |
! |
2185 |
||
2186 |
originChanged:delta |
|
2187 |
"sent after scrolling - have to update origin of editor |
|
2188 |
" |
|
2189 |
super originChanged:delta. |
|
2190 |
||
2191 |
editorWidget notNil ifTrue:[ |
|
2192 |
editorWidget origin:(editorWidget origin - delta) |
|
2193 |
] |
|
2194 |
||
1061
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2195 |
! ! |
8eba9d898259
scroll to bring selection into upper half of view
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
2196 |
|
444 | 2197 |
!SelectionInTreeView methodsFor:'selection'! |
2198 |
||
468 | 2199 |
selectNode:aNode |
2200 |
"change selection to a node |
|
2201 |
" |
|
855 | 2202 |
|index| |
848 | 2203 |
|
860 | 2204 |
(index := aNode) notNil ifTrue:[ |
2205 |
index isNumber ifFalse:[ |
|
2206 |
(index := self indexOfNode:aNode) == 0 ifTrue:[ |
|
2207 |
model doMakeVisible:aNode. |
|
2208 |
index := self indexOfNode:aNode. |
|
2209 |
] |
|
855 | 2210 |
]. |
848 | 2211 |
index == 0 ifTrue:[ |
855 | 2212 |
index := nil |
848 | 2213 |
] |
2214 |
]. |
|
2215 |
self selection:index |
|
468 | 2216 |
|
2217 |
||
2218 |
! |
|
2219 |
||
456 | 2220 |
selectedIndex |
2221 |
"get single selected index or 0 |
|
2222 |
" |
|
483 | 2223 |
selection size == 1 ifTrue:[^ selection first]. |
2224 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 2225 |
^ 0 |
444 | 2226 |
! |
2227 |
||
2228 |
selectedNode |
|
2229 |
"get the single selected node or nil |
|
2230 |
" |
|
456 | 2231 |
|idx| |
2232 |
||
2233 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
2234 |
^ listOfNodes at:idx |
|
444 | 2235 |
]. |
2236 |
^ nil |
|
514 | 2237 |
! |
2238 |
||
2239 |
selectionChangedFrom:oldSelection |
|
2240 |
"update selectionHolder if not nil |
|
2241 |
" |
|
1171 | 2242 |
self closeEditor. |
514 | 2243 |
|
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2244 |
"/ first change my selectionHolders value ... |
514 | 2245 |
selectionHolder notNil ifTrue:[ |
2246 |
self selectionToModel. |
|
2247 |
]. |
|
2248 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2249 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2250 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2251 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
2252 |
|
1171 | 2253 |
! |
2254 |
||
2255 |
setSelection:aSelection |
|
2256 |
"if no selection exists, close the editor |
|
2257 |
" |
|
2258 |
(aSelection isNil or:[aSelection == 0]) ifTrue:[ |
|
2259 |
self closeEditor |
|
2260 |
]. |
|
2261 |
super setSelection:aSelection |
|
2262 |
||
2263 |
||
444 | 2264 |
! ! |
2265 |
||
855 | 2266 |
!SelectionInTreeView methodsFor:'selection actions'! |
507 | 2267 |
|
2268 |
selectedNodeAdd:something |
|
2269 |
"add a node or collection of nodes after selected node |
|
2270 |
" |
|
2271 |
|node| |
|
2272 |
||
2273 |
something notNil ifTrue:[ |
|
2274 |
(node := self selectedNode) notNil ifTrue:[ |
|
2275 |
node parent notNil ifTrue:[ |
|
2276 |
node isCollapsable ifTrue:[ |
|
2277 |
model add:something beforeIndex:1 below:node |
|
2278 |
] ifFalse:[ |
|
2279 |
model add:something after:node |
|
2280 |
] |
|
2281 |
] ifFalse:[ |
|
2282 |
model add:something beforeIndex:1 below:(self root) |
|
2283 |
] |
|
2284 |
] |
|
2285 |
] |
|
2286 |
||
2287 |
! |
|
2288 |
||
2289 |
selectedNodeBecomeChildOfNext |
|
2290 |
"become node a child of followd node |
|
2291 |
" |
|
2292 |
|idx node cprt nprt| |
|
2293 |
||
2294 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
2295 |
idx := cprt indexOfChild:node. |
|
2296 |
||
2297 |
idx == cprt children size ifFalse:[ |
|
2298 |
nprt := cprt childAt:(idx + 1). |
|
2299 |
||
2300 |
nprt notNil ifTrue:[ |
|
855 | 2301 |
self setSelection:nil. |
2302 |
model remove:node. |
|
507 | 2303 |
model add:node beforeIndex:1 below:nprt. |
2304 |
self selectNode:node. |
|
2305 |
] |
|
2306 |
] |
|
2307 |
] |
|
2308 |
! |
|
2309 |
||
2310 |
selectedNodeBecomeSisterOfParent |
|
2311 |
"become node a sister of its current parent |
|
2312 |
" |
|
2313 |
|node cprt nprt| |
|
2314 |
||
2315 |
( (node := self selectedNode) isNil |
|
2316 |
or:[(cprt := node parent) isNil |
|
2317 |
or:[(nprt := cprt parent) isNil]] |
|
2318 |
) ifFalse:[ |
|
855 | 2319 |
self setSelection:nil. |
2320 |
model remove:node. |
|
507 | 2321 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
855 | 2322 |
self selectNode:node. |
507 | 2323 |
] |
2324 |
||
2325 |
! |
|
2326 |
||
2327 |
selectedNodeChangeSequenceOrder:anOffset |
|
2328 |
"move child 'anOffset' forward or backward in list of children |
|
2329 |
" |
|
2330 |
|idx node size parent| |
|
2331 |
||
2332 |
( (node := self selectedNode) notNil |
|
2333 |
and:[(parent := node parent) notNil |
|
2334 |
and:[(size := parent children size) > 1]] |
|
2335 |
) ifTrue:[ |
|
2336 |
idx := parent indexOfChild:node. |
|
855 | 2337 |
self setSelection:nil. |
2338 |
model remove:node. |
|
507 | 2339 |
|
2340 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
2341 |
idx := size |
|
2342 |
] ifFalse:[ |
|
2343 |
idx > size ifTrue:[idx := 1] |
|
2344 |
]. |
|
2345 |
model add:node beforeIndex:idx below:parent. |
|
2346 |
self selectNode:node. |
|
2347 |
] |
|
2348 |
! |
|
2349 |
||
2350 |
selectedNodeExpand:doExpand |
|
2351 |
"collapse or expand selected node |
|
2352 |
" |
|
855 | 2353 |
|node| |
507 | 2354 |
|
855 | 2355 |
(node := self selectedNode) notNil ifTrue:[ |
2356 |
doExpand ifTrue:[model doExpand:node] |
|
2357 |
ifFalse:[model doCollapse:node] |
|
2358 |
] |
|
507 | 2359 |
! |
2360 |
||
2361 |
selectedNodesRemove |
|
2362 |
"remove selected nodes |
|
2363 |
" |
|
855 | 2364 |
|selection| |
2365 |
||
2366 |
selection := self selection. |
|
507 | 2367 |
self selection:nil. |
855 | 2368 |
model remove:selection. |
507 | 2369 |
! ! |
2370 |
||
444 | 2371 |
!SelectionInTreeView class methodsFor:'documentation'! |
2372 |
||
2373 |
version |
|
1822 | 2374 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.91 2000-08-24 19:12:23 cg Exp $' |
444 | 2375 |
! ! |