From: Richard Heck Date: Sat, 29 Mar 2008 15:01:12 +0000 (+0000) Subject: Introduce findFile() and simplify registerFile(). X-Git-Tag: 1.6.10~5364 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=eae4e411411d8f7c74f76ab89b15d3e00c3e42af;p=features.git Introduce findFile() and simplify registerFile(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24037 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index 4109dcd746..9202a61d02 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -493,30 +493,51 @@ void EmbeddedFileList::registerFile(EmbeddedFile const & file, { BOOST_ASSERT(!buffer.embedded() || file.enabled()); - // 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; + 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() == filename) + return &*it; + return 0; +} + + void EmbeddedFileList::validate(Buffer const & buffer) { clear(); 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); };