{
BOOST_ASSERT(!buffer.embedded() || file.enabled());
- // try to find this file from the list
- std::vector<EmbeddedFile>::iterator it = begin();
- std::vector<EmbeddedFile>::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*>(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*>(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<EmbeddedFile>::const_iterator it = begin();
+ std::vector<EmbeddedFile>::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<EmbeddedFile>::iterator it = begin();
+ std::vector<EmbeddedFile>::iterator it_end = end();
+ for (; it != it_end; ++it)
+ if (it->absFilename() == filename)
+ return &*it;
+ return 0;
+}
+
+
void EmbeddedFileList::validate(Buffer const & buffer)
{
clear();
*/
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);
};