Contents Up Previous Next

wxFileDialog

This class represents the file chooser dialog.

Derived from

wxDialog
wxWindow
wxEvtHandler
wxObject

Include files

<wx/filedlg.h>

Window styles

wxFD_DEFAULT_STYLE Equivalent to wxFD_OPEN.
wxFD_OPEN This is an open dialog; usually this means that the default button's label of the dialog is "Open". Cannot be combined with wxFD_SAVE.
wxFD_SAVE This is a save dialog; usually this means that the default button's label of the dialog is "Save". Cannot be combined with wxFD_OPEN.
wxFD_OVERWRITE_PROMPT For save dialog only: prompt for a confirmation if a file will be overwritten.
wxFD_FILE_MUST_EXIST For open dialog only: the user may only select files that actually exist.
wxFD_MULTIPLE For open dialog only: allows selecting multiple files.
wxFD_CHANGE_DIR Change the current working directory to the directory where the file(s) chosen by the user are.
wxFD_PREVIEW Show the preview of the selected files (currently only supported by wxGTK using GTK+ 2.4 or later).

NB: Previous versions of wxWidgets used wxFD_CHANGE_DIR by default under MS Windows which allowed the program to simply remember the last directory where user selected the files to open/save. This (desired) functionality must be implemented in the program itself now (manually remember the last path used and pass it to the dialog the next time it is called) or by using this flag.

See also

wxFileDialog overview, wxFileSelector

Remarks

Pops up a file selector box. In Windows and GTK2.4+, this is the common file selector dialog. In X, this is a file selector box with somewhat less functionality. The path and filename are distinct elements of a full file pathname. If path is "", the current directory will be used. If filename is "", no default filename will be supplied. The wildcard determines what files are displayed in the file selector, and file extension supplies a type extension for the required filename.

Both the X and Windows versions implement a wildcard filter. Typing a filename containing wildcards (*, ?) in the filename text item, and clicking on Ok, will result in only those files matching the pattern being displayed. The wildcard may be a specification for multiple types of file with a description for each, such as:

 "BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png"
It must be noted that wildcard support in the native Motif file dialog is quite limited: only one alternative is supported, and it is displayed without the descriptive test; "BMP files (*.bmp)|*.bmp'' is displayed as "*.bmp'', and both "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif'' and "Image files|*.bmp;*.gif'' are errors.

Members

wxFileDialog::wxFileDialog
wxFileDialog::~wxFileDialog
wxFileDialog::GetDirectory
wxFileDialog::GetFilename
wxFileDialog::GetFilenames
wxFileDialog::GetFilterIndex
wxFileDialog::GetMessage
wxFileDialog::GetPath
wxFileDialog::GetPaths
wxFileDialog::GetWildcard
wxFileDialog::SetDirectory
wxFileDialog::SetFilename
wxFileDialog::SetFilterIndex
wxFileDialog::SetMessage
wxFileDialog::SetPath
wxFileDialog::SetWildcard
wxFileDialog::ShowModal


wxFileDialog::wxFileDialog

wxFileDialog(wxWindow* parent, const wxString& message = "Choose a file", const wxString& defaultDir = "", const wxString& defaultFile = "", const wxString& wildcard = "*.*", long style = wxFD_DEFAULT_STYLE, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, const wxString& name = "filedlg")

Constructor. Use wxFileDialog::ShowModal to show the dialog.

Parameters

parent

message

defaultDir

defaultFile

wildcard

style

pos

size

name


wxFileDialog::~wxFileDialog

~wxFileDialog()

Destructor.


wxFileDialog::GetDirectory

wxString GetDirectory() const

Returns the default directory.


wxFileDialog::GetFilename

wxString GetFilename() const

Returns the default filename.


wxFileDialog::GetFilenames

void GetFilenames(wxArrayString& filenames) const

Fills the array filenames with the names of the files chosen. This function should only be used with the dialogs which have wxFD_MULTIPLE style, use GetFilename for the others.

Note that under Windows, if the user selects shortcuts, the filenames include paths, since the application cannot determine the full path of each referenced file by appending the directory containing the shortcuts to the filename.


wxFileDialog::GetFilterIndex

int GetFilterIndex() const

Returns the index into the list of filters supplied, optionally, in the wildcard parameter. Before the dialog is shown, this is the index which will be used when the dialog is first displayed. After the dialog is shown, this is the index selected by the user.


wxFileDialog::GetMessage

wxString GetMessage() const

Returns the message that will be displayed on the dialog.


wxFileDialog::GetPath

wxString GetPath() const

Returns the full path (directory and filename) of the selected file.


wxFileDialog::GetPaths

void GetPaths(wxArrayString& paths) const

Fills the array paths with the full paths of the files chosen. This function should only be used with the dialogs which have wxFD_MULTIPLE style, use GetPath for the others.


wxFileDialog::GetWildcard

wxString GetWildcard() const

Returns the file dialog wildcard.


wxFileDialog::SetDirectory

void SetDirectory(const wxString& directory)

Sets the default directory.


wxFileDialog::SetFilename

void SetFilename(const wxString& setfilename)

Sets the default filename.


wxFileDialog::SetFilterIndex

void SetFilterIndex(int filterIndex)

Sets the default filter index, starting from zero.


wxFileDialog::SetMessage

void SetMessage(const wxString& message)

Sets the message that will be displayed on the dialog.


wxFileDialog::SetPath

void SetPath(const wxString& path)

Sets the path (the combined directory and filename that will be returned when the dialog is dismissed).


wxFileDialog::SetWildcard

void SetWildcard(const wxString& wildCard)

Sets the wildcard, which can contain multiple file types, for example:

"BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"

Note that the native Motif dialog has some limitations with respect to wildcards; see the Remarks section above.


wxFileDialog::ShowModal

int ShowModal()

Shows the dialog, returning wxID_OK if the user pressed OK, and wxID_CANCEL otherwise.