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