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
|
12
|
14 |
instanceVariableNames:'patternField'
|
0
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
38
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
FileSelectionBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
120
|
24 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.15 1995-05-03 16:29:13 claus Exp $
|
7
|
25 |
'!
|
|
26 |
|
|
27 |
!FileSelectionBox class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
120
|
45 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.15 1995-05-03 16:29:13 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
7
|
49 |
documentation
|
|
50 |
"
|
38
|
51 |
this class implements file selection boxes. Instances show a list of
|
|
52 |
files, and perform an action block with the selected pathname as
|
|
53 |
argument when ok is clicked.
|
|
54 |
|
|
55 |
There is an optional PatternField, which shows itself when a pattern
|
|
56 |
is defined (i.e. if there is no pattern, it is hidden).
|
|
57 |
If there is a pattern, only files matching the pattern will be shown in
|
|
58 |
the list (and directories).
|
|
59 |
|
|
60 |
In addition, there is an optional matchBlock (actually this is defined
|
|
61 |
in the FileSelectionList). Only filenames for which this matchblock
|
|
62 |
returns true will be presented.
|
62
|
63 |
"
|
|
64 |
!
|
38
|
65 |
|
62
|
66 |
examples
|
|
67 |
"
|
38
|
68 |
Example1:
|
|
69 |
|
59
|
70 |
FileSelectionBox open
|
38
|
71 |
|
|
72 |
Example2:
|
|
73 |
|
59
|
74 |
FileSelectionBox new open
|
12
|
75 |
|
38
|
76 |
Example3:
|
|
77 |
|
59
|
78 |
|box|
|
|
79 |
box := FileSelectionBox new.
|
|
80 |
box title:'Which file ?'.
|
|
81 |
box open
|
38
|
82 |
|
|
83 |
Example4:
|
|
84 |
|
59
|
85 |
|box|
|
|
86 |
box := FileSelectionBox new.
|
|
87 |
box title:'Which file ?'.
|
|
88 |
box pattern:'*.doc'.
|
|
89 |
box open
|
38
|
90 |
|
|
91 |
Example5:
|
|
92 |
|
59
|
93 |
|box|
|
|
94 |
box := FileSelectionBox new.
|
|
95 |
box title:'Which file ?'.
|
|
96 |
box pattern:'*'.
|
|
97 |
box matchBlock:[:name | name first isLowercase].
|
|
98 |
box open
|
44
|
99 |
|
120
|
100 |
Example6:
|
44
|
101 |
|
59
|
102 |
|box|
|
|
103 |
box := FileSelectionBox new.
|
|
104 |
box title:'Which directory ?'.
|
|
105 |
box pattern:'l*'.
|
|
106 |
box matchBlock:[:name | OperatingSystem isDirectory:name].
|
|
107 |
box open
|
7
|
108 |
"
|
|
109 |
! !
|
0
|
110 |
|
12
|
111 |
!FileSelectionBox class methodsFor:'defaults'!
|
|
112 |
|
77
|
113 |
requestFilename
|
|
114 |
^ self requestFilename:'filename:'
|
|
115 |
|
|
116 |
"
|
|
117 |
FileSelectionBox requestFilename
|
|
118 |
"
|
|
119 |
!
|
|
120 |
|
|
121 |
requestFilename:title
|
|
122 |
|fileBox|
|
|
123 |
|
|
124 |
fileBox := self
|
|
125 |
title:title
|
|
126 |
okText:'ok'
|
|
127 |
abortText:'cancel'
|
|
128 |
action:[:fileName | ^ fileName].
|
|
129 |
|
|
130 |
fileBox showAtPointer.
|
|
131 |
^ nil
|
|
132 |
|
|
133 |
"
|
|
134 |
FileSelectionBox requestFilename:'which file ?'
|
|
135 |
"
|
|
136 |
! !
|
|
137 |
|
|
138 |
!FileSelectionBox class methodsFor:'requests'!
|
|
139 |
|
12
|
140 |
listViewType
|
|
141 |
"return the type of listView - using a FileSelectionList here"
|
|
142 |
|
|
143 |
^ FileSelectionList
|
|
144 |
! !
|
|
145 |
|
0
|
146 |
!FileSelectionBox methodsFor:'initialization'!
|
|
147 |
|
|
148 |
initialize
|
101
|
149 |
|corner|
|
|
150 |
|
0
|
151 |
super initialize.
|
|
152 |
|
77
|
153 |
label := 'File dialog'.
|
|
154 |
|
3
|
155 |
labelField extent:(0.7 @ labelField height).
|
|
156 |
labelField label:(resources string:'select a file:').
|
|
157 |
labelField adjust:#left.
|
|
158 |
|
38
|
159 |
patternField := EditField in:self.
|
77
|
160 |
self is3D ifTrue:[
|
101
|
161 |
corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
|
77
|
162 |
] ifFalse:[
|
101
|
163 |
corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
|
77
|
164 |
].
|
101
|
165 |
patternField origin:(0.7 @ labelField origin y) corner:corner.
|
110
|
166 |
patternField rightInset:ViewSpacing.
|
3
|
167 |
patternField initialText:'*'.
|
21
|
168 |
patternField leaveAction:[:reason |
|
59
|
169 |
selectionList pattern:patternField contents.
|
|
170 |
self updateList
|
21
|
171 |
].
|
38
|
172 |
patternField hidden:true. "delay showing, until a pattern is defined"
|
3
|
173 |
|
12
|
174 |
selectionList action:[:line |
|
59
|
175 |
|entry|
|
0
|
176 |
|
59
|
177 |
entry := selectionList selectionValue.
|
|
178 |
enterField contents:entry
|
12
|
179 |
].
|
38
|
180 |
|
12
|
181 |
selectionList doubleClickAction:[:line |
|
59
|
182 |
|entry|
|
12
|
183 |
|
59
|
184 |
entry := selectionList selectionValue.
|
|
185 |
entry notNil ifTrue:[
|
|
186 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[
|
|
187 |
enterField contents:entry.
|
|
188 |
self okPressed
|
|
189 |
]
|
|
190 |
]
|
12
|
191 |
].
|
41
|
192 |
enterField addDependent:self.
|
0
|
193 |
|
|
194 |
"FileSelectionBox new show"
|
38
|
195 |
!
|
|
196 |
|
|
197 |
createEnterField
|
|
198 |
"
|
|
199 |
if the (optional) class FilenameEditField is present, use
|
|
200 |
it, since it provides filename completion. Otherwise, we have
|
|
201 |
to live with the dump field ...
|
|
202 |
"
|
|
203 |
FilenameEditField notNil ifTrue:[
|
59
|
204 |
enterField := FilenameEditField in:self.
|
38
|
205 |
] ifFalse:[
|
59
|
206 |
super createEnterField
|
38
|
207 |
]
|
77
|
208 |
!
|
|
209 |
|
|
210 |
focusSequence
|
|
211 |
patternField shown ifTrue:[
|
|
212 |
^ Array
|
|
213 |
with:patternField
|
|
214 |
with:enterField
|
|
215 |
with:selectionList
|
|
216 |
with:abortButton
|
|
217 |
with:okButton
|
|
218 |
].
|
101
|
219 |
^ super focusSequence
|
38
|
220 |
! !
|
|
221 |
|
41
|
222 |
!FileSelectionBox methodsFor:'dependencies'!
|
|
223 |
|
77
|
224 |
update:something with:argument from:changedObject
|
41
|
225 |
|commonName index|
|
|
226 |
|
|
227 |
something == #directory ifTrue:[
|
59
|
228 |
"
|
|
229 |
sent by fileNameEnterField, if a filename
|
|
230 |
completion was not possible due to multiple
|
|
231 |
matches.
|
|
232 |
"
|
|
233 |
selectionList directory:argument.
|
|
234 |
commonName := enterField contents asFilename baseName.
|
|
235 |
commonName size > 0 ifTrue:[
|
|
236 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName].
|
|
237 |
index ~~ 0 ifTrue:[
|
|
238 |
selectionList makeLineVisible:index
|
|
239 |
]
|
|
240 |
]
|
41
|
241 |
]
|
|
242 |
! !
|
|
243 |
|
38
|
244 |
!FileSelectionBox methodsFor:'user actions'!
|
|
245 |
|
|
246 |
okPressed
|
|
247 |
"called for both on ok-press and on return-key"
|
|
248 |
|
|
249 |
|dir string fname|
|
|
250 |
|
|
251 |
string := enterField contents.
|
|
252 |
string notNil ifTrue:[
|
59
|
253 |
string := string withoutSeparators.
|
|
254 |
string asFilename isAbsolute ifTrue:[
|
|
255 |
fname := string asFilename
|
|
256 |
] ifFalse:[
|
|
257 |
dir := selectionList directory pathName asFilename.
|
|
258 |
fname := dir construct:string
|
|
259 |
].
|
|
260 |
fname isDirectory ifTrue:[
|
|
261 |
selectionList directory:fname asString.
|
|
262 |
self updateList.
|
|
263 |
^ self
|
|
264 |
]
|
38
|
265 |
].
|
|
266 |
super okPressed
|
0
|
267 |
! !
|
|
268 |
|
21
|
269 |
!FileSelectionBox methodsFor:'private'!
|
|
270 |
|
|
271 |
updateList
|
|
272 |
selectionList updateList
|
|
273 |
! !
|
|
274 |
|
77
|
275 |
!FileSelectionBox methodsFor:'queries'!
|
|
276 |
|
|
277 |
preferedExtent
|
|
278 |
"return my prefered extent - thats the minimum size
|
|
279 |
to make everything visible"
|
|
280 |
|
|
281 |
|wWanted hWanted|
|
|
282 |
|
|
283 |
wWanted := ViewSpacing +
|
|
284 |
labelField preferedExtent x +
|
|
285 |
(ViewSpacing * 2) +
|
|
286 |
patternField preferedExtent x +
|
|
287 |
ViewSpacing.
|
|
288 |
(wWanted < width) ifTrue:[
|
|
289 |
wWanted := width
|
|
290 |
].
|
|
291 |
hWanted := ViewSpacing + labelField height +
|
|
292 |
ViewSpacing + enterField height +
|
|
293 |
ViewSpacing + selectionList height +
|
|
294 |
ViewSpacing + buttonPanel preferedExtent y +
|
|
295 |
ViewSpacing.
|
|
296 |
|
|
297 |
(hWanted < height) ifTrue:[
|
|
298 |
hWanted := height
|
|
299 |
].
|
|
300 |
^ (wWanted @ hWanted)
|
|
301 |
! !
|
|
302 |
|
0
|
303 |
!FileSelectionBox methodsFor:'accessing'!
|
|
304 |
|
38
|
305 |
openOn:aPath
|
|
306 |
"open the box showing files in aPath.
|
|
307 |
This is only a shortcut message - no new functionality."
|
|
308 |
|
|
309 |
self directory:aPath.
|
|
310 |
self showAtPointer
|
|
311 |
!
|
|
312 |
|
77
|
313 |
directory:directoryName
|
38
|
314 |
"change the directory shown in the list."
|
0
|
315 |
|
77
|
316 |
selectionList directory:directoryName
|
3
|
317 |
!
|
|
318 |
|
|
319 |
pattern:aPattern
|
38
|
320 |
"set the pattern - this also enables the PatternField
|
|
321 |
(if the pattern is non-nil) or hides it (if nil)."
|
7
|
322 |
|
3
|
323 |
patternField initialText:aPattern.
|
12
|
324 |
selectionList pattern:aPattern.
|
|
325 |
aPattern isNil ifTrue:[
|
59
|
326 |
patternField hidden:true.
|
|
327 |
realized ifTrue:[
|
|
328 |
patternField hide.
|
77
|
329 |
].
|
|
330 |
windowGroup notNil ifTrue:[
|
|
331 |
windowGroup focusSequence:(Array
|
|
332 |
with:enterField
|
|
333 |
with:selectionList
|
|
334 |
with:okButton
|
|
335 |
with:abortButton)
|
59
|
336 |
]
|
12
|
337 |
] ifFalse:[
|
59
|
338 |
patternField hidden:false.
|
|
339 |
realized ifTrue:[
|
|
340 |
patternField realize.
|
|
341 |
].
|
77
|
342 |
windowGroup notNil ifTrue:[
|
|
343 |
windowGroup focusSequence:(Array
|
|
344 |
with:patternField
|
|
345 |
with:enterField
|
|
346 |
with:selectionList
|
|
347 |
with:okButton
|
|
348 |
with:abortButton)
|
|
349 |
]
|
0
|
350 |
].
|
38
|
351 |
!
|
0
|
352 |
|
38
|
353 |
matchBlock:aBlock
|
|
354 |
"set the matchBlock (in the selectionList). Only files
|
|
355 |
for which the block returns true are shown.
|
110
|
356 |
The matching is actually done in the fileSelectionList."
|
0
|
357 |
|
110
|
358 |
selectionList matchBlock:aBlock
|
38
|
359 |
!
|
7
|
360 |
|
38
|
361 |
contents
|
|
362 |
"return the current entered value (i.e. the enterFields string).
|
|
363 |
redefined to return the full pathname."
|
|
364 |
|
|
365 |
|string sep|
|
|
366 |
|
|
367 |
string := super contents.
|
|
368 |
string isNil ifTrue:[
|
59
|
369 |
^ selectionList directory pathName
|
38
|
370 |
].
|
|
371 |
sep := Filename separator.
|
|
372 |
(string startsWith:sep) ifTrue:[
|
59
|
373 |
^ string
|
38
|
374 |
].
|
|
375 |
^ (selectionList directory pathName asFilename construct:string) asString
|
0
|
376 |
! !
|