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