author | ca |
Sat, 10 Feb 1996 10:36:47 +0100 | |
changeset 351 | 24a527f86c7b |
parent 296 | e1b9431b3aef |
child 438 | 8df6f72d1569 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1990 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 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 |
ListSelectionBox subclass:#FileSelectionBox |
|
351 | 14 |
instanceVariableNames:'patternField selectingDirectory' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-DialogBoxes' |
|
0 | 18 |
! |
19 |
||
7 | 20 |
!FileSelectionBox class methodsFor:'documentation'! |
21 |
||
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
7 | 36 |
documentation |
37 |
" |
|
38 | 38 |
this class implements file selection boxes. Instances show a list of |
39 |
files, and perform an action block with the selected pathname as |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
40 |
argument when ok is clicked. It is also possible, to open the box |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
41 |
without action and ask it afterward if it has been left with ok |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
42 |
(i.e. the ST-80 way, asking 'aBox accepted ifTrue:[...]') |
38 | 43 |
|
44 |
There is an optional PatternField, which shows itself when a pattern |
|
45 |
is defined (i.e. if there is no pattern, it is hidden). |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
46 |
If there is a pattern, only files matching the pattern are shown in |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
47 |
the list. Directories are not affected by the patternField. |
38 | 48 |
|
49 |
In addition, there is an optional matchBlock (actually this is defined |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
50 |
in the FileSelectionList). Only names for which this matchblock |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
51 |
returns true will be presented. The matchBlock affects both regular files |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
52 |
and names of directories. The argument passed to the matchBlock is the full |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
53 |
pathname. |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
54 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
55 |
All of the actual work is done in the fileList; see the documentation |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
56 |
of FileSelectionList for more options |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
57 |
(you can access a boxes fileList via 'aBox>>listView' and get access to all |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
58 |
of those fancy settings) |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
59 |
For example, by accessing the list, it is possible to hide all directories |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
60 |
('aBox listView ignoreDirectories:true'), to hide the parentDirectory alone |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
61 |
('aBox listView ignoreParentDirectory') and to turn off the marking |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
62 |
of subdirectories ('aBox listView markSubdirectories:false'). |
62 | 63 |
" |
64 |
! |
|
38 | 65 |
|
62 | 66 |
examples |
67 |
" |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
68 |
simple standard queries |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
69 |
|
238 | 70 |
very simple: |
351 | 71 |
|name| |
238 | 72 |
|
351 | 73 |
name := FileSelectionBox requestFilename. |
74 |
Transcript showCr:name |
|
38 | 75 |
|
238 | 76 |
|
77 |
simple: |
|
351 | 78 |
|name| |
238 | 79 |
|
351 | 80 |
name := FileSelectionBox requestFilename:'which file ?'. |
81 |
Transcript showCr:name |
|
38 | 82 |
|
238 | 83 |
|
84 |
with initial selection: |
|
351 | 85 |
|name| |
238 | 86 |
|
351 | 87 |
name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'. |
88 |
Transcript showCr:name |
|
38 | 89 |
|
238 | 90 |
|
12 | 91 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
92 |
more detailed setup |
238 | 93 |
|
94 |
setting title: |
|
38 | 95 |
|
351 | 96 |
|box| |
97 |
box := FileSelectionBox new. |
|
98 |
box title:'Which file ?'. |
|
99 |
box open. |
|
100 |
box accepted ifTrue:[ |
|
101 |
Transcript showCr:'you selected: ' , box |
|
102 |
] |
|
38 | 103 |
|
238 | 104 |
setting a matchpattern: |
38 | 105 |
|
351 | 106 |
|box| |
107 |
box := FileSelectionBox new. |
|
108 |
box title:'Which file ?'. |
|
109 |
box pattern:'*.rc'. |
|
110 |
box open |
|
111 |
||
112 |
setting multiple patterns: |
|
113 |
||
114 |
|box| |
|
115 |
box := FileSelectionBox new. |
|
116 |
box title:'Which file ?'. |
|
117 |
box pattern:'*.rc;*.st'. |
|
118 |
box open |
|
38 | 119 |
|
238 | 120 |
setting a matchblock: |
38 | 121 |
|
351 | 122 |
|box| |
123 |
box := FileSelectionBox new. |
|
124 |
box title:'Which file ?'. |
|
125 |
box directory:'/etc'. |
|
126 |
box pattern:'*'. |
|
127 |
box matchBlock:[:name | name asFilename baseName first between:$a and:$z]. |
|
128 |
box open |
|
44 | 129 |
|
238 | 130 |
both pattern and matchBlock: |
44 | 131 |
|
351 | 132 |
|box| |
133 |
box := FileSelectionBox new. |
|
134 |
box title:'Which directory ?'. |
|
135 |
box selectingDirectory:true. |
|
136 |
box pattern:'l*'. |
|
137 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
138 |
box action:[:fn | Transcript showCr:fn]. |
|
139 |
box open |
|
238 | 140 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
141 |
dont show the parent directory: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
142 |
|
351 | 143 |
|box| |
144 |
box := FileSelectionBox new. |
|
145 |
box title:'Which directory ?'. |
|
146 |
box listView ignoreParentDirectory:true. |
|
147 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
148 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
149 |
dont show any directory: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
150 |
|
351 | 151 |
|box| |
152 |
box := FileSelectionBox new. |
|
153 |
box title:'Which file ?'. |
|
154 |
box listView ignoreDirectories:true. |
|
155 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
156 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
157 |
dont show any directory or hidden file: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
158 |
(notice the basename extraction - we are not interrested in the full pathName) |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
159 |
|
351 | 160 |
|box| |
161 |
box := FileSelectionBox new. |
|
162 |
box title:'Which file ?'. |
|
163 |
box listView ignoreDirectories:true. |
|
164 |
box matchBlock:[:name | (name asFilename baseName startsWith:'.') not]. |
|
165 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
166 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
167 |
dont allow direct filename entry: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
168 |
(i.e. avoid the user choosing files from other directories) |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
169 |
|
351 | 170 |
|box| |
171 |
box := FileSelectionBox new. |
|
172 |
box title:'Which one ?'. |
|
173 |
box enterField beInvisible. |
|
174 |
box open. |
|
175 |
box accepted ifTrue:[ |
|
176 |
Transcript showCr:'path is ' , box pathName |
|
177 |
]. |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
178 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
179 |
combined with above directory ignoring, |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
180 |
this limits selection of files from a single directory: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
181 |
|
351 | 182 |
|box| |
183 |
box := FileSelectionBox new. |
|
184 |
box title:'Which file ?'. |
|
185 |
box enterField beInvisible. |
|
186 |
box listView ignoreDirectories:true. |
|
187 |
box open. |
|
188 |
box accepted ifTrue:[ |
|
189 |
Transcript showCr:'path is ' , box pathName |
|
190 |
]. |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
191 |
|
238 | 192 |
finally, an action: |
193 |
||
351 | 194 |
|box| |
195 |
box := FileSelectionBox new. |
|
196 |
box title:'Which directory ?'. |
|
197 |
box pattern:'l*'. |
|
198 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
199 |
box action:[:name | Transcript showCr:name]. |
|
200 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
201 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
202 |
concrete examples: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
203 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
204 |
only show files beginning with lowercase characters |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
205 |
and ending in '.c': |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
206 |
|
351 | 207 |
|box| |
208 |
box := FileSelectionBox new. |
|
209 |
box title:'Which directory ?'. |
|
210 |
box matchBlock:[:name | |
|
211 |
box pathName asFilename isDirectory |
|
212 |
or:[name first isLowercase |
|
213 |
and:[name endsWith:'.c']] |
|
214 |
]. |
|
215 |
box open. |
|
216 |
box accepted ifTrue:[ |
|
217 |
Transcript showCr:'full path: ' , box pathName. |
|
218 |
Transcript showCr:'files name: ' , box fileName. |
|
219 |
Transcript showCr:'directory : ' , box directory. |
|
220 |
] |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
221 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
222 |
somewhat wierd example: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
223 |
only show files, if the directory we are in begins with 'lib': |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
224 |
|
351 | 225 |
|box| |
226 |
box := FileSelectionBox new. |
|
227 |
box title:'Which directory ?'. |
|
228 |
box pattern:'l*'. |
|
229 |
box matchBlock:[:name | |
|
230 |
box directory asString beginsWith:'lib' |
|
231 |
]. |
|
232 |
box open |
|
233 |
box accepted ifTrue:[ |
|
234 |
Transcript showCr:'full path: ' , box pathName. |
|
235 |
Transcript showCr:'files name: ' , box fileName. |
|
236 |
Transcript showCr:'directory : ' , box directory. |
|
237 |
] |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
238 |
|
7 | 239 |
" |
240 |
! ! |
|
0 | 241 |
|
12 | 242 |
!FileSelectionBox class methodsFor:'defaults'! |
243 |
||
77 | 244 |
requestFilename |
245 |
^ self requestFilename:'filename:' |
|
246 |
||
247 |
" |
|
248 |
FileSelectionBox requestFilename |
|
249 |
" |
|
250 |
! |
|
251 |
||
252 |
requestFilename:title |
|
253 |
|fileBox| |
|
254 |
||
255 |
fileBox := self |
|
256 |
title:title |
|
257 |
okText:'ok' |
|
258 |
abortText:'cancel' |
|
259 |
action:[:fileName | ^ fileName]. |
|
260 |
||
261 |
fileBox showAtPointer. |
|
262 |
^ nil |
|
263 |
||
264 |
" |
|
265 |
FileSelectionBox requestFilename:'which file ?' |
|
266 |
" |
|
235 | 267 |
! |
268 |
||
269 |
requestFilename:title default:aFileName |
|
270 |
|fileBox| |
|
271 |
||
272 |
fileBox := self |
|
273 |
title:title |
|
274 |
okText:'ok' |
|
275 |
abortText:'cancel' |
|
276 |
action:[:fileName | ^ fileName]. |
|
277 |
||
278 |
fileBox initialText:aFileName. |
|
279 |
fileBox showAtPointer. |
|
280 |
^ nil |
|
281 |
||
282 |
" |
|
283 |
FileSelectionBox requestFilename:'which file ?' default:'Makefile' |
|
284 |
" |
|
285 |
! |
|
286 |
||
287 |
requestFilename:title fromDirectory: aDirectory |
|
288 |
||
289 |
|fileBox| |
|
290 |
||
291 |
fileBox := self |
|
292 |
title:title |
|
293 |
okText:'ok' |
|
294 |
abortText:'cancel' |
|
295 |
action:[:fileName | ^ fileName]. |
|
296 |
||
297 |
fileBox directory: aDirectory. |
|
298 |
fileBox showAtPointer. |
|
299 |
^ nil |
|
300 |
||
301 |
" |
|
302 |
FileSelectionBox requestFilename:'which file ?' fromDirectory:'/etc' |
|
303 |
" |
|
304 |
||
305 |
"Modified: 12.10.1995 / 11:47:27 / markus" |
|
77 | 306 |
! ! |
307 |
||
308 |
!FileSelectionBox class methodsFor:'requests'! |
|
309 |
||
12 | 310 |
listViewType |
311 |
"return the type of listView - using a FileSelectionList here" |
|
312 |
||
313 |
^ FileSelectionList |
|
314 |
! ! |
|
315 |
||
197 | 316 |
!FileSelectionBox methodsFor:'accessing'! |
3 | 317 |
|
197 | 318 |
contents |
319 |
"return the current entered value (i.e. the enterFields string). |
|
320 |
redefined to return the full pathname." |
|
321 |
||
322 |
|string sep| |
|
3 | 323 |
|
197 | 324 |
string := super contents. |
325 |
string isNil ifTrue:[ |
|
326 |
^ selectionList directory pathName |
|
121 | 327 |
]. |
197 | 328 |
sep := Filename separator. |
329 |
(string startsWith:sep) ifTrue:[ |
|
330 |
^ string |
|
77 | 331 |
]. |
197 | 332 |
^ (selectionList directory pathName asFilename construct:string) asString |
132 | 333 |
! |
334 |
||
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
335 |
directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
336 |
"return the directory which is currently shown" |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
337 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
338 |
^ selectionList directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
339 |
! |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
340 |
|
197 | 341 |
directory:directoryName |
342 |
"change the directory shown in the list." |
|
41 | 343 |
|
197 | 344 |
selectionList directory:directoryName |
132 | 345 |
! |
346 |
||
351 | 347 |
fileName |
348 |
"if some filename has been entered, return it (without the directory path) |
|
349 |
otherwise, return nil" |
|
350 |
||
351 |
|string| |
|
352 |
||
353 |
string := super contents. |
|
354 |
string isNil ifTrue:[^ nil]. |
|
355 |
^ self pathName |
|
356 |
! |
|
357 |
||
197 | 358 |
matchBlock:aBlock |
359 |
"set the matchBlock (in the selectionList). Only files |
|
360 |
for which the block returns true are shown. |
|
361 |
The matching is actually done in the fileSelectionList." |
|
77 | 362 |
|
197 | 363 |
selectionList matchBlock:aBlock |
364 |
! |
|
0 | 365 |
|
38 | 366 |
openOn:aPath |
367 |
"open the box showing files in aPath. |
|
368 |
This is only a shortcut message - no new functionality." |
|
369 |
||
370 |
self directory:aPath. |
|
371 |
self showAtPointer |
|
372 |
! |
|
373 |
||
351 | 374 |
pathName |
375 |
"same as contents - return the full pathname of the selected file, |
|
376 |
or the pathname of the directory if nothing has been entered" |
|
377 |
||
378 |
^ self contents |
|
379 |
! |
|
380 |
||
3 | 381 |
pattern:aPattern |
38 | 382 |
"set the pattern - this also enables the PatternField |
383 |
(if the pattern is non-nil) or hides it (if nil)." |
|
7 | 384 |
|
130 | 385 |
|hidePatternField focusSequence| |
386 |
||
3 | 387 |
patternField initialText:aPattern. |
12 | 388 |
selectionList pattern:aPattern. |
389 |
aPattern isNil ifTrue:[ |
|
130 | 390 |
hidePatternField := true. |
59 | 391 |
realized ifTrue:[ |
392 |
patternField hide. |
|
77 | 393 |
]. |
130 | 394 |
focusSequence := (Array |
395 |
with:enterField |
|
396 |
with:selectionList |
|
397 |
with:okButton |
|
398 |
with:abortButton) |
|
12 | 399 |
] ifFalse:[ |
130 | 400 |
hidePatternField := false. |
59 | 401 |
realized ifTrue:[ |
402 |
patternField realize. |
|
403 |
]. |
|
130 | 404 |
focusSequence := (Array |
405 |
with:patternField |
|
406 |
with:enterField |
|
407 |
with:selectionList |
|
408 |
with:okButton |
|
409 |
with:abortButton) |
|
410 |
]. |
|
411 |
||
412 |
patternField hiddenOnRealize:hidePatternField. |
|
413 |
windowGroup notNil ifTrue:[ |
|
414 |
windowGroup focusSequence:focusSequence |
|
0 | 415 |
]. |
351 | 416 |
! |
417 |
||
418 |
selectingDirectory:aBoolean |
|
419 |
selectingDirectory := aBoolean |
|
197 | 420 |
! ! |
421 |
||
422 |
!FileSelectionBox methodsFor:'change & update'! |
|
423 |
||
424 |
update:something with:argument from:changedObject |
|
425 |
|commonName index s| |
|
426 |
||
427 |
something == #directory ifTrue:[ |
|
428 |
" |
|
429 |
sent by fileNameEnterField, if a filename |
|
430 |
completion was not possible due to multiple |
|
431 |
matches. |
|
432 |
" |
|
433 |
selectionList directory:argument. |
|
434 |
s := enterField contents. |
|
435 |
s notNil ifTrue:[ |
|
436 |
commonName := s asFilename baseName. |
|
437 |
commonName size > 0 ifTrue:[ |
|
438 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName]. |
|
439 |
index ~~ 0 ifTrue:[ |
|
440 |
selectionList makeLineVisible:index |
|
441 |
] |
|
442 |
] |
|
443 |
] |
|
444 |
] |
|
445 |
! ! |
|
446 |
||
447 |
!FileSelectionBox methodsFor:'initialization'! |
|
448 |
||
449 |
createEnterField |
|
450 |
"if the (optional) class FilenameEditField is present, use |
|
451 |
it, since it provides filename completion. Otherwise, we have |
|
452 |
to live with the dump (default) field ... |
|
453 |
" |
|
454 |
FilenameEditField notNil ifTrue:[ |
|
455 |
^ FilenameEditField new. |
|
456 |
]. |
|
457 |
^ super createEnterField |
|
38 | 458 |
! |
0 | 459 |
|
197 | 460 |
focusSequence |
461 |
patternField shown ifTrue:[ |
|
462 |
^ Array |
|
463 |
with:patternField |
|
464 |
with:enterField |
|
465 |
with:selectionList |
|
466 |
with:abortButton |
|
467 |
with:okButton |
|
468 |
]. |
|
469 |
^ super focusSequence |
|
470 |
! |
|
471 |
||
472 |
initialize |
|
473 |
|corner| |
|
474 |
||
475 |
super initialize. |
|
351 | 476 |
selectingDirectory := false. |
197 | 477 |
|
478 |
label := resources string:'File dialog'. |
|
0 | 479 |
|
197 | 480 |
labelField extent:(0.7 @ labelField height). |
481 |
labelField label:(resources string:'select a file:'). |
|
482 |
labelField adjust:#left. |
|
483 |
||
484 |
patternField := EditField in:self. |
|
485 |
self is3D ifTrue:[ |
|
351 | 486 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
197 | 487 |
] ifFalse:[ |
351 | 488 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
197 | 489 |
]. |
490 |
patternField origin:(0.7 @ labelField origin y) corner:corner. |
|
491 |
patternField rightInset:ViewSpacing. |
|
492 |
patternField initialText:'*'. |
|
493 |
patternField leaveAction:[:reason | |
|
351 | 494 |
selectionList pattern:patternField contents. |
495 |
self updateList |
|
197 | 496 |
]. |
497 |
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
|
498 |
||
499 |
enterField addDependent:self. |
|
500 |
||
501 |
" |
|
502 |
FileSelectionBox open |
|
503 |
FileSelectionBox new show |
|
504 |
" |
|
38 | 505 |
! |
7 | 506 |
|
197 | 507 |
realize |
508 |
"if some default is present in the enterField, |
|
509 |
scroll to make this one visible" |
|
510 |
||
511 |
|contents| |
|
512 |
||
513 |
super realize. |
|
514 |
(contents := enterField contents) notNil ifTrue:[ |
|
515 |
contents notEmpty ifTrue:[ |
|
516 |
selectionList makeVisible:contents |
|
517 |
] |
|
518 |
] |
|
519 |
! ! |
|
520 |
||
521 |
!FileSelectionBox methodsFor:'private'! |
|
522 |
||
523 |
updateList |
|
524 |
selectionList updateList |
|
525 |
! ! |
|
38 | 526 |
|
197 | 527 |
!FileSelectionBox methodsFor:'queries'! |
528 |
||
529 |
preferredExtent |
|
530 |
"return my preferred extent - thats the minimum size |
|
531 |
to make everything visible" |
|
532 |
||
533 |
|wWanted hWanted| |
|
534 |
||
535 |
wWanted := ViewSpacing + |
|
536 |
labelField preferredExtent x + |
|
537 |
(ViewSpacing * 2) + |
|
538 |
patternField preferredExtent x + |
|
539 |
ViewSpacing. |
|
540 |
(wWanted < width) ifTrue:[ |
|
541 |
wWanted := width |
|
542 |
]. |
|
543 |
hWanted := ViewSpacing + labelField height + |
|
544 |
ViewSpacing + enterField height + |
|
545 |
ViewSpacing + selectionList height + |
|
546 |
ViewSpacing + buttonPanel preferredExtent y + |
|
547 |
ViewSpacing. |
|
38 | 548 |
|
197 | 549 |
(hWanted < height) ifTrue:[ |
550 |
hWanted := height |
|
551 |
]. |
|
552 |
^ (wWanted @ hWanted) |
|
553 |
! ! |
|
554 |
||
555 |
!FileSelectionBox methodsFor:'user actions'! |
|
556 |
||
557 |
doubleClick |
|
558 |
|entry| |
|
559 |
||
560 |
entry := selectionList selectionValue. |
|
561 |
entry notNil ifTrue:[ |
|
562 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[ |
|
563 |
enterField contents:entry. |
|
564 |
self okPressed |
|
565 |
] |
|
38 | 566 |
]. |
197 | 567 |
! |
568 |
||
569 |
okPressed |
|
570 |
"called for both on ok-press and on return-key" |
|
571 |
||
572 |
|dir string fname| |
|
573 |
||
574 |
string := enterField contents. |
|
351 | 575 |
(string notNil and:[string notEmpty]) ifTrue:[ |
576 |
string := string withoutSeparators. |
|
577 |
string asFilename isAbsolute ifTrue:[ |
|
578 |
fname := string asFilename |
|
579 |
] ifFalse:[ |
|
580 |
dir := selectionList directory pathName asFilename. |
|
581 |
fname := dir construct:string |
|
582 |
]. |
|
583 |
fname isDirectory ifTrue:[ |
|
584 |
selectingDirectory ifFalse:[ |
|
585 |
selectionList directory:fname asString. |
|
586 |
self updateList. |
|
587 |
^ self |
|
588 |
] |
|
589 |
] |
|
590 |
] ifFalse:[ |
|
591 |
selectingDirectory ifTrue:[ |
|
592 |
enterField contents:(selectionList directory pathName). |
|
593 |
]. |
|
38 | 594 |
]. |
351 | 595 |
|
197 | 596 |
super okPressed |
351 | 597 |
|
197 | 598 |
! |
599 |
||
600 |
selectionChanged |
|
601 |
|entry| |
|
602 |
||
603 |
entry := selectionList selectionValue. |
|
604 |
enterField contents:entry |
|
0 | 605 |
! ! |
197 | 606 |
|
240 | 607 |
!FileSelectionBox class methodsFor:'documentation'! |
608 |
||
609 |
version |
|
351 | 610 |
^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.28 1996-02-10 09:36:47 ca Exp $' |
240 | 611 |
! ! |