author | ca |
Wed, 29 Oct 1997 09:25:29 +0100 | |
changeset 585 | 5a0ed2305998 |
parent 569 | 2a1014d6697c |
child 589 | 979ea44d23ae |
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 |
|
517 | 15 |
instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth |
569 | 16 |
showLines listOfNodes imageInset textInset labelOffsetY |
17 |
openIndicator computeResources closeIndicator showRoot |
|
18 |
extentOpenIndicator extentCloseIndicator showDirectoryIndicator |
|
19 |
indicatorExtentDiv2 imageOpened imageClosed imageItem' |
|
490 | 20 |
classVariableNames:'ImageOpened ImageClosed ImageItem OpenIndicator CloseIndicator' |
444 | 21 |
poolDictionaries:'' |
22 |
category:'Views-Text' |
|
23 |
! |
|
24 |
||
25 |
!SelectionInTreeView class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
45 |
lists and adds the functions to show/hide subtrees. |
|
456 | 46 |
Requires SelectionInTree as model and TreeItem (or compatible) list entries. |
444 | 47 |
|
456 | 48 |
This class obsoletes SelectionInTreeView, which is no longer |
446 | 49 |
maintained but kept for backward compatibility. |
50 |
||
51 |
||
444 | 52 |
[see also:] |
456 | 53 |
SelectionInTree |
54 |
TreeItem |
|
55 |
SelectionInTreeView |
|
444 | 56 |
SelectionInListView |
494 | 57 |
FileSelectionTree |
444 | 58 |
|
59 |
[author:] |
|
60 |
Claus Atzkern |
|
61 |
" |
|
62 |
||
63 |
! |
|
64 |
||
65 |
examples |
|
66 |
" |
|
67 |
shows the tree of smalltalk classes: |
|
68 |
[exBegin] |
|
514 | 69 |
|top sel| |
456 | 70 |
|
514 | 71 |
top := StandardSystemView new; extent:300@300. |
456 | 72 |
sel := SelectionInTreeView new. |
514 | 73 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
456 | 74 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
75 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
76 |
top open. |
|
77 |
[exEnd] |
|
78 |
||
79 |
||
485 | 80 |
|
456 | 81 |
same, including nil-subclasses (i.e. really all classes): |
82 |
[exBegin] |
|
514 | 83 |
|top sel| |
444 | 84 |
|
514 | 85 |
top := StandardSystemView new; extent:300@300. |
456 | 86 |
sel := SelectionInTreeView new. |
514 | 87 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:nil). |
456 | 88 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
89 |
||
90 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
91 |
top open. |
|
92 |
[exEnd] |
|
93 |
||
485 | 94 |
|
483 | 95 |
|
485 | 96 |
shows the tree of smalltalk classes; show directory indication and no |
97 |
lines. |
|
98 |
[exBegin] |
|
514 | 99 |
|top sel| |
483 | 100 |
|
514 | 101 |
top := StandardSystemView new; extent:300@300. |
483 | 102 |
sel := SelectionInTreeView new. |
485 | 103 |
sel showLines:false. |
104 |
sel showDirectoryIndicator:true. |
|
514 | 105 |
sel root:(TreeItem newAsTreeFromSmalltalkClass:Object). |
485 | 106 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
483 | 107 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
108 |
top open. |
|
485 | 109 |
[exEnd] |
110 |
" |
|
111 |
||
514 | 112 |
|
444 | 113 |
! ! |
114 |
||
115 |
!SelectionInTreeView class methodsFor:'constants'! |
|
116 |
||
494 | 117 |
minImageInset |
118 |
"returns minimum inset from directory indication to image |
|
471 | 119 |
" |
494 | 120 |
^ 6 |
490 | 121 |
|
122 |
||
123 |
! ! |
|
124 |
||
125 |
!SelectionInTreeView class methodsFor:'default images'! |
|
126 |
||
127 |
closeIndicator |
|
128 |
CloseIndicator isNil ifTrue:[ |
|
129 |
CloseIndicator := Image fromFile:('xpmBitmaps/plus.xpm'). |
|
130 |
]. |
|
131 |
^ CloseIndicator |
|
132 |
" |
|
133 |
CloseIndicator := nil |
|
134 |
" |
|
471 | 135 |
! |
136 |
||
444 | 137 |
imageClosed |
138 |
ImageClosed isNil ifTrue:[ |
|
139 |
ImageClosed := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm'). |
|
140 |
]. |
|
141 |
^ ImageClosed |
|
142 |
" |
|
143 |
ImageClosed := nil |
|
144 |
" |
|
145 |
||
146 |
! |
|
147 |
||
148 |
imageItem |
|
149 |
ImageItem isNil ifTrue:[ |
|
150 |
ImageItem := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm') |
|
151 |
||
152 |
]. |
|
153 |
^ ImageItem |
|
154 |
" |
|
155 |
ImageItem := nil |
|
156 |
" |
|
157 |
||
158 |
! |
|
159 |
||
160 |
imageOpened |
|
161 |
ImageOpened isNil ifTrue:[ |
|
162 |
ImageOpened := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm'). |
|
163 |
||
164 |
]. |
|
165 |
^ ImageOpened |
|
166 |
" |
|
167 |
ImageOpened := nil |
|
168 |
" |
|
490 | 169 |
! |
170 |
||
171 |
openIndicator |
|
172 |
OpenIndicator isNil ifTrue:[ |
|
173 |
OpenIndicator := Image fromFile:('xpmBitmaps/minus.xpm'). |
|
174 |
]. |
|
175 |
^ OpenIndicator |
|
176 |
" |
|
177 |
OpenIndicator := nil |
|
178 |
" |
|
179 |
||
444 | 180 |
! ! |
181 |
||
182 |
!SelectionInTreeView methodsFor:'accessing'! |
|
183 |
||
490 | 184 |
nodeAtIndex:anIndex |
185 |
"returns node at an index or nil |
|
186 |
" |
|
187 |
(anIndex notNil and:[anIndex ~~ 0 and:[anIndex <= listOfNodes size]]) ifTrue:[ |
|
188 |
^ listOfNodes at:anIndex |
|
189 |
]. |
|
190 |
^ nil |
|
191 |
! |
|
192 |
||
507 | 193 |
root |
194 |
"gets the root of the model; the first item into list. |
|
195 |
" |
|
196 |
^ self nodeAtIndex:1 |
|
197 |
! |
|
198 |
||
199 |
root:aRoot |
|
200 |
"sets the root of the model; the first item into list. |
|
201 |
" |
|
514 | 202 |
aRoot notNil ifTrue:[aRoot expand]. |
507 | 203 |
model root:aRoot |
204 |
! |
|
205 |
||
490 | 206 |
textInset |
207 |
"get the left inset of the text label |
|
208 |
" |
|
209 |
^ textInset |
|
210 |
! |
|
211 |
||
212 |
textInset:anInset |
|
213 |
"set the left inset of the text label |
|
214 |
" |
|
215 |
anInset ~~ textInset ifTrue:[ |
|
216 |
anInset >= 0 ifTrue:[ |
|
217 |
textInset := anInset. |
|
218 |
self invalidate |
|
219 |
] ifFalse:[ |
|
220 |
self error |
|
221 |
] |
|
222 |
]. |
|
223 |
! ! |
|
224 |
||
225 |
!SelectionInTreeView methodsFor:'accessing-behavior'! |
|
226 |
||
227 |
showDirectoryIndicator |
|
228 |
"returns true if directories has an open/closed indicator |
|
229 |
" |
|
230 |
^ showDirectoryIndicator |
|
231 |
! |
|
232 |
||
233 |
showDirectoryIndicator:aState |
|
234 |
"set or clear open/closed indicator for directories |
|
235 |
" |
|
236 |
"show or hide lines |
|
237 |
" |
|
238 |
aState ~~ showDirectoryIndicator ifTrue:[ |
|
494 | 239 |
showDirectoryIndicator := aState. |
546 | 240 |
self recomputeDirectoryIndicator. |
490 | 241 |
self invalidate |
242 |
]. |
|
243 |
! |
|
244 |
||
245 |
showLines |
|
246 |
"returns true if lines are shown |
|
247 |
" |
|
248 |
^ showLines |
|
249 |
! |
|
250 |
||
251 |
showLines:aState |
|
252 |
"show or hide lines |
|
253 |
" |
|
254 |
aState ~~ showLines ifTrue:[ |
|
255 |
showLines := aState. |
|
256 |
self invalidate |
|
257 |
]. |
|
494 | 258 |
! |
259 |
||
260 |
showRoot |
|
261 |
"list with or without root |
|
262 |
" |
|
263 |
^ showRoot |
|
264 |
! |
|
265 |
||
266 |
showRoot:aState |
|
267 |
"list with or without root |
|
268 |
" |
|
269 |
showRoot ~~ aState ifTrue:[ |
|
514 | 270 |
model showRoot:(showRoot := aState) |
271 |
]. |
|
517 | 272 |
! |
273 |
||
274 |
validateDoubleClickBlock |
|
275 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
276 |
on a node will be performed. In case of returning false, the doubleClick will |
|
277 |
not be handled. |
|
278 |
" |
|
279 |
^ validateDoubleClickBlock |
|
280 |
||
281 |
||
282 |
! |
|
283 |
||
284 |
validateDoubleClickBlock:aOneArgBlock |
|
285 |
"set the conditionBlock; this block is evaluated before a doubleClick action |
|
286 |
on a node will be performed. In case of returning false, the doubleClick will |
|
287 |
not be handled. |
|
288 |
" |
|
289 |
validateDoubleClickBlock := aOneArgBlock |
|
290 |
||
291 |
||
514 | 292 |
! ! |
293 |
||
294 |
!SelectionInTreeView methodsFor:'accessing-channels'! |
|
295 |
||
296 |
rootHolder |
|
297 |
"get the holder which keeps the hierarchical list entry or nil |
|
298 |
" |
|
299 |
^ rootHolder |
|
300 |
! |
|
301 |
||
302 |
rootHolder:aValueHolder |
|
303 |
"set the holder which keeps the hierarchical list entry or nil |
|
304 |
" |
|
305 |
rootHolder notNil ifTrue:[ |
|
306 |
rootHolder removeDependent:self |
|
307 |
]. |
|
308 |
(rootHolder := aValueHolder) notNil ifTrue:[ |
|
309 |
rootHolder addDependent:self. |
|
310 |
self rootFromModel. |
|
494 | 311 |
]. |
514 | 312 |
! |
313 |
||
314 |
selectionHolder |
|
315 |
"get the holder which keeps a list of selected items or nil |
|
316 |
" |
|
317 |
^ selectionHolder |
|
318 |
||
319 |
! |
|
320 |
||
321 |
selectionHolder:aHolder |
|
322 |
"set the holder which keeps a list of selected items or nil |
|
323 |
" |
|
324 |
selectionHolder notNil ifTrue:[ |
|
325 |
selectionHolder removeDependent:self |
|
326 |
]. |
|
327 |
||
328 |
(selectionHolder := aHolder) notNil ifTrue:[ |
|
329 |
selectionHolder addDependent:self. |
|
330 |
self selectionFromModel |
|
331 |
]. |
|
332 |
||
490 | 333 |
! ! |
334 |
||
335 |
!SelectionInTreeView methodsFor:'accessing-images'! |
|
336 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
337 |
imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
338 |
"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
|
339 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
340 |
^ imageClosed |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
341 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
342 |
"Created: 3.7.1997 / 12:34:31 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
343 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
344 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
345 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
346 |
"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
|
347 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
348 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
349 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
350 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
351 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
352 |
|
569 | 353 |
imageOnDevice:anImage |
354 |
"associate iamge to device and clear pixel mask (in case of realized); |
|
355 |
returns the new image. |
|
356 |
" |
|
357 |
|img| |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
358 |
|
569 | 359 |
img := anImage onDevice:device. |
360 |
||
361 |
realized ifTrue:[ |
|
362 |
img := img clearMaskedPixels |
|
363 |
]. |
|
364 |
^ img |
|
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
365 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
366 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
367 |
imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
368 |
"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
|
369 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
370 |
^ imageOpened |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
371 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
372 |
"Created: 3.7.1997 / 12:34:28 / cg" |
471 | 373 |
! ! |
374 |
||
514 | 375 |
!SelectionInTreeView methodsFor:'change & update'! |
376 |
||
377 |
update:something with:aParameter from:aModel |
|
378 |
"one of my models changed its value |
|
379 |
" |
|
380 |
aModel == rootHolder ifTrue:[ |
|
381 |
^ self rootFromModel |
|
382 |
]. |
|
383 |
aModel == selectionHolder ifTrue:[ |
|
384 |
^ self selectionFromModel |
|
385 |
]. |
|
386 |
||
585 | 387 |
aModel == aModel ifTrue:[ |
388 |
something == #list ifTrue:[ |
|
389 |
^ self getListFromModel |
|
390 |
] |
|
391 |
]. |
|
514 | 392 |
^ super update:something with:aParameter from:aModel. |
393 |
||
394 |
||
395 |
||
396 |
! ! |
|
397 |
||
444 | 398 |
!SelectionInTreeView methodsFor:'drawing'! |
399 |
||
481 | 400 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
401 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 402 |
|
403 |
! |
|
404 |
||
405 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 406 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 407 |
|
408 |
! |
|
409 |
||
410 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 411 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 412 |
|
413 |
! |
|
414 |
||
415 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 416 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 417 |
|
418 |
! |
|
419 |
||
420 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 421 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
422 |
||
444 | 423 |
! |
424 |
||
425 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 426 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 427 |
|
428 |
! ! |
|
429 |
||
430 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
431 |
||
481 | 432 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
433 |
||
494 | 434 |
|size end index yBot yTop yCtr level figWidthDiv2 |
435 |
x xFig xStr node lv idx image xCross| |
|
481 | 436 |
|
552 | 437 |
level := nil. "/ to force evaluation of #ifFalse in loop |
438 |
||
494 | 439 |
index := self visibleLineToAbsoluteLine:startVisLineNr. |
440 |
size := listOfNodes size. |
|
441 |
yTop := self yOfVisibleLine:startVisLineNr. |
|
569 | 442 |
yTop := yTop - 1. |
494 | 443 |
end := endVisLineNr - startVisLineNr + 1. |
481 | 444 |
|
445 |
"/ clear rectangle line and set background color |
|
446 |
self paint:bg. |
|
447 |
self fillRectangleX:0 y:yTop width:width height:(end * fontHeight). |
|
448 |
||
494 | 449 |
index isNil ifTrue:[^ self]. |
541 | 450 |
figWidthDiv2 := imageWidth // 2. |
494 | 451 |
yCtr := yTop - (fontHeight // 2). |
485 | 452 |
|
481 | 453 |
self paint:fg on:bg. |
494 | 454 |
(end := index + end) > size ifTrue:[end := size + 1]. |
481 | 455 |
|
494 | 456 |
[index < end] whileTrue:[ |
457 |
node := listOfNodes at:index. |
|
458 |
yBot := yTop + fontHeight. |
|
459 |
yCtr := yCtr + fontHeight. |
|
485 | 460 |
|
494 | 461 |
(lv := node level) == level ifFalse:[ |
462 |
level := lv. |
|
463 |
xFig := self xOfFigureLevel:lv. |
|
464 |
xStr := self xOfStringLevel:lv. |
|
465 |
xCross := (self xOfFigureLevel:(lv-1)) + figWidthDiv2. |
|
481 | 466 |
]. |
467 |
||
468 |
showLines ifTrue:[ |
|
494 | 469 |
(node isCollapsable and:[node numberOfChildren ~~ 0]) ifTrue:[ |
470 |
x := xFig + figWidthDiv2. |
|
471 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
|
481 | 472 |
]. |
494 | 473 |
(level ~~ 1 and:[node parent children last == node]) ifTrue:[ |
569 | 474 |
self displayLineFromX:xCross y:yTop - 1 toX:xCross y:yCtr . "/ vertical |
490 | 475 |
]. |
494 | 476 |
self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr . "/ horizontal |
481 | 477 |
|
478 |
"/ draw vertical lines |
|
494 | 479 |
idx := index. |
481 | 480 |
|
494 | 481 |
[(lv > 0 and:[(idx := idx + 1) <= size])] whileTrue:[ |
482 |
(x := (listOfNodes at:idx) level) <= lv ifTrue:[ |
|
483 |
lv := x - 1. |
|
484 |
x := (self xOfFigureLevel:lv) + figWidthDiv2. |
|
569 | 485 |
self displayLineFromX:x y:yTop - 1 toX:x y:yBot. |
481 | 486 |
] |
487 |
] |
|
488 |
]. |
|
489 |
||
490 |
"/ draw image |
|
494 | 491 |
image := self figureFor:node. |
541 | 492 |
image notNil ifTrue:[ |
529 | 493 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)). |
541 | 494 |
]. |
481 | 495 |
|
496 |
"/ draw text label |
|
494 | 497 |
self drawLabelIndex:index atX:xStr y:yCtr . |
490 | 498 |
|
494 | 499 |
"/ draw directory indicator |
569 | 500 |
(showDirectoryIndicator and:[node showIndicator]) ifTrue:[ |
494 | 501 |
node isCollapsable ifTrue:[ |
502 |
image := openIndicator. |
|
503 |
x := extentOpenIndicator. |
|
504 |
] ifFalse:[ |
|
505 |
image := closeIndicator. |
|
506 |
x := extentCloseIndicator. |
|
507 |
]. |
|
508 |
self displayForm:image x:(xCross - x x) |
|
509 |
y:(yCtr - x y) |
|
485 | 510 |
]. |
481 | 511 |
"/ setup next line |
494 | 512 |
index := index + 1. |
513 |
yTop := yBot. |
|
481 | 514 |
]. |
515 |
||
541 | 516 |
"Modified: 6.10.1997 / 13:31:51 / cg" |
485 | 517 |
! |
518 |
||
444 | 519 |
drawLabelIndex:anIndex atX:x y:yCenter |
520 |
"draw text label at x and y centered |
|
521 |
" |
|
569 | 522 |
|lbl| |
444 | 523 |
|
569 | 524 |
(lbl := (listOfNodes at:anIndex) name) notNil ifTrue:[ |
525 |
self displayOpaqueString:lbl x:x y:(yCenter + labelOffsetY). |
|
526 |
] |
|
527 |
! |
|
444 | 528 |
|
569 | 529 |
redrawX:x y:y width:w height:h |
530 |
||
531 |
self shown ifTrue:[ |
|
532 |
super redrawX:x y:y width:w height:h. |
|
533 |
]. |
|
444 | 534 |
! ! |
535 |
||
494 | 536 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 537 |
|
494 | 538 |
detectNode:aOneArgBlock |
539 |
"evaluate the argument, aBlock for each node in the list until |
|
540 |
the block returns true; in this case return the node which caused |
|
541 |
the true evaluation. If none node is detected, nil is returned. |
|
542 |
" |
|
543 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 544 |
! |
545 |
||
546 |
selectedNodesDo:aOneArgBlock |
|
547 |
"evaluate the block on each node selected |
|
548 |
" |
|
549 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 550 |
! ! |
551 |
||
569 | 552 |
!SelectionInTreeView methodsFor:'event handling'! |
553 |
||
554 |
buttonMultiPress:button x:x y:y |
|
555 |
||
556 |
(self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[ |
|
557 |
^ super buttonMultiPress:button x:x y:y |
|
558 |
]. |
|
559 |
"/ discard doubleClick on indicator |
|
560 |
! |
|
561 |
||
562 |
buttonPress:button x:x y:y |
|
563 |
"check for indicator |
|
564 |
" |
|
565 |
|expand node lineNr selNode newSel size oldSelection| |
|
566 |
||
567 |
lineNr := self indicatiorLineForButton:button atX:x y:y. |
|
568 |
||
569 |
lineNr == 0 ifTrue:[ |
|
570 |
^ super buttonPress:button x:x y:y |
|
571 |
]. |
|
572 |
node := listOfNodes at:lineNr. |
|
573 |
||
574 |
( validateDoubleClickBlock isNil |
|
575 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
576 |
) ifFalse:[ |
|
577 |
^ super buttonPress:button x:x y:y |
|
578 |
]. |
|
579 |
||
580 |
dragIsActive := false. |
|
581 |
clickPosition := nil. |
|
582 |
expand := node isExpandable. |
|
583 |
||
584 |
(size := self numberOfSelections) == 0 ifTrue:[ "/ nothing selected |
|
585 |
^ self nodeAt:lineNr expand:expand. |
|
586 |
]. |
|
587 |
oldSelection := selection. |
|
588 |
||
589 |
size == 1 ifTrue:[ "/ single selection |
|
590 |
selNode := self selectedNode. |
|
591 |
||
592 |
lineNr >= self selectedIndex ifTrue:[ "/ operation will not changed |
|
593 |
^ self nodeAt:lineNr expand:expand. "/ current selected index |
|
594 |
]. |
|
595 |
model setSelectionIndex:0. "/ selected index will change |
|
596 |
self selectWithoutScroll:nil. |
|
597 |
||
598 |
self nodeAt:lineNr expand:expand. |
|
599 |
size := self indexOfNode:selNode. |
|
600 |
||
601 |
size == 0 ifTrue:[ "/ old selection no longer visible |
|
602 |
^ self selection:lineNr "/ change selection; raise notify |
|
603 |
]. |
|
604 |
self selectWithoutScroll:size. "/ can keep old selection |
|
605 |
model setSelectionIndex:selection. "/ but has to change index |
|
606 |
^ self selectionChangedFrom:oldSelection |
|
607 |
]. |
|
608 |
selNode := OrderedCollection new:size. |
|
609 |
newSel := OrderedCollection new:size. |
|
610 |
||
611 |
self selectionDo:[:i| |
|
612 |
selNode add:(listOfNodes at:i) "/ change selection to nodes |
|
613 |
]. |
|
614 |
model setSelectionIndex:0. "/ redraw current selection unselected |
|
615 |
self selectWithoutScroll:nil. |
|
616 |
self nodeAt:lineNr expand:expand. "/ perform expand/collapse operation |
|
617 |
||
618 |
selNode do:[:n||i| "/ convert old selection to new selection |
|
619 |
(i := self indexOfNode:n) ~~ 0 ifTrue:[ |
|
620 |
newSel add:i "/ can take over into new selection |
|
621 |
] |
|
622 |
]. |
|
623 |
||
624 |
newSel isEmpty ifTrue:[ "/ old selection no longer visible |
|
625 |
^ self selection:lineNr "/ change selection; raise notify |
|
626 |
]. |
|
627 |
||
628 |
newSel size == size ifTrue:[ |
|
629 |
self selectWithoutScroll:newSel. "/ can keep old selection |
|
630 |
model setSelectionIndex:selection. "/ but has to change indeces |
|
631 |
self selectionChangedFrom:oldSelection. |
|
632 |
] ifFalse:[ |
|
633 |
self selection:newSel "/ can keep part of old selection |
|
634 |
] |
|
635 |
! |
|
636 |
||
637 |
doubleClicked |
|
638 |
"handle a double click; collapse or expand selected entry |
|
639 |
in case of having children |
|
640 |
" |
|
641 |
|node| |
|
642 |
||
643 |
(node := self selectedNode) notNil ifTrue:[ |
|
644 |
( validateDoubleClickBlock isNil |
|
645 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
646 |
) ifTrue:[ |
|
647 |
self selectedNodeExpand:(node isExpandable). |
|
648 |
super doubleClicked |
|
649 |
] |
|
650 |
] |
|
651 |
||
652 |
! |
|
653 |
||
654 |
indicatiorLineForButton:aButton atX:x y:y |
|
655 |
"returns linenumber assigned to indicator at x/y or 0 |
|
656 |
" |
|
657 |
|sensor nr x0 node| |
|
658 |
||
659 |
( enabled |
|
660 |
and:[showDirectoryIndicator |
|
661 |
and:[aButton == 1 or:[aButton == #select]]] |
|
662 |
) ifTrue:[ |
|
663 |
sensor := self sensor. |
|
664 |
||
665 |
(sensor ctrlDown or:[sensor shiftDown]) ifFalse:[ |
|
666 |
nr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
667 |
||
668 |
nr notNil ifTrue:[ |
|
669 |
node := listOfNodes at:nr. |
|
670 |
x0 := self xOfFigureLevel:(node level - 1). |
|
671 |
||
672 |
(x > x0 and:[(x0 + imageWidth) > x and:[node numberOfChildren ~~ 0]]) ifTrue:[ |
|
673 |
^ nr |
|
674 |
] |
|
675 |
] |
|
676 |
] |
|
677 |
]. |
|
678 |
^ 0 |
|
679 |
! ! |
|
680 |
||
444 | 681 |
!SelectionInTreeView methodsFor:'initialization'! |
682 |
||
514 | 683 |
destroy |
684 |
"remove dependencies |
|
685 |
" |
|
686 |
rootHolder notNil ifTrue:[ |
|
687 |
rootHolder removeDependent:self |
|
688 |
]. |
|
689 |
selectionHolder notNil ifTrue:[ |
|
690 |
selectionHolder removeDependent:self |
|
691 |
]. |
|
692 |
super destroy. |
|
693 |
||
694 |
||
695 |
! |
|
696 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
697 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
698 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
699 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
700 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
701 |
super fetchDeviceResources. |
478 | 702 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
703 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
704 |
|
478 | 705 |
fetchImageResources |
706 |
"initialize heavily used device resources - to avoid rendering |
|
707 |
images again and again later; returns maximum extent of the images used. |
|
708 |
Could be redefined by subclass |
|
471 | 709 |
" |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
710 |
|extent| |
494 | 711 |
|
712 |
imageOpened isNil ifTrue:[ |
|
569 | 713 |
imageOpened := (self class imageOpened) onDevice:device |
494 | 714 |
]. |
444 | 715 |
|
494 | 716 |
imageClosed isNil ifTrue:[ |
569 | 717 |
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
|
718 |
]. |
569 | 719 |
extent := (imageOpened extent) max:(imageClosed extent). |
494 | 720 |
|
721 |
imageItem isNil ifTrue:[ |
|
569 | 722 |
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
|
723 |
]. |
569 | 724 |
^ extent max:(imageItem extent) |
444 | 725 |
! |
726 |
||
480 | 727 |
getFontParameters |
546 | 728 |
"save old computed height derived from images |
729 |
" |
|
730 |
|lineHeight| |
|
731 |
||
732 |
lineHeight := fontHeight ? 0. |
|
480 | 733 |
super getFontParameters. |
569 | 734 |
labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2). |
480 | 735 |
|
546 | 736 |
lineHeight > fontHeight ifTrue:[ |
737 |
fontHeight := lineHeight |
|
738 |
]. |
|
480 | 739 |
! |
740 |
||
444 | 741 |
initialize |
471 | 742 |
"setup instance attributes |
743 |
" |
|
444 | 744 |
super initialize. |
569 | 745 |
self bitGravity:#NorthWest. |
485 | 746 |
showLines := true. |
494 | 747 |
showRoot := true. |
546 | 748 |
computeResources := true. |
485 | 749 |
showDirectoryIndicator := false. |
494 | 750 |
textInset := 2. |
751 |
imageInset := 0. "/ set during indication enabled |
|
752 |
imageWidth := 8. "/ default: will change during startup |
|
514 | 753 |
self model:nil. "/ creates a default model. |
478 | 754 |
! |
755 |
||
569 | 756 |
realize |
757 |
super realize. |
|
758 |
self refetchDeviceResources. |
|
759 |
||
760 |
! |
|
761 |
||
478 | 762 |
refetchDeviceResources |
763 |
"reinitialize heavily used device resources - to avoid rendering |
|
764 |
images again and again later |
|
765 |
" |
|
551 | 766 |
|extent| |
478 | 767 |
|
569 | 768 |
(realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[ |
546 | 769 |
computeResources := false. |
770 |
extent := self fetchImageResources. |
|
494 | 771 |
|
546 | 772 |
extent y >= fontHeight ifTrue:[ |
773 |
fontHeight := 1 + extent y. |
|
494 | 774 |
]. |
546 | 775 |
imageWidth := extent x. |
776 |
self recomputeDirectoryIndicator. |
|
569 | 777 |
self computeNumberOfLinesShown. |
546 | 778 |
] |
444 | 779 |
! ! |
780 |
||
483 | 781 |
!SelectionInTreeView methodsFor:'model'! |
444 | 782 |
|
783 |
getListFromModel |
|
784 |
"if I have a model, get my list from it using the listMessage. |
|
785 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
786 |
" |
|
483 | 787 |
super list:(self listFromModel) keepSelection:true |
788 |
! |
|
444 | 789 |
|
483 | 790 |
listFromModel |
791 |
"get list from model and return the new list. |
|
792 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
793 |
" |
|
794 |
|msg| |
|
444 | 795 |
|
468 | 796 |
widthOfWidestLine := nil. |
444 | 797 |
|
514 | 798 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
799 |
listOfNodes := model perform:msg. |
|
800 |
listOfNodes size ~~ 0 ifTrue:[ |
|
546 | 801 |
self refetchDeviceResources. |
514 | 802 |
^ listOfNodes collect:[:n|n name] |
483 | 803 |
] |
804 |
]. |
|
805 |
listOfNodes := #(). |
|
806 |
^ #() |
|
494 | 807 |
! |
808 |
||
809 |
model:aModel |
|
514 | 810 |
"check whether model is nil; than a default model is created |
811 |
" |
|
812 |
|model| |
|
813 |
||
814 |
model := aModel ? (SelectionInTree new). |
|
815 |
model showRoot:showRoot. |
|
816 |
super model:model. |
|
817 |
! |
|
818 |
||
819 |
rootFromModel |
|
820 |
"update hierarchical list from root model; 'rootHolder' |
|
821 |
" |
|
822 |
|root| |
|
823 |
||
585 | 824 |
root := rootHolder root. |
514 | 825 |
|
826 |
self root == root ifFalse:[ |
|
827 |
self selection:nil. |
|
828 |
self root:root. |
|
585 | 829 |
]. |
514 | 830 |
! |
831 |
||
832 |
selectionFromModel |
|
833 |
"set the selection derived from the selectionHolder |
|
834 |
" |
|
545 | 835 |
|coll value sz| |
514 | 836 |
|
837 |
(value := selectionHolder value) isNil ifTrue:[ |
|
838 |
^ self deselect |
|
507 | 839 |
]. |
514 | 840 |
|
841 |
multipleSelectOk ifFalse:[ |
|
842 |
self selectNode:value |
|
843 |
] ifTrue:[ |
|
545 | 844 |
(sz := value size) ~~ 0 ifTrue:[ |
845 |
coll := OrderedCollection new:sz. |
|
514 | 846 |
|
847 |
value do:[:aNode||i| |
|
848 |
(i := self indexOfNode:aNode) notNil ifTrue:[ |
|
849 |
coll add:i |
|
850 |
] |
|
851 |
] |
|
852 |
]. |
|
853 |
coll size == 0 ifTrue:[self deselect] |
|
854 |
ifFalse:[self selection:coll] |
|
855 |
] |
|
856 |
! |
|
857 |
||
858 |
selectionToModel |
|
859 |
"write selection to selection holder |
|
860 |
" |
|
861 |
|newSel oldSel| |
|
862 |
||
863 |
oldSel := selectionHolder value. |
|
864 |
||
865 |
multipleSelectOk ifFalse:[ |
|
866 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
867 |
selectionHolder value:newSel |
|
868 |
] |
|
869 |
] ifTrue:[ |
|
870 |
selection size == 0 ifTrue:[ |
|
871 |
oldSel notNil ifTrue:[ |
|
872 |
selectionHolder value:nil |
|
873 |
] |
|
874 |
] ifFalse:[ |
|
875 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
876 |
||
877 |
newSel size ~~ oldSel size ifTrue:[ |
|
878 |
selectionHolder value:newSel. |
|
879 |
] ifFalse:[ |
|
880 |
newSel do:[:aNode| |
|
881 |
(oldSel includes:aNode) ifFalse:[ |
|
882 |
^ selectionHolder value:newSel |
|
883 |
] |
|
884 |
] |
|
885 |
] |
|
886 |
] |
|
887 |
] |
|
444 | 888 |
! ! |
889 |
||
490 | 890 |
!SelectionInTreeView methodsFor:'private'! |
891 |
||
892 |
list:aList keepSelection:keepSelection |
|
585 | 893 |
"setup new list; keep selection dependent on the boolean state |
894 |
keepSelection |
|
895 |
" |
|
490 | 896 |
|list| |
897 |
||
898 |
list := aList. |
|
899 |
||
900 |
list size == 0 ifTrue:[ |
|
901 |
listOfNodes := #() |
|
902 |
] ifFalse:[ |
|
903 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
904 |
listOfNodes := aList. |
|
546 | 905 |
self refetchDeviceResources. |
490 | 906 |
list := listOfNodes collect:[:aNode| aNode name ]. |
907 |
] |
|
908 |
]. |
|
909 |
super list:list keepSelection:keepSelection |
|
546 | 910 |
! |
911 |
||
569 | 912 |
nodeAt:anIndex expand:doExpand |
585 | 913 |
"expand or collapse the node at an index, anIndex dependent on the boolean state |
914 |
of doExpand |
|
915 |
" |
|
569 | 916 |
|node| |
917 |
||
918 |
node := listOfNodes at:anIndex. |
|
919 |
||
920 |
node hasChildren ifTrue:[ |
|
921 |
node isExpandable ifTrue:[ |
|
922 |
doExpand ifFalse:[^ self]. |
|
923 |
node expand |
|
924 |
] ifFalse:[ |
|
925 |
doExpand ifTrue:[^ self]. |
|
926 |
node collapse |
|
927 |
]. |
|
928 |
||
929 |
node numberOfChildren == 0 ifTrue:[ |
|
930 |
"/ no children; redraw selected line (image might change) |
|
931 |
self redrawLine:anIndex. |
|
932 |
] ifFalse:[ |
|
933 |
"/ with children; update list and redraw to end. |
|
585 | 934 |
model removeDependent:self. |
935 |
model recomputeList. |
|
936 |
model addDependent:self. |
|
569 | 937 |
list := self listFromModel. |
938 |
self redrawFromLine:anIndex. |
|
939 |
self contentsChanged. |
|
940 |
] |
|
941 |
] |
|
942 |
||
943 |
! |
|
944 |
||
546 | 945 |
recomputeDirectoryIndicator |
946 |
"setup attributes used by directory indicator |
|
947 |
" |
|
948 |
|x1 x2 y| |
|
949 |
||
950 |
imageInset := 0. |
|
951 |
||
952 |
(showDirectoryIndicator and:[computeResources not]) ifFalse:[ |
|
953 |
^ self |
|
954 |
]. |
|
569 | 955 |
openIndicator isNil ifTrue:[ |
956 |
openIndicator := self imageOnDevice:(self class openIndicator) |
|
957 |
]. |
|
958 |
closeIndicator isNil ifTrue:[ |
|
959 |
closeIndicator := self imageOnDevice:(self class closeIndicator) |
|
960 |
]. |
|
546 | 961 |
|
962 |
x1 := (openIndicator widthOn:self) // 2. |
|
963 |
y := openIndicator heightOn:self. |
|
964 |
extentOpenIndicator := Point x:x1 y:(y // 2). |
|
965 |
x2 := (closeIndicator widthOn:self) // 2. |
|
966 |
y := closeIndicator heightOn:self. |
|
967 |
extentCloseIndicator := Point x:x2 y:(y // 2). |
|
968 |
||
969 |
x2 > x1 ifTrue:[x1 := x2]. |
|
970 |
||
971 |
(x1 := x1 + self class minImageInset) > (imageWidth // 2) ifTrue:[ |
|
972 |
imageInset := x1 - (imageWidth // 2). |
|
973 |
]. |
|
974 |
||
490 | 975 |
! ! |
976 |
||
468 | 977 |
!SelectionInTreeView methodsFor:'private queries'! |
978 |
||
979 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
980 |
"return the length (in characters) of the longest line in a line-range |
|
981 |
" |
|
982 |
|max| |
|
983 |
||
984 |
max := self widthOfContents:firstLine and:lastLine. |
|
985 |
^ (max // fontWidth) + 1 |
|
986 |
! |
|
987 |
||
988 |
widthOfContents |
|
989 |
"return the width of the contents in pixels |
|
990 |
- used for scrollbar interface" |
|
991 |
||
992 |
list isNil ifTrue:[^ 0]. |
|
993 |
||
994 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
995 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
996 |
]. |
|
997 |
^ widthOfWidestLine + (leftMargin * 2) |
|
998 |
||
999 |
! |
|
1000 |
||
1001 |
widthOfContents:firstLine and:lastLine |
|
1002 |
"return the length (in pixels) of the longest line in a line-range |
|
1003 |
" |
|
1004 |
|max "{ Class: SmallInteger }" |
|
1005 |
thisLen "{ Class: SmallInteger }" |
|
1006 |
first "{ Class: SmallInteger }" |
|
1007 |
last "{ Class: SmallInteger }" | |
|
1008 |
||
1009 |
listOfNodes size == 0 ifTrue:[^ 0]. |
|
1010 |
||
1011 |
last := listOfNodes size. |
|
1012 |
first := firstLine. |
|
1013 |
||
1014 |
(first > last) ifTrue:[^ 0]. |
|
1015 |
||
1016 |
(lastLine < last) ifTrue:[ |
|
1017 |
last := lastLine |
|
1018 |
]. |
|
1019 |
max := 0. |
|
1020 |
||
1021 |
listOfNodes from:first to:last do:[:anItem||name| |
|
1022 |
thisLen := self xOfStringNode:anItem. |
|
1023 |
||
1024 |
(name := anItem name) notNil ifTrue:[ |
|
1025 |
thisLen := thisLen + (name widthOn:self). |
|
1026 |
]. |
|
1027 |
(thisLen > max) ifTrue:[ |
|
1028 |
max := thisLen. |
|
1029 |
] |
|
1030 |
]. |
|
1031 |
^ max + leftOffset. |
|
1032 |
! |
|
1033 |
||
1034 |
withoutRedrawAt:anIndex put:aString |
|
1035 |
"change a line without redisplay" |
|
1036 |
||
1037 |
|width| |
|
1038 |
||
1039 |
width := widthOfWidestLine. |
|
1040 |
widthOfWidestLine := nil. |
|
1041 |
||
1042 |
super withoutRedrawAt:anIndex put:aString. |
|
1043 |
||
1044 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
1045 |
width := self widthOfContents:anIndex and:anIndex. |
|
1046 |
||
1047 |
width > widthOfWidestLine ifTrue:[ |
|
1048 |
widthOfWidestLine := width |
|
1049 |
] ifFalse:[ |
|
1050 |
widthOfWidestLine := nil "/ means: unknown |
|
1051 |
] |
|
1052 |
]. |
|
1053 |
||
1054 |
||
1055 |
! ! |
|
1056 |
||
483 | 1057 |
!SelectionInTreeView methodsFor:'queries'! |
1058 |
||
1059 |
figureFor:aNode |
|
1060 |
"access figure for a node |
|
1061 |
" |
|
1062 |
aNode hasChildren ifTrue:[ |
|
1063 |
aNode isExpandable ifTrue:[ ^ imageClosed ] |
|
1064 |
ifFalse:[ ^ imageOpened ] |
|
1065 |
]. |
|
1066 |
^ imageItem |
|
1067 |
! |
|
1068 |
||
1069 |
indexOfNode:aNode |
|
1070 |
"returns index of a node |
|
1071 |
" |
|
1072 |
^ listOfNodes findFirst:[:n| n == aNode ] |
|
1073 |
! |
|
1074 |
||
494 | 1075 |
xOfFigureLevel:aLevel |
1076 |
"origin x where to draw the icon |
|
1077 |
" |
|
1078 |
|l| |
|
1079 |
||
1080 |
showRoot ifTrue:[l := aLevel] |
|
1081 |
ifFalse:[l := aLevel - 1]. |
|
1082 |
||
1083 |
showDirectoryIndicator ifFalse:[l := l - 1]. |
|
1084 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
|
1085 |
||
1086 |
! |
|
1087 |
||
483 | 1088 |
xOfFigureNode:aNode |
1089 |
"origin x where to draw the icon |
|
1090 |
" |
|
494 | 1091 |
^ self xOfFigureLevel:(aNode level) |
1092 |
! |
|
490 | 1093 |
|
494 | 1094 |
xOfStringLevel:aLevel |
1095 |
"origin x where to draw the text( label ) |
|
1096 |
" |
|
1097 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 1098 |
|
1099 |
! |
|
1100 |
||
1101 |
xOfStringNode:aNode |
|
1102 |
"origin x where to draw the text( label ) |
|
1103 |
" |
|
494 | 1104 |
^ self xOfStringLevel:(aNode level) |
483 | 1105 |
|
1106 |
! ! |
|
1107 |
||
444 | 1108 |
!SelectionInTreeView methodsFor:'selection'! |
1109 |
||
494 | 1110 |
selectFromListOfNames:aListOfNames |
1111 |
"set selection from a list of names |
|
1112 |
" |
|
497 | 1113 |
|node rdwNd| |
494 | 1114 |
|
1115 |
aListOfNames size < 1 ifTrue:[ |
|
1116 |
^ self selection:nil |
|
1117 |
]. |
|
1118 |
||
1119 |
node := model root. |
|
1120 |
||
1121 |
aListOfNames do:[:el||next| |
|
1122 |
next := node detectChild:[:e|e name = el]. |
|
1123 |
||
1124 |
next notNil ifTrue:[ |
|
1125 |
node hidden ifTrue:[ |
|
1126 |
rdwNd isNil ifTrue:[ |
|
1127 |
rdwNd := node. |
|
1128 |
self selectNode:node. |
|
1129 |
]. |
|
1130 |
node expand |
|
1131 |
]. |
|
1132 |
node := next |
|
1133 |
] |
|
1134 |
]. |
|
1135 |
||
1136 |
rdwNd notNil ifTrue:[ |
|
585 | 1137 |
model removeDependent:self. |
1138 |
model recomputeList. |
|
1139 |
model addDependent:self. |
|
494 | 1140 |
list := self listFromModel. |
1141 |
self redrawFromLine:(self indexOfNode:rdwNd). |
|
1142 |
self contentsChanged. |
|
1143 |
]. |
|
1144 |
self selectNode:node. |
|
1145 |
||
1146 |
! |
|
1147 |
||
468 | 1148 |
selectNode:aNode |
1149 |
"change selection to a node |
|
1150 |
" |
|
483 | 1151 |
self selection:(self indexOfNode:aNode) |
468 | 1152 |
|
1153 |
||
1154 |
! |
|
1155 |
||
456 | 1156 |
selectedIndex |
1157 |
"get single selected index or 0 |
|
1158 |
" |
|
483 | 1159 |
selection size == 1 ifTrue:[^ selection first]. |
1160 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 1161 |
^ 0 |
444 | 1162 |
! |
1163 |
||
1164 |
selectedNode |
|
1165 |
"get the single selected node or nil |
|
1166 |
" |
|
456 | 1167 |
|idx| |
1168 |
||
1169 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
1170 |
^ listOfNodes at:idx |
|
444 | 1171 |
]. |
1172 |
^ nil |
|
514 | 1173 |
! |
1174 |
||
1175 |
selectionChangedFrom:oldSelection |
|
1176 |
"update selectionHolder if not nil |
|
1177 |
" |
|
1178 |
super selectionChangedFrom:oldSelection. |
|
1179 |
||
1180 |
selectionHolder notNil ifTrue:[ |
|
1181 |
self selectionToModel. |
|
1182 |
]. |
|
1183 |
||
444 | 1184 |
! ! |
1185 |
||
507 | 1186 |
!SelectionInTreeView methodsFor:'selection-actions'! |
1187 |
||
1188 |
selectedNodeAdd:something |
|
1189 |
"add a node or collection of nodes after selected node |
|
1190 |
" |
|
1191 |
|node| |
|
1192 |
||
1193 |
something notNil ifTrue:[ |
|
1194 |
(node := self selectedNode) notNil ifTrue:[ |
|
1195 |
node parent notNil ifTrue:[ |
|
1196 |
node isCollapsable ifTrue:[ |
|
1197 |
model add:something beforeIndex:1 below:node |
|
1198 |
] ifFalse:[ |
|
1199 |
model add:something after:node |
|
1200 |
] |
|
1201 |
] ifFalse:[ |
|
1202 |
model add:something beforeIndex:1 below:(self root) |
|
1203 |
] |
|
1204 |
] |
|
1205 |
] |
|
1206 |
||
1207 |
! |
|
1208 |
||
1209 |
selectedNodeBecomeChildOfNext |
|
1210 |
"become node a child of followd node |
|
1211 |
" |
|
1212 |
|idx node cprt nprt| |
|
1213 |
||
1214 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
1215 |
idx := cprt indexOfChild:node. |
|
1216 |
||
1217 |
idx == cprt children size ifFalse:[ |
|
1218 |
nprt := cprt childAt:(idx + 1). |
|
1219 |
||
1220 |
nprt notNil ifTrue:[ |
|
1221 |
model removeDependent:self. |
|
1222 |
model removeSelection. |
|
1223 |
selection := nil. |
|
1224 |
model collapse:nprt. |
|
1225 |
model add:node beforeIndex:1 below:nprt. |
|
1226 |
model addDependent:self. |
|
1227 |
model expand:nprt. |
|
1228 |
||
1229 |
self selectNode:node. |
|
1230 |
] |
|
1231 |
] |
|
1232 |
] |
|
1233 |
! |
|
1234 |
||
1235 |
selectedNodeBecomeSisterOfParent |
|
1236 |
"become node a sister of its current parent |
|
1237 |
" |
|
1238 |
|node cprt nprt| |
|
1239 |
||
1240 |
( (node := self selectedNode) isNil |
|
1241 |
or:[(cprt := node parent) isNil |
|
1242 |
or:[(nprt := cprt parent) isNil]] |
|
1243 |
) ifFalse:[ |
|
1244 |
model removeDependent:self. |
|
1245 |
model removeSelection. |
|
1246 |
selection := nil. |
|
1247 |
model addDependent:self. |
|
1248 |
||
1249 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
|
1250 |
self selectNode:node. |
|
1251 |
] |
|
1252 |
||
1253 |
! |
|
1254 |
||
1255 |
selectedNodeChangeSequenceOrder:anOffset |
|
1256 |
"move child 'anOffset' forward or backward in list of children |
|
1257 |
" |
|
1258 |
|idx node size parent| |
|
1259 |
||
1260 |
( (node := self selectedNode) notNil |
|
1261 |
and:[(parent := node parent) notNil |
|
1262 |
and:[(size := parent children size) > 1]] |
|
1263 |
) ifTrue:[ |
|
1264 |
idx := parent indexOfChild:node. |
|
1265 |
||
1266 |
model removeDependent:self. |
|
1267 |
model removeSelection. |
|
1268 |
selection := nil. |
|
1269 |
model addDependent:self. |
|
1270 |
||
1271 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
1272 |
idx := size |
|
1273 |
] ifFalse:[ |
|
1274 |
idx > size ifTrue:[idx := 1] |
|
1275 |
]. |
|
1276 |
model add:node beforeIndex:idx below:parent. |
|
1277 |
self selectNode:node. |
|
1278 |
] |
|
1279 |
! |
|
1280 |
||
1281 |
selectedNodeExpand:doExpand |
|
1282 |
"collapse or expand selected node |
|
1283 |
" |
|
1284 |
|node index| |
|
1285 |
||
1286 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
|
1287 |
node := listOfNodes at:index. |
|
1288 |
||
1289 |
node hasChildren ifTrue:[ |
|
1290 |
node isExpandable ifTrue:[ |
|
1291 |
doExpand ifFalse:[^ self]. |
|
1292 |
node expand |
|
1293 |
] ifFalse:[ |
|
1294 |
doExpand ifTrue:[^ self]. |
|
1295 |
node collapse |
|
1296 |
]. |
|
1297 |
||
1298 |
node numberOfChildren == 0 ifTrue:[ |
|
1299 |
"/ no children; redraw selected line (image might change) |
|
1300 |
self redrawLine:index. |
|
1301 |
] ifFalse:[ |
|
1302 |
"/ with children; update list and redraw to end. |
|
585 | 1303 |
model removeDependent:self. |
1304 |
model recomputeList. |
|
1305 |
model addDependent:self. |
|
507 | 1306 |
list := self listFromModel. |
1307 |
self redrawFromLine:index. |
|
1308 |
self contentsChanged. |
|
1309 |
] |
|
1310 |
] |
|
1311 |
]. |
|
1312 |
! |
|
1313 |
||
1314 |
selectedNodesRemove |
|
1315 |
"remove selected nodes |
|
1316 |
" |
|
1317 |
model removeSelection. |
|
1318 |
self selection:nil. |
|
1319 |
||
1320 |
! ! |
|
1321 |
||
444 | 1322 |
!SelectionInTreeView class methodsFor:'documentation'! |
1323 |
||
1324 |
version |
|
585 | 1325 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.29 1997-10-29 08:25:02 ca Exp $' |
444 | 1326 |
! ! |