History: CEGUICommonFileDialog
Source of version: 3
Copy to clipboard
{maketoc}
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:
!CommonFileDialogInput
!!setHandle (const CEGUI::uint);
{DL()}
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.
''Default: 0 (no handle)''
{DL}
!!setFileName (const CEGUI::String);
{DL()}
Set the filename to be displayed. Can be used for instance in combination with 'Save as'.
''Default: "" (no filename)''
{DL}
!!setFilter (const CEGUI::String);
{DL()}
Filter for allowed extensions.
''Default: "All files|*.*|"''
{DL}
{DL()}
The filter is build according to the common file dialog filter string in Windows. An example: The filter
{DL()}
__"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)
{DL}
produces a list that looks like this in the combobox:
{DL()}
__HTML Files (*.htm)__
__Active Server Pages (*.asp)__
__Perl Script (*.pl)__
__All files__
{DL}
{DL}
!!setDefaultExtension (const CEGUI::String);
{DL()}
Sets the default Extension.
''Default: *.*''
{DL}
!!setTitle (const CEGUI::String);
{DL()}
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)''
{DL}
!!setOpenFileDialog (const bool);
{DL()}
Determines whether the dialog is in "Load" mode or "Save as" mode.
*TRUE for "Load" mode
*FALSE for "Save as" mode
''Default: TRUE''
{DL}
!!setDoPrompt (const bool);
{DL()}
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
''Default: TRUE''
{DL}
!!setPromptText (const CEGUI::String);
{DL()}
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''
{DL}
!CommonFileDialogOutput
!!CEGUI::uint getHandle (void);
{DL()}
Returns the handle, provided by the ´calling´ function
{DL}
!!CEGUI::String getFullQualifiedFileName (void);
{DL()}
Returns the full qualified filename. Example:
{DL()}
"C:\\TEMP\\DOCUMENT\\EXAMPLE.DOC"
{DL}
{DL}
!!CEGUI::String getDrive (void);
{DL()}
Returns the drive. Example:
{DL()}
"C:" OR "D:"
{DL}
{DL}
!!CEGUI::String getAbsolutePath (void);
{DL()}
Returns the absolute path. Example:
{DL()}
"C:\\TEMP\\DOCUMENT"
{DL}
{DL}
!!CEGUI::String getRelativePath (void);
{DL()}
Returns the path in relation to the current working directory. Example:
{DL()}
"..\\..\\MEDIA\\TEXTURES"
{DL}
{DL}
!!CEGUI::String getFileName (void);
{DL()}
Returns the filename without the path
{DL}
!!CEGUI::CommonFileDialogAction getAction (void);
{DL()}
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)
{DL}
!!CEGUI::bool isFileExisting (void);
{DL()}
Determines whether the selected file really exist.
*TRUE if the file exists
*FALSE if the file doesn't exist
{DL}
!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])
* ((File dialog code CEGUICommonFileDialog.h|CEGUICommonFileDialog.h))
* ((File dialog code CEGUIHashMapTemplates.h|CEGUIHashMapTemplates.h))
* ((File dialog code CEGUISingletonX.h|CEGUISingletonX.h))
* ((File dialog code CEGUICommonFileDialog.cpp|CEGUICommonFileDialog.cpp))
* ((File dialog code CommonFileDialog.layout|CommonFileDialog.layout)) -- contains both old (CEGUI <= 0.4.x) and new (CEGUI >= 0.5.x) unified dimension formats
__Linux version: __
Windows calls left commented to show the corresponding Linux system calls
* ((File dialog code CEGUICommonFileDialog.h for Linux|CEGUICommonFileDialog.h))
* ((File dialog code CEGUIHashMapTemplates.h for Linux|CEGUIHashMapTemplates.h))
* ((File dialog code CEGUISingletonX.h for Linux|CEGUISingletonX.h))
* ((File dialog code CEGUICommonFileDialog.cpp for Linux|CEGUICommonFileDialog.cpp))
* ((File dialog code ogregui2.layout|ogregui2.layout))
!!File dialog demo code
* ((File dialog demo code Demo Gui2.cpp|Demo_Gui2.cpp))
* ((File dialog demo code Demo Gui2 for Linux.cpp|Demo_Gui2.cpp)) - this works on Linux- uses TaharezLookSkin.scheme instead of TaharezLook2.scheme