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.
14 #include "helper_funcs.h"
18 #include "frontends/Alert.h"
19 #include "frontends/FileDialog.h"
21 #include "support/filetools.h" // OnlyPath, OnlyFilename
23 using lyx::support::MakeAbsPath;
24 using lyx::support::MakeRelPath;
25 using lyx::support::OnlyFilename;
26 using lyx::support::OnlyPath;
27 using lyx::support::prefixIs;
33 string const browseFile(string const & filename,
35 string const & pattern,
37 pair<string,string> const & dir1,
38 pair<string,string> const & dir2)
41 if (!filename.empty())
42 lastPath = OnlyPath(filename);
44 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
46 FileDialog::Result result;
50 result = fileDlg.save(lastPath, pattern,
51 OnlyFilename(filename));
53 result = fileDlg.open(lastPath, pattern,
54 OnlyFilename(filename));
56 if (result.second.empty())
59 lastPath = OnlyPath(result.second);
61 if (result.second.find_first_of("#~$% ") == string::npos)
64 Alert::error(_("Invalid filename"),
65 _("Filename can't contain any "
66 "of these characters:\n"
67 "space, '#', '~', '$' or '%'."));
74 string const browseRelFile(string const & filename,
75 string const & refpath,
77 string const & pattern,
79 pair<string,string> const & dir1,
80 pair<string,string> const & dir2)
82 string const fname = MakeAbsPath(filename, refpath);
84 string const outname = browseFile(fname, title, pattern, save,
86 string const reloutname = MakeRelPath(outname, refpath);
87 if (prefixIs(reloutname, "../"))
94 string const browseDir(string const & pathname,
96 pair<string,string> const & dir1,
97 pair<string,string> const & dir2)
100 if (!pathname.empty())
101 lastPath = OnlyPath(pathname);
103 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
105 FileDialog::Result result;
108 result = fileDlg.opendir(lastPath,
109 OnlyFilename(pathname));
111 if (result.second.empty())
112 return result.second;
114 lastPath = OnlyPath(result.second);
116 if (result.second.find_first_of("#~$% ") == string::npos)
119 Alert::error(_("Invalid filename"),
120 _("Filename can't contain any "
121 "of these characters:\n"
122 "space, '#', '~', '$' or '%'."));
125 return result.second;
129 // sorry this is just a temporary hack we should include vspace.h! (Jug)
130 extern const char * stringFromUnit(int);
132 vector<string> const getLatexUnits()
134 vector<string> units;
136 for (int i = 0; (str = stringFromUnit(i)); ++i)
137 units.push_back(str);