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