author | tz |
Sat, 07 Feb 1998 21:28:21 +0100 | |
changeset 626 | 402a50b931d5 |
parent 622 | e5bc12d7af16 |
child 745 | d3995881fa13 |
permissions | -rw-r--r-- |
404 | 1 |
" |
502 | 2 |
COPYRIGHT (c) 1997 by eXept Software AG |
404 | 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 |
||
14 |
||
15 |
SelectionBrowser subclass:#FileSelectionBrowser |
|
16 |
instanceVariableNames:'selectedFileFilter directoryView listOfFileFilters directory' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
619 | 19 |
category:'Interface-Dialogs' |
404 | 20 |
! |
21 |
||
22 |
!FileSelectionBrowser class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
502 | 26 |
COPYRIGHT (c) 1997 by eXept Software AG |
404 | 27 |
All Rights Reserved |
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 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
documentation to be added. |
|
502 | 43 |
|
44 |
[author:] |
|
45 |
Thomas Zwick |
|
404 | 46 |
" |
47 |
! ! |
|
48 |
||
49 |
!FileSelectionBrowser class methodsFor:'instance creation'! |
|
50 |
||
51 |
request: aTitle fileFilters: fileFilters |
|
52 |
||
53 |
"self request: 'Select A File' fileFilters: #('.*')" |
|
54 |
||
55 |
^self new |
|
56 |
title: aTitle; |
|
57 |
listOfFileFilters: fileFilters; |
|
58 |
open |
|
59 |
! |
|
60 |
||
61 |
request: aTitle fileName: aFileName inDirectory: dir withFileFilters: fileFilters |
|
62 |
||
63 |
"self |
|
64 |
request: 'Select Your Profile File' |
|
65 |
fileName: '.profile' |
|
66 |
inDirectory: Filename homeDirectory |
|
67 |
withFileFilters: #('.*')" |
|
68 |
||
69 |
^self new |
|
70 |
title: aTitle; |
|
71 |
fileName: aFileName; |
|
72 |
directory: dir; |
|
73 |
listOfFileFilters: fileFilters; |
|
74 |
open |
|
75 |
! |
|
76 |
||
462 | 77 |
request: aTitle pathName: aPath fileFilters: fileFilters |
78 |
||
79 |
"self request: 'Select A File' pathName: '' fileFilters: #('.*')" |
|
80 |
||
81 |
^self new |
|
82 |
title: aTitle; |
|
83 |
fileName: aPath; |
|
84 |
listOfFileFilters: fileFilters; |
|
85 |
open |
|
86 |
! |
|
87 |
||
404 | 88 |
requestFileName |
89 |
||
90 |
"self requestFileName" |
|
91 |
||
92 |
^self new title: 'Select A File'; open |
|
93 |
||
94 |
! ! |
|
95 |
||
96 |
!FileSelectionBrowser class methodsFor:'accessing'! |
|
97 |
||
98 |
loadImageFileNameFilters |
|
99 |
^self saveImageFileNameFilters addAll: #('*.jpeg' '*.jpg'); yourself |
|
100 |
||
101 |
! |
|
102 |
||
103 |
projectFileNameFilters |
|
104 |
^Array withAll: #('*.st' '*.*o' '*.s' '*.c' 'Make*' '*.project') |
|
105 |
||
106 |
! |
|
107 |
||
108 |
saveImageFileNameFilters |
|
109 |
^Array withAll: #('*.xpm' '*.xbm' '*.gif' '*.tif' '*.tiff' '*.bmp') |
|
110 |
||
111 |
! ! |
|
112 |
||
113 |
!FileSelectionBrowser class methodsFor:'interface specs'! |
|
114 |
||
115 |
windowSpec |
|
116 |
"this window spec was automatically generated by the ST/X UIPainter" |
|
117 |
||
118 |
"do not manually edit this - the painter/builder may not be able to |
|
119 |
handle the specification if its corrupted." |
|
120 |
||
121 |
" |
|
122 |
UIPainter new openOnClass:FileSelectionBrowser andSelector:#windowSpec |
|
123 |
FileSelectionBrowser new openInterface:#windowSpec |
|
124 |
" |
|
125 |
"FileSelectionBrowser open" |
|
126 |
||
127 |
<resource: #canvas> |
|
128 |
||
129 |
^ |
|
130 |
||
131 |
#(#FullSpec |
|
132 |
#'window:' |
|
133 |
#(#WindowSpec |
|
134 |
#'name:' 'File Selection Browser' |
|
615
47f5ba2850d1
do not (!) choose an window extent larger than the smallest mon res
tz
parents:
607
diff
changeset
|
135 |
#'layout:' #(#LayoutFrame 248 0 226 0 847 0 575 0) |
404 | 136 |
#'label:' 'File Selection Browser' |
137 |
#'min:' #(#Point 10 10) |
|
138 |
#'max:' #(#Point 1152 900) |
|
615
47f5ba2850d1
do not (!) choose an window extent larger than the smallest mon res
tz
parents:
607
diff
changeset
|
139 |
#'bounds:' #(#Rectangle 248 226 848 576) |
404 | 140 |
#'usePreferredExtent:' false |
141 |
) |
|
142 |
#'component:' |
|
143 |
#(#SpecCollection |
|
144 |
#'collection:' |
|
145 |
#( |
|
146 |
#(#VariableHorizontalPanelSpec |
|
147 |
#'name:' 'panel' |
|
148 |
#'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -40 1.0) |
|
149 |
#'component:' |
|
150 |
#(#SpecCollection |
|
151 |
#'collection:' |
|
152 |
#( |
|
153 |
#(#ViewSpec |
|
154 |
#'name:' 'view1' |
|
155 |
#'component:' |
|
156 |
#(#SpecCollection |
|
157 |
#'collection:' |
|
158 |
#( |
|
159 |
#(#FileSelectionTreeSpec |
|
160 |
#'name:' 'directoryTreeView' |
|
605 | 161 |
#'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -25 1.0) |
404 | 162 |
#'model:' #selectionOfDirectory |
163 |
#'hasHorizontalScrollBar:' true |
|
164 |
#'hasVerticalScrollBar:' true |
|
165 |
#'miniScrollerHorizontal:' true |
|
592 | 166 |
#'showDirectoryIndicatorForRoot:' false |
404 | 167 |
#'showDirectoryIndicator:' true |
168 |
#'valueChangeSelector:' #readDirectory |
|
169 |
#'hierarchicalList:' #rootOfDirectory |
|
170 |
#'itemClass:' 'Directory' |
|
171 |
) |
|
592 | 172 |
#(#InputFieldSpec |
173 |
#'name:' 'directoryInputField' |
|
607 | 174 |
#'layout:' #(#LayoutFrame 2 0.0 -22 1 0 1.0 0 1) |
592 | 175 |
#'model:' #selectionOfDirectory |
176 |
#'immediateAccept:' false |
|
177 |
) |
|
404 | 178 |
) |
179 |
) |
|
180 |
) |
|
181 |
#(#ViewSpec |
|
182 |
#'name:' 'view2' |
|
183 |
#'component:' |
|
184 |
#(#SpecCollection |
|
185 |
#'collection:' |
|
186 |
#( |
|
187 |
#(#InputFieldSpec |
|
188 |
#'name:' 'EditField' |
|
607 | 189 |
#'layout:' #(#LayoutFrame 1 0.0 -22 1 -2 1.0 0 1) |
404 | 190 |
#'model:' #valueOfFileName |
191 |
#'acceptOnReturn:' false |
|
192 |
#'acceptOnTab:' false |
|
193 |
) |
|
194 |
#(#SubCanvasSpec |
|
195 |
#'name:' 'subCanvas1' |
|
605 | 196 |
#'layout:' #(#LayoutFrame 1 0.0 0 0.0 0 1.0 -25 1.0) |
404 | 197 |
#'clientHolder:' #directoryView |
198 |
) |
|
199 |
) |
|
200 |
) |
|
201 |
) |
|
202 |
) |
|
203 |
) |
|
204 |
#'handles:' #(#Any 0.5 1.0) |
|
205 |
) |
|
426
b8110a424326
commit buttons replaced by subSpec in ToolApplicationModel
tz
parents:
404
diff
changeset
|
206 |
#(#UISubSpecification |
b8110a424326
commit buttons replaced by subSpec in ToolApplicationModel
tz
parents:
404
diff
changeset
|
207 |
#'name:' 'SubSpecification' |
607 | 208 |
#'layout:' #(#LayoutFrame 2 0.0 -32 1 0 1.0 -8 1.0) |
426
b8110a424326
commit buttons replaced by subSpec in ToolApplicationModel
tz
parents:
404
diff
changeset
|
209 |
#'majorKey:' #ToolApplicationModel |
452 | 210 |
#'minorKey:' #windowSpecForCommitWithoutChannels |
404 | 211 |
) |
212 |
) |
|
213 |
) |
|
214 |
) |
|
215 |
! ! |
|
216 |
||
217 |
!FileSelectionBrowser methodsFor:'accessing'! |
|
218 |
||
219 |
directory: aDirectory |
|
220 |
||
595 | 221 |
directory := (aDirectory ? Filename homeDirectory) asFilename asAbsoluteFilename name |
404 | 222 |
! |
223 |
||
224 |
directoryView |
|
225 |
||
226 |
^directoryView ? (directoryView := DirectoryView new) |
|
227 |
! |
|
228 |
||
229 |
fileName: aFileName |
|
230 |
||
231 |
self valueOfFileName value: (aFileName ? '') asFilename baseName. |
|
232 |
directory := directory ? ((aFileName ? '') asFilename directoryName). |
|
233 |
||
234 |
! |
|
235 |
||
236 |
listOfFileFilters: anArray |
|
237 |
||
238 |
listOfFileFilters := anArray |
|
239 |
! ! |
|
240 |
||
241 |
!FileSelectionBrowser methodsFor:'accessing - views'! |
|
242 |
||
592 | 243 |
directoryInputField |
244 |
||
245 |
^builder componentAt: #directoryInputField |
|
246 |
||
247 |
! |
|
248 |
||
404 | 249 |
directoryTreeView |
250 |
||
251 |
^builder componentAt: #directoryTreeView |
|
252 |
||
253 |
! ! |
|
254 |
||
255 |
!FileSelectionBrowser methodsFor:'aspects'! |
|
256 |
||
257 |
rootOfDirectory |
|
258 |
||
259 |
|holder| |
|
260 |
(holder := builder bindingAt:#rootOfDirectory) isNil ifTrue:[ |
|
261 |
builder aspectAt:#rootOfDirectory put: (holder := Filename rootDirectory name asValue). |
|
262 |
]. |
|
263 |
^ holder |
|
264 |
||
265 |
! |
|
266 |
||
267 |
selectionOfDirectory |
|
268 |
||
269 |
|holder| |
|
270 |
(holder := builder bindingAt:#selectionOfDirectory) isNil ifTrue:[ |
|
271 |
builder aspectAt:#selectionOfDirectory put: (holder := ValueHolder new) |
|
272 |
]. |
|
273 |
^ holder |
|
274 |
||
275 |
! |
|
276 |
||
277 |
valueOfFileName |
|
278 |
||
279 |
|holder| |
|
280 |
(holder := builder bindingAt:#valueOfFileName) isNil ifTrue:[ |
|
281 |
builder aspectAt:#valueOfFileName put:(holder := ValueHolder new). |
|
282 |
]. |
|
283 |
^ holder |
|
284 |
! ! |
|
285 |
||
286 |
!FileSelectionBrowser methodsFor:'callbacks'! |
|
287 |
||
288 |
fileDoubleClicked: aFileName |
|
289 |
||
290 |
self valueOfFileName value: aFileName. |
|
291 |
accept value: true. |
|
292 |
self close |
|
293 |
! |
|
294 |
||
295 |
readDirectory |
|
296 |
||
592 | 297 |
self directoryTreeView selection notNil |
298 |
ifTrue: |
|
299 |
[ |
|
300 |
directoryView directory: self selectionOfDirectory value; readDirectory. |
|
301 |
directory isNil ifTrue: [self class lastSelection: self selectionOfDirectory value] |
|
302 |
] |
|
404 | 303 |
! ! |
304 |
||
305 |
!FileSelectionBrowser methodsFor:'startup / release'! |
|
306 |
||
307 |
closeCancel |
|
308 |
||
309 |
directoryView release. |
|
310 |
super closeCancel |
|
311 |
! |
|
312 |
||
313 |
closeRequest |
|
314 |
||
315 |
directoryView release. |
|
316 |
super closeRequest |
|
317 |
||
318 |
! |
|
319 |
||
320 |
open |
|
321 |
||
322 |
super open. |
|
515 | 323 |
accept value ifTrue:[ |
324 |
^ (self selectionOfDirectory value ? '') asFilename |
|
325 |
constructString:(self valueOfFileName value ? '') |
|
404 | 326 |
]. |
515 | 327 |
^ nil |
404 | 328 |
! |
329 |
||
330 |
postBuildWith:aBuilder |
|
331 |
||
332 |
directoryView listOfFileFilters: listOfFileFilters ? #('*'). |
|
462 | 333 |
directoryView fileSelectAction: [:aFileName |self valueOfFileName value: aFileName asFilename baseName]. |
334 |
directoryView fileDoubleClickAction: [:aFileName |self fileDoubleClicked: aFileName asFilename baseName]. |
|
404 | 335 |
directoryView fileFilterSelectAction: [:fileFilter| |
336 |
self valueOfFileName value: ( |
|
337 |
((self valueOfFileName value ? 'unknown') readStream upTo: $.), '.', |
|
594 | 338 |
(fileFilter copy reverse readStream upTo: $.) reverse)]. |
592 | 339 |
self directoryTreeView selectPathname: directory ? self class lastSelection ? '/'. |
340 |
||
341 |
self directoryInputField entryCompletionBlock: |
|
342 |
[:f| |
|
343 |
|completedDirectory| |
|
344 |
(completedDirectory := Filename |
|
345 |
filenameCompletionFor: self directoryInputField contents |
|
346 |
directory:directory |
|
347 |
directoriesOnly:true |
|
348 |
filesOnly:false |
|
349 |
ifMultiple: |
|
350 |
[:dir | |
|
351 |
self directoryTreeView selection notNil ifTrue: [ |
|
622 | 352 |
self directoryTreeView selectedNodeExpand: true] |
592 | 353 |
]) asFilename exists |
354 |
ifTrue: |
|
355 |
[ |
|
356 |
self directoryInputField contents: completedDirectory. |
|
357 |
self directoryTreeView selectPathname: completedDirectory. |
|
358 |
self readDirectory |
|
359 |
] |
|
360 |
ifFalse: [self directoryInputField flash] |
|
361 |
]. |
|
404 | 362 |
|
626 | 363 |
directoryView selectionOfFile value: |
364 |
(directoryView listOfFiles detect: [:row| row baseName = self valueOfFileName value] ifNone: nil). |
|
365 |
||
404 | 366 |
^super postBuildWith:aBuilder |
367 |
! ! |
|
368 |
||
369 |
!FileSelectionBrowser class methodsFor:'documentation'! |
|
370 |
||
371 |
version |
|
372 |
^ '$Header$' |
|
373 |
! ! |