3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
16 #include "helper_funcs.h"
18 #include "frontends/FileDialog.h"
19 #include "support/filetools.h" // OnlyPath, OnlyFilename
20 #include "support/lstrings.h"
21 #include "gettext.h" // _()
22 #include "frontends/Alert.h"
29 string const browseFile(string const & filename,
31 string const & pattern,
33 pair<string,string> const & dir1,
34 pair<string,string> const & dir2)
37 if (!filename.empty())
38 lastPath = OnlyPath(filename);
40 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
42 FileDialog::Result result;
46 result = fileDlg.save(lastPath, pattern,
47 OnlyFilename(filename));
49 result = fileDlg.open(lastPath, pattern,
50 OnlyFilename(filename));
52 if (result.second.empty())
55 lastPath = OnlyPath(result.second);
57 if (result.second.find_first_of("#~$% ") == string::npos)
60 Alert::error(_("Invalid filename"),
61 _("Filename can't contain any "
62 "of these characters:\n"
63 "space, '#', '~', '$' or '%'."));
70 string const browseRelFile(string const & filename,
71 string const & refpath,
73 string const & pattern,
75 pair<string,string> const & dir1,
76 pair<string,string> const & dir2)
78 string const fname = MakeAbsPath(filename, refpath);
80 string const outname = browseFile(fname, title, pattern, save,
82 string const reloutname = MakeRelPath(outname, refpath);
83 if (prefixIs(reloutname, "../"))
90 string const browseDir(string const & pathname,
92 pair<string,string> const & dir1,
93 pair<string,string> const & dir2)
96 if (!pathname.empty())
97 lastPath = OnlyPath(pathname);
99 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
101 FileDialog::Result result;
104 result = fileDlg.opendir(lastPath,
105 OnlyFilename(pathname));
107 if (result.second.empty())
108 return result.second;
110 lastPath = OnlyPath(result.second);
112 if (result.second.find_first_of("#~$% ") == string::npos)
115 Alert::error(_("Invalid filename"),
116 _("Filename can't contain any "
117 "of these characters:\n"
118 "space, '#', '~', '$' or '%'."));
121 return result.second;
125 // sorry this is just a temporary hack we should include vspace.h! (Jug)
126 extern const char * stringFromUnit(int);
128 vector<string> const getLatexUnits()
130 vector<string> units;
132 for (int i = 0; (str = stringFromUnit(i)); ++i)
133 units.push_back(str);