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"
28 // sorry this is just a temporary hack we should include vspace.h! (Jug)
29 extern const char * stringFromUnit(int);
33 using support::FileFilterList;
34 using support::MakeAbsPath;
35 using support::MakeRelPath;
36 using support::OnlyFilename;
37 using support::OnlyPath;
38 using support::prefixIs;
43 string const browseFile(string const & filename,
45 FileFilterList const & filters,
47 pair<string,string> const & dir1,
48 pair<string,string> const & dir2)
51 if (!filename.empty())
52 lastPath = OnlyPath(filename);
54 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
56 FileDialog::Result result;
60 result = fileDlg.save(lastPath, filters,
61 OnlyFilename(filename));
63 result = fileDlg.open(lastPath, filters,
64 OnlyFilename(filename));
66 if (result.second.empty())
69 lastPath = OnlyPath(result.second);
71 if (result.second.find_first_of("#~$% ") == string::npos)
74 Alert::error(_("Invalid filename"),
75 _("Filename can't contain any "
76 "of these characters:\n"
77 "space, '#', '~', '$' or '%'."));
84 string const browseRelFile(string const & filename,
85 string const & refpath,
87 FileFilterList const & filters,
89 pair<string,string> const & dir1,
90 pair<string,string> const & dir2)
92 string const fname = MakeAbsPath(filename, refpath);
94 string const outname = browseFile(fname, title, filters, save,
96 string const reloutname = MakeRelPath(outname, refpath);
97 if (prefixIs(reloutname, "../"))
104 string const browseDir(string const & pathname,
105 string const & title,
106 pair<string,string> const & dir1,
107 pair<string,string> const & dir2)
109 string lastPath(".");
110 if (!pathname.empty())
111 lastPath = OnlyPath(pathname);
113 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
115 FileDialog::Result result;
118 result = fileDlg.opendir(lastPath,
119 OnlyFilename(pathname));
121 if (result.second.empty())
122 return result.second;
124 lastPath = OnlyPath(result.second);
126 if (result.second.find_first_of("#~$% ") == string::npos)
129 Alert::error(_("Invalid filename"),
130 _("Filename can't contain any "
131 "of these characters:\n"
132 "space, '#', '~', '$' or '%'."));
135 return result.second;
139 vector<string> const getLatexUnits()
141 vector<string> units;
143 for (int i = 0; (str = stringFromUnit(i)); ++i)
144 units.push_back(str);
149 } // namespace frontend