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 "lyx_cb.h" //ShowMessage()
16 #include "support/filetools.h"
18 #include "converter.h"
20 #include "frontends/Alert.h"
22 #include "BufferView.h"
29 bool pdf_mode = false;
31 bool Exporter::Export(Buffer * buffer, string const & format,
32 bool put_in_tempdir, string & result_file)
34 // There are so many different places that this function can be called
35 // from that the removal of auto insets is best done here. This ensures
36 // we always have a clean buffer for inserting errors found during export.
37 BufferView * bv = buffer->getUser();
39 // Remove all error insets
40 if (bv->removeAutoInsets()) {
41 #warning repaint() or update() or nothing ?
47 string backend_format;
48 vector<string> backends = Backends(buffer);
49 if (find(backends.begin(), backends.end(), format) == backends.end()) {
50 for (vector<string>::const_iterator it = backends.begin();
51 it != backends.end(); ++it) {
53 converters.getPath(*it, format);
55 pdf_mode = converters.usePdflatex(p);
60 if (backend_format.empty()) {
61 Alert::error(_("Couldn't export file"),
62 bformat(_("No information for exporting the format %1$s."),
63 formats.prettyName(format)));
67 backend_format = format;
69 string filename = buffer->getLatexName(false);
70 if (!buffer->tmppath.empty())
71 filename = AddName(buffer->tmppath, filename);
72 filename = ChangeExtension(filename,
73 formats.extension(backend_format));
76 if (backend_format == "text")
77 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
79 else if (buffer->isLinuxDoc())
80 buffer->makeLinuxDocFile(filename, !put_in_tempdir);
82 else if (buffer->isDocBook())
83 buffer->makeDocBookFile(filename, !put_in_tempdir);
85 else if (backend_format == format)
86 buffer->makeLaTeXFile(filename, string(), true);
87 else if (contains(buffer->filePath(), ' ')) {
88 Alert::error(_("File name error"),
89 _("The directory path to the document cannot contain spaces."));
92 buffer->makeLaTeXFile(filename, buffer->filePath(), false);
94 string outfile_base = (put_in_tempdir)
95 ? filename : buffer->getLatexName(false);
97 if (!converters.convert(buffer, filename, outfile_base,
98 backend_format, format, result_file))
103 _("Document exported as ")
104 + formats.prettyName(format)
106 + MakeDisplayPath(result_file) +'\'');
111 bool Exporter::Export(Buffer * buffer, string const & format,
115 return Export(buffer, format, put_in_tempdir, result_file);
119 bool Exporter::Preview(Buffer * buffer, string const & format)
122 if (!Export(buffer, format, true, result_file))
124 return formats.view(buffer, result_file, format);
128 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
130 vector<string> backends = Backends(buffer);
131 for (vector<string>::const_iterator it = backends.begin();
132 it != backends.end(); ++it)
133 if (converters.isReachable(*it, format))
139 vector<Format const *> const
140 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
142 vector<string> backends = Backends(buffer);
143 vector<Format const *> result =
144 converters.getReachable(backends[0], only_viewable, true);
145 for (vector<string>::const_iterator it = backends.begin() + 1;
146 it != backends.end(); ++it) {
147 vector<Format const *> r =
148 converters.getReachable(*it, only_viewable, false);
149 result.insert(result.end(), r.begin(), r.end());
155 string const Exporter::BufferFormat(Buffer const * buffer)
157 if (buffer->isLinuxDoc())
159 else if (buffer->isDocBook())
161 else if (buffer->isLiterate())
168 vector<string> const Exporter::Backends(Buffer const * buffer)
171 if (buffer->params.getLyXTextClass().isTeXClassAvailable())
172 v.push_back(BufferFormat(buffer));