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