The SaveFile class implements the pre-defined file-selection dialog to allow the user to choose a name and location for saving a file. This is a top-level object (i.e. it should not be opened as the child of a window).
To use the dialog, you must first create it using
Under Windows, the style property defines the behavior of the dialog (it is ignored under MacOS). It is an integer (default 0) made up of the sum of:
2 = Disable re-sizing 4 = Warn if the selection would overwrite an existing file 8 = Give error if the user selects a read-only file (Windows only) 16 = Path must exist
Under Windows and Linux, the default property defines the default file extension which will automatically be added if the user enters a filename without an extension. It is not implemented in APLX for MacOS.
The filter property sets one or more filters (file extensions or types which will be allowed). It comprises one or more sets of descriptive text, a | character, and a semi-colon delimited list of supported filters. Multiple filters should be separated by a vertical bar.
Under Windows and Linux, you specify file extensions as file wildcards. For example, the filter 'Text files|*.txt;*.log|All files|*.*' gives the user the choice of selecting "Text files" (in which case extensions .txt and .log are accepted), or "All files" (any extension is accepted).
Under MacOS, you can choose to filter either using file extensions (in which case the syntax is identical to that used for Windows and Linux), or using file types. In the latter case the filters are four-character file types rather than file extensions beginning with the wildcard '*.'. For example: 'Picture files|JPEG;PICT' would display the description "Picture files" to the user, and allow selection of files of type JPEG and PICT. The file type '****' matches all file types. You can also combine both types of filter; for example, 'Text files|*.txt;TEXT' would match files which either have the extension .txt or which are of type TEXT.
The filterindex property determines which of the filters (in index origin 1) is displayed from the drop-down list.
Displaying the dialog
When you are ready to show the dialog, call the Show method. This displays the modal dialog. The user can then select a directory; if the Cancel button is pressed, the Show method returns 0. If the OK button is pressed, the Show method returns 1. You can then read the file property to retrieve the file selected by the user. This will be a character vector.
∇DEMO_SaveFile;VERSION;⎕IO;DLG  ⍝ Sample function demonstrating use of the SaveFile object  DLG←'⎕' ⎕NEW 'SaveFile' ⋄ DLG.caption←'Save demonstration file'  ⍝  ⍝ Are we running on Windows or Mac? The way we specify the file filter  ⍝ is different...  ⎕IO←1  VERSION←'⎕' ⎕WI 'version'  :If VERSION≠0  ⍝ Running under Windows or Linux:  ⍝ Set up default file  :If VERSION=1  DLG.file←'c:\temp.txt'  :Else  DLG.file←'/temp.txt'  :EndIf  ⍝  ⍝ Set up filter  DLG.filter←'Text files (*.txt *.log)|*.txt;*.log|APL Workspaces (*.aws)| *.aws'  :Else  ⍝ Running under MacOS:  ⍝ Set up default file  DLG.file←'temp.txt'  ⍝  ⍝ Set up filter  DLG.filter←'Text files|TEXT|APL Workspaces|AXWS'  :EndIf  ⍝  ⍝ Show the dialog. If user presses Cancel, quit  →(0=DLG.Show)/0  ⍝  ⍝ He pressed OK.  'File selected: ',DLG.file ∇
Copyright © 1996-2010 MicroAPL Ltd