3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
15 #include "helper_funcs.h"
19 #include "frontends/FileDialog.h"
21 #include "support/filetools.h"
22 #include "support/lstrings.h"
23 #include "support/package.h"
29 // sorry this is just a temporary hack we should include vspace.h! (Jug)
30 extern const char * stringFromUnit(int);
34 using support::AddName;
35 using support::ChangeExtension;
36 using support::FileFilterList;
37 using support::GetExtension;
38 using support::LibFileSearch;
39 using support::MakeAbsPath;
40 using support::MakeRelPath;
41 using support::OnlyFilename;
42 using support::OnlyPath;
43 using support::package;
44 using support::prefixIs;
49 string const browseFile(string const & filename,
51 FileFilterList const & filters,
53 pair<string,string> const & dir1,
54 pair<string,string> const & dir2)
57 if (!filename.empty())
58 lastPath = OnlyPath(filename);
60 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
62 FileDialog::Result result;
65 result = fileDlg.save(lastPath, filters,
66 OnlyFilename(filename));
68 result = fileDlg.open(lastPath, filters,
69 OnlyFilename(filename));
75 string const browseRelFile(string const & filename,
76 string const & refpath,
78 FileFilterList const & filters,
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, filters, save,
87 string const reloutname = MakeRelPath(outname, refpath);
88 if (prefixIs(reloutname, "../"))
96 string const browseLibFile(string const & dir,
100 FileFilterList const & filters)
102 pair<string,string> const dir1(_("System files|#S#s"),
103 AddName(package().system_support(), dir));
105 pair<string,string> const dir2(_("User files|#U#u"),
106 AddName(package().user_support(), dir));
108 string const result = browseFile(LibFileSearch(dir, name, ext), title,
109 filters, false, dir1, dir2);
111 // remove the extension if it is the default one
113 if (GetExtension(result) == ext)
114 noextresult = ChangeExtension(result, string());
116 noextresult = result;
118 // remove the directory, if it is the default one
119 string const file = OnlyFilename(noextresult);
120 if (LibFileSearch(dir, file, ext) == result)
127 string const browseDir(string const & pathname,
128 string const & title,
129 pair<string,string> const & dir1,
130 pair<string,string> const & dir2)
132 string lastPath(".");
133 if (!pathname.empty())
134 lastPath = OnlyPath(pathname);
136 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
138 FileDialog::Result const result =
139 fileDlg.opendir(lastPath, OnlyFilename(pathname));
141 return result.second;
145 vector<string> const getLatexUnits()
147 vector<string> units;
149 for (int i = 0; (str = stringFromUnit(i)); ++i)
150 units.push_back(str);
155 } // namespace frontend