MFXUtils Class Reference

#include <MFXUtils.h>


Detailed Description

Some helper functions for FOX.

Definition at line 42 of file MFXUtils.h.


Static Public Member Functions

static FXString assureExtension (const FXString &filename, const FXString &defaultExtension) throw ()
 Corrects missing extension.
static void deleteChildren (FXWindow *w) throw ()
 Deletes all children of the given window.
static FXString getDocumentName (const FXString &filename) throw ()
 Returns the document name.
static FXString getFilename2Write (FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString &currentFolder) throw ()
 Returns the file name to write.
static FXString getTitleText (const FXString &appname, FXString filename="") throw ()
 Returns the title text in dependance to an optional file name.
static FXbool userPermitsOverwritingWhenFileExists (FXWindow *const parent, const FXString &file) throw ()
 Returns true if either the file given by its name does not exist or the user allows overwriting it.

Member Function Documentation

FXString MFXUtils::assureExtension ( const FXString &  filename,
const FXString &  defaultExtension 
) throw () [static]

Corrects missing extension.

At first, the extension is determined. If there is none, the given default extension is appended to the file name/path. Otherwise the file name/path remains as is. The so obtained correct file name is returned.

Parameters:
[in] filename The filename to evaluate
[in] defaultExtension The default extension to use
Returns:
The corrected filename (with extension if no one was given

Definition at line 81 of file MFXUtils.cpp.

00081                                                                                             {
00082     FXString ext = FXPath::extension(filename);
00083     if (ext=="") {
00084         if (filename.rfind('.')==filename.length()-1) {
00085             return filename + defaultExtension;
00086         }
00087         return filename + "." + defaultExtension;
00088     }
00089     return filename;
00090 }

void MFXUtils::deleteChildren ( FXWindow *  w  )  throw () [static]

Deletes all children of the given window.

Parameters:
[in] w The window to delete all of his children

Definition at line 41 of file MFXUtils.cpp.

Referenced by GUIDialog_ViewSettings::rebuildColorMatrices().

00041                                             {
00042     while (w->numChildren()!=0) {
00043         FXWindow *child = w->childAtIndex(0);
00044         delete child;
00045     }
00046 }

FXString MFXUtils::getDocumentName ( const FXString &  filename  )  throw () [static]

Returns the document name.

Removes the path first. Then, returns the part before the first '.' occurence of the so obtained string.

Parameters:
[in] filename The file name (including the path) to obtain the name of
Returns:
The name (without the path and the extension)

Definition at line 65 of file MFXUtils.cpp.

00065                                                           {
00066     FXString file = FXPath::name(filename);
00067     return file.before('.');
00068 }

FXString MFXUtils::getFilename2Write ( FXWindow *  parent,
const FXString &  header,
const FXString &  extension,
FXIcon *  icon,
FXString &  currentFolder 
) throw () [static]

Returns the file name to write.

A somehow complete procedure for determining the file name of a file to write. Builds a file dialog, checks whether a file was chosen, if so, checks whether it's not existing or the user allows to overwrite it etc.

Returns an empty string if the file shall not be created, the filename if it shall.

Parameters:
[in] parent The window needed to display dialogs
[in] header Title of the save-dialog
[in] extension The extension the file should have (must be in the form '.xxx'
[in] icon The icon the dialog should have
[in] currentFolder The string into which the information about the current folder shall be saved
Returns:
The name of the file to write

Definition at line 94 of file MFXUtils.cpp.

Referenced by GUIParameterTracker::onCmdSave(), GUIDialog_GLChosenEditor::onCmdSave(), and GUIDialog_Breakpoints::onCmdSave().

00096                                                                            {
00097     // get the new file name
00098     FXFileDialog opendialog(parent, header);
00099     opendialog.setIcon(icon);
00100     opendialog.setSelectMode(SELECTFILE_ANY);
00101     opendialog.setPatternList("*" + extension);
00102     if (currentFolder.length()!=0) {
00103         opendialog.setDirectory(currentFolder);
00104     }
00105     if (!opendialog.execute()) {
00106         return "";
00107     }
00108     FXString file = assureExtension(opendialog.getFilename(), extension.after('.')).text();
00109     if (!userPermitsOverwritingWhenFileExists(parent, file)) {
00110         return "";
00111     }
00112     currentFolder = opendialog.getDirectory();
00113     return file;
00114 }

FXString MFXUtils::getTitleText ( const FXString &  appname,
FXString  filename = "" 
) throw () [static]

Returns the title text in dependance to an optional file name.

The title is computed as default on windows: The application name only if no file name is given. If a file name is given, it is used without the extension, extended by the application name.

Parameters:
[in] appname The name of the application to return the title of
[in] appname The name of the file loaded by the application
Returns:
The built title

Definition at line 72 of file MFXUtils.cpp.

Referenced by GUIApplicationWindow::closeAllWindows(), GUIApplicationWindow::dependentBuild(), and GUIApplicationWindow::handleEvent_SimulationLoaded().

00072                                                                          {
00073     if (filename.length()==0) {
00074         return appname;
00075     }
00076     return getDocumentName(filename) + " - " + appname;
00077 }

FXbool MFXUtils::userPermitsOverwritingWhenFileExists ( FXWindow *const   parent,
const FXString &  file 
) throw () [static]

Returns true if either the file given by its name does not exist or the user allows overwriting it.

If the named file does not exist, true is returned. Otherwise, a message box is prompted that asks whether the file may be replaced. If the user answers "yes" in this case, true is returned. In any other cases ("no"/"cancel"), false.

Parameters:
[in] parent A parent window needed to prompt the dialog box
[in] file The file to check whether it may be generated
Returns:
Whether the named file may be written

Definition at line 50 of file MFXUtils.cpp.

Referenced by GUIDialog_ViewSettings::onCmdExportSetting(), GUISUMOViewParent::onCmdMakeSnapshot(), GUIDialog_EditViewport::onCmdSave(), and GUIDialog_ViewSettings::onCmdSaveDecals().

00051                                       {
00052     if (!FXStat::exists(file)) {
00053         return TRUE;
00054     }
00055     int answer =
00056         FXMessageBox::question(parent, MBOX_YES_NO, "File Exists", "Overwrite '%s'?", file.text());
00057     if (answer==MBOX_CLICKED_NO) {
00058         return FALSE;
00059     }
00060     return TRUE;
00061 }


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:46 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6