]> git.lyx.org Git - lyx.git/blobdiff - src/exporter.C
The "I want this in now" patch.
[lyx.git] / src / exporter.C
index fda1a6ec0f73f164a75ae52b1aa3352edd5e7650..0e0cb9ede94ad40cb2a90502d2b262ce14dca5c1 100644 (file)
@@ -1,31 +1,28 @@
-/* This file is part of
- * ====================================================== 
- * 
- *           LyX, The Document Processor
- *        
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
+/**
+ * \file exporter.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * ====================================================== */
+ * \author unknown
+ *
+ * Full author contact details are available in file CREDITS
+ */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include <algorithm>
-
 #include "exporter.h"
 #include "buffer.h"
 #include "lyx_cb.h" //ShowMessage()
 #include "support/filetools.h"
 #include "lyxrc.h"
 #include "converter.h"
+#include "format.h"
 #include "frontends/Alert.h"
 #include "gettext.h"
 #include "BufferView.h"
 
+#include <algorithm>
+
 using std::vector;
 using std::find;
 
@@ -36,31 +33,27 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        // from that the removal of auto insets is best done here.  This ensures
        // we always have a clean buffer for inserting errors found during export.
        BufferView * bv = buffer->getUser();
-       if (bv) {
-               // Remove all error insets
-               if (bv->removeAutoInsets()) {
-                       bv->redraw();
-                       bv->fitCursor();
-               }
-       }
 
        string backend_format;
+       LatexRunParams runparams;
+       runparams.flavor = LatexRunParams::LATEX;
        vector<string> backends = Backends(buffer);
        if (find(backends.begin(), backends.end(), format) == backends.end()) {
                for (vector<string>::const_iterator it = backends.begin();
                     it != backends.end(); ++it) {
-                       Converters::EdgePath p =
+                       Graph::EdgePath p =
                                converters.getPath(*it, format);
                        if (!p.empty()) {
-                               lyxrc.pdf_mode = converters.usePdflatex(p);
+                               if (converters.usePdflatex(p))
+                                       runparams.flavor = LatexRunParams::PDFLATEX;
                                backend_format = *it;
                                break;
                        }
                }
                if (backend_format.empty()) {
-                       Alert::alert(_("Cannot export file"),
-                                  _("No information for exporting to ")
-                                  + formats.prettyName(format));
+                       Alert::error(_("Couldn't export file"),
+                               bformat(_("No information for exporting the format %1$s."),
+                                  formats.prettyName(format)));
                        return false;
                }
        } else
@@ -69,7 +62,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        string filename = buffer->getLatexName(false);
        if (!buffer->tmppath.empty())
                filename = AddName(buffer->tmppath, filename);
-       filename = ChangeExtension(filename, 
+       filename = ChangeExtension(filename,
                                   formats.extension(backend_format));
 
        // Ascii backend
@@ -82,14 +75,17 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        else if (buffer->isDocBook())
                buffer->makeDocBookFile(filename, !put_in_tempdir);
        // LaTeX backend
-       else if (backend_format == format)
-               buffer->makeLaTeXFile(filename, string(), true);
-       else if (contains(buffer->filePath(), ' ')) {
-               Alert::alert(_("Cannot run latex."),
-                          _("The path to the lyx file cannot contain spaces."));
+       else if (backend_format == format) {
+               runparams.nice = true;
+               buffer->makeLaTeXFile(filename, string(), runparams);
+       } else if (contains(buffer->filePath(), ' ')) {
+               Alert::error(_("File name error"),
+                          _("The directory path to the document cannot contain spaces."));
                return false;
-       } else
-               buffer->makeLaTeXFile(filename, buffer->filePath(), false);
+       } else {
+               runparams.nice = false;
+               buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
+       }
 
        string outfile_base = (put_in_tempdir)
                ? filename : buffer->getLatexName(false);
@@ -107,6 +103,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        return true;
 }
 
+
 bool Exporter::Export(Buffer * buffer, string const & format,
                      bool put_in_tempdir)
 {
@@ -114,6 +111,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        return Export(buffer, format, put_in_tempdir, result_file);
 }
 
+
 bool Exporter::Preview(Buffer * buffer, string const & format)
 {
        string result_file;
@@ -138,7 +136,7 @@ vector<Format const *> const
 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
 {
        vector<string> backends = Backends(buffer);
-       vector<Format const *> result = 
+       vector<Format const *> result =
                converters.getReachable(backends[0], only_viewable, true);
        for (vector<string>::const_iterator it = backends.begin() + 1;
             it != backends.end(); ++it) {
@@ -162,10 +160,12 @@ string const Exporter::BufferFormat(Buffer const * buffer)
                return "latex";
 }
 
+
 vector<string> const Exporter::Backends(Buffer const * buffer)
 {
        vector<string> v;
-       v.push_back(BufferFormat(buffer));
+       if (buffer->params.getLyXTextClass().isTeXClassAvailable())
+               v.push_back(BufferFormat(buffer));
        v.push_back("text");
        return v;
 }