InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SDKFileOpenChooser Class Reference

#include <SDKFileHelper.h>

Inheritance diagram for SDKFileOpenChooser:
SDKFileHelperSDKFileOpenMultipleFileChooser

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< FilterFilters
 

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
 

Detailed Description

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();

}

See Also
ShuksanID.h for available FileTypeInfoID's
FileTypeRegistry for access to FileTypeInfo
IOpenFileDialog
kOpenFileDialogBoss

Member Typedef Documentation

List of Filter's.

Constructor & Destructor Documentation

SDKFileOpenChooser::SDKFileOpenChooser ()

Constructor.

SDKFileOpenChooser::~SDKFileOpenChooser ()
virtual

Destructor.

Member Function Documentation

void SDKFileOpenChooser::AddAllFiles ()

Add filter that allows the user to turn off filtering and show all files.

Postcondition
the user will be able to turn off filtering when SDKFileOpenChooser::ShowDialog is called.
void SDKFileOpenChooser::AddFilter (const FileTypeInfoIDfileTypeInfoID,
const PMStringfilterName 
)

Add filter by FileTypeInfoID, if the FileTypeRegistry knows about the kind of file you want use this call.

Parameters
fileTypeInfoIDIN FileTypeRegistry ID, for example kXMLFileTypeInfoID, see ShuksanID.h for available IDs.
filterNameIN name displayed in the UI to let the user to apply the filter, (must be translatable strings).
Postcondition
the user will be able to apply this filter to control the files shown by SDKFileOpenChooser::ShowDialog.
void SDKFileOpenChooser::AddFilter (const SysOSType & macFileType,
const PMStringextension,
const PMStringfilterName 
)

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.

Parameters
macFileTypeIN Mac file type, 'TEXT' or 'JPEG' for example.
extensionIN file extension, "txt" or "jpg" for example.
filterNameIN name displayed in the UI to let the user to apply the filter, (must be translatable strings).
Postcondition
the user will be able to apply this filter to control the files shown by SDKFileOpenChooser::ShowDialog.
void SDKFileOpenChooser::SetTitle (const PMStringtitle)

Set the title of the dialog.

Parameters
titleIN 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.

Postcondition
SDKFileHelper::IsChosen is kTrue if a file was chosen, kFalse otherwise.
SDKFileHelper::GetIDFile contains the chosen file if SDKFileHelper::IsChosen is kTrue.
SDKFileHelper::GetPath contains the path to the chosen file if SDKFileHelper::IsChosen is kTrue.
See Also
IOpenFileDialog
kOpenFileDialogBoss