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