![]() | InDesign SDK 20.5 |
#include <SDKFileHelper.h>

Classes | |
| class | Filter |
Public Member Functions | |
| SDKFileOpenChooser () | |
| virtual | ~SDKFileOpenChooser () |
| void | AddFilter (const FileTypeInfoID &fileTypeInfoID, const PMString &filterName) |
| void | AddFilter (const SysOSType &macFileType, const PMString &extension, const PMString &filterName) |
| void | AddAllFiles () |
| void | SetTitle (const PMString &title) |
| void | ShowDialog () |
Public Member Functions inherited from SDKFileHelper | |
| SDKFileHelper (const PMString &path) | |
| SDKFileHelper (const IDFile &file) | |
| virtual | ~SDKFileHelper () |
| bool16 | IsExisting () const |
| bool16 | IsChosen () const |
| PMString | GetPath () const |
| IDFile | GetIDFile () const |
| IDFile | GetAbsoluteFromRelative (const PMString &relativePath) const |
| PMString | GetParentFolderAsString () const |
Protected Types | |
| typedef K2Vector< Filter > | Filters |
Protected Attributes | |
| Filters | fFilters |
| PMString | fTitle |
| bool16 | fIsAllFilesEnabled |
| IOpenFileCmdData::OpenFlags | fOpenFlags |
Additional Inherited Members | |
Static Public Member Functions inherited from SDKFileHelper | |
| static bool16 | isMacPosixPathEnabled () |
Protected Member Functions inherited from SDKFileHelper | |
| SDKFileHelper () | |
| void | initFromString () |
| void | initFromSysFile () |
| void | traceInitializeDiagnostics (int32 e) const |
| PMString | calcDefaultFileName () const |
| void | setChosen (bool16 chsen) |
| void | setIDFile (const IDFile &file) |
| void | setPath (const PMString &path) |
| PMString | absoluteFromRelative (const PMString &folder, const PMString &path) const |
| bool16 | isAbsolutePath (const PMString &path) const |
| bool16 | isUnixPath (const PMString &path) const |
| bool16 | isMacPath (const PMString &path) const |
| bool16 | isWinPath (const PMString &path) const |
| PMString | getMinusLastElement (const PMString &path) const |
| PMString | getMinusFirstElement (const PMString &path) const |
| PMString | getAsMacPath (const PMString &path) const |
| PMString | getAsWinPath (const PMString &path) const |
Provides a mechanism for the user to choose a file to be opened and allows filtering of the files presented, note this class does not actually open the file, it just lets the user choose a file.
If you do not provide file filter, by default, the file open chooser allow you choose either publication files (InDesign documents if you are running under InDesign, InCopy documents if you are running under InCopy) or all files. See code below:
SDKFileOpenChooser fileChooser; fileChooser.ShowDialog(); if (fileChooser.IsChosen()) { IDFile chosenFile = fileChooser.GetIDFile(); }
The code below pops a file open chooser that shows jpg or gif files.
SDKFileOpenChooser fileChooser; fileChooser.AddFilter(kJPEGFileTypeInfoID, "JPEG files(jpg)"); fileChooser.AddFilter(kGIFFileTypeInfoID, "GIFf files(gif)"); fileChooser.ShowDialog(); if (fileChooser.IsChosen()) { IDFile chosenFile = fileChooser.GetIDFile(); }
Note that the filter names, e.g. "JPEG files(jpg)", must either be translatable string keys with a value in a StringTable (or in no translation StringTable). Manully call PMString::SetTranslatable(kFalse) no longer works. You do not need to provide translation for file extensions.
The code below pops a file open chooser for a text or txt file. Note that the FileTypeRegistry uses the extension "text" for text files. In the code below an additional filter is applied that will show files with the extension "txt" aswell.
SDKFileOpenChooser fileChooser; fileChooser.AddFilter(kTEXTFileTypeInfoID, "Text file(text)"); fileChooser.AddFilter('TEXT', "txt", "Text file(txt)"); fileChooser.ShowDialog(); if (fileChooser.IsChosen()) { IDFile chosenFile = fileChooser.GetIDFile(); }
| protected |
List of Filter's.
| SDKFileOpenChooser::SDKFileOpenChooser | ( | ) |
Constructor.
| virtual |
Destructor.
| void SDKFileOpenChooser::AddAllFiles | ( | ) |
Add filter that allows the user to turn off filtering and show all files.
| void SDKFileOpenChooser::AddFilter | ( | const FileTypeInfoID & | fileTypeInfoID, |
| const PMString & | filterName | ||
| ) |
Add filter by FileTypeInfoID, if the FileTypeRegistry knows about the kind of file you want use this call.
| fileTypeInfoID | IN FileTypeRegistry ID, for example kXMLFileTypeInfoID, see ShuksanID.h for available IDs. |
| filterName | IN name displayed in the UI to let the user to apply the filter, (must be translatable strings). |
| void SDKFileOpenChooser::AddFilter | ( | const SysOSType & | macFileType, |
| const PMString & | extension, | ||
| const PMString & | filterName | ||
| ) |
Add filter by macFileType and extension, if you know the specific Mac file type and the Win file extension you want you can use this call. It's worth checking if the FileTypeRegistry has a FileTypeInfoID for the kind of file you want before using this call, then you can avoid hard wiring file type and extension information in your code.
| macFileType | IN Mac file type, 'TEXT' or 'JPEG' for example. |
| extension | IN file extension, "txt" or "jpg" for example. |
| filterName | IN name displayed in the UI to let the user to apply the filter, (must be translatable strings). |
| void SDKFileOpenChooser::SetTitle | ( | const PMString & | title | ) |
Set the title of the dialog.
| title | IN dialog title (translatable string). |
| void SDKFileOpenChooser::ShowDialog | ( | ) |
Pops a file browse dialog to allow the user to choose a file to be opened. If any filters have been specified by the caller (SDKFileOpenChooser::AddFilter, SDKFileOpenChooser::AddAllFiles), the user will be able to apply them to control the files shown in the chooser. Otherwise two default filters will be made available; the first filter will show publication documents (InDesign documents under InDesign, InCopy documents under InCopy); the second filter will show all files.