]> git.lyx.org Git - features.git/commitdiff
Embedding: store inset pointer instead of ParConstIterator to enable more accurate...
authorBo Peng <bpeng@lyx.org>
Sun, 9 Sep 2007 07:07:13 +0000 (07:07 +0000)
committerBo Peng <bpeng@lyx.org>
Sun, 9 Sep 2007 07:07:13 +0000 (07:07 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20164 a592a061-630c-0410-9148-cb99ea01b6c8

src/EmbeddedFiles.cpp
src/EmbeddedFiles.h
src/frontends/controllers/ControlEmbeddedFiles.cpp
src/insets/Inset.h
src/insets/InsetExternal.cpp
src/insets/InsetExternal.h
src/insets/InsetGraphics.cpp
src/insets/InsetGraphics.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h

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;
index c256484b4085814c266e71853f3ed1fdc6feec6c..df8915e6bb932acf78602f2928e493c2476160ad 100644 (file)
@@ -112,7 +112,7 @@ class EmbeddedFile : public support::DocFileName
 {
 public:
        EmbeddedFile(std::string const & file, std::string const & inzip_name,
-               bool embedded, ParConstIterator const & pit);
+               bool embedded, Inset const * inset);
 
        /// filename in the zip file, usually the relative path
        std::string inzipName() const { return inzip_name_; }
@@ -121,14 +121,17 @@ public:
        /// embeddedFile() or absFilename() depending on embedding status
        std::string availableFile(Buffer const * buf) const;
 
-       /// paragraph id
-       void addParIter(ParConstIterator const & pit);
-       int parID(int idx) const;
+       /// add an inset that refers to this file
+       void addInset(Inset const * inset);
+       Inset const * inset(int idx) const;
+       /// save the location of this inset as bookmark so that
+       /// it can be located using LFUN_BOOKMARK_GOTO
+       void saveBookmark(Buffer const * buf, int idx) const;
        /// Number of Insets this file item is referred
        /// If refCount() == 0, this file must be manually inserted.
        /// This fact is used by the update() function to skip updating
        /// such items.
-       int refCount() const { return par_it_.size(); }
+       int refCount() const { return inset_list_.size(); }
 
        /// embedding status of this file
        bool embedded() const { return embedded_; }
@@ -160,7 +163,7 @@ private:
        bool valid_;
        /// Current position of the item, used to locate the files. Because one
        /// file item can be referred by several Insets, a vector is used.
-       std::vector<ParConstIterator> par_it_;
+       std::vector<Inset const *> inset_list_;
 };
 
 
@@ -186,7 +189,7 @@ public:
         * \param pit paragraph id.
         */
        void registerFile(std::string const & filename, bool embed = false,
-               ParConstIterator const & pit = ParConstIterator());
+               Inset const * inset = NULL);
 
        /// scan the buffer and get a list of EmbeddedFile
        void update();
index e73d28664212258fb033c8890dc93040958fe75a..9f8c948bfb25ba048d54225ce1f524fa9a47e0a6 100644 (file)
@@ -70,8 +70,8 @@ void ControlEmbeddedFiles::dispatchMessage(string const & msg)
 void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
 {
        BOOST_ASSERT(idx < item.refCount());
-       string const tmp = convert<string>(item.parID(idx));
-       kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
+       item.saveBookmark(&kernel().buffer(), idx);
+       kernel().lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
 }
 
 
index d8c9622fd05fc2fae4175edb58ba786d1cc1fce5..6782a5962253508df4d7a51a2ff6c3a9067ad45c 100644 (file)
@@ -440,8 +440,7 @@ public:
        /// pit is the ParConstIterator of the paragraph containing the inset
        virtual void addToToc(TocList &, Buffer const &, ParConstIterator const &) const {}
        /// report files that can be embedded with the lyx file
-       virtual void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &,
-                       ParConstIterator const &) const {};
+       virtual void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const {};
        /// Fill keys with BibTeX information
        virtual void fillWithBibKeys(Buffer const &,
                BiblioInfo &, InsetIterator const &) const { return; }
index 0899229944bf7725a7f2f9fb6542bc25c2a17950..ef9afad5f20386d284a0a643a7c0f738dba7bcfa 100644 (file)
@@ -494,9 +494,9 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 
 void InsetExternal::registerEmbeddedFiles(Buffer const &,
-       EmbeddedFiles & files, ParConstIterator const & pit) const
+       EmbeddedFiles & files) const
 {
-       files.registerFile(params_.filename.absFilename(), false, pit);
+       files.registerFile(params_.filename.absFilename(), false, this);
 }
 
 
index ac6cc991fa8e9296d38da9c89463bf39c9716b7c..c0e35531aad712f1d1fe68a2a0b07b19e6fec511 100644 (file)
@@ -149,8 +149,7 @@ public:
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
        /// external file can be embedded
-       void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &,
-                       ParConstIterator const &) const;
+       void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
 
 protected:
        InsetExternal(InsetExternal const &);
index 3ff0a613073960f5c702aee5868728998ee0a362..a54de14c98aabbedb3d3d5791460a78457f4e45f 100644 (file)
@@ -231,11 +231,11 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetGraphics::registerEmbeddedFiles(Buffer const &,
-       EmbeddedFiles & files, ParConstIterator const & pit) const
+void InsetGraphics::registerEmbeddedFiles(Buffer const &, 
+       EmbeddedFiles & files) const
 {
        files.registerFile(params().filename.absFilename(), 
-               false, pit);
+               false, this);
 }
 
 
index ee96bc3b626edd322e47ad37f1f6128e0b038b2b..98e44a5db2002286f9d98463eb1e9bf75af554b7 100644 (file)
@@ -79,7 +79,7 @@ public:
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
        /// all graphics can be embedded
-       void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &, ParConstIterator const &) const;
+       void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
 protected:
        InsetGraphics(InsetGraphics const &);
        ///
index ff09039219aeb31039c607017070bb227a8483cf..1a8ec8713c3bfce87dd037285a1e9feee6813234 100644 (file)
@@ -959,12 +959,12 @@ void InsetInclude::updateLabels(Buffer const & buffer,
 
 
 void InsetInclude::registerEmbeddedFiles(Buffer const & buffer,
-       EmbeddedFiles & files, ParConstIterator const & pit) const
+       EmbeddedFiles & files) const
 {
        // include and input are temprarily not considered.
        if (isVerbatim(params_) || isListings(params_))
                files.registerFile(includedFilename(buffer, params_).absFilename(),
-                       false, pit);
+                       false, this);
 }
 
 
index 41d11ab12663a616ed7c4cd8951e6b0a947818b4..c22b2cd61ecb46f8384c3a31f0e9e36ee992843f 100644 (file)
@@ -105,8 +105,7 @@ public:
        ///
        void updateLabels(Buffer const & buffer, ParIterator const &);
        /// child document can be embedded
-       void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &,
-                       ParConstIterator const &) const;
+       void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
 protected:
        InsetInclude(InsetInclude const &);
        ///