8015
|
1 |
"{ Package: 'stx:libtool' }"
|
|
2 |
|
|
3 |
Object subclass:#Win32FileDialog
|
|
4 |
instanceVariableNames:'fileName openFileNameStruct filters lpstrFilter lpstrFile
|
|
5 |
lpstrInitialDir lpstrTitle lpstrDefExt defFilter defExtension
|
|
6 |
style title smalltalkFileFilters defFilterIndex parent'
|
|
7 |
classVariableNames:'InitialDirectory CommonDialogConstants FilterPatternDescriptions'
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Interface-Tools-File'
|
|
10 |
!
|
|
11 |
|
|
12 |
ByteArray variableByteSubclass:#OpenFilenameStructure
|
|
13 |
instanceVariableNames:''
|
|
14 |
classVariableNames:''
|
|
15 |
poolDictionaries:''
|
|
16 |
privateIn:Win32FileDialog
|
|
17 |
!
|
|
18 |
|
|
19 |
|
|
20 |
!Win32FileDialog class methodsFor:'instance creation'!
|
|
21 |
|
|
22 |
new
|
|
23 |
|
|
24 |
^ super new initialize
|
|
25 |
! !
|
|
26 |
|
|
27 |
!Win32FileDialog class methodsFor:'accessing'!
|
|
28 |
|
|
29 |
getInitialDirectory
|
|
30 |
|
|
31 |
^ InitialDirectory
|
|
32 |
!
|
|
33 |
|
|
34 |
setInitialDirectory: aName
|
|
35 |
|
|
36 |
InitialDirectory := Directory pathName: aName
|
|
37 |
! !
|
|
38 |
|
|
39 |
!Win32FileDialog class methodsFor:'constants'!
|
|
40 |
|
|
41 |
commonDialogConstantAt: aString
|
|
42 |
|
|
43 |
^ self commonDialogConstants at: aString ifAbsent:[Transcript showCR: 'Common Dialog Constant ', aString, ' notfound!!']
|
|
44 |
!
|
|
45 |
|
|
46 |
commonDialogConstants
|
|
47 |
|
|
48 |
CommonDialogConstants isNil ifTrue:[CommonDialogConstants := self generateCommonDialogConstants ].
|
|
49 |
^ CommonDialogConstants
|
|
50 |
!
|
|
51 |
|
|
52 |
generateCommonDialogConstants
|
|
53 |
|
|
54 |
|dictionary|
|
|
55 |
|
|
56 |
dictionary := Dictionary new.
|
|
57 |
dictionary
|
|
58 |
at: 'CcPreventfullopen' put: 4;
|
|
59 |
at: 'FrShowhelp' put: 128;
|
|
60 |
at: 'PdEnablesetuptemplate' put: 32768;
|
|
61 |
at: 'FrNoupdown' put: 1024;
|
|
62 |
at: 'CfNosimulations' put: 4096;
|
|
63 |
at: 'OfnPathmustexist' put: 2048;
|
|
64 |
at: 'CfWysiwyg' put: 32768;
|
|
65 |
at: 'PdReturndc' put: 256;
|
|
66 |
at: 'PdEnableprinthook' put: 4096;
|
|
67 |
at: 'CfInittologfontstruct' put: 64;
|
|
68 |
at: 'CfScalableonly' put: 131072;
|
|
69 |
at: 'PdPrinttofile' put: 32;
|
|
70 |
at: 'CfEffects' put: 256;
|
|
71 |
at: 'PdShowhelp' put: 2048;
|
|
72 |
at: 'OfnEnabletemplatehandle' put: 128;
|
|
73 |
at: 'CfBoth' put: 3;
|
|
74 |
at: 'OfnReadonly' put: 1;
|
|
75 |
at: 'PdNopagenums' put: 8;
|
|
76 |
at: 'PdDisableprinttofile' put: 524288;
|
|
77 |
at: 'PdHideprinttofile' put: 1048576;
|
|
78 |
at: 'OfnAllowmultiselect' put: 512;
|
|
79 |
at: 'CfPrinterfonts' put: 2;
|
|
80 |
at: 'CfEnabletemplatehandle' put: 32;
|
|
81 |
at: 'PdSelection' put: 1;
|
|
82 |
at: 'OfnHidereadonly' put: 4;
|
|
83 |
at: 'PdPrintsetup' put: 64;
|
|
84 |
at: 'OfnExtentiondifferent' put: 1024;
|
|
85 |
at: 'FrReplaceall' put: 32;
|
|
86 |
at: 'FrMatchcase' put: 4;
|
|
87 |
at: 'OfnFilemustexist' put: 4096;
|
|
88 |
at: 'PdCollate' put: 16;
|
|
89 |
at: 'CfFixedpitchonly' put: 16384;
|
|
90 |
at: 'PdEnablesetuphook' put: 8192;
|
|
91 |
at: 'OfnShareaware' put: 16384;
|
|
92 |
at: 'CcEnablehook' put: 16;
|
|
93 |
at: 'CfEnabletemplate' put: 16;
|
|
94 |
at: 'Findmsgstring' put: 'commdlgFindreplace';
|
|
95 |
at: 'CfLimitsize' put: 8192;
|
|
96 |
at: 'OfnNochangedir' put: 8;
|
|
97 |
at: 'OfnCreateprompt' put: 8192;
|
|
98 |
at: 'ScreenFonttype' put: 8192;
|
|
99 |
at: 'PdUsedevmodecopies' put: 262144;
|
|
100 |
at: 'CcRgbinit' put: 1;
|
|
101 |
at: 'FrFindnext' put: 8;
|
|
102 |
at: 'CfUsestyle' put: 128;
|
|
103 |
at: 'FrEnablehook' put: 256;
|
|
104 |
at: 'PdEnableprinttemplatehandle' put: 65536;
|
|
105 |
at: 'CfShowhelp' put: 4;
|
|
106 |
at: 'FrNowholeword' put: 4096.
|
|
107 |
dictionary
|
|
108 |
at: 'ShareExist' put: 16448;
|
|
109 |
at: 'OfnOverwriteprompt' put: 2;
|
|
110 |
at: 'OfnEnablehook' put: 32;
|
|
111 |
at: 'OfnShowhelp' put: 16;
|
|
112 |
at: 'CcEnabletemplatehandle' put: 64;
|
|
113 |
at: 'SimulatedFonttype' put: 32768;
|
|
114 |
at: 'FrDown' put: 1;
|
|
115 |
at: 'PdEnableprinttemplate' put: 16384;
|
|
116 |
at: 'CfNovectorfonts' put: 2048;
|
|
117 |
at: 'PdNoselection' put: 4;
|
|
118 |
at: 'CfAnsionly' put: 1024;
|
|
119 |
at: 'OfnNovalidate' put: 256;
|
|
120 |
at: 'CfScreenfonts' put: 1;
|
|
121 |
at: 'FrWholeword' put: 2;
|
|
122 |
at: 'FrEnabletemplatehandle' put: 8192;
|
|
123 |
at: 'PdAllpages' put: 0;
|
|
124 |
at: 'CfForcefontexist' put: 65536;
|
|
125 |
at: 'CcEnabletemplate' put: 32;
|
|
126 |
at: 'PdPagenums' put: 2;
|
|
127 |
at: 'FrReplace' put: 16;
|
|
128 |
at: 'PdEnablesetuptemplatehandle' put: 131072;
|
|
129 |
at: 'CfApply' put: 512;
|
|
130 |
at: 'OfnEnabletemplate' put: 64;
|
|
131 |
at: 'DnDefaultprn' put: 1;
|
|
132 |
at: 'PdNowarning' put: 128;
|
|
133 |
at: 'CfTtonly' put: 262144;
|
|
134 |
at: 'PrinterFonttype' put: 16384;
|
|
135 |
at: 'CcShowhelp' put: 8;
|
|
136 |
at: 'CcFullopen' put: 2;
|
|
137 |
at: 'PdReturnic' put: 512;
|
|
138 |
at: 'FrEnabletemplate' put: 512;
|
|
139 |
at: 'FrDialogterm' put: 64;
|
|
140 |
at: 'Helpmsgstring' put: 'commdlgHelp';
|
|
141 |
at: 'PdReturndefault' put: 1024;
|
|
142 |
at: 'FrNomatchcase' put: 2048;
|
|
143 |
at: 'CfEnablehook' put: 8.
|
|
144 |
^ dictionary
|
|
145 |
! !
|
|
146 |
|
|
147 |
!Win32FileDialog class methodsFor:'examples'!
|
|
148 |
|
|
149 |
openFile
|
|
150 |
|
|
151 |
"
|
|
152 |
self openFile
|
|
153 |
"
|
|
154 |
|
|
155 |
^ (FileDialogWin new openFile: 'c:\untitled.txt') file.
|
|
156 |
!
|
|
157 |
|
|
158 |
saveFile
|
|
159 |
|
|
160 |
"
|
|
161 |
self saveFile
|
|
162 |
"
|
|
163 |
|
|
164 |
^ (FileDialogWin new saveFile: 'C:\vsw311\untitled.txt') file.
|
|
165 |
! !
|
|
166 |
|
|
167 |
!Win32FileDialog class methodsFor:'filters'!
|
|
168 |
|
|
169 |
filterPatternDescription: filterPattern
|
|
170 |
|
|
171 |
^ self filterPatternDescriptions at: filterPattern ifAbsent: ''
|
|
172 |
!
|
|
173 |
|
|
174 |
filterPatternDescriptions
|
|
175 |
|
|
176 |
FilterPatternDescriptions isNil ifTrue:[ FilterPatternDescriptions := self generateFilterPatternDescriptions ].
|
|
177 |
^ FilterPatternDescriptions
|
|
178 |
!
|
|
179 |
|
|
180 |
filtersFor: pattern
|
|
181 |
|
|
182 |
|filters filterPatterns|
|
|
183 |
|
|
184 |
pattern isEmptyOrNil ifTrue:[^ nil].
|
|
185 |
|
|
186 |
filters := OrderedCollection new.
|
|
187 |
filterPatterns := pattern subStrings: $;.
|
|
188 |
filterPatterns do:[:filterPattern |
|
|
189 |
filterPattern notEmpty ifTrue:[
|
|
190 |
filters add: (Array with: (self filterPatternDescription: filterPattern)
|
|
191 |
with:filterPattern)
|
|
192 |
].
|
|
193 |
].
|
|
194 |
^ filters asArray
|
|
195 |
!
|
|
196 |
|
|
197 |
generateFilterPatternDescriptions
|
|
198 |
|
|
199 |
^ Dictionary new
|
|
200 |
at: '*.txt' put: 'Text files (*.txt)';
|
|
201 |
at: '*.st' put: 'Smalltalk files (*.st)';
|
|
202 |
at: '*.csv' put: 'CSV files (*.csv)';
|
|
203 |
at: '*.xml' put: 'XML files (*.xml)';
|
|
204 |
at: '*.zip' put: 'ZIP files (*.zip)';
|
|
205 |
at: '*.xls' put: 'Excel files (*.xls)';
|
|
206 |
at: '*.ent' put: 'SGML Entity files (*.ent)';
|
|
207 |
at: '*.ccs' put: 'CCS files (*.ccs)';
|
|
208 |
at: '*.ini' put: 'Configuration files (*.ini)';
|
|
209 |
at: '*.prn' put: 'Printer Text files (*.prn)';
|
|
210 |
at: '*.dir' put: 'DapasX Database files (*.dir)';
|
|
211 |
at: '*.dat' put: 'DapasX Database files (*.dat)';
|
|
212 |
at: '*.prg' put: 'DapasX Program files (*.prg)';
|
|
213 |
at: '*.dcf' put: 'DapasX Options files (*.dcf)';
|
|
214 |
at: '*.ext' put: 'DapasX Backup files (*.ext)';
|
|
215 |
at: '*.mpl' put: 'DapasX Project files (*.mpl)';
|
|
216 |
yourself
|
|
217 |
! !
|
|
218 |
|
|
219 |
!Win32FileDialog class methodsFor:'initialize'!
|
|
220 |
|
|
221 |
startUp
|
|
222 |
|
|
223 |
"Private - Initialize the class variables. This is called
|
|
224 |
during startup."
|
|
225 |
|
|
226 |
InitialDirectory := Directory pathName: Disk drivePathName.
|
|
227 |
! !
|
|
228 |
|
|
229 |
!Win32FileDialog class methodsFor:'opening'!
|
|
230 |
|
|
231 |
fileDialogFor:ownerWindow
|
|
232 |
save:isSaveDialog
|
|
233 |
title:titleOrNil
|
|
234 |
inDirectory:dirPathOrNil
|
|
235 |
initialAnswer:initialOrNil
|
|
236 |
filter:pattern
|
|
237 |
extension:extensionOrNil
|
|
238 |
|
|
239 |
|
|
240 |
"start a native open-file dialog.
|
|
241 |
If not cancelled, the selected fileName is returned; nil otherwise.
|
|
242 |
Of course, this one looks like the
|
|
243 |
Windows file dialog - no matter which viewStyle settings are active.
|
|
244 |
Notice: if no ownerWindow is given, the dialog pops up at 0@0.
|
|
245 |
|
|
246 |
EXPERIMENTAL & non-portable: use with caution"
|
|
247 |
|
|
248 |
|filePath filterArrayOrNil|
|
|
249 |
|
|
250 |
filterArrayOrNil := self filtersFor: pattern.
|
|
251 |
|
|
252 |
filePath := self new
|
|
253 |
openFor:ownerWindow
|
|
254 |
save:isSaveDialog
|
|
255 |
title:titleOrNil
|
|
256 |
inDirectory:dirPathOrNil
|
|
257 |
initialAnswer:initialOrNil
|
|
258 |
filter:filterArrayOrNil
|
|
259 |
extension:extensionOrNil.
|
|
260 |
|
|
261 |
^ filePath
|
|
262 |
! !
|
|
263 |
|
|
264 |
!Win32FileDialog methodsFor:'accessing'!
|
|
265 |
|
|
266 |
addAllFilesFilter
|
|
267 |
|
|
268 |
self addFilter: '*.*' description: 'All Files (*.*)'.
|
|
269 |
!
|
|
270 |
|
|
271 |
addFilter: aFilter description: aDescription
|
|
272 |
"Add aFilter and aDescription to the list of File dialog
|
|
273 |
filters."
|
|
274 |
|
|
275 |
filters add: ( Association key: aFilter value: aDescription ).
|
|
276 |
!
|
|
277 |
|
|
278 |
addSmalltalkFileFilters
|
|
279 |
|
|
280 |
^ smalltalkFileFilters
|
|
281 |
!
|
|
282 |
|
|
283 |
defExtension: aDefExtension
|
|
284 |
"Specifies the default extension of File dialog."
|
|
285 |
|
|
286 |
defExtension := aDefExtension.
|
|
287 |
!
|
|
288 |
|
|
289 |
defFilter
|
|
290 |
"Answers the aDefFilterString as the default filter of File dialog."
|
|
291 |
|
|
292 |
^ defFilter
|
|
293 |
!
|
|
294 |
|
|
295 |
defFilter: aDefFilterString
|
|
296 |
"Specifies the aDefFilterString as the default filter of File dialog."
|
|
297 |
|
|
298 |
defFilter := aDefFilterString
|
|
299 |
!
|
|
300 |
|
|
301 |
defFilterIndex: defaultFilterIndex
|
|
302 |
|
|
303 |
defFilterIndex := defaultFilterIndex.
|
|
304 |
!
|
|
305 |
|
|
306 |
directory
|
|
307 |
"Answer the selected directory."
|
8037
|
308 |
InitialDirectory isNil ifTrue:[
|
|
309 |
^ Filename currentDirectory pathName asFilename
|
|
310 |
].
|
|
311 |
^ InitialDirectory "? OperatingSystem getCurrentDirectory asFilename"
|
8015
|
312 |
!
|
|
313 |
|
|
314 |
directory: directory
|
|
315 |
"Sets the initial directory."
|
|
316 |
|
|
317 |
| aFilename |
|
|
318 |
|
|
319 |
directory isNil ifTrue:[^ self.].
|
|
320 |
aFilename := directory asFilename.
|
|
321 |
aFilename exists ifTrue: [ InitialDirectory := aFilename ].
|
|
322 |
!
|
|
323 |
|
|
324 |
file
|
|
325 |
"Answer the selected file."
|
|
326 |
|
|
327 |
^fileName
|
|
328 |
!
|
|
329 |
|
|
330 |
fileSpec: aFileSpec
|
|
331 |
"Sets the initial fileName and directory in the File Dialog."
|
|
332 |
|
|
333 |
| array dir |
|
|
334 |
|
|
335 |
"SHOULD assign initial fileName and directory separately using #fileName: and #directory"
|
|
336 |
|
|
337 |
self halt.
|
|
338 |
fileName := aFileSpec.
|
|
339 |
"/ array := Filename splitPath: aFileSpec in: self directory .
|
|
340 |
"/ dir :=
|
|
341 |
"/ (( String with: ( array at: 1 ) with: $: ),
|
|
342 |
"/ ( ( array at: 2 ) isEmpty ifTrue: [ '\' ] ifFalse: [ array at: 2 ] )) asFilename.
|
|
343 |
"/ dir exists ifFalse: [ dir := OperatingSystem getCurrentDirectory asFilename ].
|
|
344 |
"/
|
|
345 |
"/ self directory: dir.
|
|
346 |
"/ fileName := array at: 3
|
|
347 |
!
|
|
348 |
|
|
349 |
filters
|
|
350 |
"Private - answers a string containing all filters and sets up
|
|
351 |
the defFilterIndex property"
|
|
352 |
|
|
353 |
| filterString count defaultFilterIndex defaultFilter|
|
|
354 |
|
|
355 |
smalltalkFileFilters notNil ifTrue: [
|
|
356 |
self
|
|
357 |
addFilter: '*.cls' description: 'Class Files (*.CLS)';
|
|
358 |
addFilter: '*.mth' description: 'Method Files (*.MTH)';
|
|
359 |
addFilter: '*.st' description: 'Smalltalk Files (*.ST)';
|
|
360 |
addFilter: '*.bnd' description: 'Library Bind Files (*.BND)';
|
|
361 |
addFilter: '*.map' description: 'Library Map Files (*.MAP)';
|
|
362 |
addFilter: '*.ini' description: 'Initialization Files (*.INI)';
|
|
363 |
addFilter: '*.obj' description: 'Object Files (*.OBJ)';
|
|
364 |
addFilter: '*.log' description: 'Log Files (*.LOG)'
|
|
365 |
].
|
|
366 |
|
|
367 |
defaultFilter := self defFilter.
|
|
368 |
(fileName notEmptyOrNil and:[defaultFilter isNil]) ifTrue:[
|
|
369 |
|initialFilenameSuffix|
|
|
370 |
initialFilenameSuffix := fileName asFilename suffix.
|
|
371 |
initialFilenameSuffix notEmptyOrNil ifTrue:[
|
|
372 |
defaultFilter := '*.', initialFilenameSuffix.
|
|
373 |
].
|
|
374 |
].
|
|
375 |
|
|
376 |
filterString := String new.
|
|
377 |
count := 0.
|
|
378 |
defaultFilterIndex := 0.
|
|
379 |
filters do: [:assoc |
|
|
380 |
count := count + 1.
|
|
381 |
assoc key = defaultFilter ifTrue: [ defaultFilterIndex := count ].
|
8037
|
382 |
filterString := filterString, assoc value, #[0] asString, assoc key , #[0] asString.
|
8015
|
383 |
].
|
|
384 |
|
|
385 |
self defFilterIndex: defaultFilterIndex.
|
|
386 |
^filterString
|
|
387 |
!
|
|
388 |
|
|
389 |
flags
|
|
390 |
"Private - Answers the dialog box current flags.
|
|
391 |
For compatibility reasons -> use style instead"
|
|
392 |
|
|
393 |
^openFileNameStruct flags
|
|
394 |
!
|
|
395 |
|
|
396 |
flags: flags
|
|
397 |
|
|
398 |
"Private - Specifies the dialog box creation flags.
|
|
399 |
Kept for compatibility reasons. Use style: instead"
|
|
400 |
|
|
401 |
self style: flags
|
|
402 |
!
|
|
403 |
|
|
404 |
hideReadonly
|
|
405 |
|
|
406 |
"Hides the file dialog's Readonly check box. "
|
|
407 |
|
|
408 |
self style: self style | (self class commonDialogConstantAt: 'OfnHidereadonly')
|
|
409 |
!
|
|
410 |
|
|
411 |
initialFileName: filename
|
|
412 |
"Sets the initial fileName string in the File Dialog."
|
|
413 |
|
|
414 |
| aString |
|
|
415 |
filename isNil ifTrue:[^ self.].
|
|
416 |
aString := filename.
|
|
417 |
filename isFilename ifTrue:[ aString := filename baseName].
|
|
418 |
fileName := aString.
|
|
419 |
!
|
|
420 |
|
|
421 |
overwritePrompt
|
|
422 |
|
|
423 |
"Prompt if the user attempts to overwrite a file"
|
|
424 |
|
|
425 |
self style: self style | (self class commonDialogConstantAt: 'OfnOverwriteprompt')
|
|
426 |
!
|
|
427 |
|
|
428 |
owner: ownerWindow
|
|
429 |
|
|
430 |
"Sets the owner of the Dialog box."
|
|
431 |
|
|
432 |
|mainView handle|
|
|
433 |
|
|
434 |
ownerWindow isNil ifTrue:[^ self].
|
|
435 |
mainView := ownerWindow windowGroup mainView.
|
|
436 |
mainView notNil ifTrue:[
|
|
437 |
handle := mainView id.
|
|
438 |
handle notNil ifTrue:[
|
|
439 |
parent := handle address
|
|
440 |
].
|
|
441 |
].
|
|
442 |
|
|
443 |
"/ super owner: anOwner.
|
|
444 |
"/ owner isWindow
|
|
445 |
"/ ifTrue: [ parent := owner ]
|
|
446 |
"/ ifFalse: [ parent := owner mainView.
|
|
447 |
"/ parent isWindow ifFalse: [
|
|
448 |
"/ parent := Notifier findWindow: WindowHandle queryActive ]].
|
|
449 |
!
|
|
450 |
|
|
451 |
pathMustExist
|
|
452 |
|
|
453 |
"Private & DEFAULT!!."
|
|
454 |
"Changed by K3/EES5-Mg, 29.01.97"
|
|
455 |
|
|
456 |
self style: self style | 16r800.
|
|
457 |
!
|
|
458 |
|
|
459 |
shareAware
|
|
460 |
|
|
461 |
"Allows a previously opened file to be opened
|
|
462 |
(e.g. change.log)"
|
|
463 |
|
|
464 |
self style: self style | (self class commonDialogConstantAt: 'OfnShareaware')
|
|
465 |
!
|
|
466 |
|
|
467 |
style
|
|
468 |
^ style ? 8
|
|
469 |
!
|
|
470 |
|
|
471 |
style:something
|
|
472 |
style := something.
|
|
473 |
!
|
|
474 |
|
|
475 |
title: aTitle
|
|
476 |
|
|
477 |
"Specifies the string to be placed in the title bar of the
|
|
478 |
File dialog."
|
|
479 |
|
|
480 |
title := aTitle
|
|
481 |
! !
|
|
482 |
|
|
483 |
!Win32FileDialog methodsFor:'dapas'!
|
|
484 |
|
|
485 |
dapasOpenFile
|
|
486 |
|
|
487 |
"Brings up the default open file dialog "
|
|
488 |
"Changed by K3/EES5-Mg, 28.02.96"
|
|
489 |
|
|
490 |
self hideReadonly;
|
|
491 |
shareAware;
|
|
492 |
addFilter: '*.*' description: 'All Files (*.*)'.
|
|
493 |
|
|
494 |
self defFilter isNil ifTrue:[ self defFilter: '*.*'].
|
|
495 |
|
|
496 |
self open.
|
|
497 |
!
|
|
498 |
|
|
499 |
dapasSaveFile
|
|
500 |
|
|
501 |
"Brings up the file save dialog."
|
|
502 |
"Changed by K3/EES5-Mg, 28.02.96"
|
|
503 |
|
|
504 |
self hideReadonly;
|
|
505 |
overwritePrompt;
|
|
506 |
addFilter: '*.*' description: 'All Files (*.*)'.
|
|
507 |
|
|
508 |
self save.
|
|
509 |
!
|
|
510 |
|
|
511 |
openFileXml
|
|
512 |
|
|
513 |
"Brings up the default open file dialog "
|
|
514 |
"Changed by K3/EES5-Mg, 28.02.96"
|
|
515 |
"Changed by GS-EC/EES3 - Bernd Eisenmann, 14.08.03"
|
|
516 |
|
|
517 |
self hideReadonly;
|
|
518 |
shareAware;
|
|
519 |
addFilter: '*.xml' description: 'XML-Datei'.
|
|
520 |
|
|
521 |
self defFilter isNil ifTrue:[ self defFilter: '*.*'].
|
|
522 |
|
|
523 |
self open.
|
|
524 |
!
|
|
525 |
|
|
526 |
openFileXmlZip
|
|
527 |
|
|
528 |
"Brings up the default open file dialog "
|
|
529 |
"Changed by K3/EES5-Mg, 28.02.96"
|
|
530 |
"Changed by GS-EC/EES3 - Bernd Eisenmann, 14.08.03"
|
|
531 |
|
|
532 |
self hideReadonly;
|
|
533 |
shareAware;
|
|
534 |
addFilter: '*.xml' description: 'XML-Datei';
|
|
535 |
addFilter: '*.zip' description: 'ZIP-Datei'.
|
|
536 |
|
|
537 |
self defFilter isNil ifTrue:[ self defFilter: '*.*'].
|
|
538 |
|
|
539 |
self open.
|
|
540 |
! !
|
|
541 |
|
|
542 |
!Win32FileDialog methodsFor:'initialize & release'!
|
|
543 |
|
|
544 |
cleanUp
|
|
545 |
"Private - Free openFileNameStruct."
|
|
546 |
|
|
547 |
self style: self flags.
|
|
548 |
lpstrFilter notNil ifTrue: [lpstrFilter free].
|
|
549 |
lpstrFile notNil ifTrue: [lpstrFile free].
|
|
550 |
lpstrInitialDir notNil ifTrue: [lpstrInitialDir free].
|
|
551 |
lpstrTitle notNil ifTrue: [ lpstrTitle free ].
|
|
552 |
lpstrDefExt notNil ifTrue: [ lpstrDefExt free ].
|
|
553 |
|
|
554 |
openFileNameStruct := nil
|
|
555 |
!
|
|
556 |
|
|
557 |
initialize
|
|
558 |
|
|
559 |
"Private - Initialize openFileNameStruct"
|
|
560 |
|
|
561 |
super initialize.
|
|
562 |
openFileNameStruct := OpenFilenameStructure new.
|
|
563 |
openFileNameStruct lStructSize: openFileNameStruct sizeInBytes.
|
|
564 |
fileName := String new.
|
|
565 |
filters := OrderedCollection new.
|
|
566 |
self style: (self class commonDialogConstantAt: 'OfnNochangedir')
|
|
567 |
! !
|
|
568 |
|
|
569 |
!Win32FileDialog methodsFor:'opening'!
|
|
570 |
|
|
571 |
open
|
|
572 |
"Brings up the open file dialog."
|
|
573 |
|
|
574 |
| error rslt openFileNameStructExternalBytes |
|
|
575 |
|
|
576 |
[
|
|
577 |
self fillStruct.
|
|
578 |
parent notNil ifTrue: [ openFileNameStruct hwndOwner: parent.].
|
|
579 |
style notNil ifTrue: [ openFileNameStruct flags: style ].
|
|
580 |
|
|
581 |
openFileNameStructExternalBytes := ExternalBytes from: openFileNameStruct asByteArray.
|
|
582 |
rslt := OperatingSystem getOpenFilename: openFileNameStructExternalBytes address.
|
|
583 |
rslt
|
|
584 |
ifTrue: [ self getFileName ]
|
|
585 |
ifFalse: [
|
|
586 |
fileName := nil.
|
|
587 |
error := OperatingSystem commDlgExtendedError.
|
|
588 |
].
|
|
589 |
] ensure:[
|
|
590 |
openFileNameStructExternalBytes free.
|
|
591 |
self cleanUp.
|
|
592 |
].
|
|
593 |
|
|
594 |
(error notNil and:[error ~= 0]) ifTrue: [self error: error ].
|
|
595 |
!
|
|
596 |
|
|
597 |
openFile
|
|
598 |
"Brings up the default open file dialog. The title is set to 'Open File'
|
|
599 |
and fileSpec is set to '*.*'. "
|
|
600 |
|
|
601 |
self openFile: '*.*'.
|
|
602 |
!
|
|
603 |
|
|
604 |
openFile: initialFileName
|
|
605 |
|
|
606 |
"Brings up the default open file dialog. The title is set to 'Open File'
|
|
607 |
and fileSpec is set to patternString. "
|
|
608 |
|
|
609 |
self title: 'Open'.
|
|
610 |
initialFileName notNil ifTrue: [ self initialFileName: initialFileName ].
|
|
611 |
self
|
|
612 |
hideReadonly;
|
|
613 |
shareAware;
|
|
614 |
addAllFilesFilter;
|
|
615 |
addFilter: '*.txt' description: 'Text Files (*.txt)'.
|
|
616 |
Smalltalk isStandAloneApp ifFalse: [ self addSmalltalkFileFilters ].
|
|
617 |
self defFilter isNil ifTrue:[ self defFilter: '*.*'].
|
|
618 |
self open.
|
|
619 |
!
|
|
620 |
|
|
621 |
openFor:ownerWindow
|
|
622 |
save:isSaveDialog
|
|
623 |
title:titleOrNil
|
|
624 |
inDirectory:dirPathOrNil
|
|
625 |
initialAnswer:initialOrNil
|
|
626 |
filter:filterArrayOrNil
|
|
627 |
extension:extensionOrNil
|
|
628 |
|
|
629 |
self
|
|
630 |
owner: ownerWindow;
|
|
631 |
title: titleOrNil;
|
|
632 |
initialFileName: initialOrNil;
|
|
633 |
defFilter: extensionOrNil.
|
|
634 |
|
|
635 |
filterArrayOrNil notNil ifTrue:[
|
|
636 |
filterArrayOrNil do:[:each | self addFilter: each last description: each first].
|
|
637 |
].
|
|
638 |
|
|
639 |
self addAllFilesFilter.
|
|
640 |
"/ self defFilter isNil ifTrue:[ self defFilter: '*.*'].
|
|
641 |
|
|
642 |
isSaveDialog
|
|
643 |
ifTrue:[
|
|
644 |
self hideReadonly;
|
|
645 |
overwritePrompt;
|
|
646 |
save.
|
|
647 |
] ifFalse:[
|
|
648 |
self hideReadonly;
|
|
649 |
shareAware;
|
|
650 |
open.
|
|
651 |
].
|
|
652 |
|
|
653 |
^ self file
|
|
654 |
!
|
|
655 |
|
|
656 |
save
|
|
657 |
"Brings up the save file dialog."
|
|
658 |
|
|
659 |
| error rslt openFileNameStructExternalBytes |
|
|
660 |
|
|
661 |
[
|
|
662 |
self fillStruct.
|
|
663 |
parent notNil ifTrue: [ openFileNameStruct hwndOwner: parent.].
|
|
664 |
style notNil ifTrue: [ openFileNameStruct flags: style ].
|
|
665 |
|
|
666 |
openFileNameStructExternalBytes := ExternalBytes from: openFileNameStruct asByteArray.
|
|
667 |
rslt := OperatingSystem getSaveFilename: openFileNameStructExternalBytes address.
|
|
668 |
rslt
|
|
669 |
ifTrue: [ self getFileName ]
|
|
670 |
ifFalse: [
|
|
671 |
fileName := nil.
|
|
672 |
error := OperatingSystem commDlgExtendedError.
|
|
673 |
].
|
|
674 |
] ensure:[
|
|
675 |
openFileNameStructExternalBytes free.
|
|
676 |
self cleanUp.
|
|
677 |
].
|
|
678 |
|
|
679 |
(error notNil and:[error ~= 0]) ifTrue: [self error: error ].
|
|
680 |
!
|
|
681 |
|
|
682 |
saveFile: aString
|
|
683 |
|
|
684 |
"Brings up the save file dialog with aString as the
|
|
685 |
default name. The title is set to 'Save File'. "
|
|
686 |
|
|
687 |
self saveTitle: 'Save File' fileName: aString
|
|
688 |
!
|
|
689 |
|
|
690 |
saveTitle: aTitle fileName: initialFileName
|
|
691 |
|
|
692 |
"Brings up the file save dialog with aTitle and aString
|
|
693 |
as the default name."
|
|
694 |
|
|
695 |
self title: aTitle;
|
|
696 |
initialFileName: initialFileName;
|
|
697 |
hideReadonly;
|
|
698 |
overwritePrompt;
|
|
699 |
addAllFilesFilter;
|
|
700 |
addFilter: '*.txt' description: 'Text Files (*.txt)'.
|
|
701 |
|
|
702 |
self save.
|
|
703 |
! !
|
|
704 |
|
|
705 |
!Win32FileDialog methodsFor:'private'!
|
|
706 |
|
|
707 |
fillStruct
|
|
708 |
"Private - fills the openFileNameStruct"
|
|
709 |
|
|
710 |
| temp |
|
|
711 |
|
8037
|
712 |
temp := fileName "asAsciiZ".
|
|
713 |
lpstrFile := ExternalBytes new:512 withAll:0.
|
8015
|
714 |
lpstrFile
|
|
715 |
replaceBytesFrom:1
|
|
716 |
to:temp size
|
|
717 |
with:temp
|
|
718 |
startingAt:1.
|
|
719 |
|
8037
|
720 |
lpstrFilter := ExternalBytes newNullTerminatedFromString: self filters.
|
8015
|
721 |
|
8037
|
722 |
lpstrInitialDir := ExternalBytes newNullTerminatedFromString: self directory pathName.
|
8015
|
723 |
|
|
724 |
openFileNameStruct
|
|
725 |
lpstrFile: lpstrFile address ;
|
|
726 |
nMaxFile: 512;
|
|
727 |
lpstrFilter: lpstrFilter address ;
|
|
728 |
nFilterIndex: defFilterIndex ; "set by filters"
|
|
729 |
lpstrInitialDir: lpstrInitialDir address.
|
|
730 |
|
|
731 |
( temp := defExtension) notNil ifTrue: [
|
8037
|
732 |
lpstrDefExt := ExternalBytes newNullTerminatedFromString: temp.
|
8015
|
733 |
openFileNameStruct lpstrDefExt: lpstrDefExt address].
|
|
734 |
|
|
735 |
( temp := title ) notNil ifTrue: [
|
8037
|
736 |
lpstrTitle := ExternalBytes newNullTerminatedFromString: temp.
|
8015
|
737 |
openFileNameStruct lpstrTitle: lpstrTitle address ].
|
|
738 |
!
|
|
739 |
|
|
740 |
getFileName
|
|
741 |
"Private - get the filename"
|
|
742 |
|
|
743 |
| directory |
|
|
744 |
|
|
745 |
self style: self flags.
|
|
746 |
fileName := lpstrFile stringAt: 1.
|
|
747 |
directory := fileName copyFrom: 1 to: openFileNameStruct nFileOffset.
|
|
748 |
self directory: directory asFilename.
|
|
749 |
! !
|
|
750 |
|
|
751 |
!Win32FileDialog::OpenFilenameStructure class methodsFor:'accessing'!
|
|
752 |
|
|
753 |
sizeInBytes
|
|
754 |
|
|
755 |
^ 76
|
|
756 |
! !
|
|
757 |
|
|
758 |
!Win32FileDialog::OpenFilenameStructure class methodsFor:'instance creation'!
|
|
759 |
|
|
760 |
new
|
|
761 |
|
|
762 |
^ super new: self sizeInBytes
|
|
763 |
! !
|
|
764 |
|
|
765 |
!Win32FileDialog::OpenFilenameStructure methodsFor:'accessing'!
|
|
766 |
|
|
767 |
flags
|
|
768 |
"Answer the receiver's flags field as a Smalltalk object."
|
|
769 |
|
8037
|
770 |
^ self doubleWordAt: 52+1
|
8015
|
771 |
!
|
|
772 |
|
|
773 |
flags: anObject
|
|
774 |
"Set the receiver's flags field as a Smalltalk object."
|
|
775 |
|
8037
|
776 |
^ self doubleWordAt: 52+1 put: anObject
|
8015
|
777 |
!
|
|
778 |
|
|
779 |
hInstance
|
|
780 |
"Get the receiver's hInstance field."
|
|
781 |
|
8037
|
782 |
^ self doubleWordAt: 8+1
|
8015
|
783 |
!
|
|
784 |
|
|
785 |
hInstance: anObject
|
|
786 |
"Set the receiver's hInstance field to the value of anObject."
|
|
787 |
|
8037
|
788 |
self doubleWordAt: 8+1 put: anObject
|
8015
|
789 |
!
|
|
790 |
|
|
791 |
hwndOwner
|
|
792 |
"Get the receiver's hwndOwner field."
|
|
793 |
|
8037
|
794 |
^ self doubleWordAt: 4+1
|
8015
|
795 |
!
|
|
796 |
|
|
797 |
hwndOwner: anObject
|
|
798 |
"Set the receiver's hwndOwner field to the value of anObject."
|
|
799 |
|
8037
|
800 |
self doubleWordAt: 4+1 put: anObject
|
8015
|
801 |
!
|
|
802 |
|
|
803 |
lCustData
|
|
804 |
"Get the receiver's lCustData field."
|
|
805 |
|
8037
|
806 |
^ self doubleWordAt: 64+1
|
8015
|
807 |
!
|
|
808 |
|
|
809 |
lCustData: anObject
|
|
810 |
"Set the receiver's lCustData field as a Smalltalk object."
|
|
811 |
|
8037
|
812 |
^ self doubleWordAt: 64+1 put: anObject
|
8015
|
813 |
!
|
|
814 |
|
|
815 |
lStructSize
|
|
816 |
"Get the receiver's lStructSize field."
|
|
817 |
|
8037
|
818 |
^ self doubleWordAt: 0+1
|
8015
|
819 |
!
|
|
820 |
|
|
821 |
lStructSize: anObject
|
|
822 |
"Set the receiver's lStructSize field to the value of anObject."
|
|
823 |
|
8037
|
824 |
self doubleWordAt:0+1 put:anObject
|
8015
|
825 |
!
|
|
826 |
|
|
827 |
lpfnHook
|
|
828 |
"Get the receiver's lpfnHook field."
|
|
829 |
|
8037
|
830 |
^ self doubleWordAt: 68+1
|
8015
|
831 |
!
|
|
832 |
|
|
833 |
lpfnHook: anObject
|
|
834 |
"Set the receiver's lpfnHook field to the value of anObject."
|
|
835 |
|
8037
|
836 |
self doubleWordAt: 68+1 put: anObject
|
8015
|
837 |
!
|
|
838 |
|
|
839 |
lpstrCustomFilter
|
|
840 |
"Get the receiver's lpstrCustomFilter field."
|
|
841 |
|
8037
|
842 |
^ self doubleWordAt: 16+1
|
8015
|
843 |
!
|
|
844 |
|
|
845 |
lpstrCustomFilter: anObject
|
|
846 |
"Set the receiver's lpstrCustomFilter field to the value of anObject."
|
|
847 |
|
8037
|
848 |
self doubleWordAt: 16+1 put: anObject
|
8015
|
849 |
!
|
|
850 |
|
|
851 |
lpstrDefExt
|
|
852 |
"Get the receiver's lpstrDefExt field."
|
|
853 |
|
8037
|
854 |
^ self doubleWordAt: 60+1
|
8015
|
855 |
!
|
|
856 |
|
|
857 |
lpstrDefExt: anObject
|
|
858 |
"Set the receiver's lpstrDefExt field to the value of anObject."
|
|
859 |
|
8037
|
860 |
self doubleWordAt: 60+1 put: anObject
|
8015
|
861 |
!
|
|
862 |
|
|
863 |
lpstrFile
|
|
864 |
"Get the receiver's lpstrFile field."
|
|
865 |
|
8037
|
866 |
^ self doubleWordAt: 28+1
|
8015
|
867 |
!
|
|
868 |
|
|
869 |
lpstrFile: anObject
|
|
870 |
"Set the receiver's lpstrFile field to the value of anObject."
|
|
871 |
|
8037
|
872 |
self doubleWordAt: 28+1 put: anObject
|
8015
|
873 |
!
|
|
874 |
|
|
875 |
lpstrFileTitle
|
|
876 |
"Get the receiver's lpstrFileTitle field."
|
|
877 |
|
8037
|
878 |
^ self doubleWordAt: 36+1
|
8015
|
879 |
!
|
|
880 |
|
|
881 |
lpstrFileTitle: anObject
|
|
882 |
"Set the receiver's lpstrFileTitle field to the value of anObject."
|
|
883 |
|
8037
|
884 |
self doubleWordAt: 36+1 put: anObject
|
8015
|
885 |
!
|
|
886 |
|
|
887 |
lpstrFilter
|
|
888 |
"Get the receiver's lpstrFilter field."
|
|
889 |
|
8037
|
890 |
^ self doubleWordAt: 12+1
|
8015
|
891 |
!
|
|
892 |
|
|
893 |
lpstrFilter: anObject
|
|
894 |
"Set the receiver's lpstrFilter field to the value of anObject."
|
|
895 |
|
8037
|
896 |
self doubleWordAt: 12+1 put: anObject
|
8015
|
897 |
!
|
|
898 |
|
|
899 |
lpstrInitialDir
|
|
900 |
"Get the receiver's lpstrInitialDir field."
|
|
901 |
|
8037
|
902 |
^ self doubleWordAt: 44+1
|
8015
|
903 |
!
|
|
904 |
|
|
905 |
lpstrInitialDir: anObject
|
|
906 |
"Set the receiver's lpstrInitialDir field to the value of anObject."
|
|
907 |
|
8037
|
908 |
self doubleWordAt: 44+1 put: anObject
|
8015
|
909 |
!
|
|
910 |
|
|
911 |
lpstrTemplateName
|
|
912 |
"Get the receiver's lpstrTemplateName field."
|
|
913 |
|
8037
|
914 |
^ self doubleWordAt: 72+1
|
8015
|
915 |
!
|
|
916 |
|
|
917 |
lpstrTemplateName: anObject
|
|
918 |
"Set the receiver's lpstrTemplateName field to the value of anObject."
|
|
919 |
|
8037
|
920 |
self doubleWordAt: 72+1 put: anObject
|
8015
|
921 |
!
|
|
922 |
|
|
923 |
lpstrTitle
|
|
924 |
"Get the receiver's lpstrTitle field."
|
|
925 |
|
8037
|
926 |
^ self doubleWordAt: 48+1
|
8015
|
927 |
!
|
|
928 |
|
|
929 |
lpstrTitle: anObject
|
|
930 |
"Set the receiver's lpstrTitle field to the value of anObject."
|
|
931 |
|
8037
|
932 |
self doubleWordAt: 48+1 put: anObject
|
8015
|
933 |
!
|
|
934 |
|
|
935 |
nFileExtension
|
|
936 |
"Get the receiver's nFileExtension field."
|
|
937 |
|
8037
|
938 |
^ self unsignedShortAt: 58+1
|
8015
|
939 |
!
|
|
940 |
|
|
941 |
nFileExtension: anObject
|
|
942 |
"Set the receiver's nFileExtension field to the value of anObject."
|
|
943 |
|
8037
|
944 |
self unsignedShortAt: 58+1 put: anObject
|
8015
|
945 |
!
|
|
946 |
|
|
947 |
nFileOffset
|
|
948 |
"Get the receiver's nFileOffset field."
|
|
949 |
|
8037
|
950 |
^ self unsignedShortAt: 56+1
|
8015
|
951 |
!
|
|
952 |
|
|
953 |
nFileOffset: anObject
|
|
954 |
"Set the receiver's nFileOffset field to the value of anObject."
|
|
955 |
|
8037
|
956 |
self unsignedShortAt: 56+1 put: anObject
|
8015
|
957 |
!
|
|
958 |
|
|
959 |
nFilterIndex
|
|
960 |
"Get the receiver's nFilterIndex field."
|
|
961 |
|
8037
|
962 |
^ self doubleWordAt: 24+1
|
8015
|
963 |
!
|
|
964 |
|
|
965 |
nFilterIndex: anObject
|
|
966 |
"Set the receiver's nFilterIndex field to the value of anObject."
|
|
967 |
|
8037
|
968 |
self doubleWordAt: 24+1 put: anObject
|
8015
|
969 |
!
|
|
970 |
|
|
971 |
nMaxCustFilter
|
|
972 |
"Get the receiver's nMaxCustFilter field."
|
|
973 |
|
8037
|
974 |
^ self doubleWordAt: 20+1
|
8015
|
975 |
!
|
|
976 |
|
|
977 |
nMaxCustFilter: anObject
|
|
978 |
"Set the receiver's nMaxCustFilter field to the value of anObject."
|
|
979 |
|
8037
|
980 |
self doubleWordAt: 20+1 put: anObject
|
8015
|
981 |
!
|
|
982 |
|
|
983 |
nMaxFile
|
|
984 |
"Get the receiver's nMaxFile field."
|
|
985 |
|
8037
|
986 |
^ self doubleWordAt: 32+1
|
8015
|
987 |
!
|
|
988 |
|
|
989 |
nMaxFile: anObject
|
|
990 |
"Set the receiver's nMaxFile field to the value of anObject."
|
|
991 |
|
8037
|
992 |
self doubleWordAt: 32+1 put: anObject
|
8015
|
993 |
!
|
|
994 |
|
|
995 |
nMaxFileTitle
|
|
996 |
"Get the receiver's nMaxFileTitle field."
|
|
997 |
|
8037
|
998 |
^ self doubleWordAt: 40+1
|
8015
|
999 |
!
|
|
1000 |
|
|
1001 |
nMaxFileTitle: anObject
|
|
1002 |
"Set the receiver's nMaxFileTitle field to the value of anObject."
|
|
1003 |
|
8037
|
1004 |
self doubleWordAt: 40+1 put: anObject
|
8015
|
1005 |
!
|
|
1006 |
|
|
1007 |
sizeInBytes
|
|
1008 |
|
|
1009 |
^ self class sizeInBytes
|
|
1010 |
! !
|
|
1011 |
|
|
1012 |
!Win32FileDialog::OpenFilenameStructure methodsFor:'printing'!
|
|
1013 |
|
|
1014 |
printOn: aStream
|
|
1015 |
|
|
1016 |
super printOn: aStream.
|
|
1017 |
aStream cr.
|
|
1018 |
aStream nextPutAll:'flags: ', self flags printString; cr.
|
|
1019 |
aStream nextPutAll:'hInstance: ', self hInstance printString; cr.
|
|
1020 |
aStream nextPutAll:'hwndOwner: ', self hwndOwner printString; cr.
|
|
1021 |
aStream nextPutAll:'lCustData: ', self lCustData printString; cr.
|
|
1022 |
aStream nextPutAll:'lpfnHook: ', self lpfnHook printString; cr.
|
|
1023 |
aStream nextPutAll:'lpstrCustomFilter: ', self lpstrCustomFilter printString; cr.
|
|
1024 |
aStream nextPutAll:'lpstrDefExt: ', self lpstrDefExt printString; cr.
|
|
1025 |
aStream nextPutAll:'lpstrFile: ', self lpstrFile printString; cr.
|
|
1026 |
aStream nextPutAll:'lpstrFileTitle: ', self lpstrFileTitle printString; cr.
|
|
1027 |
aStream nextPutAll:'lpstrFilter: ', self lpstrFilter printString; cr.
|
|
1028 |
aStream nextPutAll:'lpstrInitialDir: ', self lpstrInitialDir printString; cr.
|
|
1029 |
aStream nextPutAll:'lpstrTemplateName: ', self lpstrTemplateName printString; cr.
|
|
1030 |
aStream nextPutAll:'lStructSize: ', self lStructSize printString; cr.
|
|
1031 |
aStream nextPutAll:'nFileExtension: ', self nFileExtension printString; cr.
|
|
1032 |
aStream nextPutAll:'nFileOffset: ', self nFileOffset printString; cr.
|
|
1033 |
aStream nextPutAll:'nFilterIndex: ', self nFilterIndex printString; cr.
|
|
1034 |
aStream nextPutAll:'nMaxCustFilter: ', self nMaxCustFilter printString; cr.
|
|
1035 |
aStream nextPutAll:'nMaxFile: ', self nMaxFile printString; cr.
|
|
1036 |
aStream nextPutAll:'nMaxFileTitle: ', self nMaxFileTitle printString; cr.
|
|
1037 |
! !
|
|
1038 |
|
|
1039 |
!Win32FileDialog class methodsFor:'documentation'!
|
|
1040 |
|
|
1041 |
version
|
8037
|
1042 |
^ '$Header: /cvs/stx/stx/libtool/Win32FileDialog.st,v 1.2 2008-03-31 16:14:43 cg Exp $'
|
8015
|
1043 |
! !
|