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"
27 using namespace lyx::support;
35 vector<string> const Backends(Buffer const * buffer)
38 if (buffer->params.getLyXTextClass().isTeXClassAvailable())
39 v.push_back(BufferFormat(*buffer));
47 bool Exporter::Export(Buffer * buffer, string const & format,
48 bool put_in_tempdir, string & result_file)
50 string backend_format;
51 LatexRunParams runparams;
52 runparams.flavor = LatexRunParams::LATEX;
53 vector<string> backends = Backends(buffer);
54 if (find(backends.begin(), backends.end(), format) == backends.end()) {
55 for (vector<string>::const_iterator it = backends.begin();
56 it != backends.end(); ++it) {
58 converters.getPath(*it, format);
60 if (converters.usePdflatex(p))
61 runparams.flavor = LatexRunParams::PDFLATEX;
66 if (backend_format.empty()) {
67 Alert::error(_("Couldn't export file"),
68 bformat(_("No information for exporting the format %1$s."),
69 formats.prettyName(format)));
73 backend_format = format;
75 string filename = buffer->getLatexName(false);
76 if (!buffer->tmppath.empty())
77 filename = AddName(buffer->tmppath, filename);
78 filename = ChangeExtension(filename,
79 formats.extension(backend_format));
82 if (backend_format == "text")
83 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
85 else if (buffer->isLinuxDoc())
86 buffer->makeLinuxDocFile(filename, !put_in_tempdir);
88 else if (buffer->isDocBook())
89 buffer->makeDocBookFile(filename, !put_in_tempdir);
91 else if (backend_format == format) {
92 runparams.nice = true;
93 buffer->makeLaTeXFile(filename, string(), runparams);
94 } else if (contains(buffer->filePath(), ' ')) {
95 Alert::error(_("File name error"),
96 _("The directory path to the document cannot contain spaces."));
99 runparams.nice = false;
100 buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
103 string outfile_base = (put_in_tempdir)
104 ? filename : buffer->getLatexName(false);
106 if (!converters.convert(buffer, filename, outfile_base,
107 backend_format, format, result_file))
112 _("Document exported as ")
113 + formats.prettyName(format)
115 + MakeDisplayPath(result_file) +'\'');
120 bool Exporter::Export(Buffer * buffer, string const & format,
124 return Export(buffer, format, put_in_tempdir, result_file);
128 bool Exporter::Preview(Buffer * buffer, string const & format)
131 if (!Export(buffer, format, true, result_file))
133 return formats.view(buffer, result_file, format);
137 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
139 vector<string> backends = Backends(buffer);
140 for (vector<string>::const_iterator it = backends.begin();
141 it != backends.end(); ++it)
142 if (converters.isReachable(*it, format))
148 vector<Format const *> const
149 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
151 vector<string> backends = Backends(buffer);
152 vector<Format const *> result =
153 converters.getReachable(backends[0], only_viewable, true);
154 for (vector<string>::const_iterator it = backends.begin() + 1;
155 it != backends.end(); ++it) {
156 vector<Format const *> r =
157 converters.getReachable(*it, only_viewable, false);
158 result.insert(result.end(), r.begin(), r.end());