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