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"
24 using namespace lyx::support;
31 string const browseFile(string const & filename,
33 string const & pattern,
35 pair<string,string> const & dir1,
36 pair<string,string> const & dir2)
39 if (!filename.empty())
40 lastPath = OnlyPath(filename);
42 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
44 FileDialog::Result result;
48 result = fileDlg.save(lastPath, pattern,
49 OnlyFilename(filename));
51 result = fileDlg.open(lastPath, pattern,
52 OnlyFilename(filename));
54 if (result.second.empty())
57 lastPath = OnlyPath(result.second);
59 if (result.second.find_first_of("#~$% ") == string::npos)
62 Alert::error(_("Invalid filename"),
63 _("Filename can't contain any "
64 "of these characters:\n"
65 "space, '#', '~', '$' or '%'."));
72 string const browseRelFile(string const & filename,
73 string const & refpath,
75 string const & pattern,
77 pair<string,string> const & dir1,
78 pair<string,string> const & dir2)
80 string const fname = MakeAbsPath(filename, refpath);
82 string const outname = browseFile(fname, title, pattern, save,
84 string const reloutname = MakeRelPath(outname, refpath);
85 if (prefixIs(reloutname, "../"))
92 string const browseDir(string const & pathname,
94 pair<string,string> const & dir1,
95 pair<string,string> const & dir2)
98 if (!pathname.empty())
99 lastPath = OnlyPath(pathname);
101 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
103 FileDialog::Result result;
106 result = fileDlg.opendir(lastPath,
107 OnlyFilename(pathname));
109 if (result.second.empty())
110 return result.second;
112 lastPath = OnlyPath(result.second);
114 if (result.second.find_first_of("#~$% ") == string::npos)
117 Alert::error(_("Invalid filename"),
118 _("Filename can't contain any "
119 "of these characters:\n"
120 "space, '#', '~', '$' or '%'."));
123 return result.second;
127 // sorry this is just a temporary hack we should include vspace.h! (Jug)
128 extern const char * stringFromUnit(int);
130 vector<string> const getLatexUnits()
132 vector<string> units;
134 for (int i = 0; (str = stringFromUnit(i)); ++i)
135 units.push_back(str);