author | ca |
Fri, 15 Aug 1997 11:25:43 +0200 | |
changeset 495 | e34c13af578d |
parent 492 | 0b6a6bc3f1cb |
child 513 | fe060a9ba204 |
permissions | -rw-r--r-- |
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 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
84 |
indication (open/closed), no lines and not the root |
487 | 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. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
93 |
scr showRoot:false. |
487 | 94 |
|
95 |
scr directory:'/'. |
|
96 |
||
97 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
98 |
Transcript showCR:scr selectedPathname. |
|
99 |
]. |
|
100 |
top open |
|
101 |
[exEnd] |
|
102 |
||
103 |
||
104 |
||
105 |
open a FileSelectionTree on root path; showing only files |
|
106 |
[exBegin] |
|
107 |
|top scr| |
|
108 |
||
109 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
110 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
111 |
scr := scr scrolledView. |
|
112 |
scr itemClass:(FileSelectionItem directoriesOnly). |
|
113 |
scr directory:'/'. |
|
114 |
||
115 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
116 |
Transcript showCR:scr selectedPathname. |
|
117 |
]. |
|
118 |
top open |
|
119 |
[exEnd] |
|
120 |
||
121 |
||
122 |
||
123 |
open a FileSelectionTree on a specified path |
|
124 |
[exBegin] |
|
125 |
|top scr| |
|
126 |
||
127 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
128 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
129 |
scr := scr scrolledView. |
|
130 |
scr directory:'/'. |
|
131 |
scr showLines:false. |
|
132 |
scr action:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
133 |
scr doubleClickAction:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
134 |
top open |
|
135 |
[exEnd] |
|
136 |
||
137 |
||
138 |
||
139 |
open a FileSelectionTree on a specified path; show or hide |
|
140 |
lines on doubleClick on a file (not a directory) |
|
141 |
[exBegin] |
|
142 |
|top scr| |
|
143 |
||
144 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
145 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
146 |
scr := scr scrolledView. |
|
147 |
scr directory:'/'. |
|
148 |
||
149 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
150 |
Transcript showCR:scr selectedPathname. |
|
151 |
]. |
|
152 |
scr doubleClickAction:[:anIndex| |
|
153 |
|fn| |
|
154 |
fn := scr selectedPathname asFilename. |
|
155 |
fn isDirectory ifFalse:[ |
|
156 |
scr showLines:(scr showLines not) |
|
157 |
] |
|
158 |
]. |
|
159 |
top open |
|
160 |
[exEnd] |
|
161 |
||
162 |
||
163 |
||
492 | 164 |
example associated with a FileSelectionList |
165 |
[exBegin] |
|
166 |
|top tree list field label| |
|
167 |
||
168 |
top := StandardSystemView new label:'select'; extent:600@600. |
|
169 |
tree := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top. |
|
170 |
list := HVScrollableView for:FileSelectionList origin:(0.5 @ 25) corner:(1.0 @ 1.0) in:top. |
|
171 |
label := Label origin:(0.5 @ 2) in:top. |
|
172 |
label label:'pattern:'. |
|
173 |
field := EditField origin:0.5@2 in:top. |
|
174 |
field leftInset:(label preferredExtent x) + 5. |
|
175 |
field width:1.0. |
|
176 |
field editValue:'*'. |
|
177 |
field crAction:[list pattern:field editValue]. |
|
178 |
||
179 |
tree := tree scrolledView. |
|
180 |
list := list scrolledView. |
|
181 |
list ignoreDirectories:true. |
|
182 |
list pattern:(field editValue). |
|
183 |
||
184 |
tree itemClass:(FileSelectionItem directoriesOnly). |
|
185 |
tree directory:(Filename homeDirectory). |
|
186 |
tree showDirectoryIndicator:true. |
|
187 |
list directory:(tree directory). |
|
188 |
||
189 |
list action:[:index| Transcript showCR:'you selected: ' , list selectedPathname]. |
|
190 |
tree action:[:anIndex| |
|
191 |
list directory:(tree selectedPathname). |
|
192 |
]. |
|
193 |
top open |
|
194 |
[exEnd] |
|
195 |
||
196 |
||
197 |
||
487 | 198 |
a more complex example |
199 |
[exBegin] |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
200 |
|top listD listF field lbl inset| |
487 | 201 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
202 |
top := StandardSystemView new label:'select'; extent:600@600. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
203 |
inset := 26. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
204 |
listD := HVScrollableView for:FileSelectionTree origin:(0.0 @ inset) corner:(0.5 @ 1.0) in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
205 |
listF := HVScrollableView for:FileSelectionTree origin:(0.5 @ 0.0) corner:(1.0 @ 1.0) in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
206 |
listD := listD scrolledView. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
207 |
listF := listF scrolledView. |
487 | 208 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
209 |
listD itemClass:(FileSelectionItem directoriesOnly). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
210 |
listF itemClass:(FileSelectionItem filesOnly). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
211 |
listD showDirectoryIndicator:true. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
212 |
listD showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
213 |
listF showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
214 |
listF showRoot:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
215 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
216 |
lbl := Label label:'directory:' in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
217 |
lbl origin:5 @ ((inset - lbl preferredExtent y) // 2). |
487 | 218 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
219 |
field := FilenameEditField in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
220 |
field origin:(4 + lbl corner x) @ ((inset - field preferredExtent y) // 2). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
221 |
field width:0.5. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
222 |
field rightInset:(field origin x + 4). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
223 |
field directoriesOnly. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
224 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
225 |
field crAction:[|dir| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
226 |
dir := field editValue asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
227 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
228 |
(dir isDirectory and:[listD directory ~= dir pathName]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
229 |
listD changeDirectory:dir |
487 | 230 |
] |
231 |
]. |
|
232 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
233 |
listF action:[:anIndex||file| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
234 |
(file := listF selectedPathname) notNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
235 |
Transcript showCR:'selection: ', file |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
236 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
237 |
]. |
487 | 238 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
239 |
listD directory:(Filename homeDirectory). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
240 |
field editValue:listD directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
241 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
242 |
listD action:[:anIndex||path| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
243 |
path := listD selectedPathname. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
244 |
listF directory:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
245 |
path notNil ifTrue:[field editValue:path] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
246 |
]. |
487 | 247 |
top open |
248 |
[exEnd] |
|
249 |
" |
|
250 |
||
251 |
! ! |
|
252 |
||
253 |
!FileSelectionTree methodsFor:'accessing'! |
|
254 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
255 |
changeDirectory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
256 |
"change the root directory; try to reuse old hierarchy list and |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
257 |
the selection in case of a single selection. The pathname must |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
258 |
be a directory otherwise the root directory is set to nil |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
259 |
" |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
260 |
|oldSel child loc oldPath oldFile newFile newPath node idx| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
261 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
262 |
( aPathname notNil |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
263 |
and:[(newFile := aPathname asFilename) isDirectory |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
264 |
and:[(oldPath := self directory) notNil]] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
265 |
) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
266 |
^ self directory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
267 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
268 |
newPath := newFile pathName. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
269 |
oldFile := oldPath asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
270 |
oldSel := self selectedNode. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
271 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
272 |
(newPath startsWith:oldPath) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
273 |
node := self detectNode:[:aNode|aNode pathName = newPath]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
274 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
275 |
node isNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
276 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
277 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
278 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
279 |
(oldPath startsWith:newPath) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
280 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
281 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
282 |
child := model root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
283 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
284 |
[newPath = oldPath] whileFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
285 |
oldFile := oldFile directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
286 |
node := self itemClass pathName:oldFile. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
287 |
node expand. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
288 |
loc := node children. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
289 |
idx := loc findFirst:[:el| el pathName = oldPath ]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
290 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
291 |
idx == 0 ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
292 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
293 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
294 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
295 |
loc at:idx put:child. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
296 |
child parent:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
297 |
child := node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
298 |
oldPath := oldFile pathName. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
299 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
300 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
301 |
selection := nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
302 |
node parent:nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
303 |
model root:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
304 |
self setSelection:(self indexOfNode:oldSel). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
305 |
model setSelection:selection. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
306 |
! |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
307 |
|
487 | 308 |
directory |
309 |
"get the full pathname of the root directory |
|
310 |
" |
|
311 |
|root| |
|
312 |
||
313 |
(root := model root) notNil ifTrue:[ |
|
314 |
^ root pathName |
|
315 |
]. |
|
316 |
^ nil |
|
317 |
! |
|
318 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
319 |
directory:aPath |
487 | 320 |
"change the root directory of the selection tree to the full pathName, |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
321 |
aPath. The pathname must be a directory otherwise the root directory |
487 | 322 |
is set to nil. |
323 |
" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
324 |
|root path| |
492 | 325 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
326 |
model setSelection:(selection := nil). |
487 | 327 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
328 |
(aPath notNil and:[(path := aPath asFilename) isDirectory]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
329 |
root := self itemClass pathName:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
330 |
model root:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
331 |
model expand:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
332 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
333 |
model root:nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
334 |
] |
487 | 335 |
|
336 |
! |
|
337 |
||
338 |
itemClass |
|
339 |
"returns current itemClass used |
|
340 |
" |
|
341 |
^ itemClass |
|
342 |
! |
|
343 |
||
344 |
itemClass:anItemClass |
|
345 |
"set itemClass to be used |
|
346 |
" |
|
347 |
|directory| |
|
348 |
||
349 |
(anItemClass notNil and:[anItemClass ~~ itemClass]) ifTrue:[ |
|
350 |
itemClass := anItemClass. |
|
351 |
self refetchDeviceResources. |
|
352 |
||
353 |
(directory := self directory) notNil ifTrue:[ |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
354 |
self directory:directory "/ recompute list |
487 | 355 |
]. |
356 |
]. |
|
357 |
||
492 | 358 |
! |
359 |
||
360 |
pathnameAtIndex:anIndex |
|
361 |
"returns pathname at an index or nil |
|
362 |
" |
|
363 |
|node| |
|
364 |
||
365 |
(node := self nodeAtIndex:anIndex) notNil ifTrue:[ |
|
366 |
^ node pathName |
|
367 |
]. |
|
368 |
^ nil |
|
487 | 369 |
! ! |
370 |
||
371 |
!FileSelectionTree methodsFor:'drawing basics'! |
|
372 |
||
373 |
figureFor:aNode |
|
374 |
"get the image used for the node entry. |
|
375 |
" |
|
376 |
|keyOrImage| |
|
377 |
||
378 |
aNode == self selectedNode ifFalse:[keyOrImage := aNode imageUnselected] |
|
379 |
ifTrue:[keyOrImage := aNode imageSelected]. |
|
380 |
||
381 |
keyOrImage isSymbol ifTrue:[^ fileIcons at:keyOrImage]. |
|
382 |
^ keyOrImage |
|
383 |
! ! |
|
384 |
||
385 |
!FileSelectionTree methodsFor:'initialization'! |
|
386 |
||
387 |
fetchImageResources |
|
388 |
"initialize heavily used device resources - to avoid rendering |
|
389 |
images again and again later; returns maximum extent of the images used. |
|
390 |
" |
|
391 |
|y x t| |
|
392 |
||
393 |
fileIcons := self itemClass iconsOn:device. |
|
394 |
||
395 |
t := super fetchImageResources. |
|
396 |
y := t y. |
|
397 |
x := t x. |
|
398 |
||
399 |
fileIcons do:[:anIcon| |
|
400 |
(t := anIcon heightOn:self) > y ifTrue:[y := t]. |
|
401 |
(t := anIcon widthOn:self) > x ifTrue:[x := t]. |
|
402 |
]. |
|
403 |
^ x @ y |
|
404 |
||
405 |
! |
|
406 |
||
407 |
initialize |
|
408 |
"setup my model and set the default path to the current directory; on default |
|
409 |
multiple selection is disabled. |
|
410 |
" |
|
411 |
super initialize. |
|
412 |
itemClass := FileSelectionItem. |
|
413 |
self model:(SelectionInTree new). |
|
414 |
||
415 |
! ! |
|
416 |
||
417 |
!FileSelectionTree methodsFor:'selection'! |
|
418 |
||
419 |
selectPathname:aPath |
|
420 |
"set selection to a path |
|
421 |
" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
422 |
|components path| |
487 | 423 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
424 |
(aPath notNil and:[aPath asFilename exists]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
425 |
((path := aPath asString) = self selectedPathname) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
426 |
^ self |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
427 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
428 |
components := Filename components:(path copyFrom:(self directory size + 1)). |
487 | 429 |
]. |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
430 |
self selectFromListOfNames:components. |
487 | 431 |
! |
432 |
||
433 |
selectedPathname |
|
434 |
"if there is a single selection, the full pathname of the selected |
|
435 |
entry will be returned otherwise nil |
|
436 |
" |
|
437 |
|node| |
|
438 |
||
439 |
(node := self selectedNode) notNil ifTrue:[ |
|
440 |
^ node pathName |
|
441 |
]. |
|
442 |
^ nil |
|
443 |
||
444 |
! ! |
|
445 |
||
446 |
!FileSelectionTree class methodsFor:'documentation'! |
|
447 |
||
448 |
version |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
449 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.4 1997-08-15 09:25:43 ca Exp $' |
487 | 450 |
! ! |