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;
34 string const browseFile(string const & filename,
36 string const & pattern,
38 pair<string,string> const & dir1,
39 pair<string,string> const & dir2)
42 if (!filename.empty())
43 lastPath = OnlyPath(filename);
45 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
47 FileDialog::Result result;
51 result = fileDlg.save(lastPath, pattern,
52 OnlyFilename(filename));
54 result = fileDlg.open(lastPath, pattern,
55 OnlyFilename(filename));
57 if (result.second.empty())
60 lastPath = OnlyPath(result.second);
62 if (result.second.find_first_of("#~$% ") == string::npos)
65 Alert::error(_("Invalid filename"),
66 _("Filename can't contain any "
67 "of these characters:\n"
68 "space, '#', '~', '$' or '%'."));
75 string const browseRelFile(string const & filename,
76 string const & refpath,
78 string const & pattern,
80 pair<string,string> const & dir1,
81 pair<string,string> const & dir2)
83 string const fname = MakeAbsPath(filename, refpath);
85 string const outname = browseFile(fname, title, pattern, save,
87 string const reloutname = MakeRelPath(outname, refpath);
88 if (prefixIs(reloutname, "../"))
95 string const browseDir(string const & pathname,
97 pair<string,string> const & dir1,
98 pair<string,string> const & dir2)
100 string lastPath(".");
101 if (!pathname.empty())
102 lastPath = OnlyPath(pathname);
104 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
106 FileDialog::Result result;
109 result = fileDlg.opendir(lastPath,
110 OnlyFilename(pathname));
112 if (result.second.empty())
113 return result.second;
115 lastPath = OnlyPath(result.second);
117 if (result.second.find_first_of("#~$% ") == string::npos)
120 Alert::error(_("Invalid filename"),
121 _("Filename can't contain any "
122 "of these characters:\n"
123 "space, '#', '~', '$' or '%'."));
126 return result.second;
130 // sorry this is just a temporary hack we should include vspace.h! (Jug)
131 extern const char * stringFromUnit(int);
133 vector<string> const getLatexUnits()
135 vector<string> units;
137 for (int i = 0; (str = stringFromUnit(i)); ++i)
138 units.push_back(str);