CEGUICommonFileDialog         A Common File Dialog window for CEGUI

The code included in this page provides a Common File Dialog window for CEGUI. It is Window only, but with some effort it can be modified to Linux (I only own MSVC).
Note by ancestral: Linux version below.
Note: I have removed a direct link to the downloads, which were previous on this page and added the code itself. Use the demo code as an example how the file dialog should be used (follow step 1 through step 4). If you want the zipped version of both the filedialog code and the (working) demo, contact me by means of the Ogre forum (personal message).

The dialog makes use of an input object (CommonFileDialogInput) which configures the dialog and an output object (CommonFileDialogOutput) that contains the result. They can be used as followed:


setHandle (const CEGUI::uint);

The handle is supplied by the calling function. It serves as an identifier that determines the 'caller'.
It will be added to the output object 'CommonFileDialogOutput' after the Ok button in the CommonFileDialog has been pressed,
so the triggered function (registered by means of ´subscribe´) is able to identify who has originally called the dialog.
0 (no handle)

setFileName (const CEGUI::String);

Set the filename to be displayed. Can be used for instance in combination with 'Save as'.
"" (no filename)

setFilter (const CEGUI::String);

Filter for allowed extensions.
"All files|*.*|"

The filter is build according to the common file dialog filter string in Windows. An example
The filter
"HTML Files (*.htm)|*.htm|Active Server Pages (*.asp)|*.asp|Perl Script (*.pl)|*.pl|All files|*.*|"
(don't forget the last | or otherwise the last element will not be parsed)
produces a list that looks like this in the combobox
HTML Files (*.htm)
Active Server Pages (*.asp)
Perl Script (*.pl)
All files

setDefaultExtension (const CEGUI::String);

Sets the default Extension.

setTitle (const CEGUI::String);

Title of the window.
Default title is "Load" in case _bOpenFileDialog is TRUE (setOpenFileDialog (true)has been set)
Default title is "Save as" in case _bOpenFileDialog is FALSE (setOpenFileDialog (false)has been set)

setOpenFileDialog (const bool);

Determines whether the dialog is in "Load" mode or "Save as" mode.
*TRUE for "Load" mode
*FALSE for "Save as" mode

setDoPrompt (const bool);

Determines whether a prompt window will be displayed in certain situations. For instance "are you sure?" in case an file is going to be overwritten.
*TRUE for prompting (are you sure?)
*FALSE for non-prompting

setPromptText (const CEGUI::String);

Define text in the prompt window
Default for Load
"Cannot find the requested file.", if the selected file doesn't exist
Default for Save
"The file already exist. Replace it?", if the seleted file already exists


CEGUI::uint getHandle (void);

Returns the handle, provided by the ´calling´ function

CEGUI::String getFullQualifiedFileName (void);

Returns the full qualified filename. Example

CEGUI::String getDrive (void);

Returns the drive. Example
" OR "D

CEGUI::String getAbsolutePath (void);

Returns the absolute path. Example

CEGUI::String getRelativePath (void);

Returns the path in relation to the current working directory. Example

CEGUI::String getFileName (void);

Returns the filename without the path

CEGUI::CommonFileDialogAction getAction (void);

Determines how the dialog was closed. Three possible actions are distinguished
*getAction() == CEGUI
:ACTION_OK, file dialog was closed with the OK button
*getAction() == CEGUI
:ACTION_CANCEL, file dialog was closed with the Cancel button
*getAction() == CEGUI
:ACTION_WINDOW_CLOSED, file dialog was closed by means of a window closed (the ´X´ in the right upper corner)

CEGUI::bool isFileExisting (void);

Determines whether the selected file really exist.
*TRUE if the file exists
*FALSE if the file doesn't exist

File dialog code + demo code

File dialog code

(Users of VC 8, please note that hash_map has been moved to namespace stdext, so the compiler will complain about the 'hash_map' identifier in CEGUIHashMapTemplates.h if you don't at least add a "using namespace stdext;" line there. Other options are proposed in this thread: http://www.ogre3d.org/phpBB2/viewtopic.php?t=15801)

Linux version:

Windows calls left commented to show the corresponding Linux system calls

File dialog demo code

  • Demo_Gui2.cpp - this works on Linux- uses TaharezLookSkin.scheme instead of TaharezLook2.scheme