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"
29 string const browseFile(string const & filename,
31 string const & pattern,
33 pair<string,string> const & dir1,
34 pair<string,string> const & dir2)
37 if (!filename.empty())
38 lastPath = OnlyPath(filename);
40 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
42 FileDialog::Result result;
46 result = fileDlg.save(lastPath, pattern,
47 OnlyFilename(filename));
49 result = fileDlg.open(lastPath, pattern,
50 OnlyFilename(filename));
52 if (result.second.empty())
55 lastPath = OnlyPath(result.second);
57 if (result.second.find_first_of("#~$% ") == string::npos)
60 Alert::alert(_("Filename can't contain any "
61 "of these characters:"),
62 _("space, '#', '~', '$' or '%'."));
69 string const browseRelFile(string const & filename,
70 string const & refpath,
72 string const & pattern,
74 pair<string,string> const & dir1,
75 pair<string,string> const & dir2)
77 string const fname = MakeAbsPath(filename, refpath);
79 string const outname = browseFile(fname, title, pattern, save,
81 string const reloutname = MakeRelPath(outname, refpath);
82 if (prefixIs(reloutname, "../"))
89 string const browseDir(string const & pathname,
91 pair<string,string> const & dir1,
92 pair<string,string> const & dir2)
95 if (!pathname.empty())
96 lastPath = OnlyPath(pathname);
98 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
100 FileDialog::Result result;
103 result = fileDlg.opendir(lastPath,
104 OnlyFilename(pathname));
106 if (result.second.empty())
107 return result.second;
109 lastPath = OnlyPath(result.second);
111 if (result.second.find_first_of("#~$% ") == string::npos)
114 Alert::alert(_("directory name can't contain any "
115 "of these characters:"),
116 _("space, '#', '~', '$' or '%'."));
119 return result.second;
123 // sorry this is just a temporary hack we should include vspace.h! (Jug)
124 extern const char * stringFromUnit(int);
126 vector<string> const getLatexUnits()
128 vector<string> units;
130 for (int i = 0; (str = stringFromUnit(i)); ++i)
131 units.push_back(str);