diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index 4109dcd746..9202a61d02 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -493,27 +493,48 @@ void EmbeddedFileList::registerFile(EmbeddedFile const & file, { BOOST_ASSERT(!buffer.embedded() || file.enabled()); + string newfile = file.absFilename(); + EmbeddedFile * efp = findFile(newfile); + if (efp) { + if (efp->embedded() != file.embedded()) { + Alert::error(_("Wrong embedding status."), + bformat(_("File %1$s is included in more than one insets, " + "but with different embedding status. Assuming embedding status."), + from_utf8(efp->outputFilename()))); + efp->setEmbed(true); + // update the inset with this embedding status. + const_cast(inset)->updateEmbeddedFile(*efp); + } + efp->addInset(inset); + return; + } + file.clearInsets(); + push_back(file); + back().addInset(inset); +} + + +EmbeddedFile const * EmbeddedFileList::findFile(std::string const & filename) const +{ + // try to find this file from the list + std::vector::const_iterator it = begin(); + std::vector::const_iterator it_end = end(); + for (; it != it_end; ++it) + if (it->absFilename() == filename) + return &*it; + return 0; +} + + +EmbeddedFile * EmbeddedFileList::findFile(std::string const & filename) +{ // try to find this file from the list std::vector::iterator it = begin(); std::vector::iterator it_end = end(); for (; it != it_end; ++it) - if (it->absFilename() == file.absFilename()) { - if (it->embedded() != file.embedded()) { - Alert::error(_("Wrong embedding status."), - bformat(_("File %1$s is included in more than one insets, " - "but with different embedding status. Assuming embedding status."), - from_utf8(it->outputFilename()))); - it->setEmbed(true); - // update the inset with this embedding status. - const_cast(inset)->updateEmbeddedFile(*it); - } - it->addInset(inset); - return; - } - // - file.clearInsets(); - push_back(file); - back().addInset(inset); + if (it->absFilename() == filename) + return &*it; + return 0; } diff --git a/src/EmbeddedFiles.h b/src/EmbeddedFiles.h index 5a8df69853..3dc1550b67 100644 --- a/src/EmbeddedFiles.h +++ b/src/EmbeddedFiles.h @@ -209,13 +209,14 @@ public: */ void registerFile(EmbeddedFile const & file, Inset const * inset, Buffer const & buffer); - + /// returns a pointer to the Embedded file representing this object, + /// or null if not found. The filename should be absolute. + EmbeddedFile const * findFile(std::string const & filename) const; + EmbeddedFile * findFile(std::string const & filename); /// validate embedded fies after a file is read. void validate(Buffer const & buffer); - /// scan the buffer and get a list of EmbeddedFile void update(Buffer const & buffer); - /// write a zip file bool writeFile(support::DocFileName const & filename, Buffer const & buffer); };