3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
15 #include "buffer_funcs.h"
16 #include "support/filetools.h"
18 #include "converter.h"
20 #include "frontends/Alert.h"
25 using namespace lyx::support;
33 vector<string> const Backends(Buffer const * buffer)
36 if (buffer->params.getLyXTextClass().isTeXClassAvailable())
37 v.push_back(BufferFormat(*buffer));
45 bool Exporter::Export(Buffer * buffer, string const & format,
46 bool put_in_tempdir, string & result_file)
48 string backend_format;
49 LatexRunParams runparams;
50 runparams.flavor = LatexRunParams::LATEX;
51 vector<string> backends = Backends(buffer);
52 if (find(backends.begin(), backends.end(), format) == backends.end()) {
53 for (vector<string>::const_iterator it = backends.begin();
54 it != backends.end(); ++it) {
56 converters.getPath(*it, format);
58 if (converters.usePdflatex(p))
59 runparams.flavor = LatexRunParams::PDFLATEX;
64 if (backend_format.empty()) {
65 Alert::error(_("Couldn't export file"),
66 bformat(_("No information for exporting the format %1$s."),
67 formats.prettyName(format)));
71 backend_format = format;
73 string filename = buffer->getLatexName(false);
74 if (!buffer->tmppath.empty())
75 filename = AddName(buffer->tmppath, filename);
76 filename = ChangeExtension(filename,
77 formats.extension(backend_format));
80 if (backend_format == "text")
81 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
83 else if (buffer->isLinuxDoc())
84 buffer->makeLinuxDocFile(filename, !put_in_tempdir);
86 else if (buffer->isDocBook())
87 buffer->makeDocBookFile(filename, !put_in_tempdir);
89 else if (backend_format == format) {
90 runparams.nice = true;
91 buffer->makeLaTeXFile(filename, string(), runparams);
92 } else if (contains(buffer->filePath(), ' ')) {
93 Alert::error(_("File name error"),
94 _("The directory path to the document cannot contain spaces."));
97 runparams.nice = false;
98 buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
101 string outfile_base = (put_in_tempdir)
102 ? filename : buffer->getLatexName(false);
104 if (!converters.convert(buffer, filename, outfile_base,
105 backend_format, format, result_file))
109 buffer->message(_("Document exported as ")
110 + formats.prettyName(format)
112 + MakeDisplayPath(result_file) +'\'');
117 bool Exporter::Export(Buffer * buffer, string const & format,
121 return Export(buffer, format, put_in_tempdir, result_file);
125 bool Exporter::Preview(Buffer * buffer, string const & format)
128 if (!Export(buffer, format, true, result_file))
130 return formats.view(buffer, result_file, format);
134 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
136 vector<string> backends = Backends(buffer);
137 for (vector<string>::const_iterator it = backends.begin();
138 it != backends.end(); ++it)
139 if (converters.isReachable(*it, format))
145 vector<Format const *> const
146 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
148 vector<string> backends = Backends(buffer);
149 vector<Format const *> result =
150 converters.getReachable(backends[0], only_viewable, true);
151 for (vector<string>::const_iterator it = backends.begin() + 1;
152 it != backends.end(); ++it) {
153 vector<Format const *> r =
154 converters.getReachable(*it, only_viewable, false);
155 result.insert(result.end(), r.begin(), r.end());