]> git.lyx.org Git - lyx.git/blobdiff - src/exporter.C
Implement os::current_root for native Win32 builds.
[lyx.git] / src / exporter.C
index f91d98385558635e551022a38ea9cc548f68a1bc..ba090ea8af942df6bf915f4985e564bea679da86 100644 (file)
@@ -25,6 +25,7 @@
 #include "format.h"
 #include "gettext.h"
 #include "lyxrc.h"
+#include "mover.h"
 #include "output_plaintext.h"
 #include "outputparams.h"
 #include "frontends/Alert.h"
@@ -86,14 +87,15 @@ enum CopyStatus {
 
 /** copy file \p sourceFile to \p destFile. If \p force is false, the user
  *  will be asked before existing files are overwritten.
- *  \return 
+ *  \return
  *  - SUCCESS if this file got copied
  *  - FORCE   if subsequent calls should not ask for confirmation before
  *            overwriting files anymore.
  *  - CANCEL  if the export should be cancelled
  */
-CopyStatus copyFile(string const & sourceFile, string const & destFile,
-                   bool force)
+CopyStatus copyFile(string const & format,
+                    string const & sourceFile, string const & destFile,
+                    string const & latexFile, bool force)
 {
        CopyStatus ret = force ? FORCE : SUCCESS;
 
@@ -117,7 +119,8 @@ CopyStatus copyFile(string const & sourceFile, string const & destFile,
                }
        }
 
-       if (!lyx::support::copy(sourceFile, destFile))
+       Mover const & mover = movers(format);
+       if (!mover.copy(sourceFile, destFile, latexFile))
                Alert::error(_("Couldn't copy file"),
                             bformat(_("Copying %1$s to %2$s failed."),
                                     MakeDisplayPath(sourceFile),
@@ -136,8 +139,6 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        OutputParams runparams;
        runparams.flavor = OutputParams::LATEX;
        runparams.linelen = lyxrc.ascii_linelen;
-       ExportData exportdata;
-       runparams.exportdata = &exportdata;
        vector<string> backends = Backends(*buffer);
        if (find(backends.begin(), backends.end(), format) == backends.end()) {
                for (vector<string>::const_iterator it = backends.begin();
@@ -200,19 +201,24 @@ bool Exporter::Export(Buffer * buffer, string const & format,
                                              formats.extension(format));
                // We need to copy referenced files (e. g. included graphics
                // if format == "dvi") to the result dir.
-               vector<ExportedFile> const files = exportdata.externalFiles(format);
+               vector<ExportedFile> const files =
+                       runparams.exportdata->externalFiles(format);
                string const dest = OnlyPath(result_file);
                CopyStatus status = SUCCESS;
                for (vector<ExportedFile>::const_iterator it = files.begin();
-                               it != files.end() && status != CANCEL; ++it)
-                       status = copyFile(it->sourceName,
+                               it != files.end() && status != CANCEL; ++it) {
+                       string const fmt =
+                               formats.getFormatFromFile(it->sourceName);
+                       status = copyFile(fmt, it->sourceName,
                                          MakeAbsPath(it->exportName, dest),
-                                         status == FORCE);
+                                         it->exportName, status == FORCE);
+               }
                if (status == CANCEL) {
                        buffer->message(_("Document export cancelled."));
                } else {
                        // Finally copy the main file
-                       status = copyFile(tmp_result_file, result_file,
+                       status = copyFile(format, tmp_result_file,
+                                         result_file, result_file,
                                          status == FORCE);
                        buffer->message(bformat(_("Document exported as %1$s"
                                                  "to file `%2$s'"),
@@ -282,8 +288,8 @@ bool operator==(ExportedFile const & f1, ExportedFile const & f2)
 
 
 void ExportData::addExternalFile(string const & format,
-                                 string const & sourceName,
-                                 string const & exportName)
+                                string const & sourceName,
+                                string const & exportName)
 {
        BOOST_ASSERT(lyx::support::AbsolutePath(sourceName));
 
@@ -297,7 +303,7 @@ void ExportData::addExternalFile(string const & format,
 
 
 void ExportData::addExternalFile(string const & format,
-                                 string const & sourceName)
+                                string const & sourceName)
 {
        addExternalFile(format, sourceName, OnlyFilename(sourceName));
 }