author | ca |
Tue, 14 Apr 1998 13:31:23 +0200 | |
changeset 855 | 1714ba38f374 |
parent 850 | 70c2c0e9318f |
child 860 | 64d52b8e3dbd |
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 |
||
14 |
SelectionInListView subclass:#SelectionInTreeView |
|
847 | 15 |
instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth |
16 |
showLines listOfNodes imageInset textInset labelOffsetY lineMask |
|
17 |
lineColor computeResources showRoot showDirectoryIndicator |
|
18 |
closeIndicator openIndicator showDirectoryIndicatorForRoot |
|
19 |
imageOpened imageClosed imageItem discardMotionEvents |
|
855 | 20 |
registeredImages supportsExpandAll buildInArray |
21 |
drawVLinesFromLevel' |
|
847 | 22 |
classVariableNames:'' |
23 |
poolDictionaries:'' |
|
24 |
category:'Views-Text' |
|
444 | 25 |
! |
26 |
||
27 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
28 |
||
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
32 |
All Rights Reserved |
|
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
||
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
47 |
lists and adds the functions to show/hide subtrees. |
|
456 | 48 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 49 |
|
456 | 50 |
This class obsoletes SelectionInTreeView, which is no longer |
446 | 51 |
maintained but kept for backward compatibility. |
52 |
||
53 |
||
444 | 54 |
[see also:] |
456 | 55 |
SelectionInTree |
56 |
TreeItem |
|
57 |
SelectionInTreeView |
|
444 | 58 |
SelectionInListView |
494 | 59 |
FileSelectionTree |
444 | 60 |
|
61 |
[author:] |
|
62 |
Claus Atzkern |
|
63 |
" |
|
64 |
||
65 |
! |
|
66 |
||
67 |
examples |
|
68 |
" |
|
69 |
shows the tree of smalltalk classes: |
|
70 |
[exBegin] |
|
514 | 71 |
|top sel| |
456 | 72 |
|
514 | 73 |
top := StandardSystemView new; extent:300@300. |
456 | 74 |
sel := SelectionInTreeView new. |
514 | 75 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
456 | 76 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
77 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
78 |
top open. |
|
79 |
[exEnd] |
|
80 |
||
81 |
||
485 | 82 |
|
456 | 83 |
same, including nil-subclasses (i.e. really all classes): |
84 |
[exBegin] |
|
514 | 85 |
|top sel| |
444 | 86 |
|
514 | 87 |
top := StandardSystemView new; extent:300@300. |
456 | 88 |
sel := SelectionInTreeView new. |
514 | 89 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:nil). |
456 | 90 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
685 | 91 |
sel lineColor:(Color red). |
456 | 92 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
93 |
top open. |
|
94 |
[exEnd] |
|
95 |
||
485 | 96 |
|
483 | 97 |
|
485 | 98 |
shows the tree of smalltalk classes; show directory indication and no |
99 |
lines. |
|
100 |
[exBegin] |
|
514 | 101 |
|top sel| |
483 | 102 |
|
514 | 103 |
top := StandardSystemView new; extent:300@300. |
483 | 104 |
sel := SelectionInTreeView new. |
485 | 105 |
sel showLines:false. |
106 |
sel showDirectoryIndicator:true. |
|
514 | 107 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
485 | 108 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 109 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
110 |
top open. |
|
485 | 111 |
[exEnd] |
112 |
" |
|
113 |
||
514 | 114 |
|
444 | 115 |
! ! |
116 |
||
117 |
!SelectionInTreeView class methodsFor:'constants'! |
|
118 |
||
494 | 119 |
minImageInset |
120 |
"returns minimum inset from directory indication to image |
|
471 | 121 |
" |
494 | 122 |
^ 6 |
490 | 123 |
|
124 |
||
125 |
! ! |
|
126 |
||
811 | 127 |
!SelectionInTreeView class methodsFor:'resources'! |
490 | 128 |
|
129 |
closeIndicator |
|
589 | 130 |
<resource: #fileImage> |
131 |
||
811 | 132 |
^ Icon |
133 |
constantNamed:#plus |
|
134 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/plus.xpm')] |
|
135 |
||
589 | 136 |
|
811 | 137 |
|
138 |
||
139 |
||
140 |
||
471 | 141 |
! |
142 |
||
444 | 143 |
imageClosed |
589 | 144 |
<resource: #fileImage> |
145 |
||
811 | 146 |
^ Icon |
147 |
constantNamed:#directory |
|
148 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm')] |
|
444 | 149 |
|
150 |
! |
|
151 |
||
152 |
imageItem |
|
589 | 153 |
<resource: #fileImage> |
154 |
||
811 | 155 |
^ Icon |
156 |
constantNamed:#plainFile |
|
157 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm')] |
|
444 | 158 |
|
811 | 159 |
|
444 | 160 |
|
811 | 161 |
|
162 |
||
444 | 163 |
! |
164 |
||
165 |
imageOpened |
|
589 | 166 |
<resource: #fileImage> |
167 |
||
811 | 168 |
^ Icon |
169 |
constantNamed:#directoryOpened |
|
170 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm')] |
|
444 | 171 |
|
490 | 172 |
! |
173 |
||
174 |
openIndicator |
|
589 | 175 |
<resource: #fileImage> |
176 |
||
811 | 177 |
^ Icon |
178 |
constantNamed:#minus |
|
179 |
ifAbsentPut:[Image fromFile:('xpmBitmaps/minus.xpm')] |
|
490 | 180 |
|
811 | 181 |
|
444 | 182 |
! ! |
183 |
||
184 |
!SelectionInTreeView methodsFor:'accessing'! |
|
185 |
||
685 | 186 |
lineColor |
187 |
"returns user configured line color or nil |
|
188 |
" |
|
189 |
^ lineColor |
|
190 |
||
191 |
! |
|
192 |
||
193 |
lineColor:aColor |
|
194 |
"returns user configured line color or nil |
|
195 |
" |
|
196 |
|col| |
|
197 |
||
198 |
col := aColor = fgColor ifTrue:[nil] ifFalse:[aColor]. |
|
199 |
||
200 |
col = lineColor ifFalse:[ |
|
201 |
lineColor := col. |
|
202 |
||
203 |
shown ifTrue:[ |
|
204 |
lineColor notNil ifTrue:[lineColor := lineColor on:device]. |
|
205 |
self invalidate |
|
206 |
] |
|
207 |
] |
|
208 |
! |
|
209 |
||
490 | 210 |
nodeAtIndex:anIndex |
211 |
"returns node at an index or nil |
|
212 |
" |
|
785 | 213 |
(anIndex notNil and:[anIndex between:1 and:listOfNodes size]) ifTrue:[ |
490 | 214 |
^ listOfNodes at:anIndex |
215 |
]. |
|
216 |
^ nil |
|
217 |
! |
|
218 |
||
507 | 219 |
root |
220 |
"gets the root of the model; the first item into list. |
|
221 |
" |
|
222 |
^ self nodeAtIndex:1 |
|
223 |
! |
|
224 |
||
225 |
root:aRoot |
|
226 |
"sets the root of the model; the first item into list. |
|
227 |
" |
|
514 | 228 |
aRoot notNil ifTrue:[aRoot expand]. |
507 | 229 |
model root:aRoot |
230 |
! |
|
231 |
||
490 | 232 |
textInset |
233 |
"get the left inset of the text label |
|
234 |
" |
|
235 |
^ textInset |
|
236 |
! |
|
237 |
||
238 |
textInset:anInset |
|
239 |
"set the left inset of the text label |
|
240 |
" |
|
241 |
anInset ~~ textInset ifTrue:[ |
|
242 |
anInset >= 0 ifTrue:[ |
|
243 |
textInset := anInset. |
|
244 |
self invalidate |
|
245 |
] ifFalse:[ |
|
246 |
self error |
|
247 |
] |
|
248 |
]. |
|
249 |
! ! |
|
250 |
||
251 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
252 |
||
855 | 253 |
drawVLinesFromLevel |
254 |
"returns the level vertical lines are drawn from; |
|
255 |
starting at 1 up to n |
|
256 |
" |
|
257 |
^ drawVLinesFromLevel |
|
258 |
! |
|
259 |
||
260 |
drawVLinesFromLevel:aLevel |
|
261 |
"set the level vertical lines are drawn from; |
|
262 |
starting at 1 up to n |
|
263 |
" |
|
264 |
|lv| |
|
265 |
||
266 |
lv := (aLevel ? 1) max:1. |
|
267 |
||
268 |
lv ~~ drawVLinesFromLevel ifTrue:[ |
|
269 |
drawVLinesFromLevel := lv. |
|
270 |
self invalidate |
|
271 |
] |
|
272 |
! |
|
273 |
||
490 | 274 |
showDirectoryIndicator |
275 |
"returns true if directories has an open/closed indicator |
|
276 |
" |
|
277 |
^ showDirectoryIndicator |
|
278 |
! |
|
279 |
||
280 |
showDirectoryIndicator:aState |
|
281 |
"set or clear open/closed indicator for directories |
|
282 |
" |
|
283 |
"show or hide lines |
|
284 |
" |
|
285 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
494 | 286 |
showDirectoryIndicator := aState. |
546 | 287 |
self recomputeDirectoryIndicator. |
490 | 288 |
self invalidate |
289 |
]. |
|
290 |
! |
|
291 |
||
659 | 292 |
showDirectoryIndicatorForRoot |
293 |
"returns true if root directory has an open/closed indicator if |
|
294 |
the common showDirectoryIndicator is enabled |
|
295 |
" |
|
296 |
^ showDirectoryIndicatorForRoot |
|
297 |
! |
|
298 |
||
299 |
showDirectoryIndicatorForRoot:aState |
|
300 |
"true if root directory has an open/closed indicator if |
|
301 |
the common showDirectoryIndicator is enabled |
|
302 |
" |
|
303 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
304 |
showDirectoryIndicatorForRoot := aState. |
|
305 |
self recomputeDirectoryIndicator. |
|
306 |
self invalidate |
|
307 |
]. |
|
308 |
! |
|
309 |
||
490 | 310 |
showLines |
311 |
"returns true if lines are shown |
|
312 |
" |
|
313 |
^ showLines |
|
314 |
! |
|
315 |
||
316 |
showLines:aState |
|
317 |
"show or hide lines |
|
318 |
" |
|
319 |
aState ~~ showLines ifTrue:[ |
|
320 |
showLines := aState. |
|
321 |
self invalidate |
|
322 |
]. |
|
494 | 323 |
! |
324 |
||
325 |
showRoot |
|
326 |
"list with or without root |
|
327 |
" |
|
328 |
^ showRoot |
|
329 |
! |
|
330 |
||
331 |
showRoot:aState |
|
332 |
"list with or without root |
|
333 |
" |
|
334 |
showRoot ~~ aState ifTrue:[ |
|
514 | 335 |
model showRoot:(showRoot := aState) |
336 |
]. |
|
517 | 337 |
! |
338 |
||
835 | 339 |
supportsExpandAll |
340 |
^ supportsExpandAll |
|
341 |
! |
|
342 |
||
343 |
supportsExpandAll:aBool |
|
344 |
||
345 |
supportsExpandAll := aBool |
|
346 |
! |
|
347 |
||
517 | 348 |
validateDoubleClickBlock |
349 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
350 |
on a node will be performed. In case of returning false, the doubleClick will |
|
351 |
not be handled. |
|
352 |
" |
|
353 |
^ validateDoubleClickBlock |
|
354 |
||
355 |
||
356 |
! |
|
357 |
||
358 |
validateDoubleClickBlock:aOneArgBlock |
|
359 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
360 |
on a node will be performed. In case of returning false, the doubleClick will |
|
361 |
not be handled. |
|
362 |
" |
|
363 |
validateDoubleClickBlock := aOneArgBlock |
|
364 |
||
365 |
||
514 | 366 |
! ! |
367 |
||
368 |
!SelectionInTreeView methodsFor:'accessing-channels'! |
|
369 |
||
370 |
rootHolder |
|
371 |
"get the holder which keeps the hierarchical list entry or nil |
|
372 |
" |
|
373 |
^ rootHolder |
|
374 |
! |
|
375 |
||
376 |
rootHolder:aValueHolder |
|
377 |
"set the holder which keeps the hierarchical list entry or nil |
|
378 |
" |
|
379 |
rootHolder notNil ifTrue:[ |
|
380 |
rootHolder removeDependent:self |
|
381 |
]. |
|
855 | 382 |
|
514 | 383 |
(rootHolder := aValueHolder) notNil ifTrue:[ |
384 |
rootHolder addDependent:self. |
|
385 |
self rootFromModel. |
|
494 | 386 |
]. |
514 | 387 |
! |
388 |
||
389 |
selectionHolder |
|
390 |
"get the holder which keeps a list of selected items or nil |
|
391 |
" |
|
392 |
^ selectionHolder |
|
393 |
||
394 |
! |
|
395 |
||
396 |
selectionHolder:aHolder |
|
397 |
"set the holder which keeps a list of selected items or nil |
|
398 |
" |
|
399 |
selectionHolder notNil ifTrue:[ |
|
400 |
selectionHolder removeDependent:self |
|
401 |
]. |
|
402 |
||
403 |
(selectionHolder := aHolder) notNil ifTrue:[ |
|
404 |
selectionHolder addDependent:self. |
|
405 |
self selectionFromModel |
|
406 |
]. |
|
407 |
||
490 | 408 |
! ! |
409 |
||
410 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
411 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
412 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
413 |
"return the value of the instance variable 'imageClosed' (automatically generated)" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
414 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
415 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
416 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
417 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
418 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
419 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
420 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
421 |
"return the value of the instance variable 'imageItem' (automatically generated)" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
422 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
423 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
424 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
425 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
426 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
427 |
|
569 | 428 |
imageOnDevice:anImage |
846 | 429 |
"associate image to device and clear pixel mask (in case of realized); |
569 | 430 |
returns the new image. |
431 |
" |
|
432 |
|img| |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
433 |
|
846 | 434 |
img := anImage. |
569 | 435 |
|
846 | 436 |
img device ~~ device ifTrue:[ |
437 |
img := img copy. |
|
569 | 438 |
]. |
846 | 439 |
img := img on:device. |
440 |
img := img clearMaskedPixels. |
|
441 |
^ img |
|
442 |
||
448
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 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
445 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
446 |
"return the value of the instance variable 'imageOpened' (automatically generated)" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
447 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
448 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
449 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
450 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 451 |
! ! |
452 |
||
514 | 453 |
!SelectionInTreeView methodsFor:'change & update'! |
454 |
||
855 | 455 |
modelChanged:what with:aPara |
456 |
"hierarchical list changed |
|
457 |
" |
|
458 |
|start size visLn h y0 y1 cY parent pvLv ndLv| |
|
459 |
||
460 |
aPara isNil ifTrue:[ |
|
461 |
what == #list ifTrue:[ self getListFromModel ] |
|
462 |
ifFalse:[ super update:what with:aPara from:model ]. |
|
463 |
^ self |
|
464 |
]. |
|
465 |
||
466 |
(what == #insertCollection: or:[what == #removeFrom:]) ifFalse:[ |
|
467 |
what == #at: ifTrue:[ ^ self redrawLine:aPara ]. |
|
468 |
what == #replace ifTrue:[ ^ self invalidateRepairNow:true ]. |
|
469 |
||
470 |
^ super update:what with:aPara from:model. |
|
471 |
]. |
|
472 |
list := self listFromModel. |
|
473 |
||
474 |
shown ifFalse:[ |
|
475 |
^ self contentsChanged |
|
476 |
]. |
|
477 |
(self sensor notNil and: [self sensor hasExposeEventFor:self]) ifTrue:[ "/ outstanding expose events |
|
478 |
self invalidateRepairNow:true. |
|
479 |
^ self contentsChanged |
|
480 |
]. |
|
481 |
||
482 |
start := aPara at:1. |
|
483 |
size := aPara at:2. |
|
484 |
parent := aPara at:3. |
|
485 |
||
486 |
start > 1 ifTrue:[ |
|
487 |
pvLv := (list at:start - 1) level. |
|
488 |
ndLv := parent level + 1. |
|
489 |
||
490 |
ndLv < pvLv ifTrue:[ |
|
491 |
what == #insertCollection: ifTrue:[ |
|
492 |
visLn := start + size. |
|
493 |
] ifFalse:[ |
|
494 |
visLn := start. |
|
495 |
]. |
|
496 |
||
497 |
(visLn > list size or:[(list at:visLn) level ~~ ndLv]) ifTrue:[ |
|
498 |
[(start := start - 1) ~~ 1] whileTrue:[ |
|
499 |
(list at:start) level <= ndLv ifTrue:[ |
|
500 |
self redrawFromLine:start. |
|
501 |
^ self contentsChanged. |
|
502 |
] |
|
503 |
]. |
|
504 |
self invalidateRepairNow:true. |
|
505 |
^ self contentsChanged |
|
506 |
] |
|
507 |
]. |
|
508 |
self redrawIconAndIndicatorAt:(start - 1) |
|
509 |
]. |
|
510 |
(visLn := self listLineToVisibleLine:start) isNil ifTrue:[ |
|
511 |
^ self contentsChanged |
|
512 |
]. |
|
513 |
||
514 |
h := size * fontHeight. |
|
515 |
y0 := self yOfVisibleLine:visLn. |
|
516 |
y1 := y0 + h. |
|
517 |
cY := height - y1 - 1. |
|
518 |
||
519 |
cY < 40 ifTrue:[ |
|
520 |
self redrawFromLine:start. |
|
521 |
] ifFalse:[ |
|
522 |
self catchExpose. |
|
523 |
||
524 |
what == #insertCollection: ifTrue:[ |
|
525 |
self copyFrom:self x:0 y:y0 toX:0 y:y1 width:width height:cY async:true. |
|
526 |
] ifFalse:[ |
|
527 |
self copyFrom:self x:0 y:y1 toX:0 y:y0 width:width height:cY async:true. |
|
528 |
y0 := y0 + cY. |
|
529 |
h := height - y0. |
|
530 |
]. |
|
531 |
self redrawX:0 y:y0 width:width height:h. |
|
532 |
self waitForExpose. |
|
533 |
]. |
|
534 |
device flush. |
|
535 |
self contentsChanged. |
|
536 |
! |
|
537 |
||
514 | 538 |
update:something with:aParameter from:aModel |
539 |
"one of my models changed its value |
|
785 | 540 |
" |
541 |
|idx| |
|
542 |
||
514 | 543 |
aModel == rootHolder ifTrue:[ |
544 |
^ self rootFromModel |
|
545 |
]. |
|
855 | 546 |
|
514 | 547 |
aModel == selectionHolder ifTrue:[ |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
548 |
^ self selectionFromModel |
514 | 549 |
]. |
550 |
||
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
551 |
aModel == model ifTrue:[ |
855 | 552 |
^ self modelChanged:something with:aParameter |
553 |
]. |
|
554 |
||
555 |
(aModel isKindOf:TreeItem) ifTrue:[ |
|
556 |
(something == #size or:[something == #children]) ifTrue:[ |
|
557 |
model recomputeList. |
|
558 |
^ self |
|
559 |
]. |
|
560 |
||
561 |
(idx := self indexOfNode:aModel) ~~ 0 ifTrue:[ |
|
562 |
something == #value ifTrue:[ |
|
563 |
^ self redrawLine:idx. |
|
785 | 564 |
]. |
811 | 565 |
|
855 | 566 |
something == #indication ifTrue:[ |
567 |
^ self redrawIndicatorLine:idx. |
|
811 | 568 |
]. |
855 | 569 |
]. |
570 |
^ self |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
571 |
]. |
855 | 572 |
super update:something with:aParameter from:aModel. |
811 | 573 |
|
514 | 574 |
! ! |
575 |
||
444 | 576 |
!SelectionInTreeView methodsFor:'drawing'! |
577 |
||
848 | 578 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
579 |
"redraw a visible line range with clearing the background |
|
580 |
" |
|
581 |
|y0 y1 sz| |
|
582 |
||
583 |
shown ifTrue:[ |
|
584 |
y0 := self yOfVisibleLine:startVisLineNr. |
|
585 |
y0 := y0 - 1. |
|
586 |
sz := endVisLineNr - startVisLineNr + 1. |
|
587 |
y1 := sz * fontHeight. |
|
588 |
||
589 |
"/ clear rectangle line and set background color |
|
590 |
self paint:bg. |
|
591 |
self fillRectangleX:0 y:y0 width:width height:y1. |
|
592 |
||
593 |
(y1 := self visibleLineToAbsoluteLine:startVisLineNr) notNil ifTrue:[ |
|
594 |
self redrawLinesX:0 y:y0 toX:width start:y1 stop:(y1 + sz) |
|
595 |
] |
|
596 |
] |
|
597 |
! |
|
598 |
||
481 | 599 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
600 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 601 |
|
602 |
! |
|
603 |
||
604 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 605 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 606 |
|
607 |
! |
|
608 |
||
609 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 610 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 611 |
|
612 |
! |
|
613 |
||
614 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 615 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 616 |
|
617 |
! |
|
618 |
||
619 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 620 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
621 |
||
444 | 622 |
! |
623 |
||
624 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 625 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 626 |
|
846 | 627 |
! |
628 |
||
629 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
630 |
self redrawX:0 |
|
631 |
y:(self yOfVisibleLine:startVisLineNr) |
|
632 |
width:width |
|
633 |
height:(endVisLineNr - startVisLineNr + 1 * fontHeight) |
|
634 |
||
635 |
||
848 | 636 |
! |
444 | 637 |
|
848 | 638 |
redrawIconAndIndicatorAt:aLnNr |
639 |
|visLineNr x0 x1 lv| |
|
481 | 640 |
|
769 | 641 |
shown ifTrue:[ |
848 | 642 |
visLineNr := self listLineToVisibleLine:aLnNr. |
643 |
visLineNr notNil ifTrue:[ |
|
644 |
lv := (listOfNodes at:aLnNr) level. |
|
645 |
x1 := (imageWidth + (self xOfFigureLevel:lv)) min:width. |
|
646 |
x0 := (self xOfFigureLevel:(lv - 1)) max:0. |
|
769 | 647 |
|
848 | 648 |
(x0 > width or:[x1 < 0]) ifFalse:[ |
649 |
self redrawX:x0 |
|
650 |
y:(self yOfVisibleLine:visLineNr) |
|
651 |
width:(x1 - x0) |
|
652 |
height:fontHeight |
|
653 |
] |
|
769 | 654 |
] |
848 | 655 |
]. |
769 | 656 |
! |
657 |
||
811 | 658 |
redrawIndicatorLine:aLineNr |
659 |
"redraw the directory indicator for a line |
|
660 |
" |
|
661 |
|node ext img visLn |
|
662 |
x "{ Class:SmallInteger }" |
|
663 |
y "{ Class:SmallInteger }" |
|
664 |
dX "{ Class:SmallInteger }" |
|
665 |
| |
|
666 |
||
667 |
( shown |
|
668 |
and:[showDirectoryIndicator |
|
669 |
and:[(visLn := self listLineToVisibleLine:aLineNr) notNil]] |
|
670 |
) ifFalse:[ |
|
671 |
^ self |
|
672 |
]. |
|
673 |
||
674 |
node := listOfNodes at:aLineNr. |
|
675 |
||
846 | 676 |
(node parent notNil or:[showDirectoryIndicatorForRoot]) ifFalse:[ |
811 | 677 |
^ self |
678 |
]. |
|
679 |
||
846 | 680 |
x := imageWidth // 2. |
681 |
x := x + (self xOfFigureLevel:(node level - 1)). |
|
811 | 682 |
|
683 |
"/ draw directory indicator |
|
684 |
||
685 |
img := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
|
686 |
ext := img extent // 2. |
|
687 |
dX := ext x. |
|
688 |
||
689 |
(x + dX > 0 and:[(x := x - dX) < (width - margin)]) ifTrue:[ |
|
690 |
(self isInSelection:aLineNr) ifTrue:[ self paint:hilightFgColor on:hilightBgColor ] |
|
691 |
ifFalse:[ self paint:fgColor on:bgColor ]. |
|
692 |
||
693 |
y := (self yOfVisibleLine:visLn) + (fontHeight // 2) - 1. |
|
694 |
self displayForm:img x:x y:(y - ext y) |
|
695 |
]. |
|
696 |
||
697 |
||
698 |
||
848 | 699 |
! ! |
700 |
||
701 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
702 |
||
703 |
drawLabelIndex:anIndex atX:x y:yCenter |
|
704 |
"draw text label at x and y centered |
|
705 |
" |
|
706 |
|lbl y| |
|
707 |
||
708 |
(lbl := (listOfNodes at:anIndex) name) notNil ifTrue:[ |
|
709 |
y := yCenter + labelOffsetY. |
|
710 |
self displayOpaqueString:lbl x:x y:y. |
|
711 |
] |
|
712 |
! |
|
713 |
||
714 |
drawVHLinesX:x0 y:y0 toX:x1 start:start stop:stop |
|
715 |
"redraw from line to line without clearing the background |
|
716 |
" |
|
717 |
|node prevNode parent p1 p2 showVLines showHLine lv nxtPrnt |
|
718 |
||
719 |
x "{ Class:SmallInteger }" |
|
720 |
y "{ Class:SmallInteger }" |
|
721 |
||
722 |
yTop "{ Class:SmallInteger }" |
|
723 |
yBot "{ Class:SmallInteger }" |
|
724 |
yCtr "{ Class:SmallInteger }" |
|
725 |
||
726 |
begHLnY "{ Class:SmallInteger }" |
|
727 |
begHLnX "{ Class:SmallInteger }" |
|
728 |
endHLnX "{ Class:SmallInteger }" |
|
729 |
||
730 |
widthLvl "{ Class:SmallInteger }" |
|
731 |
offsHLnX "{ Class:SmallInteger }" |
|
732 |
||
733 |
level "{ Class:SmallInteger }" |
|
855 | 734 |
startLvI "{ Class:SmallInteger }" |
735 |
startLvX "{ Class:SmallInteger }" |
|
736 |
limitLvI "{ Class:SmallInteger }" |
|
737 |
limitLvX "{ Class:SmallInteger }" |
|
848 | 738 |
| |
739 |
yBot := y0. |
|
740 |
yCtr := yBot - (fontHeight // 2). |
|
741 |
widthLvl := imageInset + imageWidth. |
|
742 |
offsHLnX := imageWidth // 2 + (self xOfFigureLevel:-1). |
|
743 |
||
744 |
parent := 4711. "/ to force a recompute |
|
745 |
prevNode := 4711. "/ to force a recomputation of the level |
|
746 |
||
747 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
748 |
self paint:lineColor on:bgColor. |
|
749 |
self mask:lineMask. |
|
750 |
begHLnY := y0. |
|
855 | 751 |
startLvI := self smallestLevelOfNodesBetween:start and:stop. |
752 |
startLvX := self xOfFigureLevel:startLvI. |
|
753 |
limitLvI := drawVLinesFromLevel + 1. |
|
754 |
limitLvX := limitLvI * widthLvl + offsHLnX. |
|
848 | 755 |
|
756 |
buildInArray atAllPut:0. |
|
757 |
||
758 |
start == 1 ifTrue:[ |
|
759 |
begHLnY := yCtr + fontHeight. |
|
760 |
]. |
|
761 |
||
762 |
start to:stop do:[:anIndex| |
|
763 |
node := listOfNodes at:anIndex. |
|
764 |
yTop := yBot - 1. |
|
765 |
yBot := yBot + fontHeight. |
|
766 |
yCtr := yCtr + fontHeight. |
|
767 |
||
768 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
|
769 |
parent := nxtPrnt. |
|
770 |
||
771 |
prevNode == parent ifTrue:[ |
|
772 |
level := level + 1. |
|
773 |
begHLnX := endHLnX. |
|
774 |
] ifFalse:[ |
|
775 |
level := node level. |
|
776 |
begHLnX := node level * widthLvl + offsHLnX. |
|
777 |
]. |
|
778 |
||
779 |
endHLnX := begHLnX + widthLvl. |
|
855 | 780 |
showVLines := begHLnX >= x0 and:[level > drawVLinesFromLevel]. |
848 | 781 |
showHLine := ( x0 < endHLnX |
782 |
and:[x1 > begHLnX |
|
783 |
and:[( parent notNil |
|
784 |
or:[showDirectoryIndicatorForRoot |
|
785 |
and:[showDirectoryIndicator]] |
|
786 |
) |
|
787 |
]] |
|
788 |
). |
|
789 |
]. |
|
790 |
||
791 |
showHLine ifTrue:[ |
|
792 |
self displayLineFromX:begHLnX y:yCtr toX:endHLnX y:yCtr |
|
793 |
]. |
|
794 |
||
795 |
showVLines ifTrue:[ |
|
796 |
y := (parent basicLastChild == node) ifTrue:[yCtr] ifFalse:[yBot]. |
|
797 |
x := begHLnX. |
|
798 |
p2 := parent. |
|
799 |
lv := level - 1. |
|
800 |
self displayLineFromX:x y:begHLnY toX:x y:y. |
|
801 |
||
855 | 802 |
[((p1 := p2 parent) notNil and:[(x := x - widthLvl) >= limitLvX])] whileTrue:[ |
848 | 803 |
(p1 basicLastChild ~~ p2 and:[x <= x1]) ifTrue:[ |
855 | 804 |
x >= startLvX ifTrue:[ |
848 | 805 |
self displayLineFromX:x y:yTop toX:x y:yBot |
806 |
] ifFalse:[ |
|
807 |
buildInArray at:lv put:yBot |
|
808 |
]. |
|
809 |
]. |
|
810 |
lv := lv - 1. |
|
811 |
p2 := p1 |
|
812 |
] |
|
813 |
]. |
|
814 |
prevNode := node. |
|
815 |
begHLnY := yCtr. |
|
816 |
]. |
|
817 |
||
855 | 818 |
"/ |
819 |
"/ draw outstanding verical lines to left |
|
820 |
"/ |
|
821 |
x := limitLvX. |
|
822 |
y := (start ~~ 1) ifTrue:[y0] ifFalse:[y0 + (fontHeight // 2)]. |
|
848 | 823 |
|
855 | 824 |
limitLvI to:startLvI do:[:i| |
825 |
(yBot := buildInArray at:i) ~~ 0 ifTrue:[ |
|
826 |
self displayLineFromX:x y:y toX:x y:yBot |
|
827 |
]. |
|
828 |
x := x + widthLvl. |
|
848 | 829 |
]. |
830 |
self mask:nil. |
|
831 |
||
811 | 832 |
! |
833 |
||
769 | 834 |
redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop |
835 |
"redraw from line to line without clearing the background |
|
836 |
" |
|
848 | 837 |
|node prevNode parent icon showIndc showIcon showText nxtPrnt |
846 | 838 |
|
839 |
x "{ Class:SmallInteger }" |
|
840 |
y "{ Class:SmallInteger }" |
|
841 |
end "{ Class:SmallInteger }" |
|
842 |
||
843 |
yBot "{ Class:SmallInteger }" |
|
844 |
yCtr "{ Class:SmallInteger }" |
|
845 |
||
848 | 846 |
xIndc "{ Class:SmallInteger }" |
846 | 847 |
xIcon "{ Class:SmallInteger }" |
848 |
xText "{ Class:SmallInteger }" |
|
849 |
||
850 |
soVDt "{ Class:SmallInteger }" |
|
851 |
||
852 |
widthLvl "{ Class:SmallInteger }" |
|
853 |
insetTxt "{ Class:SmallInteger }" |
|
848 | 854 |
|
855 |
offIndcX "{ Class:SmallInteger }" |
|
856 |
offIndcY "{ Class:SmallInteger }" |
|
857 |
offIconX "{ Class:SmallInteger }" |
|
769 | 858 |
| |
848 | 859 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
860 |
^ self |
|
861 |
]. |
|
846 | 862 |
yBot := y0. |
863 |
yCtr := yBot - (fontHeight // 2). |
|
864 |
widthLvl := imageInset + imageWidth. |
|
865 |
insetTxt := imageWidth + textInset. |
|
848 | 866 |
offIconX := self xOfFigureLevel:0. |
867 |
showIndc := false. |
|
846 | 868 |
|
869 |
showDirectoryIndicator ifTrue:[ |
|
848 | 870 |
icon := openIndicator extent // 2. |
871 |
offIndcX := imageWidth // 2 - widthLvl - icon x. |
|
872 |
offIndcY := icon y. |
|
846 | 873 |
]. |
785 | 874 |
|
875 |
showLines ifTrue:[ |
|
848 | 876 |
self drawVHLinesX:x0 y:y0 toX:x1 start:start stop:end |
785 | 877 |
]. |
485 | 878 |
|
846 | 879 |
parent := 4711. "/ to force a recompute |
880 |
prevNode := 4711. "/ to force a recomputation of the level |
|
881 |
||
882 |
start to:end do:[:anIndex| |
|
883 |
node := listOfNodes at:anIndex. |
|
884 |
yBot := yBot + fontHeight. |
|
494 | 885 |
yCtr := yCtr + fontHeight. |
485 | 886 |
|
848 | 887 |
(nxtPrnt := node parent) ~~ parent ifTrue:[ |
888 |
parent := nxtPrnt. |
|
889 |
xIcon := prevNode == parent ifTrue:[xIcon + widthLvl] |
|
890 |
ifFalse:[node level * widthLvl + offIconX]. |
|
481 | 891 |
|
848 | 892 |
xText := xIcon + insetTxt. |
893 |
showIcon := xIcon < x1 and:[xText > x0]. |
|
894 |
showText := xText < x1. |
|
769 | 895 |
|
848 | 896 |
showDirectoryIndicator ifTrue:[ |
897 |
xIndc := xIcon + offIndcX. |
|
481 | 898 |
|
848 | 899 |
showIndc := ( (parent notNil or:[showDirectoryIndicatorForRoot]) |
900 |
and:[(xIcon > x0 and:[xIndc < x1])] |
|
901 |
) |
|
902 |
] |
|
785 | 903 |
]. |
481 | 904 |
|
846 | 905 |
(showIcon and:[(icon := self figureFor:node) notNil]) ifTrue:[ |
906 |
self displayForm:icon x:xIcon y:(yCtr - (icon height // 2)) |
|
770 | 907 |
]. |
848 | 908 |
|
846 | 909 |
showText ifTrue:[ |
848 | 910 |
(self isInSelection:anIndex) ifFalse:[ |
911 |
self paint:fgColor on:bgColor |
|
912 |
] ifTrue:[ |
|
913 |
self paint:hilightFgColor on:hilightBgColor |
|
914 |
]. |
|
846 | 915 |
self drawLabelIndex:anIndex atX:xText y:yCtr . |
485 | 916 |
]. |
848 | 917 |
(showIndc and:[node showIndicator]) ifTrue:[ |
846 | 918 |
icon := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator]. |
848 | 919 |
self displayForm:icon x:xIndc y:(yCtr - offIndcY) |
846 | 920 |
]. |
921 |
prevNode := node. |
|
769 | 922 |
] |
792 | 923 |
! |
924 |
||
925 |
redrawSelFrameForYs:aList fromX:x0 toX:x1 |
|
926 |
"redraw selection frames for each line starting at an absolute |
|
927 |
y derived from the argument a list. |
|
928 |
" |
|
929 |
| |
|
930 |
spc "{ Class: SmallInteger }" |
|
931 |
dY "{ Class: SmallInteger }" |
|
932 |
w "{ Class: SmallInteger }" |
|
933 |
y "{ Class: SmallInteger }" |
|
934 |
x "{ Class: SmallInteger }" |
|
935 |
| |
|
850 | 936 |
aList isNil ifTrue:[ |
937 |
^ self |
|
938 |
]. |
|
792 | 939 |
strikeOut ifTrue:[ |
940 |
y := fontHeight // 2. |
|
941 |
self paint:bgColor. |
|
942 |
aList do:[:sY| self displayLineFromX:x0 y:(sY + y) toX:x1 y:(sY + y) ]. |
|
943 |
^ self |
|
944 |
]. |
|
945 |
spc := lineSpacing // 2. |
|
946 |
||
947 |
hilightFrameColor notNil ifTrue:[ |
|
948 |
hilightLevel == 0 ifTrue:[ |
|
949 |
dY := fontHeight - 1. |
|
950 |
self paint:hilightFrameColor. |
|
951 |
||
952 |
aList do:[:sY| |
|
953 |
y := sY - spc. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
954 |
y := y + dY. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
846 | 955 |
]. |
792 | 956 |
] |
957 |
] ifFalse:[ |
|
958 |
hilightStyle == #motif ifTrue:[ |
|
959 |
dY := fontHeight - spc - 2. |
|
960 |
self paint:bgColor. |
|
961 |
||
962 |
aList do:[:sY| |
|
963 |
y := sY - spc + 1. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
964 |
y := sY + dY. self displayLineFromX:x0 y:y toX:x1 y:y. |
|
965 |
] |
|
966 |
] |
|
967 |
]. |
|
968 |
||
969 |
hilightLevel ~~ 0 ifTrue:[ |
|
970 |
"/ draw edge |
|
971 |
||
972 |
w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset. |
|
973 |
x := margin - leftOffset. |
|
974 |
||
975 |
aList do:[:sY| |
|
976 |
self drawEdgesForX:x y:(sY - spc) width:w height:fontHeight level:hilightLevel. |
|
977 |
] |
|
978 |
] |
|
979 |
||
980 |
||
981 |
||
444 | 982 |
! ! |
983 |
||
494 | 984 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 985 |
|
494 | 986 |
detectNode:aOneArgBlock |
987 |
"evaluate the argument, aBlock for each node in the list until |
|
988 |
the block returns true; in this case return the node which caused |
|
989 |
the true evaluation. If none node is detected, nil is returned. |
|
990 |
" |
|
991 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 992 |
! |
993 |
||
994 |
selectedNodesDo:aOneArgBlock |
|
995 |
"evaluate the block on each node selected |
|
996 |
" |
|
997 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 998 |
! ! |
999 |
||
569 | 1000 |
!SelectionInTreeView methodsFor:'event handling'! |
1001 |
||
639 | 1002 |
buttonMotion:buttonMask x:x y:y |
1003 |
"mouse-move while button was pressed - handle selection changes" |
|
1004 |
||
1005 |
discardMotionEvents ifFalse:[ |
|
1006 |
super buttonMotion:buttonMask x:x y:y |
|
1007 |
] |
|
1008 |
||
1009 |
||
1010 |
! |
|
1011 |
||
569 | 1012 |
buttonMultiPress:button x:x y:y |
1013 |
||
1014 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
1015 |
^ super buttonMultiPress:button x:x y:y |
|
1016 |
]. |
|
1017 |
"/ discard doubleClick on indicator |
|
1018 |
! |
|
1019 |
||
1020 |
buttonPress:button x:x y:y |
|
1021 |
"check for indicator |
|
1022 |
" |
|
855 | 1023 |
|expand node lineNr sensor isExpd| |
569 | 1024 |
|
1025 |
lineNr := self indicatiorLineForButton:button atX:x y:y. |
|
1026 |
||
1027 |
lineNr == 0 ifTrue:[ |
|
1028 |
^ super buttonPress:button x:x y:y |
|
1029 |
]. |
|
1030 |
node := listOfNodes at:lineNr. |
|
1031 |
||
639 | 1032 |
discardMotionEvents := true. |
569 | 1033 |
dragIsActive := false. |
1034 |
clickPosition := nil. |
|
1035 |
||
639 | 1036 |
self hasSelection ifTrue:[ |
1037 |
(selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[ |
|
1038 |
self selection:lineNr |
|
1039 |
] ifFalse:[ |
|
1040 |
self selection:nil |
|
569 | 1041 |
] |
1042 |
]. |
|
855 | 1043 |
|
1044 |
isExpd := node isExpandable. |
|
835 | 1045 |
|
855 | 1046 |
( supportsExpandAll |
1047 |
and:[(sensor := self sensor) notNil |
|
1048 |
and:[(sensor ctrlDown or:[sensor shiftDown])]] |
|
1049 |
) ifTrue:[ |
|
1050 |
isExpd ifTrue:[model doExpandAll:node] |
|
1051 |
ifFalse:[model doCollapseAll:node] |
|
835 | 1052 |
] ifFalse:[ |
855 | 1053 |
isExpd ifTrue:[model doExpand:node] |
1054 |
ifFalse:[model doCollapse:node]. |
|
835 | 1055 |
]. |
848 | 1056 |
|
639 | 1057 |
! |
1058 |
||
1059 |
buttonRelease:button x:x y:y |
|
1060 |
"stop any autoscroll" |
|
569 | 1061 |
|
639 | 1062 |
discardMotionEvents ifTrue:[ |
1063 |
clickPosition := nil. |
|
1064 |
discardMotionEvents := false. |
|
1065 |
]. |
|
1066 |
super buttonRelease:button x:x y:y |
|
1067 |
||
569 | 1068 |
! |
1069 |
||
1070 |
doubleClicked |
|
1071 |
"handle a double click; collapse or expand selected entry |
|
1072 |
in case of having children |
|
1073 |
" |
|
1074 |
|node| |
|
1075 |
||
1076 |
(node := self selectedNode) notNil ifTrue:[ |
|
1077 |
( validateDoubleClickBlock isNil |
|
1078 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
1079 |
) ifTrue:[ |
|
1080 |
self selectedNodeExpand:(node isExpandable). |
|
1081 |
super doubleClicked |
|
1082 |
] |
|
1083 |
] |
|
1084 |
||
1085 |
! |
|
1086 |
||
1087 |
indicatiorLineForButton:aButton atX:x y:y |
|
1088 |
"returns linenumber assigned to indicator at x/y or 0 |
|
1089 |
" |
|
846 | 1090 |
|sensor nr x0 node| |
569 | 1091 |
|
1092 |
( enabled |
|
1093 |
and:[showDirectoryIndicator |
|
1094 |
and:[aButton == 1 or:[aButton == #select]]] |
|
1095 |
) ifTrue:[ |
|
835 | 1096 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
569 | 1097 |
|
835 | 1098 |
nr notNil ifTrue:[ |
1099 |
node := listOfNodes at:nr. |
|
1100 |
node hasChildren ifTrue:[ |
|
1101 |
x0 := self xOfFigureLevel:(node level - 1). |
|
569 | 1102 |
|
835 | 1103 |
(x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[ |
1104 |
^ nr |
|
569 | 1105 |
] |
1106 |
] |
|
1107 |
] |
|
1108 |
]. |
|
1109 |
^ 0 |
|
756 | 1110 |
! |
1111 |
||
835 | 1112 |
isCtrlMetaAltOrShiftPressed |
1113 |
"returns true if CTRL, META, ALT or SHIFT is pressed |
|
1114 |
" |
|
1115 |
|sensor| |
|
1116 |
||
1117 |
(sensor := self sensor) notNil ifTrue:[ |
|
1118 |
^ ( sensor ctrlDown |
|
1119 |
or:[sensor altDown |
|
1120 |
or:[sensor shiftDown |
|
1121 |
or:[sensor metaDown]]] |
|
1122 |
) |
|
1123 |
]. |
|
1124 |
^ false |
|
1125 |
! |
|
1126 |
||
756 | 1127 |
key:key select:index x:x y:y |
1128 |
"select an entry by a keyboard action. This is treated like a doubleClick |
|
1129 |
on that entry. |
|
1130 |
Add on: In case that the entry is not selectable, scroll to the entry |
|
1131 |
" |
|
1132 |
(enabled and:[keyActionStyle notNil]) ifFalse:[ |
|
1133 |
^ self |
|
1134 |
]. |
|
1135 |
||
1136 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
780 | 1137 |
^ super key:key select:index x:x y:y |
756 | 1138 |
]. |
1139 |
||
1140 |
keyActionStyle == #pass ifTrue:[ |
|
1141 |
^ self |
|
1142 |
]. |
|
1143 |
||
1144 |
self gotoLine:index |
|
785 | 1145 |
! |
1146 |
||
811 | 1147 |
keyPress:key x:x y:y |
1148 |
"handle keyboard input" |
|
1149 |
||
1150 |
<resource: #keyboard ( #CursorLeft #CursorRight ) > |
|
1151 |
||
1152 |
|idx node inc end| |
|
1153 |
||
1154 |
enabled ifFalse:[ |
|
1155 |
^ self |
|
1156 |
]. |
|
1157 |
||
1158 |
(key == #CursorLeft or:[key == #CursorRight]) ifTrue:[ |
|
1159 |
(idx := self selectedIndex) == 0 ifTrue:[ ^ self ]. |
|
1160 |
||
1161 |
(key == #CursorLeft) ifTrue:[ inc := -1. end := 0 ] |
|
1162 |
ifFalse:[ inc := 1. end := 1 + listOfNodes size ]. |
|
1163 |
||
1164 |
[(idx := idx + inc) ~~ end] whileTrue:[ |
|
1165 |
node := listOfNodes at:idx. |
|
825 | 1166 |
node hasChildren ifTrue:[ |
811 | 1167 |
^ self key:key select:idx x:x y:y |
1168 |
] |
|
1169 |
]. |
|
1170 |
^ self |
|
1171 |
]. |
|
1172 |
^ super keyPress:key x:x y:y |
|
1173 |
||
1174 |
||
1175 |
||
1176 |
||
1177 |
! |
|
1178 |
||
785 | 1179 |
redrawX:x y:y width:w height:h |
1180 |
"a region must be redrawn" |
|
1181 |
||
792 | 1182 |
|savClip startLn sel |
1183 |
lnSpace "{ Class:SmallInteger }" |
|
785 | 1184 |
y0 "{ Class:SmallInteger }" |
1185 |
y1 "{ Class:SmallInteger }" |
|
1186 |
visStart "{ Class:SmallInteger }" |
|
1187 |
visEnd "{ Class:SmallInteger }" |
|
1188 |
stopLn "{ Class:SmallInteger }" |
|
1189 |
maxY "{ Class:SmallInteger }" |
|
792 | 1190 |
maxX "{ Class:SmallInteger }" |
1191 |
dltLine "{ Class:SmallInteger }" |
|
785 | 1192 |
startY "{ Class:SmallInteger }"| |
1193 |
||
1194 |
shown ifFalse:[^ self]. |
|
1195 |
||
1196 |
visStart := self visibleLineOfY:(y + 1). |
|
1197 |
startLn := self visibleLineToAbsoluteLine:visStart. |
|
1198 |
||
1199 |
self paint:bgColor. |
|
1200 |
self fillRectangleX:x y:y width:w height:h. |
|
792 | 1201 |
startLn isNil ifTrue:[ ^ self ]. |
785 | 1202 |
|
792 | 1203 |
sel := nil. |
1204 |
maxX := x + w. |
|
1205 |
maxY := y + h. |
|
1206 |
lnSpace := lineSpacing // 2. |
|
1207 |
visEnd := self visibleLineOfY:maxY. |
|
1208 |
startY := self yOfVisibleLine:visStart. |
|
1209 |
dltLine := startLn - visStart. |
|
1210 |
stopLn := dltLine + visEnd. |
|
1211 |
savClip := clipRect. |
|
785 | 1212 |
|
792 | 1213 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
1214 |
||
1215 |
self hasSelection ifTrue:[ |
|
1216 |
"/ redraw the background for all selected lines in the invalid range |
|
785 | 1217 |
|
792 | 1218 |
self selectionDo:[:lnNr| |
1219 |
(lnNr between:startLn and:stopLn) ifTrue:[ |
|
1220 |
sel isNil ifTrue:[ |
|
1221 |
sel := OrderedCollection new. |
|
785 | 1222 |
self paint:hilightBgColor. |
792 | 1223 |
]. |
1224 |
sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)). |
|
1225 |
y0 := y0 - lnSpace. |
|
1226 |
y1 := y0 + fontHeight min:maxY. |
|
1227 |
y0 := y0 max:y. |
|
1228 |
self fillRectangleX:x y:y0 width:w height:y1 - y0. |
|
785 | 1229 |
] |
792 | 1230 |
] |
785 | 1231 |
]. |
1232 |
||
792 | 1233 |
self redrawLinesX:x y:startY - lnSpace toX:maxX start:startLn stop:stopLn. |
1234 |
||
1235 |
"/ draw selection frames |
|
1236 |
self redrawSelFrameForYs:sel fromX:x toX:maxX. |
|
1237 |
||
1238 |
self clippingRectangle:savClip. |
|
569 | 1239 |
! ! |
1240 |
||
444 | 1241 |
!SelectionInTreeView methodsFor:'initialization'! |
1242 |
||
685 | 1243 |
create |
1244 |
super create. |
|
695
3e5240577e37
dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents:
685
diff
changeset
|
1245 |
lineMask := lineMask onDevice:device. |
685 | 1246 |
|
846 | 1247 |
lineColor := lineColor isNil ifTrue:[fgColor] |
1248 |
ifFalse:[lineColor onDevice:device]. |
|
685 | 1249 |
! |
1250 |
||
514 | 1251 |
destroy |
1252 |
"remove dependencies |
|
1253 |
" |
|
811 | 1254 |
rootHolder removeDependent:self. |
1255 |
selectionHolder removeDependent:self. |
|
1256 |
||
1257 |
model notNil ifTrue:[ |
|
1258 |
model stopRunningTasks |
|
514 | 1259 |
]. |
1260 |
super destroy. |
|
1261 |
||
1262 |
! |
|
1263 |
||
785 | 1264 |
fetchDefaultImages |
1265 |
"returns a directory with default keys and images; could be |
|
1266 |
redefined by subclass. |
|
1267 |
" |
|
1268 |
^ nil |
|
1269 |
! |
|
1270 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1271 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1272 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1273 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1274 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1275 |
super fetchDeviceResources. |
478 | 1276 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1277 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
1278 |
|
478 | 1279 |
fetchImageResources |
1280 |
"initialize heavily used device resources - to avoid rendering |
|
1281 |
images again and again later; returns maximum extent of the images used. |
|
1282 |
Could be redefined by subclass |
|
471 | 1283 |
" |
785 | 1284 |
|img x y keysAndIcons| |
494 | 1285 |
|
1286 |
imageOpened isNil ifTrue:[ |
|
846 | 1287 |
imageOpened := self imageOnDevice:(self class imageOpened) |
494 | 1288 |
]. |
444 | 1289 |
|
494 | 1290 |
imageClosed isNil ifTrue:[ |
569 | 1291 |
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
|
1292 |
]. |
785 | 1293 |
|
1294 |
x := (imageOpened width) max:(imageClosed width). |
|
1295 |
y := (imageOpened height) max:(imageClosed height). |
|
494 | 1296 |
|
1297 |
imageItem isNil ifTrue:[ |
|
569 | 1298 |
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
|
1299 |
]. |
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1300 |
|
785 | 1301 |
x := (imageItem width) max:x. |
1302 |
y := (imageItem height) max:y. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1303 |
|
785 | 1304 |
(keysAndIcons := self fetchDefaultImages) notNil ifTrue:[ |
1305 |
keysAndIcons keysAndValuesDo:[:aKey :anIcon| |
|
1306 |
(anIcon isImage and:[aKey notNil]) ifTrue:[ |
|
846 | 1307 |
registeredImages at:aKey put:(self imageOnDevice:anIcon) |
785 | 1308 |
] |
1309 |
] |
|
1310 |
]. |
|
1311 |
registeredImages keysAndValuesDo:[:k :img| |
|
1312 |
x := (img width) max:x. |
|
1313 |
y := (img height) max:y. |
|
1314 |
]. |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1315 |
|
785 | 1316 |
(listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[ |
1317 |
x := (img width) max:x. |
|
1318 |
y := (img height) max:y. |
|
1319 |
]. |
|
1320 |
^ x @ y |
|
444 | 1321 |
! |
1322 |
||
480 | 1323 |
getFontParameters |
546 | 1324 |
"save old computed height derived from images |
1325 |
" |
|
1326 |
|lineHeight| |
|
1327 |
||
1328 |
lineHeight := fontHeight ? 0. |
|
480 | 1329 |
super getFontParameters. |
569 | 1330 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 1331 |
|
546 | 1332 |
lineHeight > fontHeight ifTrue:[ |
1333 |
fontHeight := lineHeight |
|
1334 |
]. |
|
685 | 1335 |
fontHeight odd ifTrue:[ |
1336 |
fontHeight := fontHeight + 1 |
|
1337 |
] |
|
480 | 1338 |
! |
1339 |
||
444 | 1340 |
initialize |
471 | 1341 |
"setup instance attributes |
1342 |
" |
|
444 | 1343 |
super initialize. |
835 | 1344 |
supportsExpandAll := true. |
569 | 1345 |
self bitGravity:#NorthWest. |
773 | 1346 |
showRoot := showDirectoryIndicatorForRoot := showLines := computeResources := true. |
1347 |
showDirectoryIndicator := discardMotionEvents := false. |
|
685 | 1348 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
773 | 1349 |
registeredImages := IdentityDictionary new. |
855 | 1350 |
drawVLinesFromLevel := 1. |
659 | 1351 |
textInset := 4. |
494 | 1352 |
imageInset := 0. "/ set during indication enabled |
1353 |
imageWidth := 8. "/ default: will change during startup |
|
848 | 1354 |
|
1355 |
buildInArray := Array new:50. "/ used for temporary calculation |
|
1356 |
"/ suppress garbage collection |
|
1357 |
||
514 | 1358 |
self model:nil. "/ creates a default model. |
846 | 1359 |
|
478 | 1360 |
! |
1361 |
||
569 | 1362 |
realize |
1363 |
super realize. |
|
1364 |
self refetchDeviceResources. |
|
1365 |
! |
|
1366 |
||
811 | 1367 |
recomputeDirectoryIndicator |
1368 |
"setup attributes used by directory indicator |
|
1369 |
" |
|
1370 |
|x w| |
|
1371 |
||
1372 |
imageInset := 0. |
|
1373 |
||
1374 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
1375 |
^ self |
|
1376 |
]. |
|
1377 |
openIndicator isNil ifTrue:[ |
|
1378 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
1379 |
]. |
|
1380 |
closeIndicator isNil ifTrue:[ |
|
1381 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
1382 |
]. |
|
1383 |
x := (openIndicator width) max:(closeIndicator width). |
|
1384 |
x := x // 2. |
|
1385 |
w := imageWidth // 2. |
|
1386 |
||
1387 |
(x := x + self class minImageInset) > w ifTrue:[ |
|
1388 |
imageInset := x - w. |
|
1389 |
]. |
|
1390 |
||
1391 |
||
1392 |
||
1393 |
! |
|
1394 |
||
478 | 1395 |
refetchDeviceResources |
1396 |
"reinitialize heavily used device resources - to avoid rendering |
|
1397 |
images again and again later |
|
1398 |
" |
|
551 | 1399 |
|extent| |
478 | 1400 |
|
569 | 1401 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 1402 |
computeResources := false. |
1403 |
extent := self fetchImageResources. |
|
494 | 1404 |
|
546 | 1405 |
extent y >= fontHeight ifTrue:[ |
1406 |
fontHeight := 1 + extent y. |
|
494 | 1407 |
]. |
685 | 1408 |
fontHeight odd ifTrue:[ |
1409 |
fontHeight := fontHeight + 1 |
|
1410 |
]. |
|
846 | 1411 |
"/ round and not odd: because of line drawing |
685 | 1412 |
|
846 | 1413 |
imageWidth := (extent x) // 2. |
1414 |
imageWidth odd ifTrue:[imageWidth := imageWidth + 1]. |
|
1415 |
imageWidth := imageWidth * 2. |
|
1416 |
||
546 | 1417 |
self recomputeDirectoryIndicator. |
569 | 1418 |
self computeNumberOfLinesShown. |
546 | 1419 |
] |
444 | 1420 |
! ! |
1421 |
||
483 | 1422 |
!SelectionInTreeView methodsFor:'model'! |
444 | 1423 |
|
1424 |
getListFromModel |
|
1425 |
"if I have a model, get my list from it using the listMessage. |
|
1426 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1427 |
" |
|
483 | 1428 |
super list:(self listFromModel) keepSelection:true |
1429 |
! |
|
444 | 1430 |
|
483 | 1431 |
listFromModel |
1432 |
"get list from model and return the new list. |
|
1433 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
1434 |
" |
|
846 | 1435 |
|msg| |
838 | 1436 |
|
846 | 1437 |
widthOfWidestLine := nil. |
847 | 1438 |
list := listOfNodes := (msg := listMsg ? aspectMsg) notNil ifTrue:[model perform:msg] ifFalse:[#()]. |
1439 |
self refetchDeviceResources. |
|
846 | 1440 |
^ listOfNodes |
494 | 1441 |
! |
1442 |
||
1443 |
model:aModel |
|
514 | 1444 |
"check whether model is nil; than a default model is created |
1445 |
" |
|
855 | 1446 |
|model root| |
514 | 1447 |
|
811 | 1448 |
model notNil ifTrue:[ |
1449 |
model stopRunningTasks |
|
1450 |
]. |
|
1451 |
||
514 | 1452 |
model := aModel ? (SelectionInTree new). |
855 | 1453 |
root := model root. |
1454 |
||
514 | 1455 |
model showRoot:showRoot. |
855 | 1456 |
|
1457 |
root notNil ifTrue:[ |
|
1458 |
root expand |
|
1459 |
]. |
|
514 | 1460 |
super model:model. |
855 | 1461 |
self getListFromModel |
811 | 1462 |
|
514 | 1463 |
! |
1464 |
||
1465 |
rootFromModel |
|
1466 |
"update hierarchical list from root model; 'rootHolder' |
|
1467 |
" |
|
1468 |
|root| |
|
1469 |
||
585 | 1470 |
root := rootHolder root. |
514 | 1471 |
|
1472 |
self root == root ifFalse:[ |
|
1473 |
self selection:nil. |
|
1474 |
self root:root. |
|
585 | 1475 |
]. |
514 | 1476 |
! |
1477 |
||
1478 |
selectionFromModel |
|
1479 |
"set the selection derived from the selectionHolder |
|
1480 |
" |
|
855 | 1481 |
|coll value size idx| |
514 | 1482 |
|
1483 |
(value := selectionHolder value) isNil ifTrue:[ |
|
1484 |
^ self deselect |
|
507 | 1485 |
]. |
514 | 1486 |
|
848 | 1487 |
(multipleSelectOk and:[value isCollection]) ifFalse:[ |
1488 |
^ self selectNode:value |
|
1489 |
]. |
|
1490 |
||
855 | 1491 |
(size := value size) == 0 ifTrue:[ |
848 | 1492 |
^ self deselect |
1493 |
]. |
|
1494 |
||
855 | 1495 |
size == 1 ifTrue:[ |
848 | 1496 |
^ self selectNode:(value at:1) |
1497 |
]. |
|
1498 |
||
855 | 1499 |
model doMakeVisible:value. |
1500 |
||
1501 |
coll := OrderedCollection new:size. |
|
514 | 1502 |
|
848 | 1503 |
value do:[:aNode| |
855 | 1504 |
(idx := self indexOfNode:aNode) ~~ 0 ifTrue:[coll add:idx] |
848 | 1505 |
]. |
1506 |
self selection:coll |
|
514 | 1507 |
! |
1508 |
||
1509 |
selectionToModel |
|
1510 |
"write selection to selection holder |
|
1511 |
" |
|
1512 |
|newSel oldSel| |
|
1513 |
||
1514 |
oldSel := selectionHolder value. |
|
1515 |
||
1516 |
multipleSelectOk ifFalse:[ |
|
1517 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
1518 |
selectionHolder value:newSel |
|
1519 |
] |
|
1520 |
] ifTrue:[ |
|
1521 |
selection size == 0 ifTrue:[ |
|
1522 |
oldSel notNil ifTrue:[ |
|
1523 |
selectionHolder value:nil |
|
1524 |
] |
|
1525 |
] ifFalse:[ |
|
1526 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
1527 |
||
1528 |
newSel size ~~ oldSel size ifTrue:[ |
|
1529 |
selectionHolder value:newSel. |
|
1530 |
] ifFalse:[ |
|
1531 |
newSel do:[:aNode| |
|
785 | 1532 |
(oldSel includesIdentical:aNode) ifFalse:[ |
514 | 1533 |
^ selectionHolder value:newSel |
1534 |
] |
|
1535 |
] |
|
1536 |
] |
|
1537 |
] |
|
1538 |
] |
|
444 | 1539 |
! ! |
1540 |
||
490 | 1541 |
!SelectionInTreeView methodsFor:'private'! |
1542 |
||
1543 |
list:aList keepSelection:keepSelection |
|
585 | 1544 |
"setup new list; keep selection dependent on the boolean state |
1545 |
keepSelection |
|
1546 |
" |
|
838 | 1547 |
|list time| |
490 | 1548 |
|
846 | 1549 |
list := (aList size == 0) ifTrue:[#()] ifFalse:[aList]. |
1550 |
super list:list keepSelection:keepSelection. |
|
1551 |
self refetchDeviceResources. |
|
490 | 1552 |
|
811 | 1553 |
! ! |
1554 |
||
1555 |
!SelectionInTreeView methodsFor:'private - drag and drop'! |
|
569 | 1556 |
|
811 | 1557 |
collectionOfDragObjects |
1558 |
"returns collection of dragable objects assigned to selection |
|
1559 |
Here, by default, a collection of text-dragObjects is generated; |
|
1560 |
however, if a dragObjectConverter is defined, that one gets a chance |
|
1561 |
to convert as appropriate." |
|
1562 |
||
1563 |
|collection converted selection dLbl dObj node| |
|
1564 |
||
1565 |
selection := self selectionAsCollection. |
|
1566 |
||
1567 |
collection := selection collect:[:nr| |
|
1568 |
node := listOfNodes at:nr. |
|
1569 |
dObj := self dragObjectForNode:node. |
|
1570 |
dObj theObject:(node contents). |
|
846 | 1571 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
811 | 1572 |
dObj displayObject:dLbl. |
1573 |
dObj |
|
1574 |
]. |
|
1575 |
||
1576 |
dragObjectConverter notNil ifTrue:[ |
|
1577 |
converted := OrderedCollection new. |
|
1578 |
collection keysAndValuesDo:[:nr :obj | |
|
1579 |
(dObj := dragObjectConverter value:obj) notNil ifTrue:[ |
|
846 | 1580 |
node := listOfNodes at:nr. |
1581 |
dLbl := LabelAndIcon icon:(self figureFor:node) string:(node name). |
|
811 | 1582 |
converted displayObject:dLbl. |
1583 |
converted add:dObj |
|
1584 |
] |
|
1585 |
]. |
|
1586 |
collection := converted |
|
1587 |
]. |
|
1588 |
^ collection. |
|
1589 |
||
1590 |
||
569 | 1591 |
|
1592 |
! |
|
1593 |
||
811 | 1594 |
dragObjectForNode:aNode |
1595 |
"returns the dragable object for a node; could be redefined in subclass |
|
546 | 1596 |
" |
811 | 1597 |
^ DropObject new:aNode. |
546 | 1598 |
|
811 | 1599 |
|
1600 |
! |
|
546 | 1601 |
|
811 | 1602 |
startDragX:x y:y |
1603 |
"start drag |
|
1604 |
" |
|
1605 |
dragIsActive := true. |
|
546 | 1606 |
|
811 | 1607 |
DragAndDropManager startDrag:(self collectionOfDragObjects) |
1608 |
from:self |
|
1609 |
atEnd:endDragAction |
|
546 | 1610 |
|
1611 |
||
490 | 1612 |
! ! |
1613 |
||
468 | 1614 |
!SelectionInTreeView methodsFor:'private queries'! |
1615 |
||
1616 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
1617 |
"return the length (in characters) of the longest line in a line-range |
|
1618 |
" |
|
846 | 1619 |
^ self widthOfContents // fontWidth + 1 |
468 | 1620 |
! |
1621 |
||
848 | 1622 |
smallestLevelOfNodesBetween:start and:stop |
1623 |
"returns the smallest level of the nodes in a line range |
|
1624 |
" |
|
1625 |
|prevNode currParent nextParent |
|
1626 |
||
1627 |
lvl "{ Class:SmallInteger }" |
|
1628 |
min "{ Class:SmallInteger }" |
|
1629 |
end "{ Class:SmallInteger }" |
|
1630 |
beg "{ Class:SmallInteger }" |
|
1631 |
| |
|
1632 |
||
1633 |
(end := stop min:(listOfNodes size)) < start ifTrue:[ |
|
1634 |
^ 0 |
|
1635 |
]. |
|
1636 |
||
1637 |
prevNode := listOfNodes at:start. |
|
1638 |
currParent := prevNode parent. |
|
1639 |
||
1640 |
currParent isNil ifTrue:[ |
|
1641 |
^ 1 |
|
1642 |
]. |
|
1643 |
||
1644 |
(min := prevNode level) == 2 ifTrue:[ |
|
1645 |
^ min |
|
1646 |
]. |
|
1647 |
beg := start + 1. |
|
1648 |
||
1649 |
listOfNodes from:beg to:end do:[:currNode| |
|
1650 |
(nextParent := currNode parent) == currParent ifFalse:[ |
|
1651 |
(currParent := nextParent) == prevNode ifFalse:[ |
|
1652 |
(lvl := currNode level) == 2 ifTrue:[ |
|
1653 |
^ 2 |
|
1654 |
]. |
|
1655 |
min := min min:lvl |
|
1656 |
] |
|
1657 |
]. |
|
1658 |
prevNode := currNode |
|
1659 |
]. |
|
1660 |
^ min |
|
1661 |
||
1662 |
||
1663 |
||
1664 |
||
1665 |
! |
|
1666 |
||
468 | 1667 |
widthOfContents |
1668 |
"return the width of the contents in pixels |
|
1669 |
- used for scrollbar interface" |
|
1670 |
||
846 | 1671 |
listOfNodes isNil ifTrue:[^ 0]. |
468 | 1672 |
|
1673 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
846 | 1674 |
widthOfWidestLine := self widthOfLongestLine |
468 | 1675 |
]. |
1676 |
^ widthOfWidestLine + (leftMargin * 2) |
|
1677 |
||
1678 |
! |
|
1679 |
||
846 | 1680 |
widthOfLongestLine |
1681 |
"return the width of the longest line in pixels |
|
468 | 1682 |
" |
848 | 1683 |
|parent pItem p |
846 | 1684 |
startX "{ Class: SmallInteger }" |
1685 |
deltaX "{ Class: SmallInteger }" |
|
838 | 1686 |
level "{ Class: SmallInteger }" |
1687 |
width "{ Class: SmallInteger }" |
|
1688 |
maxSz "{ Class: SmallInteger }"| |
|
468 | 1689 |
|
848 | 1690 |
buildInArray atAllPut:0. |
846 | 1691 |
parent := nil. |
1692 |
maxSz := 1. |
|
838 | 1693 |
level := 1. |
846 | 1694 |
|
1695 |
listOfNodes do:[:anItem| |
|
848 | 1696 |
(p := anItem parent) ~~ parent ifTrue:[ |
1697 |
buildInArray at:level put:maxSz. |
|
846 | 1698 |
|
848 | 1699 |
(parent := p) == pItem ifTrue:[level := level + 1] |
1700 |
ifFalse:[level := anItem level]. |
|
1701 |
||
1702 |
maxSz := buildInArray at:level. |
|
846 | 1703 |
]. |
1704 |
pItem := anItem. |
|
1705 |
maxSz := maxSz max:(anItem name size). |
|
1706 |
]. |
|
848 | 1707 |
buildInArray at:level put:maxSz. |
468 | 1708 |
|
846 | 1709 |
startX := self xOfStringLevel:1. |
1710 |
deltaX := imageInset + imageWidth. |
|
1711 |
width := '1' widthOn:self. |
|
1712 |
maxSz := 0. |
|
468 | 1713 |
|
848 | 1714 |
buildInArray do:[:el| |
846 | 1715 |
el == 0 ifTrue:[ ^ maxSz + leftOffset ]. |
1716 |
maxSz := maxSz max:(el * width + startX). |
|
1717 |
startX := startX + deltaX. |
|
468 | 1718 |
]. |
846 | 1719 |
! ! |
1720 |
||
1721 |
!SelectionInTreeView methodsFor:'private redefinitions'! |
|
1722 |
||
1723 |
expandTabs |
|
1724 |
"nothing to do |
|
1725 |
" |
|
838 | 1726 |
|
1727 |
||
468 | 1728 |
! |
1729 |
||
846 | 1730 |
list:aCollection expandTabs:expand scanForNonStrings:scan |
1731 |
||
1732 |
includesNonStrings := false. |
|
1733 |
self list:aCollection expandTabs:false scanForNonStrings:false includesNonStrings:false |
|
1734 |
! |
|
1735 |
||
468 | 1736 |
withoutRedrawAt:anIndex put:aString |
1737 |
"change a line without redisplay" |
|
1738 |
||
1739 |
|width| |
|
1740 |
||
1741 |
width := widthOfWidestLine. |
|
1742 |
widthOfWidestLine := nil. |
|
1743 |
super withoutRedrawAt:anIndex put:aString. |
|
846 | 1744 |
widthOfWidestLine := width. |
468 | 1745 |
|
846 | 1746 |
(widthOfWidestLine notNil and:[aString size ~~ 0]) ifTrue:[ |
1747 |
width := self xOfStringNode:(listOfNodes at:anIndex) |
|
1748 |
+ (aString widthOn:self) |
|
1749 |
+ leftOffset. |
|
1750 |
||
838 | 1751 |
widthOfWidestLine := widthOfWidestLine max:width. |
468 | 1752 |
]. |
1753 |
! ! |
|
1754 |
||
483 | 1755 |
!SelectionInTreeView methodsFor:'queries'! |
1756 |
||
1757 |
figureFor:aNode |
|
1758 |
"access figure for a node |
|
1759 |
" |
|
785 | 1760 |
|icon img| |
1761 |
||
1762 |
(icon := aNode icon) notNil ifTrue:[ |
|
1763 |
img := registeredImages at:icon ifAbsent:nil. |
|
773 | 1764 |
|
785 | 1765 |
img notNil ifTrue:[ |
1766 |
^ img |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1767 |
]. |
785 | 1768 |
icon isImage ifTrue:[ |
846 | 1769 |
img := self imageOnDevice:icon. |
785 | 1770 |
registeredImages at:icon put:img. |
1771 |
^ img |
|
1772 |
] |
|
763
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1773 |
]. |
dd29c58e8ea6
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
760
diff
changeset
|
1774 |
|
846 | 1775 |
aNode hasChildren ifFalse:[ |
1776 |
^ imageItem |
|
1777 |
]. |
|
1778 |
^ aNode hidden ifTrue:[imageClosed] ifFalse:[imageOpened] |
|
785 | 1779 |
|
483 | 1780 |
! |
1781 |
||
1782 |
indexOfNode:aNode |
|
1783 |
"returns index of a node |
|
1784 |
" |
|
785 | 1785 |
^ listOfNodes identityIndexOf:aNode |
483 | 1786 |
! |
1787 |
||
494 | 1788 |
xOfFigureLevel:aLevel |
1789 |
"origin x where to draw the icon |
|
1790 |
" |
|
785 | 1791 |
|l "{ Class:SmallInteger }"| |
494 | 1792 |
|
785 | 1793 |
l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1]. |
494 | 1794 |
|
659 | 1795 |
showDirectoryIndicator ifFalse:[ |
1796 |
l := l - 1 |
|
1797 |
] ifTrue:[ |
|
1798 |
showDirectoryIndicatorForRoot ifFalse:[ |
|
1799 |
l := l - 1 |
|
1800 |
] |
|
1801 |
]. |
|
494 | 1802 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
1803 |
||
1804 |
! |
|
1805 |
||
483 | 1806 |
xOfFigureNode:aNode |
1807 |
"origin x where to draw the icon |
|
1808 |
" |
|
494 | 1809 |
^ self xOfFigureLevel:(aNode level) |
1810 |
! |
|
490 | 1811 |
|
494 | 1812 |
xOfStringLevel:aLevel |
1813 |
"origin x where to draw the text( label ) |
|
1814 |
" |
|
1815 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 1816 |
|
1817 |
! |
|
1818 |
||
1819 |
xOfStringNode:aNode |
|
1820 |
"origin x where to draw the text( label ) |
|
1821 |
" |
|
494 | 1822 |
^ self xOfStringLevel:(aNode level) |
483 | 1823 |
|
1824 |
! ! |
|
1825 |
||
444 | 1826 |
!SelectionInTreeView methodsFor:'selection'! |
1827 |
||
468 | 1828 |
selectNode:aNode |
1829 |
"change selection to a node |
|
1830 |
" |
|
855 | 1831 |
|index| |
848 | 1832 |
|
1833 |
aNode isNil ifTrue:[ |
|
1834 |
index := nil |
|
1835 |
] ifFalse:[ |
|
855 | 1836 |
(index := self indexOfNode:aNode) == 0 ifTrue:[ |
1837 |
model doMakeVisible:aNode. |
|
1838 |
index := self indexOfNode:aNode. |
|
1839 |
]. |
|
848 | 1840 |
index == 0 ifTrue:[ |
855 | 1841 |
index := nil |
848 | 1842 |
] |
1843 |
]. |
|
1844 |
self selection:index |
|
468 | 1845 |
|
1846 |
||
1847 |
! |
|
1848 |
||
456 | 1849 |
selectedIndex |
1850 |
"get single selected index or 0 |
|
1851 |
" |
|
483 | 1852 |
selection size == 1 ifTrue:[^ selection first]. |
1853 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 1854 |
^ 0 |
444 | 1855 |
! |
1856 |
||
1857 |
selectedNode |
|
1858 |
"get the single selected node or nil |
|
1859 |
" |
|
456 | 1860 |
|idx| |
1861 |
||
1862 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
1863 |
^ listOfNodes at:idx |
|
444 | 1864 |
]. |
1865 |
^ nil |
|
514 | 1866 |
! |
1867 |
||
1868 |
selectionChangedFrom:oldSelection |
|
1869 |
"update selectionHolder if not nil |
|
1870 |
" |
|
1871 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1872 |
"/ first change my selectionHolders value ... |
514 | 1873 |
selectionHolder notNil ifTrue:[ |
1874 |
self selectionToModel. |
|
1875 |
]. |
|
1876 |
||
623
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1877 |
"/ ... then make notifications. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1878 |
super selectionChangedFrom:oldSelection. |
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1879 |
|
4de870640523
first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
1880 |
|
444 | 1881 |
! ! |
1882 |
||
855 | 1883 |
!SelectionInTreeView methodsFor:'selection actions'! |
507 | 1884 |
|
1885 |
selectedNodeAdd:something |
|
1886 |
"add a node or collection of nodes after selected node |
|
1887 |
" |
|
1888 |
|node| |
|
1889 |
||
1890 |
something notNil ifTrue:[ |
|
1891 |
(node := self selectedNode) notNil ifTrue:[ |
|
1892 |
node parent notNil ifTrue:[ |
|
1893 |
node isCollapsable ifTrue:[ |
|
1894 |
model add:something beforeIndex:1 below:node |
|
1895 |
] ifFalse:[ |
|
1896 |
model add:something after:node |
|
1897 |
] |
|
1898 |
] ifFalse:[ |
|
1899 |
model add:something beforeIndex:1 below:(self root) |
|
1900 |
] |
|
1901 |
] |
|
1902 |
] |
|
1903 |
||
1904 |
! |
|
1905 |
||
1906 |
selectedNodeBecomeChildOfNext |
|
1907 |
"become node a child of followd node |
|
1908 |
" |
|
1909 |
|idx node cprt nprt| |
|
1910 |
||
1911 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
1912 |
idx := cprt indexOfChild:node. |
|
1913 |
||
1914 |
idx == cprt children size ifFalse:[ |
|
1915 |
nprt := cprt childAt:(idx + 1). |
|
1916 |
||
1917 |
nprt notNil ifTrue:[ |
|
855 | 1918 |
self setSelection:nil. |
1919 |
model remove:node. |
|
507 | 1920 |
model add:node beforeIndex:1 below:nprt. |
1921 |
self selectNode:node. |
|
1922 |
] |
|
1923 |
] |
|
1924 |
] |
|
1925 |
! |
|
1926 |
||
1927 |
selectedNodeBecomeSisterOfParent |
|
1928 |
"become node a sister of its current parent |
|
1929 |
" |
|
1930 |
|node cprt nprt| |
|
1931 |
||
1932 |
( (node := self selectedNode) isNil |
|
1933 |
or:[(cprt := node parent) isNil |
|
1934 |
or:[(nprt := cprt parent) isNil]] |
|
1935 |
) ifFalse:[ |
|
855 | 1936 |
self setSelection:nil. |
1937 |
model remove:node. |
|
507 | 1938 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
855 | 1939 |
self selectNode:node. |
507 | 1940 |
] |
1941 |
||
1942 |
! |
|
1943 |
||
1944 |
selectedNodeChangeSequenceOrder:anOffset |
|
1945 |
"move child 'anOffset' forward or backward in list of children |
|
1946 |
" |
|
1947 |
|idx node size parent| |
|
1948 |
||
1949 |
( (node := self selectedNode) notNil |
|
1950 |
and:[(parent := node parent) notNil |
|
1951 |
and:[(size := parent children size) > 1]] |
|
1952 |
) ifTrue:[ |
|
1953 |
idx := parent indexOfChild:node. |
|
855 | 1954 |
self setSelection:nil. |
1955 |
model remove:node. |
|
507 | 1956 |
|
1957 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
1958 |
idx := size |
|
1959 |
] ifFalse:[ |
|
1960 |
idx > size ifTrue:[idx := 1] |
|
1961 |
]. |
|
1962 |
model add:node beforeIndex:idx below:parent. |
|
1963 |
self selectNode:node. |
|
1964 |
] |
|
1965 |
! |
|
1966 |
||
1967 |
selectedNodeExpand:doExpand |
|
1968 |
"collapse or expand selected node |
|
1969 |
" |
|
855 | 1970 |
|node| |
507 | 1971 |
|
855 | 1972 |
(node := self selectedNode) notNil ifTrue:[ |
1973 |
doExpand ifTrue:[model doExpand:node] |
|
1974 |
ifFalse:[model doCollapse:node] |
|
1975 |
] |
|
507 | 1976 |
! |
1977 |
||
1978 |
selectedNodesRemove |
|
1979 |
"remove selected nodes |
|
1980 |
" |
|
855 | 1981 |
|selection| |
1982 |
||
1983 |
selection := self selection. |
|
507 | 1984 |
self selection:nil. |
855 | 1985 |
model remove:selection. |
507 | 1986 |
! ! |
1987 |
||
444 | 1988 |
!SelectionInTreeView class methodsFor:'documentation'! |
1989 |
||
1990 |
version |
|
855 | 1991 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.58 1998-04-14 11:31:23 ca Exp $' |
444 | 1992 |
! ! |