152 |fn| |
152 |fn| |
153 fn := scr selectedPathname asFilename. |
153 fn := scr selectedPathname asFilename. |
154 fn isDirectory ifFalse:[ |
154 fn isDirectory ifFalse:[ |
155 scr showLines:(scr showLines not) |
155 scr showLines:(scr showLines not) |
156 ] |
156 ] |
|
157 ]. |
|
158 top open |
|
159 [exEnd] |
|
160 |
|
161 |
|
162 |
|
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). |
157 ]. |
191 ]. |
158 top open |
192 top open |
159 [exEnd] |
193 [exEnd] |
160 |
194 |
161 |
195 |
244 directory:aPathname |
278 directory:aPathname |
245 "change the root directory of the selection tree to the full pathName, |
279 "change the root directory of the selection tree to the full pathName, |
246 aPathname. The pathname must be a directory otherwise the root directory |
280 aPathname. The pathname must be a directory otherwise the root directory |
247 is set to nil. |
281 is set to nil. |
248 " |
282 " |
249 |root| |
283 |root dir path keep| |
250 |
284 |
|
285 (aPathname notNil and:[(path := aPathname asFilename) isDirectory]) ifFalse:[ |
|
286 model root:nil. |
|
287 ^ self selection:nil |
|
288 ]. |
|
289 |
|
290 (dir := self directory) notNil ifTrue:[ |
|
291 dir := dir asFilename. |
|
292 keep := path pathName = dir directory pathName. |
|
293 ] ifFalse:[ |
|
294 keep := false |
|
295 ]. |
251 self selection:nil. |
296 self selection:nil. |
252 |
297 |
253 (aPathname notNil and:[aPathname asFilename isDirectory]) ifFalse:[ |
298 root := self itemClass pathName:path. |
254 model root:nil. |
299 model root:root keepRoot:keep. |
255 ^ self |
|
256 ]. |
|
257 |
|
258 root := self itemClass pathName:aPathname. |
|
259 model root:root. |
|
260 model expand:root. |
300 model expand:root. |
|
301 |
|
302 keep ifTrue:[ |
|
303 self selectPathname:(dir pathName) |
|
304 ]. |
|
305 |
261 ! |
306 ! |
262 |
307 |
263 itemClass |
308 itemClass |
264 "returns current itemClass used |
309 "returns current itemClass used |
265 " |
310 " |
326 itemClass := FileSelectionItem. |
382 itemClass := FileSelectionItem. |
327 self model:(SelectionInTree new). |
383 self model:(SelectionInTree new). |
328 |
384 |
329 ! ! |
385 ! ! |
330 |
386 |
331 !FileSelectionTree methodsFor:'queries'! |
|
332 |
|
333 canSelect:aFilename |
|
334 "returns true if a file is selectable dependant on |
|
335 filter ... |
|
336 " |
|
337 |root| |
|
338 |
|
339 (itemClass isSelectableFile:aFilename) ifTrue:[ |
|
340 (root := self directory) notNil ifTrue:[ |
|
341 ^ aFilename asString startsWith:root |
|
342 ] |
|
343 ]. |
|
344 ^ false |
|
345 ! ! |
|
346 |
|
347 !FileSelectionTree methodsFor:'selection'! |
387 !FileSelectionTree methodsFor:'selection'! |
348 |
388 |
349 selectPathname:aPath |
389 selectPathname:aPath |
350 "set selection to a path |
390 "set selection to a path |
351 " |
391 " |
352 |node comp rdwNd path| |
392 |node comp rdwNd path| |
353 |
393 |
354 (self canSelect:aPath) ifFalse:[ |
394 (aPath notNil and:[aPath asFilename exists]) ifFalse:[ |
355 ^ self selection:nil |
395 ^ self selection:nil |
356 ]. |
396 ]. |
357 ((path := aPath asString) = self selectedPathname) ifTrue:[ |
397 ((path := aPath asString) = self selectedPathname) ifTrue:[ |
358 "/ already selected |
398 "/ already selected |
359 ^ self |
399 ^ self |