author | Claus Gittinger <cg@exept.de> |
Wed, 09 Sep 1998 22:10:13 +0200 | |
changeset 1670 | 8d24855a9f0b |
parent 1643 | 2710f3be2a77 |
child 1671 | 5afdf222b738 |
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' |
1320 | 15 |
classVariableNames:'LastFileSelectionDirectory' |
351 | 16 |
poolDictionaries:'' |
17 |
category:'Views-DialogBoxes' |
|
0 | 18 |
! |
19 |
||
849 | 20 |
!FileSelectionBox class methodsFor:'documentation'! |
7 | 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'). |
585 | 63 |
|
64 |
[author:] |
|
65 |
Claus Gittinger |
|
66 |
||
67 |
[see also:] |
|
68 |
DialogBox |
|
648 | 69 |
EnterBox2 FilenameEnterBox YesNoBox |
593 | 70 |
ListSelectionBox FileSaveBox |
71 |
FileSelectionList SelectionInListView |
|
62 | 72 |
" |
73 |
! |
|
38 | 74 |
|
62 | 75 |
examples |
76 |
" |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
77 |
simple standard queries |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
78 |
|
238 | 79 |
very simple: |
593 | 80 |
[exBegin] |
351 | 81 |
|name| |
238 | 82 |
|
593 | 83 |
name := FileSelectionBox requestFileName. |
655 | 84 |
Transcript showCR:name |
593 | 85 |
[exEnd] |
38 | 86 |
|
238 | 87 |
|
88 |
simple: |
|
593 | 89 |
[exBegin] |
351 | 90 |
|name| |
238 | 91 |
|
593 | 92 |
name := FileSelectionBox requestFileName:'which file ?'. |
655 | 93 |
Transcript showCR:name |
593 | 94 |
[exEnd] |
38 | 95 |
|
238 | 96 |
|
97 |
with initial selection: |
|
593 | 98 |
[exBegin] |
351 | 99 |
|name| |
238 | 100 |
|
593 | 101 |
name := FileSelectionBox requestFileName:'which file ?' default:'Make.proto'. |
655 | 102 |
Transcript showCR:name |
593 | 103 |
[exEnd] |
38 | 104 |
|
238 | 105 |
|
12 | 106 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
107 |
more detailed setup |
238 | 108 |
|
109 |
setting title: |
|
593 | 110 |
[exBegin] |
351 | 111 |
|box| |
112 |
box := FileSelectionBox new. |
|
113 |
box title:'Which file ?'. |
|
114 |
box open. |
|
115 |
box accepted ifTrue:[ |
|
1411 | 116 |
Transcript showCR:'you selected: ' , box pathName |
351 | 117 |
] |
593 | 118 |
[exEnd] |
38 | 119 |
|
238 | 120 |
setting a matchpattern: |
593 | 121 |
[exBegin] |
351 | 122 |
|box| |
123 |
box := FileSelectionBox new. |
|
124 |
box title:'Which file ?'. |
|
125 |
box pattern:'*.rc'. |
|
126 |
box open |
|
593 | 127 |
[exEnd] |
351 | 128 |
|
129 |
setting multiple patterns: |
|
593 | 130 |
[exBegin] |
351 | 131 |
|box| |
132 |
box := FileSelectionBox new. |
|
133 |
box title:'Which file ?'. |
|
134 |
box pattern:'*.rc;*.st'. |
|
135 |
box open |
|
593 | 136 |
[exEnd] |
38 | 137 |
|
238 | 138 |
setting a matchblock: |
593 | 139 |
[exBegin] |
351 | 140 |
|box| |
141 |
box := FileSelectionBox new. |
|
142 |
box title:'Which file ?'. |
|
143 |
box directory:'/etc'. |
|
144 |
box pattern:'*'. |
|
145 |
box matchBlock:[:name | name asFilename baseName first between:$a and:$z]. |
|
146 |
box open |
|
593 | 147 |
[exEnd] |
44 | 148 |
|
238 | 149 |
both pattern and matchBlock: |
593 | 150 |
[exBegin] |
351 | 151 |
|box| |
152 |
box := FileSelectionBox new. |
|
153 |
box title:'Which directory ?'. |
|
154 |
box selectingDirectory:true. |
|
155 |
box pattern:'l*'. |
|
156 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
655 | 157 |
box action:[:fn | Transcript showCR:fn]. |
351 | 158 |
box open |
593 | 159 |
[exEnd] |
238 | 160 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
161 |
dont show the parent directory: |
593 | 162 |
[exBegin] |
351 | 163 |
|box| |
164 |
box := FileSelectionBox new. |
|
165 |
box title:'Which directory ?'. |
|
166 |
box listView ignoreParentDirectory:true. |
|
167 |
box open |
|
593 | 168 |
[exEnd] |
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
169 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
170 |
dont show any directory: |
593 | 171 |
[exBegin] |
351 | 172 |
|box| |
173 |
box := FileSelectionBox new. |
|
174 |
box title:'Which file ?'. |
|
175 |
box listView ignoreDirectories:true. |
|
176 |
box open |
|
593 | 177 |
[exEnd] |
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 |
dont show any directory or hidden file: |
842
a27a1c6ddde0
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
800
diff
changeset
|
180 |
(notice the basename extraction - we are not interested in the full pathName) |
593 | 181 |
[exBegin] |
351 | 182 |
|box| |
183 |
box := FileSelectionBox new. |
|
184 |
box title:'Which file ?'. |
|
185 |
box listView ignoreDirectories:true. |
|
186 |
box matchBlock:[:name | (name asFilename baseName startsWith:'.') not]. |
|
187 |
box open |
|
593 | 188 |
[exEnd] |
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
189 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
190 |
dont allow direct filename entry: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
191 |
(i.e. avoid the user choosing files from other directories) |
593 | 192 |
[exBegin] |
351 | 193 |
|box| |
194 |
box := FileSelectionBox new. |
|
195 |
box title:'Which one ?'. |
|
196 |
box enterField beInvisible. |
|
197 |
box open. |
|
198 |
box accepted ifTrue:[ |
|
655 | 199 |
Transcript showCR:'path is ' , box pathName |
351 | 200 |
]. |
593 | 201 |
[exEnd] |
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
202 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
203 |
combined with above directory ignoring, |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
204 |
this limits selection of files from a single directory: |
593 | 205 |
[exBegin] |
351 | 206 |
|box| |
207 |
box := FileSelectionBox new. |
|
208 |
box title:'Which file ?'. |
|
209 |
box enterField beInvisible. |
|
210 |
box listView ignoreDirectories:true. |
|
211 |
box open. |
|
212 |
box accepted ifTrue:[ |
|
655 | 213 |
Transcript showCR:'path is ' , box pathName |
351 | 214 |
]. |
593 | 215 |
[exEnd] |
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
216 |
|
238 | 217 |
finally, an action: |
593 | 218 |
[exBegin] |
351 | 219 |
|box| |
220 |
box := FileSelectionBox new. |
|
221 |
box title:'Which directory ?'. |
|
222 |
box pattern:'l*'. |
|
223 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
655 | 224 |
box action:[:name | Transcript showCR:name]. |
351 | 225 |
box open |
593 | 226 |
[exEnd] |
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
227 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
228 |
concrete examples: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
229 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
230 |
only show files beginning with lowercase characters |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
231 |
and ending in '.c': |
593 | 232 |
[exBegin] |
351 | 233 |
|box| |
234 |
box := FileSelectionBox new. |
|
235 |
box title:'Which directory ?'. |
|
236 |
box matchBlock:[:name | |
|
237 |
box pathName asFilename isDirectory |
|
238 |
or:[name first isLowercase |
|
239 |
and:[name endsWith:'.c']] |
|
240 |
]. |
|
241 |
box open. |
|
242 |
box accepted ifTrue:[ |
|
655 | 243 |
Transcript showCR:'full path: ' , box pathName. |
244 |
Transcript showCR:'files name: ' , box fileName. |
|
1643
2710f3be2a77
fixed #fileName - return fileName only (not full path)
Claus Gittinger <cg@exept.de>
parents:
1639
diff
changeset
|
245 |
Transcript showCR:'directory : ' , box directory pathName. |
351 | 246 |
] |
593 | 247 |
[exEnd] |
7 | 248 |
" |
249 |
! ! |
|
0 | 250 |
|
1320 | 251 |
!FileSelectionBox class methodsFor:'accessing'! |
252 |
||
253 |
lastFileSelectionDirectory |
|
1571
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
254 |
"return the name of the directory used in the previous |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
255 |
fileSelection dialog. This will be used as default for the next dialog, |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
256 |
if no explicit path is specified (see requestFileName:* methods)" |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
257 |
|
1574 | 258 |
|f| |
259 |
||
1571
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
260 |
LastFileSelectionDirectory notNil ifTrue:[ |
1574 | 261 |
((f := LastFileSelectionDirectory asFilename) exists |
262 |
and:[f isDirectory]) ifFalse:[ |
|
263 |
LastFileSelectionDirectory := nil. |
|
264 |
] |
|
1571
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
265 |
]. |
1320 | 266 |
^ LastFileSelectionDirectory |
267 |
||
1571
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
268 |
"Created: / 9.9.1997 / 10:03:17 / cg" |
1574 | 269 |
"Modified: / 16.6.1998 / 15:11:20 / cg" |
1320 | 270 |
! |
271 |
||
272 |
lastFileSelectionDirectory:aDirectoryString |
|
1571
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
273 |
"set the name of the directory used in the previous |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
274 |
fileSelection dialog. This will be used as default for the next dialog, |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
275 |
if no explicit path is specified (see requestFileName:* methods)" |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
276 |
|
1320 | 277 |
LastFileSelectionDirectory := aDirectoryString |
278 |
||
1571
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
279 |
"Created: / 9.9.1997 / 10:03:42 / cg" |
fdaa3b9aa746
flush lastFileSelectionDirectory, if it does not exists
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
280 |
"Modified: / 15.6.1998 / 14:05:21 / cg" |
1320 | 281 |
! ! |
282 |
||
849 | 283 |
!FileSelectionBox class methodsFor:'defaults'! |
12 | 284 |
|
285 |
listViewType |
|
286 |
"return the type of listView - using a FileSelectionList here" |
|
287 |
||
288 |
^ FileSelectionList |
|
289 |
! ! |
|
290 |
||
197 | 291 |
!FileSelectionBox methodsFor:'accessing'! |
3 | 292 |
|
197 | 293 |
contents |
294 |
"return the current entered value (i.e. the enterFields string). |
|
295 |
redefined to return the full pathname." |
|
296 |
||
297 |
|string sep| |
|
3 | 298 |
|
197 | 299 |
string := super contents. |
300 |
string isNil ifTrue:[ |
|
1670
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
301 |
^ selectionList directory pathName |
121 | 302 |
]. |
1670
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
303 |
(string asFilename isAbsolute) ifTrue:[ |
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
304 |
^ string |
77 | 305 |
]. |
197 | 306 |
^ (selectionList directory pathName asFilename construct:string) asString |
1670
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
307 |
|
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
308 |
"Modified: / 9.9.1998 / 21:23:16 / cg" |
132 | 309 |
! |
310 |
||
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
311 |
directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
312 |
"return the directory which is currently shown" |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
313 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
314 |
^ selectionList directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
315 |
! |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
316 |
|
197 | 317 |
directory:directoryName |
318 |
"change the directory shown in the list." |
|
41 | 319 |
|
197 | 320 |
selectionList directory:directoryName |
132 | 321 |
! |
322 |
||
351 | 323 |
fileName |
324 |
"if some filename has been entered, return it (without the directory path) |
|
325 |
otherwise, return nil" |
|
326 |
||
327 |
|string| |
|
328 |
||
329 |
string := super contents. |
|
330 |
string isNil ifTrue:[^ nil]. |
|
1643
2710f3be2a77
fixed #fileName - return fileName only (not full path)
Claus Gittinger <cg@exept.de>
parents:
1639
diff
changeset
|
331 |
^ self pathName asFilename baseName |
2710f3be2a77
fixed #fileName - return fileName only (not full path)
Claus Gittinger <cg@exept.de>
parents:
1639
diff
changeset
|
332 |
|
2710f3be2a77
fixed #fileName - return fileName only (not full path)
Claus Gittinger <cg@exept.de>
parents:
1639
diff
changeset
|
333 |
"Modified: / 12.8.1998 / 09:54:01 / cg" |
351 | 334 |
! |
335 |
||
197 | 336 |
matchBlock:aBlock |
337 |
"set the matchBlock (in the selectionList). Only files |
|
338 |
for which the block returns true are shown. |
|
339 |
The matching is actually done in the fileSelectionList." |
|
77 | 340 |
|
197 | 341 |
selectionList matchBlock:aBlock |
342 |
! |
|
0 | 343 |
|
38 | 344 |
openOn:aPath |
345 |
"open the box showing files in aPath. |
|
346 |
This is only a shortcut message - no new functionality." |
|
347 |
||
348 |
self directory:aPath. |
|
349 |
self showAtPointer |
|
350 |
! |
|
351 |
||
351 | 352 |
pathName |
353 |
"same as contents - return the full pathname of the selected file, |
|
354 |
or the pathname of the directory if nothing has been entered" |
|
355 |
||
356 |
^ self contents |
|
357 |
! |
|
358 |
||
3 | 359 |
pattern:aPattern |
38 | 360 |
"set the pattern - this also enables the PatternField |
361 |
(if the pattern is non-nil) or hides it (if nil)." |
|
7 | 362 |
|
1270 | 363 |
|focusSequence| |
130 | 364 |
|
3 | 365 |
patternField initialText:aPattern. |
12 | 366 |
selectionList pattern:aPattern. |
367 |
aPattern isNil ifTrue:[ |
|
1270 | 368 |
patternField beInvisible. |
1356 | 369 |
self makeUntabable:patternField. |
1270 | 370 |
focusSequence := (Array |
371 |
with:enterField |
|
372 |
with:selectionList |
|
373 |
with:okButton |
|
374 |
with:abortButton) |
|
12 | 375 |
] ifFalse:[ |
1270 | 376 |
patternField beVisible. |
1356 | 377 |
self makeTabable:patternField before:enterField. |
1270 | 378 |
focusSequence := (Array |
379 |
with:patternField |
|
380 |
with:enterField |
|
381 |
with:selectionList |
|
382 |
with:okButton |
|
383 |
with:abortButton) |
|
130 | 384 |
]. |
385 |
||
386 |
windowGroup notNil ifTrue:[ |
|
1270 | 387 |
windowGroup focusSequence:focusSequence |
0 | 388 |
]. |
1270 | 389 |
|
1356 | 390 |
"Modified: 18.10.1997 / 03:02:05 / cg" |
351 | 391 |
! |
392 |
||
393 |
selectingDirectory:aBoolean |
|
849 | 394 |
"setup the box for directory selection (hides regular files). |
395 |
Use this, to ask the user for a directories name" |
|
396 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
397 |
selectingDirectory := aBoolean. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
398 |
aBoolean ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
399 |
selectionList directoryChangeAction:[:entry | self directoryChanged]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
400 |
selectionList directorySelectAction:[:entry | self directorySelected]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
401 |
selectionList ignoreFiles:true. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
402 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
403 |
|
849 | 404 |
"Modified: 22.10.1996 / 13:24:50 / cg" |
197 | 405 |
! ! |
406 |
||
407 |
!FileSelectionBox methodsFor:'change & update'! |
|
408 |
||
409 |
update:something with:argument from:changedObject |
|
410 |
|commonName index s| |
|
411 |
||
412 |
something == #directory ifTrue:[ |
|
413 |
" |
|
414 |
sent by fileNameEnterField, if a filename |
|
415 |
completion was not possible due to multiple |
|
416 |
matches. |
|
417 |
" |
|
418 |
selectionList directory:argument. |
|
419 |
s := enterField contents. |
|
420 |
s notNil ifTrue:[ |
|
421 |
commonName := s asFilename baseName. |
|
422 |
commonName size > 0 ifTrue:[ |
|
423 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName]. |
|
424 |
index ~~ 0 ifTrue:[ |
|
425 |
selectionList makeLineVisible:index |
|
426 |
] |
|
427 |
] |
|
428 |
] |
|
429 |
] |
|
430 |
! ! |
|
431 |
||
432 |
!FileSelectionBox methodsFor:'initialization'! |
|
433 |
||
434 |
createEnterField |
|
435 |
"if the (optional) class FilenameEditField is present, use |
|
436 |
it, since it provides filename completion. Otherwise, we have |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
437 |
to live with the dumb (default) field ... |
197 | 438 |
" |
439 |
FilenameEditField notNil ifTrue:[ |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
440 |
^ FilenameEditField new. |
197 | 441 |
]. |
442 |
^ super createEnterField |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
443 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
444 |
"Modified: 18.4.1996 / 20:02:24 / cg" |
38 | 445 |
! |
0 | 446 |
|
197 | 447 |
initialize |
448 |
|corner| |
|
449 |
||
450 |
super initialize. |
|
351 | 451 |
selectingDirectory := false. |
197 | 452 |
|
453 |
label := resources string:'File dialog'. |
|
0 | 454 |
|
197 | 455 |
labelField extent:(0.7 @ labelField height). |
456 |
labelField label:(resources string:'select a file:'). |
|
457 |
labelField adjust:#left. |
|
458 |
||
459 |
patternField := EditField in:self. |
|
460 |
self is3D ifTrue:[ |
|
351 | 461 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
197 | 462 |
] ifFalse:[ |
351 | 463 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
197 | 464 |
]. |
465 |
patternField origin:(0.7 @ labelField origin y) corner:corner. |
|
466 |
patternField rightInset:ViewSpacing. |
|
467 |
patternField initialText:'*'. |
|
746
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
468 |
patternField leaveAction:[:reason | self patternChanged]. |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
469 |
patternField crAction:[self patternChanged]. |
197 | 470 |
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
1356 | 471 |
"/ no, since its invisible |
472 |
"/ self makeTabable:patternField before:enterField. |
|
197 | 473 |
|
474 |
enterField addDependent:self. |
|
475 |
||
476 |
" |
|
477 |
FileSelectionBox open |
|
478 |
FileSelectionBox new show |
|
479 |
" |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
480 |
|
1356 | 481 |
"Modified: 18.10.1997 / 02:47:49 / cg" |
38 | 482 |
! |
7 | 483 |
|
1271 | 484 |
postRealize |
197 | 485 |
"if some default is present in the enterField, |
486 |
scroll to make this one visible" |
|
487 |
||
488 |
|contents| |
|
489 |
||
1271 | 490 |
super postRealize. |
197 | 491 |
(contents := enterField contents) notNil ifTrue:[ |
1271 | 492 |
contents notEmpty ifTrue:[ |
493 |
selectionList makeVisible:contents |
|
494 |
] |
|
197 | 495 |
] |
1271 | 496 |
|
497 |
"Created: 24.7.1997 / 18:19:14 / cg" |
|
197 | 498 |
! ! |
499 |
||
500 |
!FileSelectionBox methodsFor:'private'! |
|
501 |
||
502 |
updateList |
|
503 |
selectionList updateList |
|
504 |
! ! |
|
38 | 505 |
|
197 | 506 |
!FileSelectionBox methodsFor:'queries'! |
507 |
||
508 |
preferredExtent |
|
509 |
"return my preferred extent - thats the minimum size |
|
510 |
to make everything visible" |
|
511 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
512 |
|wWanted hWanted mm| |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
513 |
|
800 | 514 |
"/ If I have an explicit preferredExtent .. |
515 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
516 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
517 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
518 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
519 |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
520 |
mm := ViewSpacing. |
197 | 521 |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
522 |
wWanted := mm + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
523 |
labelField preferredExtent x + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
524 |
(mm * 2) + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
525 |
patternField preferredExtent x + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
526 |
mm. |
197 | 527 |
(wWanted < width) ifTrue:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
528 |
wWanted := width |
197 | 529 |
]. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
530 |
hWanted := mm + labelField height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
531 |
mm + enterField height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
532 |
mm + selectionList height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
533 |
mm + buttonPanel preferredExtent y + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
534 |
mm. |
38 | 535 |
|
197 | 536 |
(hWanted < height) ifTrue:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
537 |
hWanted := height |
197 | 538 |
]. |
539 |
^ (wWanted @ hWanted) |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
540 |
|
800 | 541 |
"Modified: 19.7.1996 / 20:44:04 / cg" |
197 | 542 |
! ! |
543 |
||
544 |
!FileSelectionBox methodsFor:'user actions'! |
|
545 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
546 |
directoryChanged |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
547 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
548 |
selectionList changeDirectory. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
549 |
enterField contents:(selectionList directory pathName). |
682 | 550 |
selectionList setSelection:nil. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
551 |
]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
552 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
553 |
"Created: 18.4.1996 / 18:38:21 / cg" |
682 | 554 |
"Modified: 25.5.1996 / 12:27:05 / cg" |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
555 |
! |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
556 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
557 |
directorySelected |
1639 | 558 |
"a directory was selected - show the new path in the inputField, |
559 |
if we are in directory mode" |
|
560 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
561 |
selectingDirectory ifTrue:[ |
1639 | 562 |
|newDir| |
563 |
||
564 |
newDir := (selectionList directory) |
|
565 |
construct:selectionList selectionValue. |
|
566 |
enterField contents:newDir pathName. |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
567 |
]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
568 |
|
1639 | 569 |
"Created: / 18.4.1996 / 18:46:15 / cg" |
570 |
"Modified: / 7.8.1998 / 17:19:26 / cg" |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
571 |
! |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
572 |
|
197 | 573 |
doubleClick |
574 |
|entry| |
|
575 |
||
576 |
entry := selectionList selectionValue. |
|
577 |
entry notNil ifTrue:[ |
|
1356 | 578 |
((selectionList directory asFilename construct:entry) isDirectory) ifFalse:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
579 |
selectingDirectory ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
580 |
enterField contents:entry. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
581 |
self okPressed |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
582 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
583 |
] |
38 | 584 |
]. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
585 |
|
1356 | 586 |
"Modified: 19.10.1997 / 00:17:37 / cg" |
197 | 587 |
! |
588 |
||
589 |
okPressed |
|
590 |
"called for both on ok-press and on return-key" |
|
591 |
||
592 |
|dir string fname| |
|
593 |
||
594 |
string := enterField contents. |
|
351 | 595 |
(string notNil and:[string notEmpty]) ifTrue:[ |
596 |
string := string withoutSeparators. |
|
1670
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
597 |
self halt. |
351 | 598 |
string asFilename isAbsolute ifTrue:[ |
599 |
fname := string asFilename |
|
600 |
] ifFalse:[ |
|
601 |
dir := selectionList directory pathName asFilename. |
|
602 |
fname := dir construct:string |
|
603 |
]. |
|
604 |
fname isDirectory ifTrue:[ |
|
605 |
selectingDirectory ifFalse:[ |
|
606 |
selectionList directory:fname asString. |
|
607 |
self updateList. |
|
608 |
^ self |
|
609 |
] |
|
610 |
] |
|
611 |
] ifFalse:[ |
|
612 |
selectingDirectory ifTrue:[ |
|
613 |
enterField contents:(selectionList directory pathName). |
|
614 |
]. |
|
38 | 615 |
]. |
351 | 616 |
|
197 | 617 |
super okPressed |
351 | 618 |
|
1670
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
619 |
"Modified: / 9.9.1998 / 21:21:14 / cg" |
197 | 620 |
! |
621 |
||
746
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
622 |
patternChanged |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
623 |
selectionList pattern:patternField contents. |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
624 |
self updateList |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
625 |
|
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
626 |
"Created: 4.6.1996 / 20:30:23 / cg" |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
627 |
! |
4442a4d4121f
dont want return in patternField to be accept of box
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
628 |
|
197 | 629 |
selectionChanged |
630 |
|entry| |
|
631 |
||
632 |
entry := selectionList selectionValue. |
|
1333 | 633 |
(selectionList directory asFilename construct:entry) type == #directory ifFalse:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
634 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
635 |
enterField contents:(selectionList directory pathName). |
682 | 636 |
selectionList setSelection:nil. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
637 |
^ self |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
638 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
639 |
]. |
197 | 640 |
enterField contents:entry |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
641 |
|
1333 | 642 |
"Modified: 21.9.1997 / 12:07:55 / cg" |
0 | 643 |
! ! |
197 | 644 |
|
849 | 645 |
!FileSelectionBox class methodsFor:'documentation'! |
240 | 646 |
|
647 |
version |
|
1670
8d24855a9f0b
oops - handle absolute filenames correctly under vms and msdos
Claus Gittinger <cg@exept.de>
parents:
1643
diff
changeset
|
648 |
^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.52 1998-09-09 20:10:13 cg Exp $' |
240 | 649 |
! ! |