]> git.lyx.org Git - lyx.git/blobdiff - src/EmbeddedFiles.cpp
Cosmetics.
[lyx.git] / src / EmbeddedFiles.cpp
index e6a02c4aac5a519c958b840d509c2240833222f0..a985ea646cea538572c62209ae2cf0e92c1d3bc8 100644 (file)
@@ -225,6 +225,15 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const
 }
 
 
+void EmbeddedFile::updateInsets(Buffer const * buf) const
+{
+       vector<Inset const *>::const_iterator it = inset_list_.begin();
+       vector<Inset const *>::const_iterator it_end = inset_list_.end();
+       for (; it != it_end; ++it)
+               const_cast<Inset *>(*it)->updateEmbeddedFile(*buf, *this);
+}
+
+
 bool EmbeddedFiles::enabled() const
 {
        return buffer_->params().embedded;
@@ -241,11 +250,13 @@ void EmbeddedFiles::enable(bool flag)
                // if operation is successful
                buffer_->markDirty();
                buffer_->params().embedded = flag;
+               if (flag)
+                       updateInsets();
        }
 }
 
 
-void EmbeddedFiles::registerFile(string const & filename,
+EmbeddedFile & EmbeddedFiles::registerFile(string const & filename,
        bool embed, Inset const * inset, string const & inzipName)
 {
        // filename can be relative or absolute, translate to absolute filename
@@ -260,11 +271,12 @@ void EmbeddedFiles::registerFile(string const & filename,
        if (it != file_list_.end()) {
                it->addInset(inset);
                it->validate();
-               return;
+               return *it;
        }
        // try to be more careful
        file_list_.push_back(EmbeddedFile(abs_filename, 
                getInzipName(abs_filename, inzipName), embed, inset));
+       return file_list_.back();
 }
 
 
@@ -456,7 +468,9 @@ void EmbeddedFiles::writeManifest(ostream & os) const
        EmbeddedFiles::EmbeddedFileList::const_iterator it = begin();
        EmbeddedFiles::EmbeddedFileList::const_iterator it_end = end();
        for (; it != it_end; ++it) {
-               if (!it->valid())
+               // only saved 'extra' files. Other embedded files are saved
+               // with insets.
+               if (!it->valid() || it->refCount() > 0)
                        continue;
                // save the relative path
                os << "\\filename "
@@ -468,4 +482,14 @@ void EmbeddedFiles::writeManifest(ostream & os) const
 }
 
 
+void EmbeddedFiles::updateInsets() const
+{
+       EmbeddedFiles::EmbeddedFileList::const_iterator it = begin();
+       EmbeddedFiles::EmbeddedFileList::const_iterator it_end = end();
+       for (; it != it_end; ++it)
+               if (it->valid() && it->refCount() > 0)
+                       it->updateInsets(buffer_);
+}
+
+
 }