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 filename = AddName(buffer->temppath(), filename);
89 filename = ChangeExtension(filename,
90 formats.extension(backend_format));
93 if (backend_format == "text")
94 writeFileAscii(*buffer, filename, runparams);
96 else if (buffer->isLinuxDoc()) {
97 runparams.nice = !put_in_tempdir;
98 buffer->makeLinuxDocFile(filename, runparams);
101 else if (buffer->isDocBook()) {
102 runparams.nice = !put_in_tempdir;
103 buffer->makeDocBookFile(filename, runparams);
106 else if (backend_format == format) {
107 runparams.nice = true;
108 buffer->makeLaTeXFile(filename, string(), runparams);
109 } else if (contains(buffer->filePath(), ' ')) {
110 Alert::error(_("File name error"),
111 _("The directory path to the document cannot contain spaces."));
114 runparams.nice = false;
115 buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
118 string outfile_base = (put_in_tempdir)
119 ? filename : buffer->getLatexName(false);
121 if (!converters.convert(buffer, filename, outfile_base,
122 backend_format, format, result_file))
126 buffer->message(_("Document exported as ")
127 + formats.prettyName(format)
129 + MakeDisplayPath(result_file) +'\'');
134 bool Exporter::Export(Buffer * buffer, string const & format,
138 return Export(buffer, format, put_in_tempdir, result_file);
142 bool Exporter::Preview(Buffer * buffer, string const & format)
145 if (!Export(buffer, format, true, result_file))
147 return formats.view(*buffer, result_file, format);
151 bool Exporter::IsExportable(Buffer const & buffer, string const & format)
153 vector<string> backends = Backends(buffer);
154 for (vector<string>::const_iterator it = backends.begin();
155 it != backends.end(); ++it)
156 if (converters.isReachable(*it, format))
162 vector<Format const *> const
163 Exporter::GetExportableFormats(Buffer const & buffer, bool only_viewable)
165 vector<string> backends = Backends(buffer);
166 vector<Format const *> result =
167 converters.getReachable(backends[0], only_viewable, true);
168 for (vector<string>::const_iterator it = backends.begin() + 1;
169 it != backends.end(); ++it) {
170 vector<Format const *> r =
171 converters.getReachable(*it, only_viewable, false);
172 result.insert(result.end(), r.begin(), r.end());