487
|
1 |
"
|
488
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG
|
487
|
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 |
|
|
15 |
SelectionInTreeView subclass:#FileSelectionTree
|
|
16 |
instanceVariableNames:'fileIcons itemClass'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Text'
|
|
20 |
!
|
|
21 |
|
|
22 |
!FileSelectionTree class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
488
|
26 |
COPYRIGHT (c) 1997 by eXept Software AG
|
487
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
|
|
37 |
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
|
42 |
somewhat like a FileSelectionInList; but specialized for hierarchical (i.e. tree-like)
|
|
43 |
lists and adds the functions to show/hide subtrees.
|
|
44 |
Requires SelectionInTree as model and FileSelectionItem (or compatible) list entries.
|
|
45 |
|
|
46 |
You can define your own TreeItem instead of useing the default class FileSelectionItem
|
|
47 |
by seting the class through to #itemClass:
|
|
48 |
|
|
49 |
[see also:]
|
|
50 |
FileSelectionItem
|
|
51 |
SelectionInTree
|
|
52 |
SelectionInTreeView
|
|
53 |
SelectionInListView
|
|
54 |
|
|
55 |
[author:]
|
|
56 |
Claus Atzkern
|
|
57 |
"
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
!
|
|
62 |
|
|
63 |
examples
|
|
64 |
"
|
|
65 |
open a FileSelectionTree on current directory
|
|
66 |
[exBegin]
|
|
67 |
|top scr|
|
|
68 |
|
|
69 |
top := StandardSystemView new label:'select'; extent:300@500.
|
|
70 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top.
|
|
71 |
scr := scr scrolledView.
|
|
72 |
|
|
73 |
scr directory:Filename currentDirectory.
|
|
74 |
|
|
75 |
scr action:[:anIndex| Transcript showCR:anIndex.
|
|
76 |
Transcript showCR:scr selectedPathname.
|
|
77 |
].
|
|
78 |
top open
|
|
79 |
[exEnd]
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
open a FileSelectionTree on root path; show directory
|
|
84 |
indication (open/closed) and no lines
|
|
85 |
[exBegin]
|
|
86 |
|top scr|
|
|
87 |
|
|
88 |
top := StandardSystemView new label:'select'; extent:300@500.
|
|
89 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top.
|
|
90 |
scr := scr scrolledView.
|
|
91 |
scr showDirectoryIndicator:true.
|
|
92 |
scr showLines:false.
|
|
93 |
|
|
94 |
scr directory:'/'.
|
|
95 |
|
|
96 |
scr action:[:anIndex| Transcript showCR:anIndex.
|
|
97 |
Transcript showCR:scr selectedPathname.
|
|
98 |
].
|
|
99 |
top open
|
|
100 |
[exEnd]
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
open a FileSelectionTree on root path; showing only files
|
|
105 |
[exBegin]
|
|
106 |
|top scr|
|
|
107 |
|
|
108 |
top := StandardSystemView new label:'select'; extent:300@500.
|
|
109 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top.
|
|
110 |
scr := scr scrolledView.
|
|
111 |
scr itemClass:(FileSelectionItem directoriesOnly).
|
|
112 |
scr directory:'/'.
|
|
113 |
|
|
114 |
scr action:[:anIndex| Transcript showCR:anIndex.
|
|
115 |
Transcript showCR:scr selectedPathname.
|
|
116 |
].
|
|
117 |
top open
|
|
118 |
[exEnd]
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
open a FileSelectionTree on a specified path
|
|
123 |
[exBegin]
|
|
124 |
|top scr|
|
|
125 |
|
|
126 |
top := StandardSystemView new label:'select'; extent:300@500.
|
|
127 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top.
|
|
128 |
scr := scr scrolledView.
|
|
129 |
scr directory:'/'.
|
|
130 |
scr showLines:false.
|
|
131 |
scr action:[:anIndex| Transcript showCR:scr selectedPathname ].
|
|
132 |
scr doubleClickAction:[:anIndex| Transcript showCR:scr selectedPathname ].
|
|
133 |
top open
|
|
134 |
[exEnd]
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
open a FileSelectionTree on a specified path; show or hide
|
|
139 |
lines on doubleClick on a file (not a directory)
|
|
140 |
[exBegin]
|
|
141 |
|top scr|
|
|
142 |
|
|
143 |
top := StandardSystemView new label:'select'; extent:300@500.
|
|
144 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top.
|
|
145 |
scr := scr scrolledView.
|
|
146 |
scr directory:'/'.
|
|
147 |
|
|
148 |
scr action:[:anIndex| Transcript showCR:anIndex.
|
|
149 |
Transcript showCR:scr selectedPathname.
|
|
150 |
].
|
|
151 |
scr doubleClickAction:[:anIndex|
|
|
152 |
|fn|
|
|
153 |
fn := scr selectedPathname asFilename.
|
|
154 |
fn isDirectory ifFalse:[
|
|
155 |
scr showLines:(scr showLines not)
|
|
156 |
]
|
|
157 |
].
|
|
158 |
top open
|
|
159 |
[exEnd]
|
|
160 |
|
|
161 |
|
|
162 |
|
492
|
163 |
example associated with a FileSelectionList
|
|
164 |
[exBegin]
|
|
165 |
|top tree list field label|
|
|
166 |
|
|
167 |
top := StandardSystemView new label:'select'; extent:600@600.
|
|
168 |
tree := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top.
|
|
169 |
list := HVScrollableView for:FileSelectionList origin:(0.5 @ 25) corner:(1.0 @ 1.0) in:top.
|
|
170 |
label := Label origin:(0.5 @ 2) in:top.
|
|
171 |
label label:'pattern:'.
|
|
172 |
field := EditField origin:0.5@2 in:top.
|
|
173 |
field leftInset:(label preferredExtent x) + 5.
|
|
174 |
field width:1.0.
|
|
175 |
field editValue:'*'.
|
|
176 |
field crAction:[list pattern:field editValue].
|
|
177 |
|
|
178 |
tree := tree scrolledView.
|
|
179 |
list := list scrolledView.
|
|
180 |
list ignoreDirectories:true.
|
|
181 |
list pattern:(field editValue).
|
|
182 |
|
|
183 |
tree itemClass:(FileSelectionItem directoriesOnly).
|
|
184 |
tree directory:(Filename homeDirectory).
|
|
185 |
tree showDirectoryIndicator:true.
|
|
186 |
list directory:(tree directory).
|
|
187 |
|
|
188 |
list action:[:index| Transcript showCR:'you selected: ' , list selectedPathname].
|
|
189 |
tree action:[:anIndex|
|
|
190 |
list directory:(tree selectedPathname).
|
|
191 |
].
|
|
192 |
top open
|
|
193 |
[exEnd]
|
|
194 |
|
|
195 |
|
|
196 |
|
487
|
197 |
a more complex example
|
|
198 |
[exBegin]
|
|
199 |
|action top tree slvw file tgD tgF button hzPn|
|
|
200 |
|
|
201 |
top := StandardSystemView new label:'select'; extent:600@600.
|
|
202 |
tree := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top.
|
|
203 |
slvw := HVScrollableView for:FileSelectionTree origin:(0.5 @ 30) corner:(1.0 @ 1.0) in:top.
|
|
204 |
hzPn := HorizontalPanelView origin:(0.5 @ 0.0) corner:(1.0 @ 30) in:top.
|
|
205 |
tree := tree scrolledView.
|
|
206 |
slvw := slvw scrolledView.
|
|
207 |
|
|
208 |
tree itemClass:(FileSelectionItem directoriesOnly).
|
|
209 |
tree directory:(Filename homeDirectory).
|
|
210 |
|
|
211 |
slvw doubleClickSelectionBlock:[:anIndex|
|
|
212 |
(file := slvw selectedPathname asFilename) isDirectory ifTrue:[
|
|
213 |
anIndex == 1 ifTrue:[file := file directory].
|
|
214 |
tree selectPathname:file
|
|
215 |
].
|
|
216 |
false
|
|
217 |
].
|
|
218 |
slvw showLines:false.
|
|
219 |
|
|
220 |
tree action:[:anIndex|
|
|
221 |
slvw directory:(tree selectedPathname)
|
|
222 |
].
|
|
223 |
action := [:tg||cls|
|
|
224 |
tgF isOn ifTrue:[
|
|
225 |
tgD isOn ifTrue:[cls := FileSelectionItem]
|
|
226 |
ifFalse:[cls := FileSelectionItem filesOnly]
|
|
227 |
] ifFalse:[
|
|
228 |
tgD isOn ifTrue:[
|
|
229 |
cls := FileSelectionItem directoriesOnly
|
|
230 |
] ifFalse:[
|
|
231 |
tg turnOn.
|
|
232 |
tg == tgD ifTrue:[cls := FileSelectionItem directoriesOnly]
|
|
233 |
ifFalse:[cls := FileSelectionItem filesOnly]
|
|
234 |
]
|
|
235 |
].
|
|
236 |
slvw itemClass:cls.
|
|
237 |
].
|
|
238 |
hzPn verticalLayout:#fitSpace.
|
|
239 |
hzPn horizontalLayout:#fitSpace.
|
|
240 |
tgD := CheckBox label:'directory' in:hzPn.
|
|
241 |
tgF := CheckBox label:'file' in:hzPn.
|
|
242 |
button := Button label:'File Browser' in:hzPn.
|
|
243 |
|
|
244 |
button action:[
|
|
245 |
(file := slvw selectedPathname) isNil ifTrue:[
|
|
246 |
file := tree selectedPathname
|
|
247 |
].
|
|
248 |
file notNil ifTrue:[
|
|
249 |
file asFilename isDirectory ifTrue:[FileBrowser openOn:file]
|
|
250 |
ifFalse:[FileBrowser openOnFileNamed:file]
|
|
251 |
]
|
|
252 |
].
|
|
253 |
|
|
254 |
tgD turnOn.
|
|
255 |
tgF turnOn.
|
|
256 |
tgD action:[:v| action value:tgF].
|
|
257 |
tgF action:[:v| action value:tgD].
|
|
258 |
|
|
259 |
top open
|
|
260 |
[exEnd]
|
|
261 |
"
|
|
262 |
|
|
263 |
! !
|
|
264 |
|
|
265 |
!FileSelectionTree methodsFor:'accessing'!
|
|
266 |
|
|
267 |
directory
|
|
268 |
"get the full pathname of the root directory
|
|
269 |
"
|
|
270 |
|root|
|
|
271 |
|
|
272 |
(root := model root) notNil ifTrue:[
|
|
273 |
^ root pathName
|
|
274 |
].
|
|
275 |
^ nil
|
|
276 |
!
|
|
277 |
|
|
278 |
directory:aPathname
|
|
279 |
"change the root directory of the selection tree to the full pathName,
|
|
280 |
aPathname. The pathname must be a directory otherwise the root directory
|
|
281 |
is set to nil.
|
|
282 |
"
|
492
|
283 |
|root dir path keep|
|
|
284 |
|
|
285 |
(aPathname notNil and:[(path := aPathname asFilename) isDirectory]) ifFalse:[
|
|
286 |
model root:nil.
|
|
287 |
^ self selection:nil
|
|
288 |
].
|
487
|
289 |
|
492
|
290 |
(dir := self directory) notNil ifTrue:[
|
|
291 |
dir := dir asFilename.
|
|
292 |
keep := path pathName = dir directory pathName.
|
|
293 |
] ifFalse:[
|
|
294 |
keep := false
|
|
295 |
].
|
487
|
296 |
self selection:nil.
|
|
297 |
|
492
|
298 |
root := self itemClass pathName:path.
|
|
299 |
model root:root keepRoot:keep.
|
|
300 |
model expand:root.
|
|
301 |
|
|
302 |
keep ifTrue:[
|
|
303 |
self selectPathname:(dir pathName)
|
487
|
304 |
].
|
|
305 |
|
|
306 |
!
|
|
307 |
|
|
308 |
itemClass
|
|
309 |
"returns current itemClass used
|
|
310 |
"
|
|
311 |
^ itemClass
|
|
312 |
!
|
|
313 |
|
|
314 |
itemClass:anItemClass
|
|
315 |
"set itemClass to be used
|
|
316 |
"
|
|
317 |
|directory|
|
|
318 |
|
|
319 |
(anItemClass notNil and:[anItemClass ~~ itemClass]) ifTrue:[
|
|
320 |
itemClass := anItemClass.
|
|
321 |
self refetchDeviceResources.
|
|
322 |
|
|
323 |
(directory := self directory) notNil ifTrue:[
|
|
324 |
self directory:directory
|
|
325 |
].
|
|
326 |
].
|
|
327 |
|
492
|
328 |
!
|
|
329 |
|
|
330 |
pathnameAtIndex:anIndex
|
|
331 |
"returns pathname at an index or nil
|
|
332 |
"
|
|
333 |
|node|
|
|
334 |
|
|
335 |
(node := self nodeAtIndex:anIndex) notNil ifTrue:[
|
|
336 |
^ node pathName
|
|
337 |
].
|
|
338 |
^ nil
|
487
|
339 |
! !
|
|
340 |
|
|
341 |
!FileSelectionTree methodsFor:'drawing basics'!
|
|
342 |
|
|
343 |
figureFor:aNode
|
|
344 |
"get the image used for the node entry.
|
|
345 |
"
|
|
346 |
|keyOrImage|
|
|
347 |
|
|
348 |
aNode == self selectedNode ifFalse:[keyOrImage := aNode imageUnselected]
|
|
349 |
ifTrue:[keyOrImage := aNode imageSelected].
|
|
350 |
|
|
351 |
keyOrImage isSymbol ifTrue:[^ fileIcons at:keyOrImage].
|
|
352 |
^ keyOrImage
|
|
353 |
! !
|
|
354 |
|
|
355 |
!FileSelectionTree methodsFor:'initialization'!
|
|
356 |
|
|
357 |
fetchImageResources
|
|
358 |
"initialize heavily used device resources - to avoid rendering
|
|
359 |
images again and again later; returns maximum extent of the images used.
|
|
360 |
"
|
|
361 |
|y x t|
|
|
362 |
|
|
363 |
fileIcons := self itemClass iconsOn:device.
|
|
364 |
|
|
365 |
t := super fetchImageResources.
|
|
366 |
y := t y.
|
|
367 |
x := t x.
|
|
368 |
|
|
369 |
fileIcons do:[:anIcon|
|
|
370 |
(t := anIcon heightOn:self) > y ifTrue:[y := t].
|
|
371 |
(t := anIcon widthOn:self) > x ifTrue:[x := t].
|
|
372 |
].
|
|
373 |
^ x @ y
|
|
374 |
|
|
375 |
!
|
|
376 |
|
|
377 |
initialize
|
|
378 |
"setup my model and set the default path to the current directory; on default
|
|
379 |
multiple selection is disabled.
|
|
380 |
"
|
|
381 |
super initialize.
|
|
382 |
itemClass := FileSelectionItem.
|
|
383 |
self model:(SelectionInTree new).
|
|
384 |
|
|
385 |
! !
|
|
386 |
|
|
387 |
!FileSelectionTree methodsFor:'selection'!
|
|
388 |
|
|
389 |
selectPathname:aPath
|
|
390 |
"set selection to a path
|
|
391 |
"
|
|
392 |
|node comp rdwNd path|
|
|
393 |
|
492
|
394 |
(aPath notNil and:[aPath asFilename exists]) ifFalse:[
|
487
|
395 |
^ self selection:nil
|
|
396 |
].
|
|
397 |
((path := aPath asString) = self selectedPathname) ifTrue:[
|
|
398 |
"/ already selected
|
|
399 |
^ self
|
|
400 |
].
|
|
401 |
|
|
402 |
comp := Filename components:(path copyFrom:(self directory size + 1)).
|
|
403 |
node := model root.
|
|
404 |
|
|
405 |
comp do:[:el||next|
|
|
406 |
next := node detectChild:[:e|e name = el].
|
|
407 |
|
|
408 |
next notNil ifTrue:[
|
|
409 |
node hidden ifTrue:[
|
|
410 |
rdwNd isNil ifTrue:[
|
|
411 |
rdwNd := node.
|
|
412 |
self selectNode:node.
|
|
413 |
].
|
|
414 |
node expand
|
|
415 |
].
|
|
416 |
node := next
|
|
417 |
]
|
|
418 |
].
|
|
419 |
|
|
420 |
rdwNd notNil ifTrue:[
|
|
421 |
model updateList.
|
|
422 |
list := self listFromModel.
|
|
423 |
self redrawFromLine:(self indexOfNode:rdwNd).
|
|
424 |
self contentsChanged.
|
|
425 |
].
|
|
426 |
self selectNode:node.
|
|
427 |
!
|
|
428 |
|
|
429 |
selectedPathname
|
|
430 |
"if there is a single selection, the full pathname of the selected
|
|
431 |
entry will be returned otherwise nil
|
|
432 |
"
|
|
433 |
|node|
|
|
434 |
|
|
435 |
(node := self selectedNode) notNil ifTrue:[
|
|
436 |
^ node pathName
|
|
437 |
].
|
|
438 |
^ nil
|
|
439 |
|
|
440 |
! !
|
|
441 |
|
|
442 |
!FileSelectionTree class methodsFor:'documentation'!
|
|
443 |
|
|
444 |
version
|
492
|
445 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.3 1997-08-11 11:02:30 ca Exp $'
|
487
|
446 |
! !
|