0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
41
|
24 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.8 1994-08-07 20:49:39 claus Exp $
|
7
|
25 |
'!
|
|
26 |
|
|
27 |
!FileSelectionBox class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
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 |
"
|
41
|
45 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.8 1994-08-07 20:49:39 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.
|
|
63 |
|
|
64 |
Example1:
|
|
65 |
|
|
66 |
FileSelectionBox open
|
|
67 |
|
|
68 |
Example2:
|
|
69 |
|
|
70 |
FileSelectionBox new open
|
12
|
71 |
|
38
|
72 |
Example3:
|
|
73 |
|
|
74 |
|box|
|
|
75 |
box := FileSelectionBox new.
|
|
76 |
box title:'Which file ?'.
|
|
77 |
box open
|
|
78 |
|
|
79 |
Example4:
|
|
80 |
|
|
81 |
|box|
|
|
82 |
box := FileSelectionBox new.
|
|
83 |
box title:'Which file ?'.
|
|
84 |
box pattern:'*.doc'.
|
|
85 |
box open
|
|
86 |
|
|
87 |
Example5:
|
|
88 |
|
|
89 |
|box|
|
|
90 |
box := FileSelectionBox new.
|
|
91 |
box title:'Which file ?'.
|
|
92 |
box pattern:'*'.
|
|
93 |
box matchBlock:[:name | name first isLowercase].
|
|
94 |
box open
|
7
|
95 |
"
|
|
96 |
! !
|
0
|
97 |
|
12
|
98 |
!FileSelectionBox class methodsFor:'defaults'!
|
|
99 |
|
|
100 |
listViewType
|
|
101 |
"return the type of listView - using a FileSelectionList here"
|
|
102 |
|
|
103 |
^ FileSelectionList
|
|
104 |
! !
|
|
105 |
|
0
|
106 |
!FileSelectionBox methodsFor:'initialization'!
|
|
107 |
|
|
108 |
initialize
|
|
109 |
super initialize.
|
|
110 |
|
3
|
111 |
labelField extent:(0.7 @ labelField height).
|
|
112 |
labelField label:(resources string:'select a file:').
|
|
113 |
labelField adjust:#left.
|
|
114 |
|
38
|
115 |
patternField := EditField in:self.
|
|
116 |
patternField
|
|
117 |
origin:(0.7 @ labelField origin y)
|
|
118 |
corner:(1.0 @ (labelField origin y+patternField heightIncludingBorder)).
|
3
|
119 |
patternField initialText:'*'.
|
21
|
120 |
patternField leaveAction:[:reason |
|
|
121 |
selectionList pattern:patternField contents.
|
|
122 |
self updateList
|
|
123 |
].
|
38
|
124 |
patternField hidden:true. "delay showing, until a pattern is defined"
|
3
|
125 |
|
12
|
126 |
selectionList action:[:line |
|
0
|
127 |
|entry|
|
|
128 |
|
|
129 |
entry := selectionList selectionValue.
|
12
|
130 |
enterField contents:entry
|
|
131 |
].
|
38
|
132 |
|
12
|
133 |
selectionList doubleClickAction:[:line |
|
|
134 |
|entry|
|
|
135 |
|
|
136 |
entry := selectionList selectionValue.
|
38
|
137 |
entry notNil ifTrue:[
|
|
138 |
((selectionList directory typeOf:entry) == #directory) ifFalse:[
|
|
139 |
enterField contents:entry.
|
|
140 |
self okPressed
|
|
141 |
]
|
|
142 |
]
|
12
|
143 |
].
|
41
|
144 |
enterField addDependent:self.
|
0
|
145 |
|
|
146 |
"FileSelectionBox new show"
|
38
|
147 |
!
|
|
148 |
|
|
149 |
createEnterField
|
|
150 |
"
|
|
151 |
if the (optional) class FilenameEditField is present, use
|
|
152 |
it, since it provides filename completion. Otherwise, we have
|
|
153 |
to live with the dump field ...
|
|
154 |
"
|
|
155 |
FilenameEditField notNil ifTrue:[
|
|
156 |
enterField := FilenameEditField in:self.
|
|
157 |
] ifFalse:[
|
|
158 |
super createEnterField
|
|
159 |
]
|
|
160 |
! !
|
|
161 |
|
41
|
162 |
!FileSelectionBox methodsFor:'dependencies'!
|
|
163 |
|
|
164 |
update:something with:argument
|
|
165 |
|commonName index|
|
|
166 |
|
|
167 |
something == #directory ifTrue:[
|
|
168 |
"
|
|
169 |
sent by fileNameEnterField, if a filename
|
|
170 |
completion was not possible due to multiple
|
|
171 |
matches.
|
|
172 |
"
|
|
173 |
selectionList directory:argument.
|
|
174 |
commonName := enterField contents asFilename baseName.
|
|
175 |
commonName size > 0 ifTrue:[
|
|
176 |
index := selectionList list findFirst:[:entry | entry startsWith:commonName].
|
|
177 |
index ~~ 0 ifTrue:[
|
|
178 |
selectionList makeLineVisible:index
|
|
179 |
]
|
|
180 |
]
|
|
181 |
]
|
|
182 |
! !
|
|
183 |
|
38
|
184 |
!FileSelectionBox methodsFor:'user actions'!
|
|
185 |
|
|
186 |
okPressed
|
|
187 |
"called for both on ok-press and on return-key"
|
|
188 |
|
|
189 |
|dir string fname|
|
|
190 |
|
|
191 |
string := enterField contents.
|
|
192 |
string notNil ifTrue:[
|
|
193 |
string := string withoutSeparators.
|
|
194 |
string asFilename isAbsolute ifTrue:[
|
|
195 |
fname := string asFilename
|
|
196 |
] ifFalse:[
|
|
197 |
dir := selectionList directory pathName asFilename.
|
|
198 |
fname := dir construct:string
|
|
199 |
].
|
|
200 |
fname isDirectory ifTrue:[
|
|
201 |
selectionList directory:fname asString.
|
|
202 |
self updateList.
|
|
203 |
^ self
|
|
204 |
]
|
|
205 |
].
|
|
206 |
super okPressed
|
0
|
207 |
! !
|
|
208 |
|
21
|
209 |
!FileSelectionBox methodsFor:'private'!
|
|
210 |
|
|
211 |
updateList
|
|
212 |
selectionList updateList
|
|
213 |
! !
|
|
214 |
|
0
|
215 |
!FileSelectionBox methodsFor:'accessing'!
|
|
216 |
|
38
|
217 |
openOn:aPath
|
|
218 |
"open the box showing files in aPath.
|
|
219 |
This is only a shortcut message - no new functionality."
|
|
220 |
|
|
221 |
self directory:aPath.
|
|
222 |
self showAtPointer
|
|
223 |
!
|
|
224 |
|
0
|
225 |
directory:nameOrDirectory
|
38
|
226 |
"change the directory shown in the list."
|
0
|
227 |
|
12
|
228 |
selectionList directory:nameOrDirectory
|
3
|
229 |
!
|
|
230 |
|
|
231 |
pattern:aPattern
|
38
|
232 |
"set the pattern - this also enables the PatternField
|
|
233 |
(if the pattern is non-nil) or hides it (if nil)."
|
7
|
234 |
|
3
|
235 |
patternField initialText:aPattern.
|
12
|
236 |
selectionList pattern:aPattern.
|
|
237 |
aPattern isNil ifTrue:[
|
|
238 |
patternField hidden:true.
|
|
239 |
realized ifTrue:[
|
|
240 |
patternField hide.
|
|
241 |
]
|
|
242 |
] ifFalse:[
|
|
243 |
patternField hidden:false.
|
|
244 |
realized ifTrue:[
|
|
245 |
patternField realize.
|
|
246 |
].
|
0
|
247 |
].
|
38
|
248 |
!
|
0
|
249 |
|
38
|
250 |
matchBlock:aBlock
|
|
251 |
"set the matchBlock (in the selectionList). Only files
|
|
252 |
for which the block returns true are shown.
|
|
253 |
This matching is actually done in the fileSeelctionList."
|
0
|
254 |
|
38
|
255 |
selectionList matchBlock:aBlock
|
|
256 |
!
|
7
|
257 |
|
38
|
258 |
contents
|
|
259 |
"return the current entered value (i.e. the enterFields string).
|
|
260 |
redefined to return the full pathname."
|
|
261 |
|
|
262 |
|string sep|
|
|
263 |
|
|
264 |
string := super contents.
|
|
265 |
string isNil ifTrue:[
|
|
266 |
^ selectionList directory pathName
|
|
267 |
].
|
|
268 |
sep := Filename separator.
|
|
269 |
(string startsWith:sep) ifTrue:[
|
|
270 |
^ string
|
|
271 |
].
|
|
272 |
^ (selectionList directory pathName asFilename construct:string) asString
|
0
|
273 |
! !
|