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
22 #include "support/globbing.h"
24 using lyx::support::FileFilterList;
25 using lyx::support::MakeAbsPath;
26 using lyx::support::MakeRelPath;
27 using lyx::support::OnlyFilename;
28 using lyx::support::OnlyPath;
29 using lyx::support::prefixIs;
36 string const browseFile(string const & filename,
38 FileFilterList const & filters,
40 pair<string,string> const & dir1,
41 pair<string,string> const & dir2)
44 if (!filename.empty())
45 lastPath = OnlyPath(filename);
47 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
49 FileDialog::Result result;
53 result = fileDlg.save(lastPath, filters,
54 OnlyFilename(filename));
56 result = fileDlg.open(lastPath, filters,
57 OnlyFilename(filename));
59 if (result.second.empty())
62 lastPath = OnlyPath(result.second);
64 if (result.second.find_first_of("#~$% ") == string::npos)
67 Alert::error(_("Invalid filename"),
68 _("Filename can't contain any "
69 "of these characters:\n"
70 "space, '#', '~', '$' or '%'."));
77 string const browseRelFile(string const & filename,
78 string const & refpath,
80 FileFilterList const & filters,
82 pair<string,string> const & dir1,
83 pair<string,string> const & dir2)
85 string const fname = MakeAbsPath(filename, refpath);
87 string const outname = browseFile(fname, title, filters, save,
89 string const reloutname = MakeRelPath(outname, refpath);
90 if (prefixIs(reloutname, "../"))
97 string const browseDir(string const & pathname,
99 pair<string,string> const & dir1,
100 pair<string,string> const & dir2)
102 string lastPath(".");
103 if (!pathname.empty())
104 lastPath = OnlyPath(pathname);
106 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
108 FileDialog::Result result;
111 result = fileDlg.opendir(lastPath,
112 OnlyFilename(pathname));
114 if (result.second.empty())
115 return result.second;
117 lastPath = OnlyPath(result.second);
119 if (result.second.find_first_of("#~$% ") == string::npos)
122 Alert::error(_("Invalid filename"),
123 _("Filename can't contain any "
124 "of these characters:\n"
125 "space, '#', '~', '$' or '%'."));
128 return result.second;
132 // sorry this is just a temporary hack we should include vspace.h! (Jug)
133 extern const char * stringFromUnit(int);
135 vector<string> const getLatexUnits()
137 vector<string> units;
139 for (int i = 0; (str = stringFromUnit(i)); ++i)
140 units.push_back(str);