X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fexporter.C;h=4a779ca0e3ced8c9667fa8bfb4b1c0fbeabe0c91;hb=77866d9e88cbbd1f5f580a7daf15751352792e12;hp=df330952c71c9e0c651df808228c3af8ac3070dd;hpb=29f7055e9527314060b4a74c31a46155ff264a63;p=lyx.git diff --git a/src/exporter.C b/src/exporter.C index df330952c7..4a779ca0e3 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. + * Copyright 1995-2001 The LyX Team. * * ====================================================== */ @@ -14,30 +14,50 @@ #pragma implementation #endif +#include + #include "exporter.h" #include "buffer.h" #include "lyx_cb.h" //ShowMessage() #include "support/filetools.h" #include "lyxrc.h" #include "converter.h" +#include "frontends/Alert.h" +#include "gettext.h" using std::vector; +using std::find; -bool Exporter::Export(Buffer * buffer, string const & format0, +bool Exporter::Export(Buffer * buffer, string const & format, bool put_in_tempdir, string & result_file) { - string format; - string using_format = Converter::SplitFormat(format0, format); - - string backend_format = (format == "text") - ? format : BufferFormat(buffer); - bool only_backend = backend_format == format; + string backend_format; + vector backends = Backends(buffer); + if (find(backends.begin(), backends.end(), format) == backends.end()) { + for (vector::const_iterator it = backends.begin(); + it != backends.end(); ++it) { + Converters::EdgePath p = + converters.getPath(*it, format); + if (!p.empty()) { + lyxrc.pdf_mode = converters.usePdflatex(p); + backend_format = *it; + break; + } + } + if (backend_format.empty()) { + Alert::alert(_("Cannot export file"), + _("No information for exporting to ") + + formats.prettyName(format)); + return false; + } + } else + backend_format = format; string filename = buffer->getLatexName(false); if (!buffer->tmppath.empty()) filename = AddName(buffer->tmppath, filename); filename = ChangeExtension(filename, - formats.Extension(backend_format)); + formats.extension(backend_format)); // Ascii backend if (backend_format == "text") @@ -49,23 +69,26 @@ bool Exporter::Export(Buffer * buffer, string const & format0, else if (buffer->isDocBook()) buffer->makeDocBookFile(filename, true); // LaTeX backend - else if (only_backend) + else if (backend_format == format) buffer->makeLaTeXFile(filename, string(), true); - else - buffer->makeLaTeXFile(filename, buffer->filepath, false); + else if (contains(buffer->filePath(), ' ')) { + Alert::alert(_("Cannot run latex."), + _("The path to the lyx file cannot contain spaces.")); + return false; + } else + buffer->makeLaTeXFile(filename, buffer->filePath(), false); string outfile_base = (put_in_tempdir) ? filename : buffer->getLatexName(false); - if (!Converter::Convert(buffer, filename, outfile_base, - backend_format, format, using_format, - result_file)) + if (!converters.convert(buffer, filename, outfile_base, + backend_format, format, result_file)) return false; if (!put_in_tempdir) ShowMessage(buffer, _("Document exported as ") - + formats.PrettyName(format) + + formats.prettyName(format) + _(" to file `") + MakeDisplayPath(result_file) +'\''); return true; @@ -78,32 +101,38 @@ bool Exporter::Export(Buffer * buffer, string const & format, return Export(buffer, format, put_in_tempdir, result_file); } -bool Exporter::Preview(Buffer * buffer, string const & format0) +bool Exporter::Preview(Buffer * buffer, string const & format) { string result_file; - if (!Export(buffer, format0, true, result_file)) + if (!Export(buffer, format, true, result_file)) return false; - string format; - Converter::SplitFormat(format0, format); - return formats.View(buffer, result_file, format); + return formats.view(buffer, result_file, format); } bool Exporter::IsExportable(Buffer const * buffer, string const & format) { - return format == "text" || - Converter::IsReachable(BufferFormat(buffer), format); + vector backends = Backends(buffer); + for (vector::const_iterator it = backends.begin(); + it != backends.end(); ++it) + if (converters.isReachable(*it, format)) + return true; + return false; } -vector const +vector const Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable) { - vector result = - Converter::GetReachable(BufferFormat(buffer), only_viewable); - Format * format = formats.GetFormat("text"); - if (format && (!only_viewable || !format->viewer.empty())) - result.push_back(FormatPair(format , 0, "")); + vector backends = Backends(buffer); + vector result = + converters.getReachable(backends[0], only_viewable, true); + for (vector::const_iterator it = backends.begin() + 1; + it != backends.end(); ++it) { + vector r = + converters.getReachable(*it, only_viewable, false); + result.insert(result.end(), r.begin(), r.end()); + } return result; } @@ -119,3 +148,11 @@ string const Exporter::BufferFormat(Buffer const * buffer) else return "latex"; } + +vector const Exporter::Backends(Buffer const * buffer) +{ + vector v; + v.push_back(BufferFormat(buffer)); + v.push_back("text"); + return v; +}