|
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." |
|
308 |
|
309 ^ InitialDirectory ? OperatingSystem getCurrentDirectory asFilename |
|
310 ! |
|
311 |
|
312 directory: directory |
|
313 "Sets the initial directory." |
|
314 |
|
315 | aFilename | |
|
316 |
|
317 directory isNil ifTrue:[^ self.]. |
|
318 aFilename := directory asFilename. |
|
319 aFilename exists ifTrue: [ InitialDirectory := aFilename ]. |
|
320 ! |
|
321 |
|
322 file |
|
323 "Answer the selected file." |
|
324 |
|
325 ^fileName |
|
326 ! |
|
327 |
|
328 fileSpec: aFileSpec |
|
329 "Sets the initial fileName and directory in the File Dialog." |
|
330 |
|
331 | array dir | |
|
332 |
|
333 "SHOULD assign initial fileName and directory separately using #fileName: and #directory" |
|
334 |
|
335 self halt. |
|
336 fileName := aFileSpec. |
|
337 "/ array := Filename splitPath: aFileSpec in: self directory . |
|
338 "/ dir := |
|
339 "/ (( String with: ( array at: 1 ) with: $: ), |
|
340 "/ ( ( array at: 2 ) isEmpty ifTrue: [ '\' ] ifFalse: [ array at: 2 ] )) asFilename. |
|
341 "/ dir exists ifFalse: [ dir := OperatingSystem getCurrentDirectory asFilename ]. |
|
342 "/ |
|
343 "/ self directory: dir. |
|
344 "/ fileName := array at: 3 |
|
345 ! |
|
346 |
|
347 filters |
|
348 "Private - answers a string containing all filters and sets up |
|
349 the defFilterIndex property" |
|
350 |
|
351 | filterString count defaultFilterIndex defaultFilter| |
|
352 |
|
353 smalltalkFileFilters notNil ifTrue: [ |
|
354 self |
|
355 addFilter: '*.cls' description: 'Class Files (*.CLS)'; |
|
356 addFilter: '*.mth' description: 'Method Files (*.MTH)'; |
|
357 addFilter: '*.st' description: 'Smalltalk Files (*.ST)'; |
|
358 addFilter: '*.bnd' description: 'Library Bind Files (*.BND)'; |
|
359 addFilter: '*.map' description: 'Library Map Files (*.MAP)'; |
|
360 addFilter: '*.ini' description: 'Initialization Files (*.INI)'; |
|
361 addFilter: '*.obj' description: 'Object Files (*.OBJ)'; |
|
362 addFilter: '*.log' description: 'Log Files (*.LOG)' |
|
363 ]. |
|
364 |
|
365 defaultFilter := self defFilter. |
|
366 (fileName notEmptyOrNil and:[defaultFilter isNil]) ifTrue:[ |
|
367 |initialFilenameSuffix| |
|
368 initialFilenameSuffix := fileName asFilename suffix. |
|
369 initialFilenameSuffix notEmptyOrNil ifTrue:[ |
|
370 defaultFilter := '*.', initialFilenameSuffix. |
|
371 ]. |
|
372 ]. |
|
373 |
|
374 filterString := String new. |
|
375 count := 0. |
|
376 defaultFilterIndex := 0. |
|
377 filters do: [:assoc | |
|
378 count := count + 1. |
|
379 assoc key = defaultFilter ifTrue: [ defaultFilterIndex := count ]. |
|
380 filterString := filterString, assoc value asAsciiZ, assoc key asAsciiZ |
|
381 ]. |
|
382 |
|
383 self defFilterIndex: defaultFilterIndex. |
|
384 ^filterString |
|
385 ! |
|
386 |
|
387 flags |
|
388 "Private - Answers the dialog box current flags. |
|
389 For compatibility reasons -> use style instead" |
|
390 |
|
391 ^openFileNameStruct flags |
|
392 ! |
|
393 |
|
394 flags: flags |
|
395 |
|
396 "Private - Specifies the dialog box creation flags. |
|
397 Kept for compatibility reasons. Use style: instead" |
|
398 |
|
399 self style: flags |
|
400 ! |
|
401 |
|
402 hideReadonly |
|
403 |
|
404 "Hides the file dialog's Readonly check box. " |
|
405 |
|
406 self style: self style | (self class commonDialogConstantAt: 'OfnHidereadonly') |
|
407 ! |
|
408 |
|
409 initialFileName: filename |
|
410 "Sets the initial fileName string in the File Dialog." |
|
411 |
|
412 | aString | |
|
413 filename isNil ifTrue:[^ self.]. |
|
414 aString := filename. |
|
415 filename isFilename ifTrue:[ aString := filename baseName]. |
|
416 fileName := aString. |
|
417 ! |
|
418 |
|
419 overwritePrompt |
|
420 |
|
421 "Prompt if the user attempts to overwrite a file" |
|
422 |
|
423 self style: self style | (self class commonDialogConstantAt: 'OfnOverwriteprompt') |
|
424 ! |
|
425 |
|
426 owner: ownerWindow |
|
427 |
|
428 "Sets the owner of the Dialog box." |
|
429 |
|
430 |mainView handle| |
|
431 |
|
432 ownerWindow isNil ifTrue:[^ self]. |
|
433 mainView := ownerWindow windowGroup mainView. |
|
434 mainView notNil ifTrue:[ |
|
435 handle := mainView id. |
|
436 handle notNil ifTrue:[ |
|
437 parent := handle address |
|
438 ]. |
|
439 ]. |
|
440 |
|
441 "/ super owner: anOwner. |
|
442 "/ owner isWindow |
|
443 "/ ifTrue: [ parent := owner ] |
|
444 "/ ifFalse: [ parent := owner mainView. |
|
445 "/ parent isWindow ifFalse: [ |
|
446 "/ parent := Notifier findWindow: WindowHandle queryActive ]]. |
|
447 ! |
|
448 |
|
449 pathMustExist |
|
450 |
|
451 "Private & DEFAULT!!." |
|
452 "Changed by K3/EES5-Mg, 29.01.97" |
|
453 |
|
454 self style: self style | 16r800. |
|
455 ! |
|
456 |
|
457 shareAware |
|
458 |
|
459 "Allows a previously opened file to be opened |
|
460 (e.g. change.log)" |
|
461 |
|
462 self style: self style | (self class commonDialogConstantAt: 'OfnShareaware') |
|
463 ! |
|
464 |
|
465 style |
|
466 ^ style ? 8 |
|
467 ! |
|
468 |
|
469 style:something |
|
470 style := something. |
|
471 ! |
|
472 |
|
473 title: aTitle |
|
474 |
|
475 "Specifies the string to be placed in the title bar of the |
|
476 File dialog." |
|
477 |
|
478 title := aTitle |
|
479 ! ! |
|
480 |
|
481 !Win32FileDialog methodsFor:'dapas'! |
|
482 |
|
483 dapasOpenFile |
|
484 |
|
485 "Brings up the default open file dialog " |
|
486 "Changed by K3/EES5-Mg, 28.02.96" |
|
487 |
|
488 self hideReadonly; |
|
489 shareAware; |
|
490 addFilter: '*.*' description: 'All Files (*.*)'. |
|
491 |
|
492 self defFilter isNil ifTrue:[ self defFilter: '*.*']. |
|
493 |
|
494 self open. |
|
495 ! |
|
496 |
|
497 dapasSaveFile |
|
498 |
|
499 "Brings up the file save dialog." |
|
500 "Changed by K3/EES5-Mg, 28.02.96" |
|
501 |
|
502 self hideReadonly; |
|
503 overwritePrompt; |
|
504 addFilter: '*.*' description: 'All Files (*.*)'. |
|
505 |
|
506 self save. |
|
507 ! |
|
508 |
|
509 openFileXml |
|
510 |
|
511 "Brings up the default open file dialog " |
|
512 "Changed by K3/EES5-Mg, 28.02.96" |
|
513 "Changed by GS-EC/EES3 - Bernd Eisenmann, 14.08.03" |
|
514 |
|
515 self hideReadonly; |
|
516 shareAware; |
|
517 addFilter: '*.xml' description: 'XML-Datei'. |
|
518 |
|
519 self defFilter isNil ifTrue:[ self defFilter: '*.*']. |
|
520 |
|
521 self open. |
|
522 ! |
|
523 |
|
524 openFileXmlZip |
|
525 |
|
526 "Brings up the default open file dialog " |
|
527 "Changed by K3/EES5-Mg, 28.02.96" |
|
528 "Changed by GS-EC/EES3 - Bernd Eisenmann, 14.08.03" |
|
529 |
|
530 self hideReadonly; |
|
531 shareAware; |
|
532 addFilter: '*.xml' description: 'XML-Datei'; |
|
533 addFilter: '*.zip' description: 'ZIP-Datei'. |
|
534 |
|
535 self defFilter isNil ifTrue:[ self defFilter: '*.*']. |
|
536 |
|
537 self open. |
|
538 ! ! |
|
539 |
|
540 !Win32FileDialog methodsFor:'initialize & release'! |
|
541 |
|
542 cleanUp |
|
543 "Private - Free openFileNameStruct." |
|
544 |
|
545 self style: self flags. |
|
546 lpstrFilter notNil ifTrue: [lpstrFilter free]. |
|
547 lpstrFile notNil ifTrue: [lpstrFile free]. |
|
548 lpstrInitialDir notNil ifTrue: [lpstrInitialDir free]. |
|
549 lpstrTitle notNil ifTrue: [ lpstrTitle free ]. |
|
550 lpstrDefExt notNil ifTrue: [ lpstrDefExt free ]. |
|
551 |
|
552 openFileNameStruct := nil |
|
553 ! |
|
554 |
|
555 initialize |
|
556 |
|
557 "Private - Initialize openFileNameStruct" |
|
558 |
|
559 super initialize. |
|
560 openFileNameStruct := OpenFilenameStructure new. |
|
561 openFileNameStruct lStructSize: openFileNameStruct sizeInBytes. |
|
562 fileName := String new. |
|
563 filters := OrderedCollection new. |
|
564 self style: (self class commonDialogConstantAt: 'OfnNochangedir') |
|
565 ! ! |
|
566 |
|
567 !Win32FileDialog methodsFor:'opening'! |
|
568 |
|
569 open |
|
570 "Brings up the open file dialog." |
|
571 |
|
572 | error rslt openFileNameStructExternalBytes | |
|
573 |
|
574 [ |
|
575 self fillStruct. |
|
576 parent notNil ifTrue: [ openFileNameStruct hwndOwner: parent.]. |
|
577 style notNil ifTrue: [ openFileNameStruct flags: style ]. |
|
578 |
|
579 openFileNameStructExternalBytes := ExternalBytes from: openFileNameStruct asByteArray. |
|
580 rslt := OperatingSystem getOpenFilename: openFileNameStructExternalBytes address. |
|
581 rslt |
|
582 ifTrue: [ self getFileName ] |
|
583 ifFalse: [ |
|
584 fileName := nil. |
|
585 error := OperatingSystem commDlgExtendedError. |
|
586 ]. |
|
587 ] ensure:[ |
|
588 openFileNameStructExternalBytes free. |
|
589 self cleanUp. |
|
590 ]. |
|
591 |
|
592 (error notNil and:[error ~= 0]) ifTrue: [self error: error ]. |
|
593 ! |
|
594 |
|
595 openFile |
|
596 "Brings up the default open file dialog. The title is set to 'Open File' |
|
597 and fileSpec is set to '*.*'. " |
|
598 |
|
599 self openFile: '*.*'. |
|
600 ! |
|
601 |
|
602 openFile: initialFileName |
|
603 |
|
604 "Brings up the default open file dialog. The title is set to 'Open File' |
|
605 and fileSpec is set to patternString. " |
|
606 |
|
607 self title: 'Open'. |
|
608 initialFileName notNil ifTrue: [ self initialFileName: initialFileName ]. |
|
609 self |
|
610 hideReadonly; |
|
611 shareAware; |
|
612 addAllFilesFilter; |
|
613 addFilter: '*.txt' description: 'Text Files (*.txt)'. |
|
614 Smalltalk isStandAloneApp ifFalse: [ self addSmalltalkFileFilters ]. |
|
615 self defFilter isNil ifTrue:[ self defFilter: '*.*']. |
|
616 self open. |
|
617 ! |
|
618 |
|
619 openFor:ownerWindow |
|
620 save:isSaveDialog |
|
621 title:titleOrNil |
|
622 inDirectory:dirPathOrNil |
|
623 initialAnswer:initialOrNil |
|
624 filter:filterArrayOrNil |
|
625 extension:extensionOrNil |
|
626 |
|
627 self |
|
628 owner: ownerWindow; |
|
629 title: titleOrNil; |
|
630 initialFileName: initialOrNil; |
|
631 defFilter: extensionOrNil. |
|
632 |
|
633 filterArrayOrNil notNil ifTrue:[ |
|
634 filterArrayOrNil do:[:each | self addFilter: each last description: each first]. |
|
635 ]. |
|
636 |
|
637 self addAllFilesFilter. |
|
638 "/ self defFilter isNil ifTrue:[ self defFilter: '*.*']. |
|
639 |
|
640 isSaveDialog |
|
641 ifTrue:[ |
|
642 self hideReadonly; |
|
643 overwritePrompt; |
|
644 save. |
|
645 ] ifFalse:[ |
|
646 self hideReadonly; |
|
647 shareAware; |
|
648 open. |
|
649 ]. |
|
650 |
|
651 ^ self file |
|
652 ! |
|
653 |
|
654 save |
|
655 "Brings up the save file dialog." |
|
656 |
|
657 | error rslt openFileNameStructExternalBytes | |
|
658 |
|
659 [ |
|
660 self fillStruct. |
|
661 parent notNil ifTrue: [ openFileNameStruct hwndOwner: parent.]. |
|
662 style notNil ifTrue: [ openFileNameStruct flags: style ]. |
|
663 |
|
664 openFileNameStructExternalBytes := ExternalBytes from: openFileNameStruct asByteArray. |
|
665 rslt := OperatingSystem getSaveFilename: openFileNameStructExternalBytes address. |
|
666 rslt |
|
667 ifTrue: [ self getFileName ] |
|
668 ifFalse: [ |
|
669 fileName := nil. |
|
670 error := OperatingSystem commDlgExtendedError. |
|
671 ]. |
|
672 ] ensure:[ |
|
673 openFileNameStructExternalBytes free. |
|
674 self cleanUp. |
|
675 ]. |
|
676 |
|
677 (error notNil and:[error ~= 0]) ifTrue: [self error: error ]. |
|
678 ! |
|
679 |
|
680 saveFile: aString |
|
681 |
|
682 "Brings up the save file dialog with aString as the |
|
683 default name. The title is set to 'Save File'. " |
|
684 |
|
685 self saveTitle: 'Save File' fileName: aString |
|
686 ! |
|
687 |
|
688 saveTitle: aTitle fileName: initialFileName |
|
689 |
|
690 "Brings up the file save dialog with aTitle and aString |
|
691 as the default name." |
|
692 |
|
693 self title: aTitle; |
|
694 initialFileName: initialFileName; |
|
695 hideReadonly; |
|
696 overwritePrompt; |
|
697 addAllFilesFilter; |
|
698 addFilter: '*.txt' description: 'Text Files (*.txt)'. |
|
699 |
|
700 self save. |
|
701 ! ! |
|
702 |
|
703 !Win32FileDialog methodsFor:'private'! |
|
704 |
|
705 fillStruct |
|
706 "Private - fills the openFileNameStruct" |
|
707 |
|
708 | temp | |
|
709 |
|
710 temp := fileName asAsciiZ. |
|
711 lpstrFile := ExternalBytes new: 512. |
|
712 lpstrFile |
|
713 replaceBytesFrom:1 |
|
714 to:temp size |
|
715 with:temp |
|
716 startingAt:1. |
|
717 |
|
718 lpstrFilter := ExternalBytes fromString: self filters. |
|
719 |
|
720 lpstrInitialDir := ExternalBytes fromString: self directory pathName. |
|
721 |
|
722 openFileNameStruct |
|
723 lpstrFile: lpstrFile address ; |
|
724 nMaxFile: 512; |
|
725 lpstrFilter: lpstrFilter address ; |
|
726 nFilterIndex: defFilterIndex ; "set by filters" |
|
727 lpstrInitialDir: lpstrInitialDir address. |
|
728 |
|
729 ( temp := defExtension) notNil ifTrue: [ |
|
730 lpstrDefExt := ExternalBytes fromString: temp. |
|
731 openFileNameStruct lpstrDefExt: lpstrDefExt address]. |
|
732 |
|
733 ( temp := title ) notNil ifTrue: [ |
|
734 lpstrTitle := ExternalBytes fromString: temp. |
|
735 openFileNameStruct lpstrTitle: lpstrTitle address ]. |
|
736 ! |
|
737 |
|
738 getFileName |
|
739 "Private - get the filename" |
|
740 |
|
741 | directory | |
|
742 |
|
743 self style: self flags. |
|
744 fileName := lpstrFile stringAt: 1. |
|
745 directory := fileName copyFrom: 1 to: openFileNameStruct nFileOffset. |
|
746 self directory: directory asFilename. |
|
747 ! ! |
|
748 |
|
749 !Win32FileDialog::OpenFilenameStructure class methodsFor:'accessing'! |
|
750 |
|
751 sizeInBytes |
|
752 |
|
753 ^ 76 |
|
754 ! ! |
|
755 |
|
756 !Win32FileDialog::OpenFilenameStructure class methodsFor:'instance creation'! |
|
757 |
|
758 new |
|
759 |
|
760 ^ super new: self sizeInBytes |
|
761 ! ! |
|
762 |
|
763 !Win32FileDialog::OpenFilenameStructure methodsFor:'accessing'! |
|
764 |
|
765 flags |
|
766 "Answer the receiver's flags field as a Smalltalk object." |
|
767 |
|
768 ^ self doubleWordAtOffset: 52 |
|
769 ! |
|
770 |
|
771 flags: anObject |
|
772 "Set the receiver's flags field as a Smalltalk object." |
|
773 |
|
774 ^ self doubleWordAtOffset: 52 put: anObject |
|
775 ! |
|
776 |
|
777 hInstance |
|
778 "Get the receiver's hInstance field." |
|
779 |
|
780 ^ self doubleWordAtOffset: 4 |
|
781 ! |
|
782 |
|
783 hInstance: anObject |
|
784 "Set the receiver's hInstance field to the value of anObject." |
|
785 |
|
786 self doubleWordAtOffset: 8 put: anObject |
|
787 ! |
|
788 |
|
789 hwndOwner |
|
790 "Get the receiver's hwndOwner field." |
|
791 |
|
792 ^ self doubleWordAtOffset: 4 |
|
793 ! |
|
794 |
|
795 hwndOwner: anObject |
|
796 "Set the receiver's hwndOwner field to the value of anObject." |
|
797 |
|
798 self doubleWordAtOffset: 4 put: anObject |
|
799 ! |
|
800 |
|
801 lCustData |
|
802 "Get the receiver's lCustData field." |
|
803 |
|
804 ^ self doubleWordAtOffset: 64 |
|
805 ! |
|
806 |
|
807 lCustData: anObject |
|
808 "Set the receiver's lCustData field as a Smalltalk object." |
|
809 |
|
810 ^ self doubleWordAtOffset: 64 put: anObject |
|
811 ! |
|
812 |
|
813 lStructSize |
|
814 "Get the receiver's lStructSize field." |
|
815 |
|
816 ^ self doubleWordAtOffset: 0 |
|
817 ! |
|
818 |
|
819 lStructSize: anObject |
|
820 "Set the receiver's lStructSize field to the value of anObject." |
|
821 |
|
822 self doubleWordAtOffset: 0 put: anObject |
|
823 ! |
|
824 |
|
825 lpfnHook |
|
826 "Get the receiver's lpfnHook field." |
|
827 |
|
828 ^ self doubleWordAtOffset: 68 |
|
829 ! |
|
830 |
|
831 lpfnHook: anObject |
|
832 "Set the receiver's lpfnHook field to the value of anObject." |
|
833 |
|
834 self doubleWordAtOffset: 68 put: anObject |
|
835 ! |
|
836 |
|
837 lpstrCustomFilter |
|
838 "Get the receiver's lpstrCustomFilter field." |
|
839 |
|
840 ^ self doubleWordAtOffset: 16 |
|
841 ! |
|
842 |
|
843 lpstrCustomFilter: anObject |
|
844 "Set the receiver's lpstrCustomFilter field to the value of anObject." |
|
845 |
|
846 self doubleWordAtOffset: 16 put: anObject |
|
847 ! |
|
848 |
|
849 lpstrDefExt |
|
850 "Get the receiver's lpstrDefExt field." |
|
851 |
|
852 ^ self doubleWordAtOffset: 60 |
|
853 ! |
|
854 |
|
855 lpstrDefExt: anObject |
|
856 "Set the receiver's lpstrDefExt field to the value of anObject." |
|
857 |
|
858 self doubleWordAtOffset: 60 put: anObject |
|
859 ! |
|
860 |
|
861 lpstrFile |
|
862 "Get the receiver's lpstrFile field." |
|
863 |
|
864 ^ self doubleWordAtOffset: 28 |
|
865 ! |
|
866 |
|
867 lpstrFile: anObject |
|
868 "Set the receiver's lpstrFile field to the value of anObject." |
|
869 |
|
870 self doubleWordAtOffset: 28 put: anObject |
|
871 ! |
|
872 |
|
873 lpstrFileTitle |
|
874 "Get the receiver's lpstrFileTitle field." |
|
875 |
|
876 ^ self doubleWordAtOffset: 36 |
|
877 ! |
|
878 |
|
879 lpstrFileTitle: anObject |
|
880 "Set the receiver's lpstrFileTitle field to the value of anObject." |
|
881 |
|
882 self doubleWordAtOffset: 36 put: anObject |
|
883 ! |
|
884 |
|
885 lpstrFilter |
|
886 "Get the receiver's lpstrFilter field." |
|
887 |
|
888 ^ self doubleWordAtOffset: 12 |
|
889 ! |
|
890 |
|
891 lpstrFilter: anObject |
|
892 "Set the receiver's lpstrFilter field to the value of anObject." |
|
893 |
|
894 self doubleWordAtOffset: 12 put: anObject |
|
895 ! |
|
896 |
|
897 lpstrInitialDir |
|
898 "Get the receiver's lpstrInitialDir field." |
|
899 |
|
900 ^ self doubleWordAtOffset: 44 |
|
901 ! |
|
902 |
|
903 lpstrInitialDir: anObject |
|
904 "Set the receiver's lpstrInitialDir field to the value of anObject." |
|
905 |
|
906 self doubleWordAtOffset: 44 put: anObject |
|
907 ! |
|
908 |
|
909 lpstrTemplateName |
|
910 "Get the receiver's lpstrTemplateName field." |
|
911 |
|
912 ^ self doubleWordAtOffset: 72 |
|
913 ! |
|
914 |
|
915 lpstrTemplateName: anObject |
|
916 "Set the receiver's lpstrTemplateName field to the value of anObject." |
|
917 |
|
918 self doubleWordAtOffset: 72 put: anObject |
|
919 ! |
|
920 |
|
921 lpstrTitle |
|
922 "Get the receiver's lpstrTitle field." |
|
923 |
|
924 ^ self doubleWordAtOffset: 48 |
|
925 ! |
|
926 |
|
927 lpstrTitle: anObject |
|
928 "Set the receiver's lpstrTitle field to the value of anObject." |
|
929 |
|
930 self doubleWordAtOffset: 48 put: anObject |
|
931 ! |
|
932 |
|
933 nFileExtension |
|
934 "Get the receiver's nFileExtension field." |
|
935 |
|
936 ^ self unsignedShortAtOffset: 58 |
|
937 ! |
|
938 |
|
939 nFileExtension: anObject |
|
940 "Set the receiver's nFileExtension field to the value of anObject." |
|
941 |
|
942 self unsignedShortAtOffset: 58 put: anObject |
|
943 ! |
|
944 |
|
945 nFileOffset |
|
946 "Get the receiver's nFileOffset field." |
|
947 |
|
948 ^ self unsignedShortAtOffset: 56 |
|
949 ! |
|
950 |
|
951 nFileOffset: anObject |
|
952 "Set the receiver's nFileOffset field to the value of anObject." |
|
953 |
|
954 self unsignedShortAtOffset: 56 put: anObject |
|
955 ! |
|
956 |
|
957 nFilterIndex |
|
958 "Get the receiver's nFilterIndex field." |
|
959 |
|
960 ^ self doubleWordAtOffset: 24 |
|
961 ! |
|
962 |
|
963 nFilterIndex: anObject |
|
964 "Set the receiver's nFilterIndex field to the value of anObject." |
|
965 |
|
966 self doubleWordAtOffset: 24 put: anObject |
|
967 ! |
|
968 |
|
969 nMaxCustFilter |
|
970 "Get the receiver's nMaxCustFilter field." |
|
971 |
|
972 ^ self doubleWordAtOffset: 20 |
|
973 ! |
|
974 |
|
975 nMaxCustFilter: anObject |
|
976 "Set the receiver's nMaxCustFilter field to the value of anObject." |
|
977 |
|
978 self doubleWordAtOffset: 20 put: anObject |
|
979 ! |
|
980 |
|
981 nMaxFile |
|
982 "Get the receiver's nMaxFile field." |
|
983 |
|
984 ^ self doubleWordAtOffset: 32 |
|
985 ! |
|
986 |
|
987 nMaxFile: anObject |
|
988 "Set the receiver's nMaxFile field to the value of anObject." |
|
989 |
|
990 self doubleWordAtOffset: 32 put: anObject |
|
991 ! |
|
992 |
|
993 nMaxFileTitle |
|
994 "Get the receiver's nMaxFileTitle field." |
|
995 |
|
996 ^ self doubleWordAtOffset: 40 |
|
997 ! |
|
998 |
|
999 nMaxFileTitle: anObject |
|
1000 "Set the receiver's nMaxFileTitle field to the value of anObject." |
|
1001 |
|
1002 self doubleWordAtOffset: 40 put: anObject |
|
1003 ! |
|
1004 |
|
1005 sizeInBytes |
|
1006 |
|
1007 ^ self class sizeInBytes |
|
1008 ! ! |
|
1009 |
|
1010 !Win32FileDialog::OpenFilenameStructure methodsFor:'printing'! |
|
1011 |
|
1012 printOn: aStream |
|
1013 |
|
1014 super printOn: aStream. |
|
1015 aStream cr. |
|
1016 aStream nextPutAll:'flags: ', self flags printString; cr. |
|
1017 aStream nextPutAll:'hInstance: ', self hInstance printString; cr. |
|
1018 aStream nextPutAll:'hwndOwner: ', self hwndOwner printString; cr. |
|
1019 aStream nextPutAll:'lCustData: ', self lCustData printString; cr. |
|
1020 aStream nextPutAll:'lpfnHook: ', self lpfnHook printString; cr. |
|
1021 aStream nextPutAll:'lpstrCustomFilter: ', self lpstrCustomFilter printString; cr. |
|
1022 aStream nextPutAll:'lpstrDefExt: ', self lpstrDefExt printString; cr. |
|
1023 aStream nextPutAll:'lpstrFile: ', self lpstrFile printString; cr. |
|
1024 aStream nextPutAll:'lpstrFileTitle: ', self lpstrFileTitle printString; cr. |
|
1025 aStream nextPutAll:'lpstrFilter: ', self lpstrFilter printString; cr. |
|
1026 aStream nextPutAll:'lpstrInitialDir: ', self lpstrInitialDir printString; cr. |
|
1027 aStream nextPutAll:'lpstrTemplateName: ', self lpstrTemplateName printString; cr. |
|
1028 aStream nextPutAll:'lStructSize: ', self lStructSize printString; cr. |
|
1029 aStream nextPutAll:'nFileExtension: ', self nFileExtension printString; cr. |
|
1030 aStream nextPutAll:'nFileOffset: ', self nFileOffset printString; cr. |
|
1031 aStream nextPutAll:'nFilterIndex: ', self nFilterIndex printString; cr. |
|
1032 aStream nextPutAll:'nMaxCustFilter: ', self nMaxCustFilter printString; cr. |
|
1033 aStream nextPutAll:'nMaxFile: ', self nMaxFile printString; cr. |
|
1034 aStream nextPutAll:'nMaxFileTitle: ', self nMaxFileTitle printString; cr. |
|
1035 ! ! |
|
1036 |
|
1037 !Win32FileDialog class methodsFor:'documentation'! |
|
1038 |
|
1039 version |
|
1040 ^ '$Header: /cvs/stx/stx/libtool/Win32FileDialog.st,v 1.1 2008-03-12 16:39:04 fm Exp $' |
|
1041 ! ! |