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"
18 #include "lyxlength.h"
20 #include "frontends/FileDialog.h"
22 #include "support/filetools.h"
23 #include "support/lstrings.h"
24 #include "support/package.h"
32 using support::AddName;
33 using support::ChangeExtension;
34 using support::FileFilterList;
35 using support::GetExtension;
36 using support::LibFileSearch;
37 using support::MakeAbsPath;
38 using support::MakeRelPath;
39 using support::OnlyFilename;
40 using support::OnlyPath;
41 using support::package;
42 using support::prefixIs;
47 string const browseFile(string const & filename,
49 FileFilterList const & filters,
51 pair<string,string> const & dir1,
52 pair<string,string> const & dir2)
55 if (!filename.empty())
56 lastPath = OnlyPath(filename);
58 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
60 FileDialog::Result result;
63 result = fileDlg.save(lastPath, filters,
64 OnlyFilename(filename));
66 result = fileDlg.open(lastPath, filters,
67 OnlyFilename(filename));
73 string const browseRelFile(string const & filename,
74 string const & refpath,
76 FileFilterList const & filters,
78 pair<string,string> const & dir1,
79 pair<string,string> const & dir2)
81 string const fname = MakeAbsPath(filename, refpath);
83 string const outname = browseFile(fname, title, filters, save,
85 string const reloutname = MakeRelPath(outname, refpath);
86 if (prefixIs(reloutname, "../"))
94 string const browseLibFile(string const & dir,
98 FileFilterList const & filters)
100 pair<string,string> const dir1(_("System files|#S#s"),
101 AddName(package().system_support(), dir));
103 pair<string,string> const dir2(_("User files|#U#u"),
104 AddName(package().user_support(), dir));
106 string const result = browseFile(LibFileSearch(dir, name, ext), title,
107 filters, false, dir1, dir2);
109 // remove the extension if it is the default one
111 if (GetExtension(result) == ext)
112 noextresult = ChangeExtension(result, string());
114 noextresult = result;
116 // remove the directory, if it is the default one
117 string const file = OnlyFilename(noextresult);
118 if (LibFileSearch(dir, file, ext) == result)
125 string const browseDir(string const & pathname,
126 string const & title,
127 pair<string,string> const & dir1,
128 pair<string,string> const & dir2)
130 string lastPath(".");
131 if (!pathname.empty())
132 lastPath = OnlyPath(pathname);
134 FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
136 FileDialog::Result const result =
137 fileDlg.opendir(lastPath, OnlyFilename(pathname));
139 return result.second;
143 vector<string> const getLatexUnits()
145 vector<string> units;
147 char const * str = stringFromUnit(i);
148 for (; str != 0; ++i, str = stringFromUnit(i))
149 units.push_back(str);
154 } // namespace frontend