]> git.lyx.org Git - features.git/blobdiff - src/EmbeddedFiles.cpp
Embedding: store inset pointer instead of ParConstIterator to enable more accurate...
[features.git] / src / EmbeddedFiles.cpp
index bad37e77898b446a8adbdb2a0cf9d30e29121e76..2680f4d56329aca3293e04a95c40b22f6db7ecdb 100644 (file)
@@ -16,7 +16,7 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "Paragraph.h"
-#include "ParIterator.h"
+#include "InsetIterator.h"
 #include "debug.h"
 #include "gettext.h"
 #include "Format.h"
@@ -31,6 +31,9 @@
 #include "support/lyxlib.h"
 #include "support/lstrings.h"
 
+#include "LyX.h"
+#include "Session.h"
+
 #include <sstream>
 #include <fstream>
 #include <utility>
@@ -67,12 +70,12 @@ using support::makedir;
 
 
 EmbeddedFile::EmbeddedFile(string const & file, string const & inzip_name,
-       bool embed, ParConstIterator const & pit)
+       bool embed, Inset const * inset)
        : DocFileName(file, true), inzip_name_(inzip_name), embedded_(embed),
-               valid_(true), par_it_()
+               valid_(true), inset_list_()
 {
-       if (pit != ParConstIterator())
-               par_it_.push_back(pit);
+       if (inset != NULL)
+               inset_list_.push_back(inset);
 }
 
 
@@ -82,17 +85,39 @@ string EmbeddedFile::embeddedFile(Buffer const * buf) const
 }
 
 
-void EmbeddedFile::addParIter(ParConstIterator const & pit)
+void EmbeddedFile::addInset(Inset const * inset)
 {
-       par_it_.push_back(pit);
+       inset_list_.push_back(inset);
 }
 
 
-int EmbeddedFile::parID(int idx) const
+Inset const * EmbeddedFile::inset(int idx) const
 {
        BOOST_ASSERT(idx < refCount());
        // some embedded file do not have a valid par iterator
-       return par_it_[idx]->id();
+       return inset_list_[idx];
+}
+
+
+void EmbeddedFile::saveBookmark(Buffer const * buf, int idx) const
+{
+       Inset const * ptr = inset(idx);
+       // This might not be the most efficient method ... 
+       for (InsetIterator it = inset_iterator_begin(buf->inset()); it; ++it)
+               if (&(*it) == ptr) {
+                       // this is basically BufferView::saveBookmark(0)
+                       LyX::ref().session().bookmarks().save(
+                               FileName(buf->fileName()),
+                               it.bottom().pit(),
+                               it.bottom().pos(),
+                               it.paragraph().id(),
+                               it.pos(),
+                               0
+                       );
+               }
+       // this inset can not be located. There is something wrong that needs
+       // to be fixed.
+       BOOST_ASSERT(true);
 }
 
 
@@ -107,8 +132,8 @@ string EmbeddedFile::availableFile(Buffer const * buf) const
 
 void EmbeddedFile::invalidate()
 {
-       // Clear par_it_ because they will be registered again.
-       par_it_.clear();
+       // Clear inset_list_ because they will be registered again.
+       inset_list_.clear();
        valid_ = false;
 }
 
@@ -219,7 +244,7 @@ bool EmbeddedFiles::enable(bool flag)
 
 
 void EmbeddedFiles::registerFile(string const & filename,
-       bool embed, ParConstIterator const & pit)
+       bool embed, Inset const * inset)
 {
        // filename can be relative or absolute, translate to absolute filename
        string abs_filename = makeAbsPath(filename, buffer_->filePath()).absFilename();
@@ -231,7 +256,7 @@ void EmbeddedFiles::registerFile(string const & filename,
                        break;
        // find this filename, keep the original embedding status
        if (it != file_list_.end()) {
-               it->addParIter(pit);
+               it->addInset(inset);
                // if the file is embedded, the embedded file should have exist
                // check for this to ensure that our logic is correct
                if (it->embedded())
@@ -241,7 +266,7 @@ void EmbeddedFiles::registerFile(string const & filename,
        }
        // try to be more careful
        file_list_.push_back(EmbeddedFile(abs_filename, 
-               getInzipName(abs_filename), embed, pit));
+               getInzipName(abs_filename), embed, inset));
        // validate if things are OK
        BOOST_ASSERT(fs::exists(file_list_.back().availableFile(buffer_)));
 }
@@ -260,17 +285,9 @@ void EmbeddedFiles::update()
                if (it->refCount() > 0)
                        it->invalidate();
 
-       ParIterator pit = buffer_->par_iterator_begin();
-       ParIterator pit_end = buffer_->par_iterator_end();
-       for (; pit != pit_end; ++pit) {
-               // For each paragraph, traverse its insets and register embedded files
-               InsetList::const_iterator iit = pit->insetlist.begin();
-               InsetList::const_iterator iit_end = pit->insetlist.end();
-               for (; iit != iit_end; ++iit) {
-                       Inset & inset = *iit->inset;
-                       inset.registerEmbeddedFiles(*buffer_, *this, pit);
-               }
-       }
+       for (InsetIterator it = inset_iterator_begin(buffer_->inset()); it; ++it)
+               it->registerEmbeddedFiles(*buffer_, *this);
+
        LYXERR(Debug::FILES) << "Manifest updated: " << endl
                << *this
                << "End Manifest" << endl;