author | Claus Gittinger <cg@exept.de> |
Fri, 18 Sep 1998 16:03:10 +0200 | |
changeset 997 | 2a8a32256d4a |
parent 992 | 4d408220a60b |
child 998 | ad33f2625598 |
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 |
" |
|
745 | 42 |
The FileSelectionBrowser allows you to browse in file directories |
43 |
and to select files in order to load file contents or to save |
|
44 |
something to files. |
|
45 |
||
46 |
[start with:] |
|
47 |
FileSelectionBrowser open |
|
502 | 48 |
|
49 |
[author:] |
|
745 | 50 |
Thomas Zwick, eXept Software AG |
404 | 51 |
" |
52 |
! ! |
|
53 |
||
54 |
!FileSelectionBrowser class methodsFor:'instance creation'! |
|
55 |
||
56 |
request: aTitle fileName: aFileName inDirectory: dir withFileFilters: fileFilters |
|
957 | 57 |
^self new |
58 |
title: aTitle; |
|
59 |
fileName: aFileName; |
|
60 |
directory: dir; |
|
61 |
listOfFileFilters: fileFilters; |
|
62 |
open |
|
63 |
||
745 | 64 |
" |
65 |
self |
|
404 | 66 |
request: 'Select Your Profile File' |
67 |
fileName: '.profile' |
|
68 |
inDirectory: Filename homeDirectory |
|
745 | 69 |
withFileFilters: #('.*') |
70 |
" |
|
404 | 71 |
|
957 | 72 |
"Modified: / 17.8.1998 / 10:15:50 / cg" |
73 |
! |
|
74 |
||
75 |
request: aTitle fileName: aFileName withFileFilters: fileFilters |
|
404 | 76 |
^self new |
77 |
title: aTitle; |
|
78 |
fileName: aFileName; |
|
79 |
listOfFileFilters: fileFilters; |
|
80 |
open |
|
81 |
||
745 | 82 |
" |
83 |
self |
|
84 |
request: 'Select Your Profile File' |
|
85 |
fileName: '/etc/fstab' |
|
86 |
withFileFilters: #('*') |
|
87 |
" |
|
462 | 88 |
|
957 | 89 |
"Modified: / 17.8.1998 / 10:15:50 / cg" |
745 | 90 |
! |
91 |
||
92 |
request: aTitle pathName: aPath withFileFilters: fileFilters |
|
957 | 93 |
^self new |
94 |
title: aTitle; |
|
95 |
directory: aPath; |
|
96 |
listOfFileFilters: fileFilters; |
|
97 |
open |
|
98 |
||
745 | 99 |
" |
871 | 100 |
self |
101 |
request: 'Select A File' |
|
102 |
pathName: '/etc' |
|
103 |
withFileFilters: #('*.conf') |
|
745 | 104 |
" |
105 |
||
957 | 106 |
"Modified: / 17.8.1998 / 10:15:50 / cg" |
745 | 107 |
! |
108 |
||
109 |
request: aTitle withFileFilters: fileFilters |
|
957 | 110 |
^self new |
111 |
title: aTitle; |
|
112 |
listOfFileFilters: fileFilters; |
|
113 |
open |
|
745 | 114 |
" |
115 |
self request: 'Select A File' fileFilters: #('.*') |
|
116 |
" |
|
117 |
||
957 | 118 |
"Modified: / 17.8.1998 / 10:15:49 / cg" |
462 | 119 |
! |
120 |
||
404 | 121 |
requestFileName |
957 | 122 |
^self new title: 'Select A File'; open |
745 | 123 |
" |
124 |
self requestFileName |
|
125 |
" |
|
404 | 126 |
|
957 | 127 |
"Modified: / 17.8.1998 / 10:15:48 / cg" |
404 | 128 |
! ! |
129 |
||
130 |
!FileSelectionBrowser class methodsFor:'accessing'! |
|
131 |
||
132 |
loadImageFileNameFilters |
|
992 | 133 |
^ OrderedCollection |
134 |
withAll: #( |
|
135 |
'*.xpm ; *.xbm ; *.gif ; *.tif ; *.tiff ; *.bmp ; *.jpeg ; *.jpg' |
|
136 |
'*' |
|
137 |
) |
|
404 | 138 |
|
992 | 139 |
"Modified: / 12.9.1998 / 17:23:42 / cg" |
404 | 140 |
! |
141 |
||
142 |
projectFileNameFilters |
|
992 | 143 |
^Array withAll: #( |
144 |
'*.st ; *.*o ; *.s ; *.c ; Make* ; *.project' |
|
145 |
'*' |
|
146 |
) |
|
404 | 147 |
|
992 | 148 |
"Modified: / 12.9.1998 / 17:23:22 / cg" |
404 | 149 |
! |
150 |
||
151 |
saveImageFileNameFilters |
|
992 | 152 |
^ OrderedCollection |
153 |
withAll: #( |
|
154 |
'*.xpm ; *.xbm ; *.gif ; *.tif ; *.tiff ; *.bmp' |
|
155 |
'*' |
|
156 |
) |
|
404 | 157 |
|
992 | 158 |
"Modified: / 12.9.1998 / 17:23:54 / cg" |
404 | 159 |
! ! |
160 |
||
161 |
!FileSelectionBrowser class methodsFor:'interface specs'! |
|
162 |
||
163 |
windowSpec |
|
745 | 164 |
"This resource specification was automatically generated |
165 |
by the UIPainter of ST/X." |
|
404 | 166 |
|
745 | 167 |
"Do not manually edit this!! If it is corrupted, |
168 |
the UIPainter may not be able to read the specification." |
|
404 | 169 |
|
170 |
" |
|
171 |
UIPainter new openOnClass:FileSelectionBrowser andSelector:#windowSpec |
|
172 |
FileSelectionBrowser new openInterface:#windowSpec |
|
745 | 173 |
FileSelectionBrowser open |
404 | 174 |
" |
175 |
||
176 |
<resource: #canvas> |
|
177 |
||
178 |
^ |
|
179 |
||
180 |
#(#FullSpec |
|
745 | 181 |
#window: |
404 | 182 |
#(#WindowSpec |
745 | 183 |
#name: 'File Selection Browser' |
184 |
#layout: #(#LayoutFrame 379 0 259 0 978 0 608 0) |
|
185 |
#label: 'File Selection Browser' |
|
186 |
#min: #(#Point 10 10) |
|
187 |
#max: #(#Point 1152 900) |
|
188 |
#bounds: #(#Rectangle 379 259 979 609) |
|
189 |
#usePreferredExtent: false |
|
404 | 190 |
) |
745 | 191 |
#component: |
404 | 192 |
#(#SpecCollection |
745 | 193 |
#collection: |
404 | 194 |
#( |
195 |
#(#VariableHorizontalPanelSpec |
|
745 | 196 |
#name: 'panel' |
197 |
#layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -40 1.0) |
|
198 |
#component: |
|
404 | 199 |
#(#SpecCollection |
745 | 200 |
#collection: |
404 | 201 |
#( |
202 |
#(#ViewSpec |
|
745 | 203 |
#name: 'view1' |
204 |
#component: |
|
404 | 205 |
#(#SpecCollection |
745 | 206 |
#collection: |
404 | 207 |
#( |
208 |
#(#FileSelectionTreeSpec |
|
745 | 209 |
#name: 'directoryTreeView' |
210 |
#layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -25 1.0) |
|
211 |
#model: #selectionOfDirectory |
|
212 |
#hasHorizontalScrollBar: true |
|
213 |
#hasVerticalScrollBar: true |
|
214 |
#miniScrollerHorizontal: true |
|
215 |
#showDirectoryIndicatorForRoot: false |
|
216 |
#showDirectoryIndicator: true |
|
217 |
#valueChangeSelector: #readDirectory |
|
218 |
#hierarchicalList: #rootOfDirectory |
|
219 |
#itemClass: 'Directory' |
|
404 | 220 |
) |
592 | 221 |
#(#InputFieldSpec |
745 | 222 |
#name: 'directoryInputField' |
223 |
#layout: #(#LayoutFrame 2 0.0 -22 1 0 1.0 0 1) |
|
224 |
#model: #selectionOfDirectory |
|
225 |
#immediateAccept: false |
|
592 | 226 |
) |
404 | 227 |
) |
228 |
) |
|
229 |
) |
|
230 |
#(#ViewSpec |
|
745 | 231 |
#name: 'view2' |
232 |
#component: |
|
404 | 233 |
#(#SpecCollection |
745 | 234 |
#collection: |
404 | 235 |
#( |
236 |
#(#InputFieldSpec |
|
745 | 237 |
#name: 'EditField' |
238 |
#layout: #(#LayoutFrame 1 0.0 -22 1 -2 1.0 0 1) |
|
239 |
#model: #valueOfFileName |
|
240 |
#acceptOnReturn: false |
|
241 |
#acceptOnTab: false |
|
404 | 242 |
) |
243 |
#(#SubCanvasSpec |
|
745 | 244 |
#name: 'subCanvas1' |
245 |
#layout: #(#LayoutFrame 1 0.0 0 0.0 0 1.0 -25 1.0) |
|
246 |
#clientHolder: #directoryView |
|
404 | 247 |
) |
248 |
) |
|
249 |
) |
|
250 |
) |
|
251 |
) |
|
252 |
) |
|
745 | 253 |
#handles: #(#Any 0.5 1.0) |
404 | 254 |
) |
426
b8110a424326
commit buttons replaced by subSpec in ToolApplicationModel
tz
parents:
404
diff
changeset
|
255 |
#(#UISubSpecification |
745 | 256 |
#name: 'SubSpecification' |
257 |
#layout: #(#LayoutFrame 2 0.0 -32 1 0 1.0 -8 1.0) |
|
258 |
#majorKey: #ToolApplicationModel |
|
259 |
#minorKey: #windowSpecForCommitWithoutChannels |
|
404 | 260 |
) |
261 |
) |
|
262 |
) |
|
263 |
) |
|
264 |
! ! |
|
265 |
||
266 |
!FileSelectionBrowser methodsFor:'accessing'! |
|
267 |
||
268 |
directory: aDirectory |
|
269 |
||
957 | 270 |
directory := (aDirectory ? Filename currentDirectory) asFilename asAbsoluteFilename pathName |
745 | 271 |
|
957 | 272 |
"Modified: / 17.8.1998 / 10:15:53 / cg" |
404 | 273 |
! |
274 |
||
275 |
directoryView |
|
276 |
||
277 |
^directoryView ? (directoryView := DirectoryView new) |
|
278 |
! |
|
279 |
||
280 |
fileName: aFileName |
|
281 |
||
282 |
self valueOfFileName value: (aFileName ? '') asFilename baseName. |
|
957 | 283 |
directory := directory ? ((aFileName ? '') asFilename asAbsoluteFilename directoryName). |
284 |
||
285 |
"Modified: / 17.8.1998 / 10:15:54 / cg" |
|
404 | 286 |
! |
287 |
||
288 |
listOfFileFilters: anArray |
|
289 |
||
290 |
listOfFileFilters := anArray |
|
291 |
! ! |
|
292 |
||
293 |
!FileSelectionBrowser methodsFor:'accessing - views'! |
|
294 |
||
592 | 295 |
directoryInputField |
296 |
||
297 |
^builder componentAt: #directoryInputField |
|
298 |
||
299 |
! |
|
300 |
||
404 | 301 |
directoryTreeView |
302 |
||
303 |
^builder componentAt: #directoryTreeView |
|
304 |
||
305 |
! ! |
|
306 |
||
307 |
!FileSelectionBrowser methodsFor:'aspects'! |
|
308 |
||
309 |
rootOfDirectory |
|
310 |
||
311 |
|holder| |
|
312 |
(holder := builder bindingAt:#rootOfDirectory) isNil ifTrue:[ |
|
313 |
builder aspectAt:#rootOfDirectory put: (holder := Filename rootDirectory name asValue). |
|
314 |
]. |
|
315 |
^ holder |
|
316 |
||
317 |
! |
|
318 |
||
319 |
selectionOfDirectory |
|
320 |
||
321 |
|holder| |
|
322 |
(holder := builder bindingAt:#selectionOfDirectory) isNil ifTrue:[ |
|
323 |
builder aspectAt:#selectionOfDirectory put: (holder := ValueHolder new) |
|
324 |
]. |
|
325 |
^ holder |
|
326 |
||
327 |
! |
|
328 |
||
329 |
valueOfFileName |
|
330 |
||
331 |
|holder| |
|
332 |
(holder := builder bindingAt:#valueOfFileName) isNil ifTrue:[ |
|
333 |
builder aspectAt:#valueOfFileName put:(holder := ValueHolder new). |
|
334 |
]. |
|
335 |
^ holder |
|
336 |
! ! |
|
337 |
||
338 |
!FileSelectionBrowser methodsFor:'callbacks'! |
|
339 |
||
340 |
fileDoubleClicked: aFileName |
|
341 |
||
342 |
self valueOfFileName value: aFileName. |
|
343 |
accept value: true. |
|
344 |
self close |
|
345 |
! |
|
346 |
||
347 |
readDirectory |
|
348 |
||
592 | 349 |
self directoryTreeView selection notNil |
350 |
ifTrue: |
|
351 |
[ |
|
745 | 352 |
directoryView directory: self selectionOfDirectory value; readDirectory. |
353 |
self class lastSelection notNil ifTrue: [self class lastSelection: self selectionOfDirectory value] |
|
592 | 354 |
] |
404 | 355 |
! ! |
356 |
||
357 |
!FileSelectionBrowser methodsFor:'startup / release'! |
|
358 |
||
359 |
closeCancel |
|
360 |
||
361 |
directoryView release. |
|
362 |
super closeCancel |
|
363 |
! |
|
364 |
||
365 |
closeRequest |
|
366 |
||
367 |
directoryView release. |
|
368 |
super closeRequest |
|
369 |
||
370 |
! |
|
371 |
||
372 |
open |
|
373 |
||
374 |
super open. |
|
515 | 375 |
accept value ifTrue:[ |
376 |
^ (self selectionOfDirectory value ? '') asFilename |
|
377 |
constructString:(self valueOfFileName value ? '') |
|
404 | 378 |
]. |
515 | 379 |
^ nil |
957 | 380 |
|
381 |
"Modified: / 17.8.1998 / 10:15:55 / cg" |
|
404 | 382 |
! |
383 |
||
384 |
postBuildWith:aBuilder |
|
385 |
||
386 |
directoryView listOfFileFilters: listOfFileFilters ? #('*'). |
|
462 | 387 |
directoryView fileSelectAction: [:aFileName |self valueOfFileName value: aFileName asFilename baseName]. |
388 |
directoryView fileDoubleClickAction: [:aFileName |self fileDoubleClicked: aFileName asFilename baseName]. |
|
404 | 389 |
directoryView fileFilterSelectAction: [:fileFilter| |
992 | 390 |
"/ CG: obscure code - isn't the code below the same as ? |
391 |
"/ self valueOfFileName value:((self valueOfFileName value ? 'unknown') |
|
392 |
"/ asFilename |
|
393 |
"/ withSuffix:(fileFilter asFilename suffix)) |
|
394 |
self valueOfFileName value: ( |
|
395 |
((self valueOfFileName value ? 'unknown') readStream upTo: $.), '.', |
|
396 |
(fileFilter copy reverse readStream upTo: $.) reverse) |
|
397 |
]. |
|
745 | 398 |
self directoryTreeView selectPathname: directory ? self class lastSelection ? Filename currentDirectory asAbsoluteFilename name. |
592 | 399 |
|
400 |
self directoryInputField entryCompletionBlock: |
|
401 |
[:f| |
|
402 |
|completedDirectory| |
|
403 |
(completedDirectory := Filename |
|
404 |
filenameCompletionFor: self directoryInputField contents |
|
969 | 405 |
directory:(directory asFilename) |
592 | 406 |
directoriesOnly:true |
407 |
filesOnly:false |
|
408 |
ifMultiple: |
|
409 |
[:dir | |
|
410 |
self directoryTreeView selection notNil ifTrue: [ |
|
622 | 411 |
self directoryTreeView selectedNodeExpand: true] |
592 | 412 |
]) asFilename exists |
413 |
ifTrue: |
|
414 |
[ |
|
415 |
self directoryInputField contents: completedDirectory. |
|
416 |
self directoryTreeView selectPathname: completedDirectory. |
|
417 |
self readDirectory |
|
418 |
] |
|
419 |
ifFalse: [self directoryInputField flash] |
|
420 |
]. |
|
404 | 421 |
|
626 | 422 |
directoryView selectionOfFile value: |
423 |
(directoryView listOfFiles detect: [:row| row baseName = self valueOfFileName value] ifNone: nil). |
|
424 |
||
404 | 425 |
^super postBuildWith:aBuilder |
969 | 426 |
|
992 | 427 |
"Modified: / 12.9.1998 / 17:10:44 / cg" |
404 | 428 |
! ! |
429 |
||
430 |
!FileSelectionBrowser class methodsFor:'documentation'! |
|
431 |
||
432 |
version |
|
433 |
^ '$Header$' |
|
434 |
! ! |