]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/helper_funcs.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / helper_funcs.C
index aafd5f35377a67be33e5f9acee9cd5903f83f706..ddf9ce9dff8bbcbe7c4ec2c5978a708dcbad2e9f 100644 (file)
 #include "helper_funcs.h"
 
 #include "gettext.h"
+#include "lyxlength.h"
 
-#include "frontends/Alert.h"
 #include "frontends/FileDialog.h"
 
 #include "support/filetools.h"
+#include "support/lstrings.h"
 #include "support/package.h"
 
 using std::pair;
 using std::vector;
 using std::string;
 
-// sorry this is just a temporary hack we should include vspace.h! (Jug)
-extern const char * stringFromUnit(int);
-
 namespace lyx {
 
 using support::AddName;
@@ -61,27 +59,12 @@ string const browseFile(string const & filename,
 
        FileDialog::Result result;
 
-       while (true) {
-               if (save)
-                       result = fileDlg.save(lastPath, filters,
-                               OnlyFilename(filename));
-               else
-                       result = fileDlg.open(lastPath, filters,
-                               OnlyFilename(filename));
-
-               if (result.second.empty())
-                       return result.second;
-
-               lastPath = OnlyPath(result.second);
-
-               if (result.second.find_first_of("#~$% ") == string::npos)
-                       break;
-
-               Alert::error(_("Invalid filename"),
-                       _("Filename can't contain any "
-                       "of these characters:\n"
-                       "space, '#', '~', '$' or '%'."));
-       }
+       if (save)
+               result = fileDlg.save(lastPath, filters,
+                                     OnlyFilename(filename));
+       else
+               result = fileDlg.open(lastPath, filters,
+                                     OnlyFilename(filename));
 
        return result.second;
 }
@@ -121,7 +104,7 @@ string const browseLibFile(string const & dir,
                                       AddName(package().user_support(), dir));
 
        string const result = browseFile(LibFileSearch(dir, name, ext), title,
-                                  filters, false, dir1, dir2);
+                                        filters, false, dir1, dir2);
 
        // remove the extension if it is the default one
        string noextresult;
@@ -140,9 +123,9 @@ string const browseLibFile(string const & dir,
 
 
 string const browseDir(string const & pathname,
-                       string const & title,
-                       pair<string,string> const & dir1,
-                       pair<string,string> const & dir2)
+                      string const & title,
+                      pair<string,string> const & dir1,
+                      pair<string,string> const & dir2)
 {
        string lastPath(".");
        if (!pathname.empty())
@@ -150,25 +133,8 @@ string const browseDir(string const & pathname,
 
        FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
 
-       FileDialog::Result result;
-
-       while (true) {
-               result = fileDlg.opendir(lastPath,
-                               OnlyFilename(pathname));
-
-               if (result.second.empty())
-                       return result.second;
-
-               lastPath = OnlyPath(result.second);
-
-               if (result.second.find_first_of("#~$% ") == string::npos)
-                       break;
-
-               Alert::error(_("Invalid filename"),
-                       _("Filename can't contain any "
-                       "of these characters:\n"
-                       "space, '#', '~', '$' or '%'."));
-       }
+       FileDialog::Result const result =
+               fileDlg.opendir(lastPath, OnlyFilename(pathname));
 
        return result.second;
 }
@@ -177,9 +143,10 @@ string const browseDir(string const & pathname,
 vector<string> const getLatexUnits()
 {
        vector<string> units;
-       char const * str;
-       for (int i = 0; (str = stringFromUnit(i)); ++i)
-           units.push_back(str);
+       int i = 0;
+       char const * str = stringFromUnit(i);
+       for (; str != 0; ++i, str = stringFromUnit(i))
+               units.push_back(str);
 
        return units;
 }