author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 19:26:41 +0200 | |
changeset 585 | 8f395aba0173 |
parent 548 | c418699a90c0 |
child 593 | 86dd024ed773 |
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'). |
585 | 63 |
|
64 |
[author:] |
|
65 |
Claus Gittinger |
|
66 |
||
67 |
[see also:] |
|
68 |
DialogBox |
|
69 |
EnterBox2 YesNoBox |
|
70 |
ListSelectionBox FileSaveBox |
|
62 | 71 |
" |
72 |
! |
|
38 | 73 |
|
62 | 74 |
examples |
75 |
" |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
76 |
simple standard queries |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
77 |
|
238 | 78 |
very simple: |
351 | 79 |
|name| |
238 | 80 |
|
351 | 81 |
name := FileSelectionBox requestFilename. |
82 |
Transcript showCr:name |
|
38 | 83 |
|
238 | 84 |
|
85 |
simple: |
|
351 | 86 |
|name| |
238 | 87 |
|
351 | 88 |
name := FileSelectionBox requestFilename:'which file ?'. |
89 |
Transcript showCr:name |
|
38 | 90 |
|
238 | 91 |
|
92 |
with initial selection: |
|
351 | 93 |
|name| |
238 | 94 |
|
351 | 95 |
name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'. |
96 |
Transcript showCr:name |
|
38 | 97 |
|
238 | 98 |
|
12 | 99 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
100 |
more detailed setup |
238 | 101 |
|
102 |
setting title: |
|
38 | 103 |
|
351 | 104 |
|box| |
105 |
box := FileSelectionBox new. |
|
106 |
box title:'Which file ?'. |
|
107 |
box open. |
|
108 |
box accepted ifTrue:[ |
|
109 |
Transcript showCr:'you selected: ' , box |
|
110 |
] |
|
38 | 111 |
|
238 | 112 |
setting a matchpattern: |
38 | 113 |
|
351 | 114 |
|box| |
115 |
box := FileSelectionBox new. |
|
116 |
box title:'Which file ?'. |
|
117 |
box pattern:'*.rc'. |
|
118 |
box open |
|
119 |
||
120 |
setting multiple patterns: |
|
121 |
||
122 |
|box| |
|
123 |
box := FileSelectionBox new. |
|
124 |
box title:'Which file ?'. |
|
125 |
box pattern:'*.rc;*.st'. |
|
126 |
box open |
|
38 | 127 |
|
238 | 128 |
setting a matchblock: |
38 | 129 |
|
351 | 130 |
|box| |
131 |
box := FileSelectionBox new. |
|
132 |
box title:'Which file ?'. |
|
133 |
box directory:'/etc'. |
|
134 |
box pattern:'*'. |
|
135 |
box matchBlock:[:name | name asFilename baseName first between:$a and:$z]. |
|
136 |
box open |
|
44 | 137 |
|
238 | 138 |
both pattern and matchBlock: |
44 | 139 |
|
351 | 140 |
|box| |
141 |
box := FileSelectionBox new. |
|
142 |
box title:'Which directory ?'. |
|
143 |
box selectingDirectory:true. |
|
144 |
box pattern:'l*'. |
|
145 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
146 |
box action:[:fn | Transcript showCr:fn]. |
|
147 |
box open |
|
238 | 148 |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
149 |
dont show the parent 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 directory ?'. |
|
154 |
box listView ignoreParentDirectory: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: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
158 |
|
351 | 159 |
|box| |
160 |
box := FileSelectionBox new. |
|
161 |
box title:'Which file ?'. |
|
162 |
box listView ignoreDirectories:true. |
|
163 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
164 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
165 |
dont show any directory or hidden file: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
166 |
(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
|
167 |
|
351 | 168 |
|box| |
169 |
box := FileSelectionBox new. |
|
170 |
box title:'Which file ?'. |
|
171 |
box listView ignoreDirectories:true. |
|
172 |
box matchBlock:[:name | (name asFilename baseName startsWith:'.') not]. |
|
173 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
174 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
175 |
dont allow direct filename entry: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
176 |
(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
|
177 |
|
351 | 178 |
|box| |
179 |
box := FileSelectionBox new. |
|
180 |
box title:'Which one ?'. |
|
181 |
box enterField beInvisible. |
|
182 |
box open. |
|
183 |
box accepted ifTrue:[ |
|
184 |
Transcript showCr:'path is ' , box pathName |
|
185 |
]. |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
186 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
187 |
combined with above directory ignoring, |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
188 |
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
|
189 |
|
351 | 190 |
|box| |
191 |
box := FileSelectionBox new. |
|
192 |
box title:'Which file ?'. |
|
193 |
box enterField beInvisible. |
|
194 |
box listView ignoreDirectories:true. |
|
195 |
box open. |
|
196 |
box accepted ifTrue:[ |
|
197 |
Transcript showCr:'path is ' , box pathName |
|
198 |
]. |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
199 |
|
238 | 200 |
finally, an action: |
201 |
||
351 | 202 |
|box| |
203 |
box := FileSelectionBox new. |
|
204 |
box title:'Which directory ?'. |
|
205 |
box pattern:'l*'. |
|
206 |
box matchBlock:[:name | OperatingSystem isDirectory:name]. |
|
207 |
box action:[:name | Transcript showCr:name]. |
|
208 |
box open |
|
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
209 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
210 |
concrete examples: |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
211 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
212 |
only show files beginning with lowercase characters |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
213 |
and ending in '.c': |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
214 |
|
351 | 215 |
|box| |
216 |
box := FileSelectionBox new. |
|
217 |
box title:'Which directory ?'. |
|
218 |
box matchBlock:[:name | |
|
219 |
box pathName asFilename isDirectory |
|
220 |
or:[name first isLowercase |
|
221 |
and:[name endsWith:'.c']] |
|
222 |
]. |
|
223 |
box open. |
|
224 |
box accepted ifTrue:[ |
|
225 |
Transcript showCr:'full path: ' , box pathName. |
|
226 |
Transcript showCr:'files name: ' , box fileName. |
|
227 |
Transcript showCr:'directory : ' , box directory. |
|
228 |
] |
|
7 | 229 |
" |
230 |
! ! |
|
0 | 231 |
|
12 | 232 |
!FileSelectionBox class methodsFor:'defaults'! |
233 |
||
234 |
listViewType |
|
235 |
"return the type of listView - using a FileSelectionList here" |
|
236 |
||
237 |
^ FileSelectionList |
|
238 |
! ! |
|
239 |
||
197 | 240 |
!FileSelectionBox methodsFor:'accessing'! |
3 | 241 |
|
197 | 242 |
contents |
243 |
"return the current entered value (i.e. the enterFields string). |
|
244 |
redefined to return the full pathname." |
|
245 |
||
246 |
|string sep| |
|
3 | 247 |
|
197 | 248 |
string := super contents. |
249 |
string isNil ifTrue:[ |
|
250 |
^ selectionList directory pathName |
|
121 | 251 |
]. |
197 | 252 |
sep := Filename separator. |
253 |
(string startsWith:sep) ifTrue:[ |
|
254 |
^ string |
|
77 | 255 |
]. |
197 | 256 |
^ (selectionList directory pathName asFilename construct:string) asString |
132 | 257 |
! |
258 |
||
296
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
259 |
directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
260 |
"return the directory which is currently shown" |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
261 |
|
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
262 |
^ selectionList directory |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
263 |
! |
e1b9431b3aef
more examples in the documentation category
Claus Gittinger <cg@exept.de>
parents:
240
diff
changeset
|
264 |
|
197 | 265 |
directory:directoryName |
266 |
"change the directory shown in the list." |
|
41 | 267 |
|
197 | 268 |
selectionList directory:directoryName |
132 | 269 |
! |
270 |
||
351 | 271 |
fileName |
272 |
"if some filename has been entered, return it (without the directory path) |
|
273 |
otherwise, return nil" |
|
274 |
||
275 |
|string| |
|
276 |
||
277 |
string := super contents. |
|
278 |
string isNil ifTrue:[^ nil]. |
|
279 |
^ self pathName |
|
280 |
! |
|
281 |
||
197 | 282 |
matchBlock:aBlock |
283 |
"set the matchBlock (in the selectionList). Only files |
|
284 |
for which the block returns true are shown. |
|
285 |
The matching is actually done in the fileSelectionList." |
|
77 | 286 |
|
197 | 287 |
selectionList matchBlock:aBlock |
288 |
! |
|
0 | 289 |
|
38 | 290 |
openOn:aPath |
291 |
"open the box showing files in aPath. |
|
292 |
This is only a shortcut message - no new functionality." |
|
293 |
||
294 |
self directory:aPath. |
|
295 |
self showAtPointer |
|
296 |
! |
|
297 |
||
351 | 298 |
pathName |
299 |
"same as contents - return the full pathname of the selected file, |
|
300 |
or the pathname of the directory if nothing has been entered" |
|
301 |
||
302 |
^ self contents |
|
303 |
! |
|
304 |
||
3 | 305 |
pattern:aPattern |
38 | 306 |
"set the pattern - this also enables the PatternField |
307 |
(if the pattern is non-nil) or hides it (if nil)." |
|
7 | 308 |
|
130 | 309 |
|hidePatternField focusSequence| |
310 |
||
3 | 311 |
patternField initialText:aPattern. |
12 | 312 |
selectionList pattern:aPattern. |
313 |
aPattern isNil ifTrue:[ |
|
130 | 314 |
hidePatternField := true. |
59 | 315 |
realized ifTrue:[ |
316 |
patternField hide. |
|
77 | 317 |
]. |
130 | 318 |
focusSequence := (Array |
319 |
with:enterField |
|
320 |
with:selectionList |
|
321 |
with:okButton |
|
322 |
with:abortButton) |
|
12 | 323 |
] ifFalse:[ |
130 | 324 |
hidePatternField := false. |
59 | 325 |
realized ifTrue:[ |
326 |
patternField realize. |
|
327 |
]. |
|
130 | 328 |
focusSequence := (Array |
329 |
with:patternField |
|
330 |
with:enterField |
|
331 |
with:selectionList |
|
332 |
with:okButton |
|
333 |
with:abortButton) |
|
334 |
]. |
|
335 |
||
336 |
patternField hiddenOnRealize:hidePatternField. |
|
337 |
windowGroup notNil ifTrue:[ |
|
338 |
windowGroup focusSequence:focusSequence |
|
0 | 339 |
]. |
351 | 340 |
! |
341 |
||
342 |
selectingDirectory:aBoolean |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
343 |
selectingDirectory := aBoolean. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
344 |
aBoolean ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
345 |
selectionList directoryChangeAction:[:entry | self directoryChanged]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
346 |
selectionList directorySelectAction:[:entry | self directorySelected]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
347 |
selectionList ignoreFiles:true. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
348 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
349 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
350 |
"Modified: 18.4.1996 / 18:50:10 / cg" |
197 | 351 |
! ! |
352 |
||
353 |
!FileSelectionBox methodsFor:'change & update'! |
|
354 |
||
355 |
update:something with:argument from:changedObject |
|
356 |
|commonName index s| |
|
357 |
||
358 |
something == #directory ifTrue:[ |
|
359 |
" |
|
360 |
sent by fileNameEnterField, if a filename |
|
361 |
completion was not possible due to multiple |
|
362 |
matches. |
|
363 |
" |
|
364 |
selectionList directory:argument. |
|
365 |
s := enterField contents. |
|
366 |
s notNil ifTrue:[ |
|
367 |
commonName := s asFilename baseName. |
|
368 |
commonName size > 0 ifTrue:[ |
|
369 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName]. |
|
370 |
index ~~ 0 ifTrue:[ |
|
371 |
selectionList makeLineVisible:index |
|
372 |
] |
|
373 |
] |
|
374 |
] |
|
375 |
] |
|
376 |
! ! |
|
377 |
||
378 |
!FileSelectionBox methodsFor:'initialization'! |
|
379 |
||
380 |
createEnterField |
|
381 |
"if the (optional) class FilenameEditField is present, use |
|
382 |
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
|
383 |
to live with the dumb (default) field ... |
197 | 384 |
" |
385 |
FilenameEditField notNil ifTrue:[ |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
386 |
^ FilenameEditField new. |
197 | 387 |
]. |
388 |
^ super createEnterField |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
389 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
390 |
"Modified: 18.4.1996 / 20:02:24 / cg" |
38 | 391 |
! |
0 | 392 |
|
197 | 393 |
focusSequence |
394 |
patternField shown ifTrue:[ |
|
395 |
^ Array |
|
396 |
with:patternField |
|
397 |
with:enterField |
|
398 |
with:selectionList |
|
399 |
with:abortButton |
|
400 |
with:okButton |
|
401 |
]. |
|
402 |
^ super focusSequence |
|
403 |
! |
|
404 |
||
405 |
initialize |
|
406 |
|corner| |
|
407 |
||
408 |
super initialize. |
|
351 | 409 |
selectingDirectory := false. |
197 | 410 |
|
411 |
label := resources string:'File dialog'. |
|
0 | 412 |
|
197 | 413 |
labelField extent:(0.7 @ labelField height). |
414 |
labelField label:(resources string:'select a file:'). |
|
415 |
labelField adjust:#left. |
|
416 |
||
417 |
patternField := EditField in:self. |
|
418 |
self is3D ifTrue:[ |
|
351 | 419 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
197 | 420 |
] ifFalse:[ |
351 | 421 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
197 | 422 |
]. |
423 |
patternField origin:(0.7 @ labelField origin y) corner:corner. |
|
424 |
patternField rightInset:ViewSpacing. |
|
425 |
patternField initialText:'*'. |
|
426 |
patternField leaveAction:[:reason | |
|
351 | 427 |
selectionList pattern:patternField contents. |
428 |
self updateList |
|
197 | 429 |
]. |
430 |
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
|
431 |
||
432 |
enterField addDependent:self. |
|
433 |
||
434 |
" |
|
435 |
FileSelectionBox open |
|
436 |
FileSelectionBox new show |
|
437 |
" |
|
38 | 438 |
! |
7 | 439 |
|
197 | 440 |
realize |
441 |
"if some default is present in the enterField, |
|
442 |
scroll to make this one visible" |
|
443 |
||
444 |
|contents| |
|
445 |
||
446 |
super realize. |
|
447 |
(contents := enterField contents) notNil ifTrue:[ |
|
448 |
contents notEmpty ifTrue:[ |
|
449 |
selectionList makeVisible:contents |
|
450 |
] |
|
451 |
] |
|
452 |
! ! |
|
453 |
||
454 |
!FileSelectionBox methodsFor:'private'! |
|
455 |
||
456 |
updateList |
|
457 |
selectionList updateList |
|
458 |
! ! |
|
38 | 459 |
|
197 | 460 |
!FileSelectionBox methodsFor:'queries'! |
461 |
||
462 |
preferredExtent |
|
463 |
"return my preferred extent - thats the minimum size |
|
464 |
to make everything visible" |
|
465 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
466 |
|wWanted hWanted mm| |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
467 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
468 |
mm := ViewSpacing. |
197 | 469 |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
470 |
wWanted := mm + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
471 |
labelField preferredExtent x + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
472 |
(mm * 2) + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
473 |
patternField preferredExtent x + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
474 |
mm. |
197 | 475 |
(wWanted < width) ifTrue:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
476 |
wWanted := width |
197 | 477 |
]. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
478 |
hWanted := mm + labelField height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
479 |
mm + enterField height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
480 |
mm + selectionList height + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
481 |
mm + buttonPanel preferredExtent y + |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
482 |
mm. |
38 | 483 |
|
197 | 484 |
(hWanted < height) ifTrue:[ |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
485 |
hWanted := height |
197 | 486 |
]. |
487 |
^ (wWanted @ hWanted) |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
488 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
489 |
"Modified: 19.4.1996 / 14:34:47 / cg" |
197 | 490 |
! ! |
491 |
||
492 |
!FileSelectionBox methodsFor:'user actions'! |
|
493 |
||
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
494 |
directoryChanged |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
495 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
496 |
selectionList changeDirectory. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
497 |
enterField contents:(selectionList directory pathName). |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
498 |
selectionList selection:nil. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
499 |
]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
500 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
501 |
"Created: 18.4.1996 / 18:38:21 / cg" |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
502 |
"Modified: 18.4.1996 / 18:47:34 / cg" |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
503 |
! |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
504 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
505 |
directorySelected |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
506 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
507 |
enterField contents:(selectionList directory pathName |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
508 |
, '/' , selectionList selectionValue). |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
509 |
]. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
510 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
511 |
"Modified: 18.4.1996 / 18:40:41 / cg" |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
512 |
"Created: 18.4.1996 / 18:46:15 / cg" |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
513 |
! |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
514 |
|
197 | 515 |
doubleClick |
516 |
|entry| |
|
517 |
||
518 |
entry := selectionList selectionValue. |
|
519 |
entry notNil ifTrue:[ |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
520 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
521 |
selectingDirectory ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
522 |
enterField contents:entry. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
523 |
self okPressed |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
524 |
] |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
525 |
] |
38 | 526 |
]. |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
527 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
528 |
"Modified: 18.4.1996 / 18:33:14 / cg" |
197 | 529 |
! |
530 |
||
531 |
okPressed |
|
532 |
"called for both on ok-press and on return-key" |
|
533 |
||
534 |
|dir string fname| |
|
535 |
||
536 |
string := enterField contents. |
|
351 | 537 |
(string notNil and:[string notEmpty]) ifTrue:[ |
538 |
string := string withoutSeparators. |
|
539 |
string asFilename isAbsolute ifTrue:[ |
|
540 |
fname := string asFilename |
|
541 |
] ifFalse:[ |
|
542 |
dir := selectionList directory pathName asFilename. |
|
543 |
fname := dir construct:string |
|
544 |
]. |
|
545 |
fname isDirectory ifTrue:[ |
|
546 |
selectingDirectory ifFalse:[ |
|
547 |
selectionList directory:fname asString. |
|
548 |
self updateList. |
|
549 |
^ self |
|
550 |
] |
|
551 |
] |
|
552 |
] ifFalse:[ |
|
553 |
selectingDirectory ifTrue:[ |
|
554 |
enterField contents:(selectionList directory pathName). |
|
555 |
]. |
|
38 | 556 |
]. |
351 | 557 |
|
197 | 558 |
super okPressed |
351 | 559 |
|
197 | 560 |
! |
561 |
||
562 |
selectionChanged |
|
563 |
|entry| |
|
564 |
||
565 |
entry := selectionList selectionValue. |
|
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
566 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
567 |
selectingDirectory ifTrue:[ |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
568 |
enterField contents:(selectionList directory pathName). |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
569 |
selectionList selection:nil. |
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
570 |
^ self |
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 |
enterField contents:entry |
548
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
574 |
|
c418699a90c0
moved all request methods (class protocol) to DialogBox
Claus Gittinger <cg@exept.de>
parents:
438
diff
changeset
|
575 |
"Modified: 18.4.1996 / 18:34:57 / cg" |
0 | 576 |
! ! |
197 | 577 |
|
240 | 578 |
!FileSelectionBox class methodsFor:'documentation'! |
579 |
||
580 |
version |
|
585 | 581 |
^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelBox.st,v 1.31 1996-04-25 17:19:06 cg Exp $' |
240 | 582 |
! ! |