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
17 #include "lyx_cb.h" //ShowMessage()
18 #include "support/filetools.h"
19 #include "support/BoostFormat.h"
21 #include "converter.h"
23 #include "frontends/Alert.h"
25 #include "BufferView.h"
30 bool pdf_mode = false;
32 bool Exporter::Export(Buffer * buffer, string const & format,
33 bool put_in_tempdir, string & result_file)
35 // There are so many different places that this function can be called
36 // from that the removal of auto insets is best done here. This ensures
37 // we always have a clean buffer for inserting errors found during export.
38 BufferView * bv = buffer->getUser();
40 // Remove all error insets
41 if (bv->removeAutoInsets()) {
42 #warning repaint() or update() or nothing ?
48 string backend_format;
49 vector<string> backends = Backends(buffer);
50 if (find(backends.begin(), backends.end(), format) == backends.end()) {
51 for (vector<string>::const_iterator it = backends.begin();
52 it != backends.end(); ++it) {
54 converters.getPath(*it, format);
56 pdf_mode = converters.usePdflatex(p);
61 if (backend_format.empty()) {
63 // FIXME: better english ...
64 Alert::error(_("Couldn't export file"),
65 boost::io::str(boost::format(_("No information for exporting the format %1$s."))
66 % formats.prettyName(format)));
68 Alert::error(_("Couldn't export file"),
69 _("No information for exporting the format ")
70 + formats.prettyName(format) + ".");
75 backend_format = format;
77 string filename = buffer->getLatexName(false);
78 if (!buffer->tmppath.empty())
79 filename = AddName(buffer->tmppath, filename);
80 filename = ChangeExtension(filename,
81 formats.extension(backend_format));
84 if (backend_format == "text")
85 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
87 else if (buffer->isLinuxDoc())
88 buffer->makeLinuxDocFile(filename, !put_in_tempdir);
90 else if (buffer->isDocBook())
91 buffer->makeDocBookFile(filename, !put_in_tempdir);
93 else if (backend_format == format)
94 buffer->makeLaTeXFile(filename, string(), true);
95 else if (contains(buffer->filePath(), ' ')) {
96 Alert::error(_("File name error"),
97 _("The directory path to the document cannot contain spaces."));
100 buffer->makeLaTeXFile(filename, buffer->filePath(), false);
102 string outfile_base = (put_in_tempdir)
103 ? filename : buffer->getLatexName(false);
105 if (!converters.convert(buffer, filename, outfile_base,
106 backend_format, format, result_file))
111 _("Document exported as ")
112 + formats.prettyName(format)
114 + MakeDisplayPath(result_file) +'\'');
119 bool Exporter::Export(Buffer * buffer, string const & format,
123 return Export(buffer, format, put_in_tempdir, result_file);
127 bool Exporter::Preview(Buffer * buffer, string const & format)
130 if (!Export(buffer, format, true, result_file))
132 return formats.view(buffer, result_file, format);
136 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
138 vector<string> backends = Backends(buffer);
139 for (vector<string>::const_iterator it = backends.begin();
140 it != backends.end(); ++it)
141 if (converters.isReachable(*it, format))
147 vector<Format const *> const
148 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
150 vector<string> backends = Backends(buffer);
151 vector<Format const *> result =
152 converters.getReachable(backends[0], only_viewable, true);
153 for (vector<string>::const_iterator it = backends.begin() + 1;
154 it != backends.end(); ++it) {
155 vector<Format const *> r =
156 converters.getReachable(*it, only_viewable, false);
157 result.insert(result.end(), r.begin(), r.end());
163 string const Exporter::BufferFormat(Buffer const * buffer)
165 if (buffer->isLinuxDoc())
167 else if (buffer->isDocBook())
169 else if (buffer->isLiterate())
176 vector<string> const Exporter::Backends(Buffer const * buffer)
179 v.push_back(BufferFormat(buffer));