diff --git a/lib/ChangeLog b/lib/ChangeLog index bcb28bbe79..782e1a6d84 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2004-06-01 Georg Baum + + * external_templates: add ReferencedFile commands where appropriate + 2004-05-31 Georg Baum * Makefile.am: remove compiled python files diff --git a/lib/external_templates b/lib/external_templates index 6154609fee..651d7e6a58 100644 --- a/lib/external_templates +++ b/lib/external_templates @@ -69,6 +69,8 @@ Template RasterImage UpdateFormat eps UpdateResult "$$AbsPath$$Basename.eps" Requirement "graphicx" + ReferencedFile latex "$$AbsPath$$Basename.eps" + ReferencedFile dvi "$$AbsPath$$Basename.eps" FormatEnd Format PDFLaTeX TransformOption Rotate RotationLatexOption @@ -80,6 +82,7 @@ Template RasterImage UpdateFormat png UpdateResult "$$AbsPath$$Basename.png" Requirement "graphicx" + ReferencedFile latex "$$AbsPath$$Basename.png" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" @@ -90,6 +93,8 @@ Template RasterImage Product "" UpdateFormat eps UpdateResult "$$AbsPath$$Basename.eps" + ReferencedFile docbook "$$AbsPath$$Basename.eps" + ReferencedFile docbook-xml "$$AbsPath$$Basename.eps" FormatEnd Format LinuxDoc Product "[Bitmap: $$FName]" @@ -116,6 +121,9 @@ Template XFig Requirement "graphicx" # Preamble WarnNotFound # Preamble InputOrWarn + ReferencedFile latex "$$AbsPath$$Basename.pstex_t" + ReferencedFile latex "$$AbsPath$$Basename.pstex" + ReferencedFile dvi "$$AbsPath$$Basename.pstex" FormatEnd Format PDFLaTeX TransformCommand Rotate RotationLatexCommand @@ -126,6 +134,8 @@ Template XFig Requirement "graphicx" # Preamble WarnNotFound # Preamble InputOrWarn + ReferencedFile latex "$$AbsPath$$Basename.pdftex_t" + ReferencedFile latex "$$AbsPath$$Basename.pdftex" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" @@ -136,6 +146,8 @@ Template XFig Product "" UpdateFormat eps UpdateResult "$$AbsPath$$Basename.eps" + ReferencedFile docbook "$$AbsPath$$Basename.eps" + ReferencedFile docbook-xml "$$AbsPath$$Basename.eps" FormatEnd Format LinuxDoc Product "[XFig: $$FName]" @@ -170,6 +182,7 @@ Template ChessDiagram Format LaTeX Product "\\loadgame{$$AbsOrRelPathMaster$$Basename}\\showboard" Requirement "chess" + ReferencedFile latex "$$AbsPath$$Basename$$Extension" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" diff --git a/src/ChangeLog b/src/ChangeLog index bcd94908b0..ac65455113 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2004-06-01 Georg Baum + + * exporter.C (checkOverwrite): new method + * exporter.C (copyFile): new method + * exporter.C (Export): copy referenced files to the document dir + * exporter.[Ch]: new class ExportedFile + * exporter.[Ch]: new class ExportData. Contains currently the + names of referenced external files + * outputparams.h: add exportdata member. + 2004-05-28 Lars Gullik Bjonnes * Makefile.am (DISTCLEANFILES): add version.C, stamp-version and diff --git a/src/exporter.C b/src/exporter.C index a40fb40fb7..f91d983855 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -29,13 +29,20 @@ #include "outputparams.h" #include "frontends/Alert.h" +#include "support/FileInfo.h" #include "support/filetools.h" +#include "support/lyxlib.h" +#include "support/os.h" using lyx::support::AddName; using lyx::support::bformat; using lyx::support::ChangeExtension; using lyx::support::contains; +using lyx::support::MakeAbsPath; using lyx::support::MakeDisplayPath; +using lyx::support::OnlyFilename; +using lyx::support::OnlyPath; +using lyx::support::prefixIs; using std::find; using std::string; @@ -53,6 +60,72 @@ vector const Backends(Buffer const & buffer) return v; } + +/// ask the user what to do if a file already exists +int checkOverwrite(string const & filename) +{ + if (lyx::support::FileInfo(filename, true).exist()) { + string text = bformat(_("The file %1$s already exists.\n\n" + "Do you want to over-write that file?"), + MakeDisplayPath(filename)); + return Alert::prompt(_("Over-write file?"), + text, 0, 2, + _("&Over-write"), _("Over-write &all"), + _("&Cancel export")); + } + return 0; +} + + +enum CopyStatus { + SUCCESS, + FORCE, + CANCEL +}; + + +/** copy file \p sourceFile to \p destFile. If \p force is false, the user + * will be asked before existing files are overwritten. + * \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 ret = force ? FORCE : SUCCESS; + + // Only copy files that are in our tmp dir, all other files would + // overwrite themselves. This check could be changed to + // boost::filesystem::equivalent(sourceFile, destFile) if export to + // other directories than the document directory is desired. + if (!prefixIs(OnlyPath(sourceFile), lyx::support::os::getTmpDir())) + return ret; + + if (!force) { + switch(checkOverwrite(destFile)) { + case 0: + ret = SUCCESS; + break; + case 1: + ret = FORCE; + break; + default: + return CANCEL; + } + } + + if (!lyx::support::copy(sourceFile, destFile)) + Alert::error(_("Couldn't copy file"), + bformat(_("Copying %1$s to %2$s failed."), + MakeDisplayPath(sourceFile), + MakeDisplayPath(destFile))); + + return ret; +} + } //namespace anon @@ -63,6 +136,8 @@ 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 backends = Backends(*buffer); if (find(backends.begin(), backends.end(), format) == backends.end()) { for (vector::const_iterator it = backends.begin(); @@ -115,18 +190,37 @@ bool Exporter::Export(Buffer * buffer, string const & format, buffer->makeLaTeXFile(filename, buffer->filePath(), runparams); } - string outfile_base = (put_in_tempdir) - ? filename : buffer->getLatexName(false); - - if (!converters.convert(buffer, filename, outfile_base, + if (!converters.convert(buffer, filename, filename, backend_format, format, result_file)) return false; - if (!put_in_tempdir) - buffer->message(_("Document exported as ") - + formats.prettyName(format) - + _(" to file `") - + MakeDisplayPath(result_file) +'\''); + if (!put_in_tempdir) { + string const tmp_result_file = result_file; + result_file = ChangeExtension(buffer->fileName(), + formats.extension(format)); + // We need to copy referenced files (e. g. included graphics + // if format == "dvi") to the result dir. + vector const files = exportdata.externalFiles(format); + string const dest = OnlyPath(result_file); + CopyStatus status = SUCCESS; + for (vector::const_iterator it = files.begin(); + it != files.end() && status != CANCEL; ++it) + status = copyFile(it->sourceName, + MakeAbsPath(it->exportName, dest), + status == FORCE); + if (status == CANCEL) { + buffer->message(_("Document export cancelled.")); + } else { + // Finally copy the main file + status = copyFile(tmp_result_file, result_file, + status == FORCE); + buffer->message(bformat(_("Document exported as %1$s" + "to file `%2$s'"), + formats.prettyName(format), + MakeDisplayPath(result_file))); + } + } + return true; } @@ -173,3 +267,47 @@ Exporter::GetExportableFormats(Buffer const & buffer, bool only_viewable) } return result; } + + +ExportedFile::ExportedFile(string const & s, string const & e) : + sourceName(s), exportName(e) {} + + +bool operator==(ExportedFile const & f1, ExportedFile const & f2) +{ + return f1.sourceName == f2.sourceName && + f1.exportName == f2.exportName; + +} + + +void ExportData::addExternalFile(string const & format, + string const & sourceName, + string const & exportName) +{ + BOOST_ASSERT(lyx::support::AbsolutePath(sourceName)); + + // Make sure that we have every file only once, otherwise copyFile() + // would ask several times if it should overwrite a file. + vector & files = externalfiles[format]; + ExportedFile file(sourceName, exportName); + if (find(files.begin(), files.end(), file) == files.end()) + files.push_back(file); +} + + +void ExportData::addExternalFile(string const & format, + string const & sourceName) +{ + addExternalFile(format, sourceName, OnlyFilename(sourceName)); +} + + +vector const +ExportData::externalFiles(string const & format) const +{ + FileMap::const_iterator cit = externalfiles.find(format); + if (cit != externalfiles.end()) + return cit->second; + return vector(); +} diff --git a/src/exporter.h b/src/exporter.h index 826ce82add..0cdbd4e96e 100644 --- a/src/exporter.h +++ b/src/exporter.h @@ -13,6 +13,7 @@ #ifndef EXPORTER_H #define EXPORTER_H +#include #include #include @@ -42,4 +43,44 @@ public: GetExportableFormats(Buffer const & buffer, bool only_viewable); /// }; + + +struct ExportedFile { + ExportedFile(std::string const &, std::string const &); + /// absolute name of the source file + std::string sourceName; + /// final name that the exported file should get (absolute name or + /// relative to the directory of the master document) + std::string exportName; +}; + + +bool operator==(ExportedFile const &, ExportedFile const &); + + +class ExportData { +public: + /** add a referenced file for one format. + * No inset should ever write any file outside the tempdir. + * Instead, files that need to be exported have to be registered + * with this method. + * Then the exporter mechanism copies them to the right place, asks + * for confirmation before overwriting existing files etc. + */ + void addExternalFile(std::string const &, std::string const &, + std::string const &); + /// add a referenced file for one format. + /// The final name is the source file name without path + void addExternalFile(std::string const &, std::string const &); + /// get referenced files for one format + std::vector const + externalFiles(std::string const &) const; +private: + typedef std::map > FileMap; + /** Files that are referenced by the export result in the + * different formats. + */ + FileMap externalfiles; +}; + #endif diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index b4ef5755c0..bb04ae3ead 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,21 @@ +2004-06-01 Georg Baum + + * ExternalSupport.[Ch] (doSubstitution): exchange filename argument + with external_in_tmpdir and compute filename ourself + * ExternalSupport.[Ch] (updateExternal): add exportdata argument and + use it to store referenced file(s) + * ExternalSupport.C (writeExternal): write relative filename if + running latex + * ExternalTemplate.[Ch]: add ReferencedFile command + * insetgraphics.C (prepareFile, docbook, linuxdoc): add file to + runparams.exportdata + * insetgraphics.C (prepareFile): write relative filename if + running latex + * insetinclude.C (latex, docbook, linuxdoc): add file to + runparams.exportdata and write it to the temp dir instead of + writing it to the final destination + * insetinclude.C (docbook, linuxdoc): don't copy runparams + 2004-05-19 Angus Leeming * insetcite.[Ch]: small change because namespace biblio is diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index 118b94e640..38e4970f97 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -19,6 +19,7 @@ #include "buffer.h" #include "converter.h" #include "debug.h" +#include "exporter.h" #include "format.h" #include "support/filetools.h" @@ -58,31 +59,32 @@ void editExternal(InsetExternalParams const & params, Buffer const & buffer) } -namespace { - -/** Substitute meta-variables in the string \p s. - \p filename has to be the filename as read from the .lyx file (this - can be an absolute path or a path relative to the parent document). - Otherwise, the $$AbsOrRelPath* variables would not work. - If we are using a temporary directory, \p filename is the mangled name. -*/ string const doSubstitution(InsetExternalParams const & params, Buffer const & buffer, string const & s, - string const & filename) + bool external_in_tmpdir) { + Buffer const * m_buffer = buffer.getMasterBuffer(); + string const parentpath = external_in_tmpdir ? + m_buffer->temppath() : + buffer.filePath(); + string const filename = external_in_tmpdir ? + params.filename.mangledFilename() : + params.filename.outputFilename(parentpath); string result; string const basename = support::ChangeExtension( support::OnlyFilename(filename), string()); - string const absname = support::MakeAbsPath(filename, buffer.filePath()); + string const absname = support::MakeAbsPath(filename, parentpath); string const filepath = support::OnlyPath(filename); string const abspath = support::OnlyPath(absname); - Buffer const * m_buffer = buffer.getMasterBuffer(); + string const masterpath = external_in_tmpdir ? + m_buffer->temppath() : + m_buffer->filePath(); string relToMasterPath = support::OnlyPath( - support::MakeRelPath(absname, m_buffer->filePath())); + support::MakeRelPath(absname, masterpath)); if (relToMasterPath == "./") relToMasterPath.clear(); string relToParentPath = support::OnlyPath( - support::MakeRelPath(absname, buffer.filePath())); + support::MakeRelPath(absname, parentpath)); if (relToParentPath == "./") relToParentPath.clear(); @@ -131,6 +133,9 @@ string const doSubstitution(InsetExternalParams const & params, return result; } + +namespace { + /** update the file represented by the template. If \param external_in_tmpdir == true, then the generated file is place in the buffer's temporary directory. @@ -138,6 +143,7 @@ string const doSubstitution(InsetExternalParams const & params, void updateExternal(InsetExternalParams const & params, string const & format, Buffer const & buffer, + ExportData & exportdata, bool external_in_tmpdir) { Template const * const et_ptr = getTemplatePtr(params); @@ -185,8 +191,6 @@ void updateExternal(InsetExternalParams const & params, return; // FAILURE } - string from_file = params.filename.outputFilename(buffer.filePath()); - // The master buffer. This is useful when there are multiple levels // of include files Buffer const * m_buffer = buffer.getMasterBuffer(); @@ -209,19 +213,33 @@ void updateExternal(InsetExternalParams const & params, } } - from_file = temp_file; abs_from_file = temp_file; } string const to_file = doSubstitution(params, buffer, outputFormat.updateResult, - from_file); + external_in_tmpdir); string const abs_to_file = support::MakeAbsPath(to_file, external_in_tmpdir ? m_buffer->temppath() : buffer.filePath()); + // record the referenced files for the exporter + typedef Template::Format::FileMap FileMap; + FileMap::const_iterator rit = outputFormat.referencedFiles.begin(); + FileMap::const_iterator rend = outputFormat.referencedFiles.end(); + for (; rit != rend; ++rit) { + vector::const_iterator fit = rit->second.begin(); + vector::const_iterator fend = rit->second.end(); + for (; fit != fend; ++fit) { + string const file = doSubstitution(params, buffer, + *fit, + external_in_tmpdir); + exportdata.addExternalFile(rit->first, file); + } + } + // Do we need to perform the conversion? // Yes if to_file does not exist or if from_file is newer than to_file if (support::compare_timestamps(abs_from_file, abs_to_file) < 0) @@ -248,6 +266,7 @@ string const substituteOptions(InsetExternalParams const & params, int writeExternal(InsetExternalParams const & params, string const & format, Buffer const & buffer, ostream & os, + ExportData & exportdata, bool external_in_tmpdir) { Template const * const et_ptr = getTemplatePtr(params); @@ -264,34 +283,16 @@ int writeExternal(InsetExternalParams const & params, return 0; } - updateExternal(params, format, buffer, external_in_tmpdir); - - string from_file = params.filename.outputFilename(buffer.filePath()); - if (external_in_tmpdir && !from_file.empty()) { - // We are running stuff through LaTeX - from_file = - support::MakeAbsPath(params.filename.mangledFilename(), - buffer.getMasterBuffer()->temppath()); - } + updateExternal(params, format, buffer, exportdata, external_in_tmpdir); string str = doSubstitution(params, buffer, cit->second.product, - from_file); + external_in_tmpdir); str = substituteCommands(params, str, format); str = substituteOptions(params, str, format); os << str; return int(lyx::count(str.begin(), str.end(),'\n') + 1); } - -/// Substitute meta-variables in this string -string const doSubstitution(InsetExternalParams const & params, - Buffer const & buffer, string const & s) -{ - string const buffer_path = buffer.filePath(); - string const filename = params.filename.outputFilename(buffer_path); - return doSubstitution(params, buffer, s, filename); -} - namespace { // Empty template, specialised below. diff --git a/src/insets/ExternalSupport.h b/src/insets/ExternalSupport.h index 3d9e98801e..1e5bbc5583 100644 --- a/src/insets/ExternalSupport.h +++ b/src/insets/ExternalSupport.h @@ -17,6 +17,7 @@ #include class Buffer; +class ExportData; class InsetExternalParams; namespace lyx { @@ -33,10 +34,17 @@ void editExternal(InsetExternalParams const & params, Buffer const & buffer); -/// Substitute meta-variables in string s, making use of params and buffer. +/** Substitute meta-variables in string \p s, making use of \p params and + \p buffer. + If \p external_in_tmpdir is true, all files are assumed to be in the + master buffers temp path, and the mangled filename is used. + Otherwise, the output filename (absolute or relative to the parent + document, as written in the .lyx file) is used. +*/ std::string const doSubstitution(InsetExternalParams const & params, Buffer const & buffer, - std::string const & s); + std::string const & s, + bool external_in_tmpdir = false); /** Write the output for a specific file format @@ -48,6 +56,7 @@ int writeExternal(InsetExternalParams const &, std::string const & format, Buffer const &, std::ostream &, + ExportData &, bool external_in_tmpdir = false); } // namespace external diff --git a/src/insets/ExternalTemplate.C b/src/insets/ExternalTemplate.C index 5caa2246c0..482a0663db 100644 --- a/src/insets/ExternalTemplate.C +++ b/src/insets/ExternalTemplate.C @@ -146,6 +146,18 @@ public: ost << "\t\tPreamble " << *pit << '\n'; } + typedef Template::Format::FileMap FileMap; + FileMap::const_iterator rit = ft.referencedFiles.begin(); + FileMap::const_iterator rend = ft.referencedFiles.end(); + for (; rit != rend; ++rit) { + vector::const_iterator fit = rit->second.begin(); + vector::const_iterator fend = rit->second.end(); + for (; fit != fend; ++fit) { + ost << "\t\tReferencedFile " << rit->first + << " \"" << *fit << "\"\n"; + } + } + ost << "\tFormatEnd\n"; } private: @@ -452,6 +464,7 @@ void Template::Format::readFormat(LyXLex & lex) FO_PREAMBLE, FO_TRANSFORMCOMMAND, FO_TRANSFORMOPTION, + FO_REFERENCEDFILE, FO_END }; @@ -460,6 +473,7 @@ void Template::Format::readFormat(LyXLex & lex) { "option", FO_OPTION }, { "preamble", FO_PREAMBLE }, { "product", FO_PRODUCT }, + { "referencedfile", FO_REFERENCEDFILE }, { "requirement", FO_REQUIREMENT }, { "transformcommand", FO_TRANSFORMCOMMAND }, { "transformoption", FO_TRANSFORMOPTION }, @@ -521,6 +535,15 @@ void Template::Format::readFormat(LyXLex & lex) break; } + case FO_REFERENCEDFILE: { + lex.next(true); + string const format = lex.getString(); + lex.next(true); + string const file = lex.getString(); + referencedFiles[format].push_back(file); + break; + } + case FO_END: return; } diff --git a/src/insets/ExternalTemplate.h b/src/insets/ExternalTemplate.h index b25f53d1d1..91f06a8e19 100644 --- a/src/insets/ExternalTemplate.h +++ b/src/insets/ExternalTemplate.h @@ -76,6 +76,11 @@ struct Template { /// The factory functions for each supported transformation. std::map command_transformers; std::map option_transformers; + + typedef std::map > FileMap; + /// Referenced files for some formats + FileMap referencedFiles; }; /// typedef std::map Formats; diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index bd0219db1e..822893a403 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -22,6 +22,7 @@ #include "cursor.h" #include "debug.h" #include "dispatchresult.h" +#include "exporter.h" #include "funcrequest.h" #include "gettext.h" #include "LaTeXFeatures.h" @@ -687,32 +688,37 @@ int InsetExternal::latex(Buffer const & buf, ostream & os, et.formats.find("PDFLaTeX"); if (cit != et.formats.end()) return external::writeExternal(params_, "PDFLaTeX", - buf, os, external_in_tmpdir); + buf, os, + *(runparams.exportdata), + external_in_tmpdir); } - - return external::writeExternal(params_, "LaTeX", - buf, os, external_in_tmpdir); + return external::writeExternal(params_, "LaTeX", buf, os, + *(runparams.exportdata), + external_in_tmpdir); } int InsetExternal::plaintext(Buffer const & buf, ostream & os, - OutputParams const &) const + OutputParams const & runparams) const { - return external::writeExternal(params_, "Ascii", buf, os); + return external::writeExternal(params_, "Ascii", buf, os, + *(runparams.exportdata)); } int InsetExternal::linuxdoc(Buffer const & buf, ostream & os, - OutputParams const &) const + OutputParams const & runparams) const { - return external::writeExternal(params_, "LinuxDoc", buf, os); + return external::writeExternal(params_, "LinuxDoc", buf, os, + *(runparams.exportdata)); } int InsetExternal::docbook(Buffer const & buf, ostream & os, - OutputParams const &) const + OutputParams const & runparams) const { - return external::writeExternal(params_, "DocBook", buf, os); + return external::writeExternal(params_, "DocBook", buf, os, + *(runparams.exportdata)); } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index ee67049c86..d444d36828 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -58,6 +58,7 @@ TODO #include "cursor.h" #include "debug.h" #include "dispatchresult.h" +#include "exporter.h" #include "format.h" #include "funcrequest.h" #include "gettext.h" @@ -93,6 +94,7 @@ using lyx::support::GetExtension; using lyx::support::getExtFromContents; using lyx::support::IsFileReadable; using lyx::support::LibFileSearch; +using lyx::support::OnlyFilename; using lyx::support::rtrim; using lyx::support::subst; using lyx::support::Systemcall; @@ -453,6 +455,10 @@ string const InsetGraphics::prepareFile(Buffer const & buf, if (zipped) { if (params().noUnzip) { + // We don't know wether latex can actually handle + // this file, but we can't check, because that would + // mean to unzip the file and thereby making the + // noUnzip parameter meaningless. lyxerr[Debug::GRAPHICS] << "\tpass zipped file to LaTeX.\n"; // LaTeX needs the bounding box file in the tmp dir @@ -462,7 +468,10 @@ string const InsetGraphics::prepareFile(Buffer const & buf, ChangeExtension(temp_file, "bb")); if (status == FAILURE) return orig_file; - return temp_file; + runparams.exportdata->addExternalFile("latex", temp_file); + runparams.exportdata->addExternalFile("latex", bb_file); + runparams.exportdata->addExternalFile("dvi", temp_file); + return OnlyFilename(temp_file); } string const unzipped_temp_file = unzippedFileName(temp_file); @@ -493,8 +502,12 @@ string const InsetGraphics::prepareFile(Buffer const & buf, lyxerr[Debug::GRAPHICS] << "\tthe orig file is: " << orig_file << endl; - if (from == to) - return stripExtensionIfPossible(temp_file, to); + if (from == to) { + // The extension of temp_file might be != to! + runparams.exportdata->addExternalFile("latex", temp_file); + runparams.exportdata->addExternalFile("dvi", temp_file); + return OnlyFilename(stripExtensionIfPossible(temp_file, to)); + } string const to_file_base = RemoveExtension(temp_file); string const to_file = ChangeExtension(to_file_base, to); @@ -507,7 +520,9 @@ string const InsetGraphics::prepareFile(Buffer const & buf, << bformat(_("No conversion of %1$s is needed after all"), rel_file) << std::endl; - return to_file_base; + runparams.exportdata->addExternalFile("latex", to_file); + runparams.exportdata->addExternalFile("dvi", to_file); + return OnlyFilename(to_file_base); } lyxerr[Debug::GRAPHICS] @@ -523,13 +538,16 @@ string const InsetGraphics::prepareFile(Buffer const & buf, string const command = "sh " + LibFileSearch("scripts", "convertDefault.sh") + ' ' + from + ':' + temp_file + ' ' + - to + ':' + to_file_base + '.' + to; + to + ':' + to_file; lyxerr[Debug::GRAPHICS] << "No converter defined! I use convertDefault.sh:\n\t" << command << endl; Systemcall one; one.startscript(Systemcall::Wait, command); - if (!IsFileReadable(ChangeExtension(to_file_base, to))) { + if (IsFileReadable(to_file)) { + runparams.exportdata->addExternalFile("latex", to_file); + runparams.exportdata->addExternalFile("dvi", to_file); + } else { string str = bformat(_("No information for converting %1$s " "format files to %2$s.\n" "Try defining a convertor in the preferences."), from, to); @@ -537,7 +555,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf, } } - return to_file_base; + return OnlyFilename(to_file_base); } @@ -651,6 +669,8 @@ int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os, params().filename.relFilename(buf.filePath()): params().filename.absFilename(); + runparams.exportdata->addExternalFile("linuxdoc", + params().filename.absFilename()); os << "\n"; os << ""; return 0; @@ -658,14 +678,18 @@ int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os, // For explanation on inserting graphics into DocBook checkout: -// http://en.tldp.org/LDP/LDP-Author-Guide/inserting-pictures.html +// http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html // See also the docbook guide at http://www.docbook.org/ int InsetGraphics::docbook(Buffer const &, ostream & os, - OutputParams const &) const + OutputParams const & runparams) const { // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will // need to switch to MediaObject. However, for now this is sufficient and // easier to use. + runparams.exportdata->addExternalFile("docbook", + params().filename.absFilename()); + runparams.exportdata->addExternalFile("docbook-xml", + params().filename.absFilename()); os << ""; return 0; } diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 2f3a064896..da8f3c795c 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -20,6 +20,7 @@ #include "cursor.h" #include "debug.h" #include "dispatchresult.h" +#include "exporter.h" #include "funcrequest.h" #include "gettext.h" #include "LaTeXFeatures.h" @@ -332,13 +333,15 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, } // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".tex"); + string const exportfile = ChangeExtension(incfile, ".tex"); + string const mangled = FileName(ChangeExtension(included_file, + ".tex")).mangledFilename(); + string const writefile = MakeAbsPath(mangled, m_buffer->temppath()); - if (!runparams.nice) { - incfile = FileName(writefile).mangledFilename(); - writefile = MakeAbsPath(incfile, m_buffer->temppath()); - } + if (!runparams.nice) + incfile = mangled; lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; + lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; if (loadIfNeeded(buffer, params_)) { @@ -366,7 +369,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, tmp->makeLaTeXFile(writefile, OnlyPath(masterFilename(buffer)), runparams, false); - } else if (!runparams.nice) { + } else { // Copy the file to the temp dir, so that .aux files etc. // are not created in the original dir. Files included by // this file will be found via input@path, see ../buffer.C. @@ -388,6 +391,9 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, if (isVerbatim(params_)) { os << '\\' << params_.getCmdName() << '{' << incfile << '}'; } else if (type(params_) == INPUT) { + runparams.exportdata->addExternalFile("latex", writefile, + exportfile); + // \input wants file with extension (default is .tex) if (!IsLyXFilename(included_file)) { os << '\\' << params_.getCmdName() << '{' << incfile << '}'; @@ -397,6 +403,9 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, << '}'; } } else { + runparams.exportdata->addExternalFile("latex", writefile, + exportfile); + // \include don't want extension and demands that the // file really have .tex os << '\\' << params_.getCmdName() << '{' @@ -428,31 +437,34 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os, string const included_file = includedFilename(buffer, params_); + // write it to a file (so far the complete file) + string const exportfile = ChangeExtension(incfile, ".sgml"); + string writefile = ChangeExtension(included_file, ".sgml"); + if (loadIfNeeded(buffer, params_)) { Buffer * tmp = bufferlist.getBuffer(included_file); - // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".sgml"); - - if (!runparams.nice) { - incfile = FileName(writefile).mangledFilename(); - writefile = MakeAbsPath(incfile, - buffer.getMasterBuffer()->temppath()); - } + writefile = MakeAbsPath(FileName(writefile).mangledFilename(), + buffer.getMasterBuffer()->temppath()); + if (!runparams.nice) + incfile = writefile; lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; + lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; - OutputParams runp = runparams; - tmp->makeLinuxDocFile(writefile, runp, true); + tmp->makeLinuxDocFile(writefile, runparams, true); } if (isVerbatim(params_)) { os << ""; - } else + } else { + runparams.exportdata->addExternalFile("linuxdoc", writefile, + exportfile); os << '&' << include_label << ';'; + } return 0; } @@ -469,25 +481,31 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os, string const included_file = includedFilename(buffer, params_); + // write it to a file (so far the complete file) + string const exportfile = ChangeExtension(incfile, ".sgml"); + string writefile = ChangeExtension(included_file, ".sgml"); + if (loadIfNeeded(buffer, params_)) { Buffer * tmp = bufferlist.getBuffer(included_file); - // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".sgml"); - - if (!runparams.nice) { - incfile = FileName(writefile).mangledFilename(); - writefile = MakeAbsPath(incfile, - buffer.getMasterBuffer()->temppath()); - } + string const mangled = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(mangled, + buffer.getMasterBuffer()->temppath()); + if (!runparams.nice) + incfile = mangled; lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; + lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; - OutputParams runp = runparams; - tmp->makeDocBookFile(writefile, runp, true); + tmp->makeDocBookFile(writefile, runparams, true); } + runparams.exportdata->addExternalFile("docbook", writefile, + exportfile); + runparams.exportdata->addExternalFile("docbook-xml", writefile, + exportfile); + if (isVerbatim(params_)) { os << "