Bo Peng wrote:
I am reading your patch and hopefully can make it
 work.

+               // Make sure we are up to date.
+               buffer_->updateBibfilesCache();
+               EmbeddedFileList & efl = buffer_->embeddedFiles();
+               vector<FileName> const files = getFiles();
+               vector<FileName>::const_iterator fit = files.begin();
+               vector<FileName>::const_iterator fen = files.end();

This is wrong. Because buffer_->embeddedFiles(), unless an update() is
called,
updateBibfilesCache() calls EmbeddedFileList::enable(), which calls update(). This is what the other question was about, really.

does not have current embedded files. Also, InsetBibtex should
minds its own business here. The problem here is that your
vector<FileName> files = getFiles() does not know if these files ought
to be embedded or not, thus not know if they need to be copyed to
another buffer.
You left out the rest of the code.
+        // Make sure we are up to date.
+        buffer_->updateBibfilesCache();
+        EmbeddedFileList & efl = buffer_->embeddedFiles();
+        vector<FileName> const files = getFiles();
+        vector<FileName>::const_iterator fit = files.begin();
+        vector<FileName>::const_iterator fen = files.end();
+        for (; fit != fen; ++fit) {
+            EmbeddedFile * efp = efl.findFile(fit->absFilename());
+            if (!efp) {
+                Alert::error(_("Embedding error"),
+                    bformat(_("Failed to find %1$s"),
+                        from_utf8(fit->absFilename())));
+            } else {
+                try {
+                    updateEmbeddedFile(efp->copyTo(&buffer));
+                } catch (ExceptionMessage const & message) {
+                    Alert::error(message.title_, message.details_);
+                    // failed to embed
+                    efp->setEmbed(false);
+                    updateEmbeddedFile(*efp);
+                }
The vector<FileName> tells us what files we have, and then we look up their EmbeddedFile objects to find out what needs copying. Those are up-to-date for the reasons mentioned above.

But I agree with you that maybe this could be better done elsewhere.

rh

Reply via email to