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 Exporter::Export(Buffer * buffer, string const & format,
31 bool put_in_tempdir, string & result_file)
33 // There are so many different places that this function can be called
34 // from that the removal of auto insets is best done here. This ensures
35 // we always have a clean buffer for inserting errors found during export.
36 BufferView * bv = buffer->getUser();
38 // Remove all error insets
39 if (bv->removeAutoInsets()) {
40 #warning repaint() or update() or nothing ?
46 string backend_format;
47 vector<string> backends = Backends(buffer);
48 if (find(backends.begin(), backends.end(), format) == backends.end()) {
49 for (vector<string>::const_iterator it = backends.begin();
50 it != backends.end(); ++it) {
52 converters.getPath(*it, format);
54 lyxrc.pdf_mode = converters.usePdflatex(p);
59 if (backend_format.empty()) {
61 // FIXME: better english ...
62 Alert::error(_("Couldn't export file"),
63 boost::io::str(boost::format(_("No information for exporting the format %1$s."))
64 % formats.prettyName(format)));
66 Alert::error(_("Couldn't export file"),
67 _("No information for exporting the format ")
68 + 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 buffer->makeLaTeXFile(filename, string(), true);
93 else if (contains(buffer->filePath(), ' ')) {
94 Alert::error(_("File name error"),
95 _("The directory path to the document cannot contain spaces."));
98 buffer->makeLaTeXFile(filename, buffer->filePath(), false);
100 string outfile_base = (put_in_tempdir)
101 ? filename : buffer->getLatexName(false);
103 if (!converters.convert(buffer, filename, outfile_base,
104 backend_format, format, result_file))
109 _("Document exported as ")
110 + formats.prettyName(format)
112 + MakeDisplayPath(result_file) +'\'');
117 bool Exporter::Export(Buffer * buffer, string const & format,
121 return Export(buffer, format, put_in_tempdir, result_file);
125 bool Exporter::Preview(Buffer * buffer, string const & format)
128 if (!Export(buffer, format, true, result_file))
130 return formats.view(buffer, result_file, format);
134 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
136 vector<string> backends = Backends(buffer);
137 for (vector<string>::const_iterator it = backends.begin();
138 it != backends.end(); ++it)
139 if (converters.isReachable(*it, format))
145 vector<Format const *> const
146 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
148 vector<string> backends = Backends(buffer);
149 vector<Format const *> result =
150 converters.getReachable(backends[0], only_viewable, true);
151 for (vector<string>::const_iterator it = backends.begin() + 1;
152 it != backends.end(); ++it) {
153 vector<Format const *> r =
154 converters.getReachable(*it, only_viewable, false);
155 result.insert(result.end(), r.begin(), r.end());
161 string const Exporter::BufferFormat(Buffer const * buffer)
163 if (buffer->isLinuxDoc())
165 else if (buffer->isDocBook())
167 else if (buffer->isLiterate())
174 vector<string> const Exporter::Backends(Buffer const * buffer)
177 v.push_back(BufferFormat(buffer));