- string format;
- string using_format = Converter::SplitFormat(format0, format);
-
- string filename = buffer->fileName();
- string backend_format = BufferExtension(buffer);
- bool only_backend = backend_format == format;
-
- //string file = buffer->getLatexName(true);
- string file = filename;
- if (!buffer->tmppath.empty())
- file = AddName(buffer->tmppath, file);
- file = ChangeExtension(file, backend_format);
-
- if (buffer->isLinuxDoc())
- buffer->makeLinuxDocFile(file, only_backend);
- else if (only_backend)
- buffer->makeLaTeXFile(file, string(), true);
- else
- buffer->makeLaTeXFile(file, buffer->filepath, false);
-
- bool return_value = Converter::convert(buffer, file, format0);
- if (!return_value)
+ string backend_format;
+ OutputParams runparams;
+ runparams.flavor = OutputParams::LATEX;
+ runparams.linelen = lyxrc.plaintext_linelen;
+ vector<string> backends = Backends(*buffer);
+ if (find(backends.begin(), backends.end(), format) == backends.end()) {
+ // Get shortest path to format
+ Graph::EdgePath path;
+ for (vector<string>::const_iterator it = backends.begin();
+ it != backends.end(); ++it) {
+ Graph::EdgePath p = theConverters().getPath(*it, format);
+ if (!p.empty() && (path.empty() || p.size() < path.size())) {
+ backend_format = *it;
+ path = p;
+ }
+ }
+ if (!path.empty())
+ runparams.flavor = theConverters().getFlavor(path);
+ else {
+ Alert::error(_("Couldn't export file"),
+ bformat(_("No information for exporting the format %1$s."),
+ formats.prettyName(format)));
+ return false;
+ }
+ } else {
+ backend_format = format;
+ // FIXME: Don't hardcode format names here, but use a flag
+ if (backend_format == "pdflatex")
+ runparams.flavor = OutputParams::PDFLATEX;
+ }
+
+ string filename = buffer->getLatexName(false);
+ filename = addName(buffer->temppath(), filename);
+ filename = changeExtension(filename,
+ formats.extension(backend_format));
+
+ // Plain text backend
+ if (backend_format == "text")
+ writePlaintextFile(*buffer, FileName(filename), runparams);
+ // no backend
+ else if (backend_format == "lyx")
+ buffer->writeFile(FileName(filename));
+ // Docbook backend
+ else if (buffer->isDocBook()) {
+ runparams.nice = !put_in_tempdir;
+ buffer->makeDocBookFile(FileName(filename), runparams);
+ }
+ // LaTeX backend
+ else if (backend_format == format) {
+ runparams.nice = true;
+ if (!buffer->makeLaTeXFile(FileName(filename), string(), runparams))
+ return false;
+ } else if (!lyxrc.tex_allows_spaces
+ && contains(buffer->filePath(), ' ')) {
+ Alert::error(_("File name error"),
+ _("The directory path to the document cannot contain spaces."));
+ return false;
+ } else {
+ runparams.nice = false;
+ if (!buffer->makeLaTeXFile(FileName(filename), buffer->filePath(), runparams))
+ return false;
+ }
+
+ string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
+ string const ext = formats.extension(format);
+ FileName const tmp_result_file(changeExtension(filename, ext));
+ bool const success = theConverters().convert(buffer, FileName(filename),
+ tmp_result_file, FileName(buffer->fileName()), backend_format, format,
+ buffer->errorList(error_type));
+ // Emit the signal to show the error list.
+ if (format != backend_format)
+ buffer->errors(error_type);
+ if (!success)