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