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 "lyx_cb.h" //ShowMessage()
17 #include "support/filetools.h"
19 #include "converter.h"
21 #include "frontends/Alert.h"
23 #include "BufferView.h"
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))
110 _("Document exported as ")
111 + formats.prettyName(format)
113 + MakeDisplayPath(result_file) +'\'');
118 bool Exporter::Export(Buffer * buffer, string const & format,
122 return Export(buffer, format, put_in_tempdir, result_file);
126 bool Exporter::Preview(Buffer * buffer, string const & format)
129 if (!Export(buffer, format, true, result_file))
131 return formats.view(buffer, result_file, format);
135 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
137 vector<string> backends = Backends(buffer);
138 for (vector<string>::const_iterator it = backends.begin();
139 it != backends.end(); ++it)
140 if (converters.isReachable(*it, format))
146 vector<Format const *> const
147 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
149 vector<string> backends = Backends(buffer);
150 vector<Format const *> result =
151 converters.getReachable(backends[0], only_viewable, true);
152 for (vector<string>::const_iterator it = backends.begin() + 1;
153 it != backends.end(); ++it) {
154 vector<Format const *> r =
155 converters.getReachable(*it, only_viewable, false);
156 result.insert(result.end(), r.begin(), r.end());