Am Samstag, 15. Mai 2004 14:45 schrieb Georg Baum: > The only clean > solution that I can imagine is to introduce a switch in the external > template that tells wether a file is "input like" or "includegraphics > like", because the template is the only place where this is known. Any > other ideas?
This does not work for the xfig template, because the lyx file includes $$Basename.pstex_t but the graphic is in the file $$Basename.pstex. Here comes the second attempt: Collect the referenced external file names separately for each format of the exported document. E.g. if my doc includes a.lyx, b.fig (xfig external template) and c.eps (graphics inset), then the list would look like: externalFiles["latex"] = "a.tex", "b.pstex", "b.pstex_t", "c.eps" externalFiles["dvi"] = "b.pstex", "c.eps" In case of the external template, this is achieved by a new template command ReferencedFile <format> <filename> where <format> is a known format. Currently the information for the latex format is not needed, because no graphics are exported and the .tex files are written directly. I added it nevertheless because it does not hurt and might be useful in the future. I think this is a clean solution. However, I don't like the way how the file overwriting prevention works: - The "cancel" button is mislabelled: It does not cancel the export, but does not copy the file. Any idea for a better name? - There should be a fourth button that really cancels the export. Apart from that, we need to check before overwriting files at other places, too, and I don't see at the moment how this should be done. Nevertheless, I would like to apply that as is. If somebody has a better idea, it can be improved later, and if not, it is still better than the current state. Any objections? Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/ChangeLog lyx-1.4-cvs/lib/ChangeLog --- lyx-1.4-clean/lib/ChangeLog 2004-05-21 08:54:59.000000000 +0200 +++ lyx-1.4-cvs/lib/ChangeLog 2004-05-21 19:27:48.000000000 +0200 @@ -1,3 +1,7 @@ +2004-05-21 Georg Baum <[EMAIL PROTECTED]> + + * external_templates: add ReferencedFile commands where appropriate + 2004-05-19 Uwe Stöhr <[EMAIL PROTECTED]> * lib/math.bind: fix some bindings to work with german keyboard; diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/external_templates lyx-1.4-cvs/lib/external_templates --- lyx-1.4-clean/lib/external_templates 2004-04-30 13:42:12.000000000 +0200 +++ lyx-1.4-cvs/lib/external_templates 2004-05-21 15:53:36.000000000 +0200 @@ -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,16 +82,20 @@ Template RasterImage UpdateFormat png UpdateResult "$$AbsPath$$Basename.png" Requirement "graphicx" + ReferencedFile latex "$$AbsPath$$Basename.png" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" UpdateFormat asciiimage UpdateResult "$$AbsPath$$Basename.asc" + ReferencedFile text "$$AbsPath$$Basename.asc" FormatEnd Format DocBook Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>" 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 +122,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,16 +135,21 @@ 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\")" UpdateFormat asciixfig UpdateResult "$$AbsPath$$Basename.asc" + ReferencedFile text "$$AbsPath$$Basename.asc" FormatEnd Format DocBook Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>" UpdateFormat eps UpdateResult "$$AbsPath$$Basename.eps" + ReferencedFile docbook "$$AbsPath$$Basename.eps" + ReferencedFile docbook-xml "$$AbsPath$$Basename.eps" FormatEnd Format LinuxDoc Product "[XFig: $$FName]" @@ -170,11 +184,13 @@ Template ChessDiagram Format LaTeX Product "\\loadgame{$$AbsOrRelPathMaster$$Basename}\\showboard" Requirement "chess" + ReferencedFile latex "$$AbsPath$$Basename$$Extension" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" UpdateFormat asciichess UpdateResult "$$AbsPath$$Basename.asc" + ReferencedFile text "$$AbsPath$$Basename.asc" FormatEnd Format DocBook Product "[Chess: $$AbsOrRelPathMaster$$Basename]" diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog --- lyx-1.4-clean/src/ChangeLog 2004-05-21 08:55:11.000000000 +0200 +++ lyx-1.4-cvs/src/ChangeLog 2004-05-21 19:32:16.000000000 +0200 @@ -1,3 +1,12 @@ +2004-05-21 Georg Baum <[EMAIL PROTECTED]> + + * exporter.C (checkOverwrite): new method + * exporter.C (copyFile): new method + * exporter.C: copy referenceed files to the document dir + * exporter.[Ch]: add class ExportData. Contains currently the + names of referenced external files + * outputparams.h: add exportdata member. + 2004-05-19 Angus Leeming <[EMAIL PROTECTED]> * LaTeXFeatures.C: diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/exporter.C lyx-1.4-cvs/src/exporter.C --- lyx-1.4-clean/src/exporter.C 2004-02-25 13:00:48.000000000 +0100 +++ lyx-1.4-cvs/src/exporter.C 2004-05-21 19:33:05.000000000 +0200 @@ -29,13 +29,18 @@ #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::MakeDisplayPath; +using lyx::support::OnlyPath; +using lyx::support::prefixIs; using std::find; using std::string; @@ -53,6 +58,53 @@ vector<string> const Backends(Buffer con return v; } + +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")); + } + return 0; +} + + +/** + * copy file \p sourceFile to \p destFile. If \p force is false, the user + * will be asked before existing files are overwritten. + * \return true if subsequent calls should not ask for confirmation before + * overwriting files anymore. + */ +bool copyFile(string const & sourceFile, string const & destFile, bool force) +{ + int ret = force ? 1 : 0; + + // 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) { + ret = checkOverwrite(destFile); + if (ret == 2) + return false; + } + + 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 +115,8 @@ bool Exporter::Export(Buffer * buffer, s 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(); @@ -122,11 +179,21 @@ bool Exporter::Export(Buffer * buffer, s backend_format, format, result_file)) return false; - if (!put_in_tempdir) + if (!put_in_tempdir) { buffer->message(_("Document exported as ") + formats.prettyName(format) + _(" to file `") + MakeDisplayPath(result_file) +'\''); + // We need to copy referenced files (e. g. included graphics + // if format == "dvi") to the result dir. + vector<string> const files = exportdata.externalFiles(format); + string const dest = OnlyPath(result_file); + bool force = false; + for (vector<string>::const_iterator it = files.begin(); + it != files.end(); ++it) + force = copyFile(*it, AddName(dest, *it), force); + } + return true; } @@ -173,3 +241,24 @@ Exporter::GetExportableFormats(Buffer co } return result; } + + +void ExportData::addExternalFile(string const & format, string const & file) +{ + BOOST_ASSERT(lyx::support::AbsolutePath(file)); + + // Make sure that we have every file only once, otherwise copyFile() + // would ask several times if it should overwrite a file. + vector<string> & files = externalfiles[format]; + if (find(files.begin(), files.end(), file) == files.end()) + files.push_back(file); +} + + +vector<string> const ExportData::externalFiles(string const & format) const +{ + FileMap::const_iterator cit = externalfiles.find(format); + if (cit != externalfiles.end()) + return cit->second; + return vector<string>(); +} diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/exporter.h lyx-1.4-cvs/src/exporter.h --- lyx-1.4-clean/src/exporter.h 2003-10-07 08:45:24.000000000 +0200 +++ lyx-1.4-cvs/src/exporter.h 2004-05-21 18:45:41.000000000 +0200 @@ -13,6 +13,7 @@ #ifndef EXPORTER_H #define EXPORTER_H +#include <map> #include <string> #include <vector> @@ -42,4 +43,20 @@ public: GetExportableFormats(Buffer const & buffer, bool only_viewable); /// }; + +class ExportData { +public: + /// add a referenced file for one format + void addExternalFile(std::string const &, std::string const &); + /// get referenced files for one format + std::vector<std::string> const + externalFiles(std::string const &) const; +private: + typedef std::map<std::string, std::vector<std::string> > FileMap; + /** Files that are referenced by the export result in the + * different formats. + */ + FileMap externalfiles; +}; + #endif diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog --- lyx-1.4-clean/src/insets/ChangeLog 2004-05-21 08:56:11.000000000 +0200 +++ lyx-1.4-cvs/src/insets/ChangeLog 2004-05-21 19:56:44.000000000 +0200 @@ -1,3 +1,20 @@ +2004-05-21 Georg Baum <[EMAIL PROTECTED]> + + * ExternalSupport.[Ch] (doSubstitution): exchange filename argument + by external_in_tmpdir and compute filename ourself + * ExternalSupport.[Ch] (updateExternal): add exportdata argument and + use it to store referenced file(s) + * ExternalTemplate.[Ch]: add ReferencedFile command + * ExternalSupport.C (writeExternal): write relative filename if + running latex + * 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 + * insetinclude.C (docbook, linuxdoc): don't copy runparams + 2004-05-19 Angus Leeming <[EMAIL PROTECTED]> * insetcite.[Ch]: small change because namespace biblio is diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalSupport.C lyx-1.4-cvs/src/insets/ExternalSupport.C --- lyx-1.4-clean/src/insets/ExternalSupport.C 2004-04-13 12:36:09.000000000 +0200 +++ lyx-1.4-cvs/src/insets/ExternalSupport.C 2004-05-21 19:44:03.000000000 +0200 @@ -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 co } -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(InsetExterna 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(InsetExterna 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 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,32 @@ void updateExternal(InsetExternalParams } } - 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()); + typedef Template::Format::FileMap FileMap; + FileMap::const_iterator rit = outputFormat.referencedFiles.begin(); + FileMap::const_iterator rend = outputFormat.referencedFiles.end(); + for (; rit != rend; ++rit) { + vector<string>::const_iterator fit = rit->second.begin(); + vector<string>::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 +265,7 @@ string const substituteOptions(InsetExte 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 +284,16 @@ int writeExternal(InsetExternalParams co return 0; } - updateExternal(params, format, buffer, external_in_tmpdir); + updateExternal(params, format, buffer, exportdata, 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()); - } - 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 -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalSupport.h lyx-1.4-cvs/src/insets/ExternalSupport.h --- lyx-1.4-clean/src/insets/ExternalSupport.h 2003-10-07 22:25:10.000000000 +0200 +++ lyx-1.4-cvs/src/insets/ExternalSupport.h 2004-05-20 12:17:45.000000000 +0200 @@ -17,6 +17,7 @@ #include <string> class Buffer; +class ExportData; class InsetExternalParams; namespace lyx { @@ -33,10 +34,17 @@ void editExternal(InsetExternalParams co 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 co std::string const & format, Buffer const &, std::ostream &, + ExportData &, bool external_in_tmpdir = false); } // namespace external diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalTemplate.C lyx-1.4-cvs/src/insets/ExternalTemplate.C --- lyx-1.4-clean/src/insets/ExternalTemplate.C 2004-04-30 13:43:07.000000000 +0200 +++ lyx-1.4-cvs/src/insets/ExternalTemplate.C 2004-05-21 19:42:37.000000000 +0200 @@ -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<string>::const_iterator fit = rit->second.begin(); + vector<string>::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 FO_PREAMBLE, FO_TRANSFORMCOMMAND, FO_TRANSFORMOPTION, + FO_REFERENCEDFILE, FO_END }; @@ -460,6 +473,7 @@ void Template::Format::readFormat(LyXLex { "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 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 -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalTemplate.h lyx-1.4-cvs/src/insets/ExternalTemplate.h --- lyx-1.4-clean/src/insets/ExternalTemplate.h 2004-04-30 13:43:07.000000000 +0200 +++ lyx-1.4-cvs/src/insets/ExternalTemplate.h 2004-05-21 19:42:22.000000000 +0200 @@ -76,6 +76,11 @@ struct Template { /// The factory functions for each supported transformation. std::map<TransformID, TransformStore> command_transformers; std::map<TransformID, TransformStore> option_transformers; + + typedef std::map<std::string, + std::vector<std::string> > FileMap; + /// Referenced files for some formats + FileMap referencedFiles; }; /// typedef std::map<std::string, Format> Formats; diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetexternal.C lyx-1.4-cvs/src/insets/insetexternal.C --- lyx-1.4-clean/src/insets/insetexternal.C 2004-04-19 20:06:35.000000000 +0200 +++ lyx-1.4-cvs/src/insets/insetexternal.C 2004-05-20 12:18:43.000000000 +0200 @@ -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 & et.formats.find("PDFLaTeX"); if (cit != et.formats.end()) return external::writeExternal(params_, "PDFLaTeX", - buf, os, external_in_tmpdir); - } - - return external::writeExternal(params_, "LaTeX", - buf, os, external_in_tmpdir); + buf, os, + *(runparams.exportdata), + 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 -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetgraphics.C lyx-1.4-cvs/src/insets/insetgraphics.C --- lyx-1.4-clean/src/insets/insetgraphics.C 2004-05-07 13:41:40.000000000 +0200 +++ lyx-1.4-cvs/src/insets/insetgraphics.C 2004-05-21 15:55:04.000000000 +0200 @@ -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( 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( 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( 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( << 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( 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 +556,7 @@ string const InsetGraphics::prepareFile( } } - return to_file_base; + return OnlyFilename(to_file_base); } @@ -651,6 +670,8 @@ int InsetGraphics::linuxdoc(Buffer const params().filename.relFilename(buf.filePath()): params().filename.absFilename(); + runparams.exportdata->addExternalFile("linuxdoc", + params().filename.absFilename()); os << "<eps file=\"" << file_name << "\">\n"; os << "<img src=\"" << file_name << "\">"; return 0; @@ -658,14 +679,18 @@ int InsetGraphics::linuxdoc(Buffer const // 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 << "<graphic fileref=\"&" << graphic_label << ";\">"; return 0; } diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetinclude.C lyx-1.4-cvs/src/insets/insetinclude.C --- lyx-1.4-clean/src/insets/insetinclude.C 2004-04-19 20:06:36.000000000 +0200 +++ lyx-1.4-cvs/src/insets/insetinclude.C 2004-05-21 15:54:24.000000000 +0200 @@ -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" @@ -388,6 +407,8 @@ int InsetInclude::latex(Buffer const & b if (isVerbatim(params_)) { os << '\\' << params_.getCmdName() << '{' << incfile << '}'; } else if (type(params_) == INPUT) { + runparams.exportdata->addExternalFile("latex", writefile); + // \input wants file with extension (default is .tex) if (!IsLyXFilename(included_file)) { os << '\\' << params_.getCmdName() << '{' << incfile << '}'; @@ -397,6 +418,8 @@ int InsetInclude::latex(Buffer const & b << '}'; } } else { + runparams.exportdata->addExternalFile("latex", writefile); + // \include don't want extension and demands that the // file really have .tex os << '\\' << params_.getCmdName() << '{' @@ -428,12 +451,12 @@ int InsetInclude::linuxdoc(Buffer const string const included_file = includedFilename(buffer, params_); + // write it to a file (so far the complete file) + 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, @@ -443,16 +466,17 @@ int InsetInclude::linuxdoc(Buffer const lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; - OutputParams runp = runparams; - tmp->makeLinuxDocFile(writefile, runp, true); + tmp->makeLinuxDocFile(writefile, runparams, true); } if (isVerbatim(params_)) { os << "<![CDATA[" << GetFileContents(included_file) << "]]>"; - } else + } else { + runparams.exportdata->addExternalFile("linuxdoc", writefile); os << '&' << include_label << ';'; + } return 0; } @@ -469,12 +494,12 @@ int InsetInclude::docbook(Buffer const & string const included_file = includedFilename(buffer, params_); + // write it to a file (so far the complete file) + 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, @@ -484,10 +509,12 @@ int InsetInclude::docbook(Buffer const & lyxerr[Debug::LATEX] << "incfile:" << incfile << 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); + runparams.exportdata->addExternalFile("docbook-xml", writefile); + if (isVerbatim(params_)) { os << "<inlinegraphic fileref=\"" << '&' << include_label << ';' diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/outputparams.h lyx-1.4-cvs/src/outputparams.h --- lyx-1.4-clean/src/outputparams.h 2004-05-14 19:53:31.000000000 +0200 +++ lyx-1.4-cvs/src/outputparams.h 2004-05-20 17:09:44.000000000 +0200 @@ -15,6 +15,9 @@ #include "support/types.h" +class ExportData; + + struct OutputParams { // enum FLAVOR { @@ -26,7 +29,7 @@ struct OutputParams { OutputParams() : flavor(LATEX), nice(false), moving_arg(false), free_spacing(false), use_babel(false), - mixed_content(false), linelen(0) + mixed_content(false), linelen(0), exportdata(0) {} /** The latex that we export depends occasionally on what is to @@ -65,6 +68,12 @@ struct OutputParams { /** Line length to use with ascii export. */ lyx::size_type linelen; + + /** Export data filled in by the latex(), docbook() etc methods. + This is a hack: Make it possible to add stuff to constant + OutputParams instances. + */ + ExportData *exportdata; }; #endif // LATEXRUNPARAMS_H