author | Claus Gittinger <cg@exept.de> |
Mon, 06 Oct 1997 14:32:48 +0200 | |
changeset 541 | 4e7032015683 |
parent 533 | d7867efb6f60 |
child 545 | d01d14358b07 |
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 |
514 | 16 |
showLines listOfNodes imageInset textInset openIndicator |
17 |
closeIndicator showRoot extentOpenIndicator extentCloseIndicator |
|
18 |
showDirectoryIndicator indicatorExtentDiv2 imageOpened |
|
19 |
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. |
240 |
self refetchDeviceResources. |
|
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 |
imageClosed:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
346 |
"set 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
|
347 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
348 |
imageClosed := something. |
494 | 349 |
self refetchDeviceResources. |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
350 |
! |
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 |
imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
353 |
"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
|
354 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
355 |
^ imageItem |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
356 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
357 |
"Created: 3.7.1997 / 12:34:34 / cg" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
358 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
359 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
360 |
imageItem:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
361 |
"set 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
|
362 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
363 |
imageItem := something. |
494 | 364 |
self refetchDeviceResources. |
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" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
373 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
374 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
375 |
imageOpened:something |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
376 |
"set 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
|
377 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
378 |
imageOpened := something. |
494 | 379 |
self refetchDeviceResources. |
471 | 380 |
! ! |
381 |
||
514 | 382 |
!SelectionInTreeView methodsFor:'change & update'! |
383 |
||
384 |
update:something with:aParameter from:aModel |
|
385 |
"one of my models changed its value |
|
386 |
" |
|
387 |
aModel == rootHolder ifTrue:[ |
|
388 |
^ self rootFromModel |
|
389 |
]. |
|
390 |
aModel == selectionHolder ifTrue:[ |
|
391 |
^ self selectionFromModel |
|
392 |
]. |
|
393 |
||
394 |
^ super update:something with:aParameter from:aModel. |
|
395 |
||
396 |
||
397 |
||
398 |
! ! |
|
399 |
||
444 | 400 |
!SelectionInTreeView methodsFor:'drawing'! |
401 |
||
481 | 402 |
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg |
403 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
|
444 | 404 |
|
405 |
! |
|
406 |
||
407 |
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg |
|
481 | 408 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 409 |
|
410 |
! |
|
411 |
||
412 |
drawLine:line inVisible:visLineNr with:fg and:bg |
|
481 | 413 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 414 |
|
415 |
! |
|
416 |
||
417 |
drawVisibleLine:visLineNr col:col with:fg and:bg |
|
481 | 418 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 419 |
|
420 |
! |
|
421 |
||
422 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
|
481 | 423 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
424 |
||
444 | 425 |
! |
426 |
||
427 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg |
|
481 | 428 |
self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg |
444 | 429 |
|
430 |
! ! |
|
431 |
||
432 |
!SelectionInTreeView methodsFor:'drawing basics'! |
|
433 |
||
481 | 434 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
435 |
||
494 | 436 |
|size end index yBot yTop yCtr level figWidthDiv2 |
437 |
x xFig xStr node lv idx image xCross| |
|
481 | 438 |
|
494 | 439 |
index := self visibleLineToAbsoluteLine:startVisLineNr. |
440 |
size := listOfNodes size. |
|
441 |
yTop := self yOfVisibleLine:startVisLineNr. |
|
442 |
end := endVisLineNr - startVisLineNr + 1. |
|
481 | 443 |
|
444 |
"/ clear rectangle line and set background color |
|
445 |
self paint:bg. |
|
446 |
self fillRectangleX:0 y:yTop width:width height:(end * fontHeight). |
|
447 |
||
494 | 448 |
index isNil ifTrue:[^ self]. |
541 | 449 |
figWidthDiv2 := imageWidth // 2. |
494 | 450 |
yCtr := yTop - (fontHeight // 2). |
485 | 451 |
|
481 | 452 |
self paint:fg on:bg. |
494 | 453 |
(end := index + end) > size ifTrue:[end := size + 1]. |
481 | 454 |
|
494 | 455 |
[index < end] whileTrue:[ |
456 |
node := listOfNodes at:index. |
|
457 |
yBot := yTop + fontHeight. |
|
458 |
yCtr := yCtr + fontHeight. |
|
485 | 459 |
|
494 | 460 |
(lv := node level) == level ifFalse:[ |
461 |
level := lv. |
|
462 |
xFig := self xOfFigureLevel:lv. |
|
463 |
xStr := self xOfStringLevel:lv. |
|
464 |
xCross := (self xOfFigureLevel:(lv-1)) + figWidthDiv2. |
|
481 | 465 |
]. |
466 |
||
467 |
showLines ifTrue:[ |
|
494 | 468 |
(node isCollapsable and:[node numberOfChildren ~~ 0]) ifTrue:[ |
469 |
x := xFig + figWidthDiv2. |
|
470 |
self displayLineFromX:x y:yCtr toX:x y:yBot |
|
481 | 471 |
]. |
494 | 472 |
(level ~~ 1 and:[node parent children last == node]) ifTrue:[ |
473 |
self displayLineFromX:xCross y:yTop toX:xCross y:yCtr . "/ vertical |
|
490 | 474 |
]. |
494 | 475 |
self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr . "/ horizontal |
481 | 476 |
|
477 |
"/ draw vertical lines |
|
494 | 478 |
idx := index. |
481 | 479 |
|
494 | 480 |
[(lv > 0 and:[(idx := idx + 1) <= size])] whileTrue:[ |
481 |
(x := (listOfNodes at:idx) level) <= lv ifTrue:[ |
|
482 |
lv := x - 1. |
|
483 |
x := (self xOfFigureLevel:lv) + figWidthDiv2. |
|
484 |
self displayLineFromX:x y:yTop toX:x y:yBot. |
|
481 | 485 |
] |
486 |
] |
|
487 |
]. |
|
488 |
||
489 |
"/ draw image |
|
494 | 490 |
image := self figureFor:node. |
541 | 491 |
image notNil ifTrue:[ |
529 | 492 |
self displayForm:image x:xFig y:(yCtr - (image height // 2)). |
541 | 493 |
]. |
481 | 494 |
|
495 |
"/ draw text label |
|
494 | 496 |
self drawLabelIndex:index atX:xStr y:yCtr . |
490 | 497 |
|
494 | 498 |
"/ draw directory indicator |
499 |
(showDirectoryIndicator and:[node hasChildren]) ifTrue:[ |
|
500 |
node isCollapsable ifTrue:[ |
|
501 |
image := openIndicator. |
|
502 |
x := extentOpenIndicator. |
|
503 |
] ifFalse:[ |
|
504 |
image := closeIndicator. |
|
505 |
x := extentCloseIndicator. |
|
506 |
]. |
|
507 |
self displayForm:image x:(xCross - x x) |
|
508 |
y:(yCtr - x y) |
|
485 | 509 |
]. |
481 | 510 |
"/ setup next line |
494 | 511 |
index := index + 1. |
512 |
yTop := yBot. |
|
481 | 513 |
]. |
514 |
||
541 | 515 |
"Modified: 6.10.1997 / 13:31:51 / cg" |
485 | 516 |
! |
517 |
||
444 | 518 |
drawLabelIndex:anIndex atX:x y:yCenter |
519 |
"draw text label at x and y centered |
|
520 |
" |
|
521 |
|y lbl| |
|
522 |
||
523 |
lbl := (listOfNodes at:anIndex) name. |
|
524 |
||
525 |
lbl notNil ifTrue:[ |
|
526 |
y := yCenter - ((lbl heightOn:self) // 2). |
|
527 |
||
528 |
(lbl respondsTo:#string) ifTrue:[ |
|
529 |
y := y + fontAscent. |
|
530 |
]. |
|
531 |
self displayOpaqueString:lbl x:x y:y. |
|
532 |
] |
|
533 |
! ! |
|
534 |
||
494 | 535 |
!SelectionInTreeView methodsFor:'enumerating'! |
490 | 536 |
|
494 | 537 |
detectNode:aOneArgBlock |
538 |
"evaluate the argument, aBlock for each node in the list until |
|
539 |
the block returns true; in this case return the node which caused |
|
540 |
the true evaluation. If none node is detected, nil is returned. |
|
541 |
" |
|
542 |
^ listOfNodes detect:aOneArgBlock ifNone:nil |
|
507 | 543 |
! |
544 |
||
545 |
selectedNodesDo:aOneArgBlock |
|
546 |
"evaluate the block on each node selected |
|
547 |
" |
|
548 |
self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ] |
|
490 | 549 |
! ! |
550 |
||
444 | 551 |
!SelectionInTreeView methodsFor:'initialization'! |
552 |
||
514 | 553 |
destroy |
554 |
"remove dependencies |
|
555 |
" |
|
556 |
rootHolder notNil ifTrue:[ |
|
557 |
rootHolder removeDependent:self |
|
558 |
]. |
|
559 |
selectionHolder notNil ifTrue:[ |
|
560 |
selectionHolder removeDependent:self |
|
561 |
]. |
|
562 |
super destroy. |
|
563 |
||
564 |
||
565 |
! |
|
566 |
||
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
567 |
fetchDeviceResources |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
568 |
"initialize heavily used device resources - to avoid rendering |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
569 |
images again and again later" |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
570 |
|
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
571 |
super fetchDeviceResources. |
478 | 572 |
self refetchDeviceResources |
448
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
573 |
! |
7f9f3531660c
cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
574 |
|
478 | 575 |
fetchImageResources |
576 |
"initialize heavily used device resources - to avoid rendering |
|
577 |
images again and again later; returns maximum extent of the images used. |
|
578 |
Could be redefined by subclass |
|
471 | 579 |
" |
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
580 |
|extent| |
494 | 581 |
|
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
582 |
extent := 0@0. |
528 | 583 |
|
494 | 584 |
imageOpened isNil ifTrue:[ |
528 | 585 |
imageOpened := self class imageOpened. |
586 |
imageOpened notNil ifTrue:[ |
|
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
587 |
imageOpened := imageOpened onDevice:device. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
588 |
] |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
589 |
]. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
590 |
imageOpened notNil ifTrue:[ |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
591 |
extent := extent max:(imageOpened extent) |
494 | 592 |
]. |
444 | 593 |
|
494 | 594 |
imageClosed isNil ifTrue:[ |
528 | 595 |
imageClosed := self class imageClosed. |
596 |
imageClosed notNil ifTrue:[ |
|
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
597 |
imageClosed := imageClosed onDevice:device. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
598 |
]. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
599 |
]. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
600 |
imageClosed notNil ifTrue:[ |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
601 |
extent := extent max:(imageClosed extent) |
494 | 602 |
]. |
603 |
||
604 |
imageItem isNil ifTrue:[ |
|
528 | 605 |
imageItem := self class imageItem. |
606 |
imageItem notNil ifTrue:[ |
|
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
607 |
imageItem := imageItem onDevice:device. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
608 |
]. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
609 |
]. |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
610 |
imageItem notNil ifTrue:[ |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
611 |
extent := extent max:(imageItem extent) |
494 | 612 |
]. |
478 | 613 |
|
533
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
614 |
^ extent |
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
615 |
|
d7867efb6f60
#fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents:
532
diff
changeset
|
616 |
"Modified: 19.9.1997 / 17:14:54 / stefan" |
444 | 617 |
! |
618 |
||
480 | 619 |
getFontParameters |
620 |
super getFontParameters. |
|
621 |
||
532
5a73277578fd
Fix #fetchImageResources in request of ca.
Stefan Vogel <sv@exept.de>
parents:
529
diff
changeset
|
622 |
self realized ifTrue:[ |
480 | 623 |
self refetchDeviceResources |
624 |
] |
|
532
5a73277578fd
Fix #fetchImageResources in request of ca.
Stefan Vogel <sv@exept.de>
parents:
529
diff
changeset
|
625 |
|
5a73277578fd
Fix #fetchImageResources in request of ca.
Stefan Vogel <sv@exept.de>
parents:
529
diff
changeset
|
626 |
"Modified: 19.9.1997 / 16:51:06 / stefan" |
480 | 627 |
! |
628 |
||
444 | 629 |
initialize |
471 | 630 |
"setup instance attributes |
631 |
" |
|
444 | 632 |
super initialize. |
485 | 633 |
showLines := true. |
494 | 634 |
showRoot := true. |
485 | 635 |
showDirectoryIndicator := false. |
494 | 636 |
textInset := 2. |
637 |
imageInset := 0. "/ set during indication enabled |
|
638 |
imageWidth := 8. "/ default: will change during startup |
|
514 | 639 |
self model:nil. "/ creates a default model. |
478 | 640 |
! |
641 |
||
642 |
refetchDeviceResources |
|
643 |
"reinitialize heavily used device resources - to avoid rendering |
|
644 |
images again and again later |
|
645 |
" |
|
494 | 646 |
|extent x1 x2 y| |
478 | 647 |
|
490 | 648 |
extent := self fetchImageResources. |
494 | 649 |
imageInset := 0. |
478 | 650 |
|
494 | 651 |
showDirectoryIndicator ifTrue:[ |
652 |
openIndicator isNil ifTrue:[ |
|
653 |
openIndicator := (self class openIndicator) onDevice:device |
|
654 |
]. |
|
655 |
||
656 |
closeIndicator isNil ifTrue:[ |
|
657 |
closeIndicator := (self class closeIndicator) onDevice:device. |
|
658 |
]. |
|
659 |
||
660 |
x1 := (openIndicator widthOn:self) // 2. |
|
661 |
y := openIndicator heightOn:self. |
|
662 |
y > extent y ifTrue:[extent y:y]. |
|
663 |
extentOpenIndicator := Point x:x1 y:(y // 2). |
|
664 |
||
665 |
x2 := (closeIndicator widthOn:self) // 2. |
|
666 |
y := closeIndicator heightOn:self. |
|
667 |
y > extent y ifTrue:[extent y:y]. |
|
668 |
extentCloseIndicator := Point x:x2 y:(y // 2). |
|
669 |
||
670 |
x2 > x1 ifTrue:[x1 := x2]. |
|
671 |
||
672 |
(x1 := x1 + self class minImageInset) > (imageWidth // 2) ifTrue:[ |
|
673 |
imageInset := x1 - (imageWidth // 2). |
|
674 |
]. |
|
478 | 675 |
]. |
494 | 676 |
extent y >= fontHeight ifTrue:[ |
677 |
fontHeight := 1 + extent y. |
|
678 |
]. |
|
679 |
imageWidth := extent x. |
|
471 | 680 |
|
444 | 681 |
! ! |
682 |
||
483 | 683 |
!SelectionInTreeView methodsFor:'model'! |
444 | 684 |
|
685 |
getListFromModel |
|
686 |
"if I have a model, get my list from it using the listMessage. |
|
687 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
688 |
" |
|
483 | 689 |
super list:(self listFromModel) keepSelection:true |
690 |
! |
|
444 | 691 |
|
483 | 692 |
listFromModel |
693 |
"get list from model and return the new list. |
|
694 |
If listMessage is nil, try aspectMessage for backward compatibilty. |
|
695 |
" |
|
696 |
|msg| |
|
444 | 697 |
|
468 | 698 |
widthOfWidestLine := nil. |
444 | 699 |
|
514 | 700 |
(msg := listMsg ? aspectMsg) notNil ifTrue:[ |
701 |
listOfNodes := model perform:msg. |
|
444 | 702 |
|
514 | 703 |
listOfNodes size ~~ 0 ifTrue:[ |
704 |
^ listOfNodes collect:[:n|n name] |
|
483 | 705 |
] |
706 |
]. |
|
707 |
listOfNodes := #(). |
|
708 |
^ #() |
|
494 | 709 |
! |
710 |
||
711 |
model:aModel |
|
514 | 712 |
"check whether model is nil; than a default model is created |
713 |
" |
|
714 |
|model| |
|
715 |
||
716 |
model := aModel ? (SelectionInTree new). |
|
717 |
model showRoot:showRoot. |
|
718 |
super model:model. |
|
719 |
! |
|
720 |
||
721 |
rootFromModel |
|
722 |
"update hierarchical list from root model; 'rootHolder' |
|
723 |
" |
|
724 |
|root| |
|
725 |
||
726 |
root := rootHolder value. |
|
727 |
||
728 |
self root == root ifFalse:[ |
|
729 |
self selection:nil. |
|
730 |
self root:root. |
|
731 |
] |
|
732 |
! |
|
733 |
||
734 |
selectionFromModel |
|
735 |
"set the selection derived from the selectionHolder |
|
736 |
" |
|
737 |
|coll value size| |
|
738 |
||
739 |
(value := selectionHolder value) isNil ifTrue:[ |
|
740 |
^ self deselect |
|
507 | 741 |
]. |
514 | 742 |
|
743 |
multipleSelectOk ifFalse:[ |
|
744 |
self selectNode:value |
|
745 |
] ifTrue:[ |
|
746 |
value size ~~ 0 ifTrue:[ |
|
747 |
coll := OrderedCollection new:(value size). |
|
748 |
||
749 |
value do:[:aNode||i| |
|
750 |
(i := self indexOfNode:aNode) notNil ifTrue:[ |
|
751 |
coll add:i |
|
752 |
] |
|
753 |
] |
|
754 |
]. |
|
755 |
coll size == 0 ifTrue:[self deselect] |
|
756 |
ifFalse:[self selection:coll] |
|
757 |
] |
|
758 |
! |
|
759 |
||
760 |
selectionToModel |
|
761 |
"write selection to selection holder |
|
762 |
" |
|
763 |
|newSel oldSel| |
|
764 |
||
765 |
oldSel := selectionHolder value. |
|
766 |
||
767 |
multipleSelectOk ifFalse:[ |
|
768 |
(newSel := self selectedNode) ~~ oldSel ifTrue:[ |
|
769 |
selectionHolder value:newSel |
|
770 |
] |
|
771 |
] ifTrue:[ |
|
772 |
selection size == 0 ifTrue:[ |
|
773 |
oldSel notNil ifTrue:[ |
|
774 |
selectionHolder value:nil |
|
775 |
] |
|
776 |
] ifFalse:[ |
|
777 |
newSel := selection collect:[:i| listOfNodes at:i]. |
|
778 |
||
779 |
newSel size ~~ oldSel size ifTrue:[ |
|
780 |
selectionHolder value:newSel. |
|
781 |
] ifFalse:[ |
|
782 |
newSel do:[:aNode| |
|
783 |
(oldSel includes:aNode) ifFalse:[ |
|
784 |
^ selectionHolder value:newSel |
|
785 |
] |
|
786 |
] |
|
787 |
] |
|
788 |
] |
|
789 |
] |
|
444 | 790 |
! ! |
791 |
||
490 | 792 |
!SelectionInTreeView methodsFor:'private'! |
793 |
||
794 |
list:aList keepSelection:keepSelection |
|
795 |
|list| |
|
796 |
||
797 |
list := aList. |
|
798 |
||
799 |
list size == 0 ifTrue:[ |
|
800 |
listOfNodes := #() |
|
801 |
] ifFalse:[ |
|
802 |
(list first respondsTo:#hasChildren) ifTrue:[ |
|
803 |
listOfNodes := aList. |
|
804 |
list := listOfNodes collect:[:aNode| aNode name ]. |
|
805 |
] |
|
806 |
]. |
|
807 |
super list:list keepSelection:keepSelection |
|
808 |
! ! |
|
809 |
||
468 | 810 |
!SelectionInTreeView methodsFor:'private queries'! |
811 |
||
812 |
lengthOfLongestLineBetween:firstLine and:lastLine |
|
813 |
"return the length (in characters) of the longest line in a line-range |
|
814 |
" |
|
815 |
|max| |
|
816 |
||
817 |
max := self widthOfContents:firstLine and:lastLine. |
|
818 |
^ (max // fontWidth) + 1 |
|
819 |
! |
|
820 |
||
821 |
widthOfContents |
|
822 |
"return the width of the contents in pixels |
|
823 |
- used for scrollbar interface" |
|
824 |
||
825 |
list isNil ifTrue:[^ 0]. |
|
826 |
||
827 |
(widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[ |
|
828 |
widthOfWidestLine := self widthOfContents:1 and:(self size). |
|
829 |
]. |
|
830 |
^ widthOfWidestLine + (leftMargin * 2) |
|
831 |
||
832 |
! |
|
833 |
||
834 |
widthOfContents:firstLine and:lastLine |
|
835 |
"return the length (in pixels) of the longest line in a line-range |
|
836 |
" |
|
837 |
|max "{ Class: SmallInteger }" |
|
838 |
thisLen "{ Class: SmallInteger }" |
|
839 |
first "{ Class: SmallInteger }" |
|
840 |
last "{ Class: SmallInteger }" | |
|
841 |
||
842 |
listOfNodes size == 0 ifTrue:[^ 0]. |
|
843 |
||
844 |
last := listOfNodes size. |
|
845 |
first := firstLine. |
|
846 |
||
847 |
(first > last) ifTrue:[^ 0]. |
|
848 |
||
849 |
(lastLine < last) ifTrue:[ |
|
850 |
last := lastLine |
|
851 |
]. |
|
852 |
max := 0. |
|
853 |
||
854 |
listOfNodes from:first to:last do:[:anItem||name| |
|
855 |
thisLen := self xOfStringNode:anItem. |
|
856 |
||
857 |
(name := anItem name) notNil ifTrue:[ |
|
858 |
thisLen := thisLen + (name widthOn:self). |
|
859 |
]. |
|
860 |
(thisLen > max) ifTrue:[ |
|
861 |
max := thisLen. |
|
862 |
] |
|
863 |
]. |
|
864 |
^ max + leftOffset. |
|
865 |
! |
|
866 |
||
867 |
withoutRedrawAt:anIndex put:aString |
|
868 |
"change a line without redisplay" |
|
869 |
||
870 |
|width| |
|
871 |
||
872 |
width := widthOfWidestLine. |
|
873 |
widthOfWidestLine := nil. |
|
874 |
||
875 |
super withoutRedrawAt:anIndex put:aString. |
|
876 |
||
877 |
(widthOfWidestLine := width) notNil ifTrue:[ |
|
878 |
width := self widthOfContents:anIndex and:anIndex. |
|
879 |
||
880 |
width > widthOfWidestLine ifTrue:[ |
|
881 |
widthOfWidestLine := width |
|
882 |
] ifFalse:[ |
|
883 |
widthOfWidestLine := nil "/ means: unknown |
|
884 |
] |
|
885 |
]. |
|
886 |
||
887 |
||
888 |
! ! |
|
889 |
||
483 | 890 |
!SelectionInTreeView methodsFor:'queries'! |
891 |
||
892 |
figureFor:aNode |
|
893 |
"access figure for a node |
|
894 |
" |
|
895 |
aNode hasChildren ifTrue:[ |
|
896 |
aNode isExpandable ifTrue:[ ^ imageClosed ] |
|
897 |
ifFalse:[ ^ imageOpened ] |
|
898 |
]. |
|
899 |
^ imageItem |
|
900 |
! |
|
901 |
||
902 |
indexOfNode:aNode |
|
903 |
"returns index of a node |
|
904 |
" |
|
905 |
^ listOfNodes findFirst:[:n| n == aNode ] |
|
906 |
! |
|
907 |
||
494 | 908 |
xOfFigureLevel:aLevel |
909 |
"origin x where to draw the icon |
|
910 |
" |
|
911 |
|l| |
|
912 |
||
913 |
showRoot ifTrue:[l := aLevel] |
|
914 |
ifFalse:[l := aLevel - 1]. |
|
915 |
||
916 |
showDirectoryIndicator ifFalse:[l := l - 1]. |
|
917 |
^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin |
|
918 |
||
919 |
! |
|
920 |
||
483 | 921 |
xOfFigureNode:aNode |
922 |
"origin x where to draw the icon |
|
923 |
" |
|
494 | 924 |
^ self xOfFigureLevel:(aNode level) |
925 |
! |
|
490 | 926 |
|
494 | 927 |
xOfStringLevel:aLevel |
928 |
"origin x where to draw the text( label ) |
|
929 |
" |
|
930 |
^ (self xOfFigureLevel:aLevel) + imageWidth + textInset |
|
483 | 931 |
|
932 |
! |
|
933 |
||
934 |
xOfStringNode:aNode |
|
935 |
"origin x where to draw the text( label ) |
|
936 |
" |
|
494 | 937 |
^ self xOfStringLevel:(aNode level) |
483 | 938 |
|
939 |
! ! |
|
940 |
||
444 | 941 |
!SelectionInTreeView methodsFor:'selection'! |
942 |
||
943 |
doubleClicked |
|
944 |
"handle a double click; collapse or expand selected entry |
|
945 |
in case of having children |
|
946 |
" |
|
507 | 947 |
|node| |
471 | 948 |
|
507 | 949 |
(node := self selectedNode) notNil ifTrue:[ |
517 | 950 |
( validateDoubleClickBlock isNil |
951 |
or:[(validateDoubleClickBlock value:node) ~~ false] |
|
952 |
) ifTrue:[ |
|
953 |
self selectedNodeExpand:(node isExpandable). |
|
954 |
super doubleClicked |
|
955 |
] |
|
456 | 956 |
] |
478 | 957 |
|
456 | 958 |
! |
959 |
||
494 | 960 |
selectFromListOfNames:aListOfNames |
961 |
"set selection from a list of names |
|
962 |
" |
|
497 | 963 |
|node rdwNd| |
494 | 964 |
|
965 |
aListOfNames size < 1 ifTrue:[ |
|
966 |
^ self selection:nil |
|
967 |
]. |
|
968 |
||
969 |
node := model root. |
|
970 |
||
971 |
aListOfNames do:[:el||next| |
|
972 |
next := node detectChild:[:e|e name = el]. |
|
973 |
||
974 |
next notNil ifTrue:[ |
|
975 |
node hidden ifTrue:[ |
|
976 |
rdwNd isNil ifTrue:[ |
|
977 |
rdwNd := node. |
|
978 |
self selectNode:node. |
|
979 |
]. |
|
980 |
node expand |
|
981 |
]. |
|
982 |
node := next |
|
983 |
] |
|
984 |
]. |
|
985 |
||
986 |
rdwNd notNil ifTrue:[ |
|
987 |
model updateList. |
|
988 |
list := self listFromModel. |
|
989 |
self redrawFromLine:(self indexOfNode:rdwNd). |
|
990 |
self contentsChanged. |
|
991 |
]. |
|
992 |
self selectNode:node. |
|
993 |
||
994 |
! |
|
995 |
||
468 | 996 |
selectNode:aNode |
997 |
"change selection to a node |
|
998 |
" |
|
483 | 999 |
self selection:(self indexOfNode:aNode) |
468 | 1000 |
|
1001 |
||
1002 |
! |
|
1003 |
||
456 | 1004 |
selectedIndex |
1005 |
"get single selected index or 0 |
|
1006 |
" |
|
483 | 1007 |
selection size == 1 ifTrue:[^ selection first]. |
1008 |
selection isNumber ifTrue:[^ selection]. |
|
456 | 1009 |
^ 0 |
444 | 1010 |
! |
1011 |
||
1012 |
selectedNode |
|
1013 |
"get the single selected node or nil |
|
1014 |
" |
|
456 | 1015 |
|idx| |
1016 |
||
1017 |
(idx := self selectedIndex) ~~ 0 ifTrue:[ |
|
1018 |
^ listOfNodes at:idx |
|
444 | 1019 |
]. |
1020 |
^ nil |
|
514 | 1021 |
! |
1022 |
||
1023 |
selectionChangedFrom:oldSelection |
|
1024 |
"update selectionHolder if not nil |
|
1025 |
" |
|
1026 |
super selectionChangedFrom:oldSelection. |
|
1027 |
||
1028 |
selectionHolder notNil ifTrue:[ |
|
1029 |
self selectionToModel. |
|
1030 |
]. |
|
1031 |
||
444 | 1032 |
! ! |
1033 |
||
507 | 1034 |
!SelectionInTreeView methodsFor:'selection-actions'! |
1035 |
||
1036 |
selectedNodeAdd:something |
|
1037 |
"add a node or collection of nodes after selected node |
|
1038 |
" |
|
1039 |
|node| |
|
1040 |
||
1041 |
something notNil ifTrue:[ |
|
1042 |
(node := self selectedNode) notNil ifTrue:[ |
|
1043 |
node parent notNil ifTrue:[ |
|
1044 |
node isCollapsable ifTrue:[ |
|
1045 |
model add:something beforeIndex:1 below:node |
|
1046 |
] ifFalse:[ |
|
1047 |
model add:something after:node |
|
1048 |
] |
|
1049 |
] ifFalse:[ |
|
1050 |
model add:something beforeIndex:1 below:(self root) |
|
1051 |
] |
|
1052 |
] |
|
1053 |
] |
|
1054 |
||
1055 |
! |
|
1056 |
||
1057 |
selectedNodeBecomeChildOfNext |
|
1058 |
"become node a child of followd node |
|
1059 |
" |
|
1060 |
|idx node cprt nprt| |
|
1061 |
||
1062 |
((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[ |
|
1063 |
idx := cprt indexOfChild:node. |
|
1064 |
||
1065 |
idx == cprt children size ifFalse:[ |
|
1066 |
nprt := cprt childAt:(idx + 1). |
|
1067 |
||
1068 |
nprt notNil ifTrue:[ |
|
1069 |
model removeDependent:self. |
|
1070 |
model removeSelection. |
|
1071 |
selection := nil. |
|
1072 |
model collapse:nprt. |
|
1073 |
model add:node beforeIndex:1 below:nprt. |
|
1074 |
model addDependent:self. |
|
1075 |
model expand:nprt. |
|
1076 |
||
1077 |
self selectNode:node. |
|
1078 |
] |
|
1079 |
] |
|
1080 |
] |
|
1081 |
! |
|
1082 |
||
1083 |
selectedNodeBecomeSisterOfParent |
|
1084 |
"become node a sister of its current parent |
|
1085 |
" |
|
1086 |
|node cprt nprt| |
|
1087 |
||
1088 |
( (node := self selectedNode) isNil |
|
1089 |
or:[(cprt := node parent) isNil |
|
1090 |
or:[(nprt := cprt parent) isNil]] |
|
1091 |
) ifFalse:[ |
|
1092 |
model removeDependent:self. |
|
1093 |
model removeSelection. |
|
1094 |
selection := nil. |
|
1095 |
model addDependent:self. |
|
1096 |
||
1097 |
model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt. |
|
1098 |
self selectNode:node. |
|
1099 |
] |
|
1100 |
||
1101 |
! |
|
1102 |
||
1103 |
selectedNodeChangeSequenceOrder:anOffset |
|
1104 |
"move child 'anOffset' forward or backward in list of children |
|
1105 |
" |
|
1106 |
|idx node size parent| |
|
1107 |
||
1108 |
( (node := self selectedNode) notNil |
|
1109 |
and:[(parent := node parent) notNil |
|
1110 |
and:[(size := parent children size) > 1]] |
|
1111 |
) ifTrue:[ |
|
1112 |
idx := parent indexOfChild:node. |
|
1113 |
||
1114 |
model removeDependent:self. |
|
1115 |
model removeSelection. |
|
1116 |
selection := nil. |
|
1117 |
model addDependent:self. |
|
1118 |
||
1119 |
(idx := idx + anOffset) < 1 ifTrue:[ |
|
1120 |
idx := size |
|
1121 |
] ifFalse:[ |
|
1122 |
idx > size ifTrue:[idx := 1] |
|
1123 |
]. |
|
1124 |
model add:node beforeIndex:idx below:parent. |
|
1125 |
self selectNode:node. |
|
1126 |
] |
|
1127 |
! |
|
1128 |
||
1129 |
selectedNodeExpand:doExpand |
|
1130 |
"collapse or expand selected node |
|
1131 |
" |
|
1132 |
|node index| |
|
1133 |
||
1134 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
|
1135 |
node := listOfNodes at:index. |
|
1136 |
||
1137 |
node hasChildren ifTrue:[ |
|
1138 |
node isExpandable ifTrue:[ |
|
1139 |
doExpand ifFalse:[^ self]. |
|
1140 |
node expand |
|
1141 |
] ifFalse:[ |
|
1142 |
doExpand ifTrue:[^ self]. |
|
1143 |
node collapse |
|
1144 |
]. |
|
1145 |
||
1146 |
node numberOfChildren == 0 ifTrue:[ |
|
1147 |
"/ no children; redraw selected line (image might change) |
|
1148 |
self redrawLine:index. |
|
1149 |
] ifFalse:[ |
|
1150 |
"/ with children; update list and redraw to end. |
|
1151 |
model updateList. |
|
1152 |
list := self listFromModel. |
|
1153 |
self redrawFromLine:index. |
|
1154 |
self contentsChanged. |
|
1155 |
] |
|
1156 |
] |
|
1157 |
]. |
|
1158 |
! |
|
1159 |
||
1160 |
selectedNodesRemove |
|
1161 |
"remove selected nodes |
|
1162 |
" |
|
1163 |
model removeSelection. |
|
1164 |
self selection:nil. |
|
1165 |
||
1166 |
! ! |
|
1167 |
||
444 | 1168 |
!SelectionInTreeView class methodsFor:'documentation'! |
1169 |
||
1170 |
version |
|
541 | 1171 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.23 1997-10-06 12:32:48 cg Exp $' |
444 | 1172 |
! ! |