3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Alfredo Braunstein
8 * \author Lars Gullik Bjønnes
9 * \author Jean Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
14 * Full author contact details are available in file CREDITS.
22 #include "buffer_funcs.h"
23 #include "bufferparams.h"
24 #include "converter.h"
28 #include "output_plaintext.h"
29 #include "outputparams.h"
30 #include "frontends/Alert.h"
32 #include "support/filetools.h"
34 using lyx::support::AddName;
35 using lyx::support::bformat;
36 using lyx::support::ChangeExtension;
37 using lyx::support::contains;
38 using lyx::support::MakeDisplayPath;
47 vector<string> const Backends(Buffer const & buffer)
50 if (buffer.params().getLyXTextClass().isTeXClassAvailable())
51 v.push_back(BufferFormat(buffer));
59 bool Exporter::Export(Buffer * buffer, string const & format,
60 bool put_in_tempdir, string & result_file)
62 string backend_format;
63 OutputParams runparams;
64 runparams.flavor = OutputParams::LATEX;
65 runparams.linelen = lyxrc.ascii_linelen;
66 vector<string> backends = Backends(*buffer);
67 if (find(backends.begin(), backends.end(), format) == backends.end()) {
68 for (vector<string>::const_iterator it = backends.begin();
69 it != backends.end(); ++it) {
71 converters.getPath(*it, format);
73 runparams.flavor = converters.getFlavor(p);
78 if (backend_format.empty()) {
79 Alert::error(_("Couldn't export file"),
80 bformat(_("No information for exporting the format %1$s."),
81 formats.prettyName(format)));
85 backend_format = format;
87 string filename = buffer->getLatexName(false);
88 if (!buffer->temppath().empty())
89 filename = AddName(buffer->temppath(), filename);
90 filename = ChangeExtension(filename,
91 formats.extension(backend_format));
94 if (backend_format == "text")
95 writeFileAscii(*buffer, filename, runparams);
97 else if (buffer->isLinuxDoc()) {
98 runparams.nice = !put_in_tempdir;
99 buffer->makeLinuxDocFile(filename, runparams);
102 else if (buffer->isDocBook()) {
103 runparams.nice = !put_in_tempdir;
104 buffer->makeDocBookFile(filename, runparams);
107 else if (backend_format == format) {
108 runparams.nice = true;
109 buffer->makeLaTeXFile(filename, string(), runparams);
110 } else if (contains(buffer->filePath(), ' ')) {
111 Alert::error(_("File name error"),
112 _("The directory path to the document cannot contain spaces."));
115 runparams.nice = false;
116 buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
119 string outfile_base = (put_in_tempdir)
120 ? filename : buffer->getLatexName(false);
122 if (!converters.convert(buffer, filename, outfile_base,
123 backend_format, format, result_file))
127 buffer->message(_("Document exported as ")
128 + formats.prettyName(format)
130 + MakeDisplayPath(result_file) +'\'');
135 bool Exporter::Export(Buffer * buffer, string const & format,
139 return Export(buffer, format, put_in_tempdir, result_file);
143 bool Exporter::Preview(Buffer * buffer, string const & format)
146 if (!Export(buffer, format, true, result_file))
148 return formats.view(*buffer, result_file, format);
152 bool Exporter::IsExportable(Buffer const & buffer, string const & format)
154 vector<string> backends = Backends(buffer);
155 for (vector<string>::const_iterator it = backends.begin();
156 it != backends.end(); ++it)
157 if (converters.isReachable(*it, format))
163 vector<Format const *> const
164 Exporter::GetExportableFormats(Buffer const & buffer, bool only_viewable)
166 vector<string> backends = Backends(buffer);
167 vector<Format const *> result =
168 converters.getReachable(backends[0], only_viewable, true);
169 for (vector<string>::const_iterator it = backends.begin() + 1;
170 it != backends.end(); ++it) {
171 vector<Format const *> r =
172 converters.getReachable(*it, only_viewable, false);
173 result.insert(result.end(), r.begin(), r.end());