MFXUtils.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include "MFXUtils.h"
00031
00032 #ifdef CHECK_MEMORY_LEAKS
00033 #include <foreign/nvwa/debug_new.h>
00034 #endif // CHECK_MEMORY_LEAKS
00035
00036
00037
00038
00039
00040 void
00041 MFXUtils::deleteChildren(FXWindow *w) throw() {
00042 while (w->numChildren()!=0) {
00043 FXWindow *child = w->childAtIndex(0);
00044 delete child;
00045 }
00046 }
00047
00048
00049 FXbool
00050 MFXUtils::userPermitsOverwritingWhenFileExists(FXWindow * const parent,
00051 const FXString &file) throw() {
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 }
00062
00063
00064 FXString
00065 MFXUtils::getDocumentName(const FXString &filename) throw() {
00066 FXString file = FXPath::name(filename);
00067 return file.before('.');
00068 }
00069
00070
00071 FXString
00072 MFXUtils::getTitleText(const FXString &appname, FXString filename) throw() {
00073 if (filename.length()==0) {
00074 return appname;
00075 }
00076 return getDocumentName(filename) + " - " + appname;
00077 }
00078
00079
00080 FXString
00081 MFXUtils::assureExtension(const FXString &filename, const FXString &defaultExtension) throw() {
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 }
00091
00092
00093 FXString
00094 MFXUtils::getFilename2Write(FXWindow *parent,
00095 const FXString &header, const FXString &extension,
00096 FXIcon *icon, FXString ¤tFolder) throw() {
00097
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 }
00115
00116
00117
00118
00119
00120