]> git.lyx.org Git - features.git/commitdiff
* "Goto label" in reference dialog works with master and child documents
authorStefan Schimanski <sts@lyx.org>
Sun, 16 Nov 2008 21:28:06 +0000 (21:28 +0000)
committerStefan Schimanski <sts@lyx.org>
Sun, 16 Nov 2008 21:28:06 +0000 (21:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27590 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/BufferView.cpp

index f73bbb1ba1d5f5ceb30259ebda60c2a261543836..444887bdb6e810d8904cacf4ffda1ab722748a39 100644 (file)
 #include <fstream>
 #include <iomanip>
 #include <map>
+#include <set>
 #include <sstream>
 #include <stack>
 #include <vector>
@@ -124,6 +125,8 @@ typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
 
 } // namespace anon
 
+class BufferSet : public std::set<Buffer const *> {};
+
 class Buffer::Impl
 {
 public:
@@ -1682,12 +1685,38 @@ void Buffer::setParent(Buffer const * buffer)
 }
 
 
-Buffer const * Buffer::parent()
+Buffer const * Buffer::parent() const
 {
        return d->parent_buffer;
 }
 
 
+void Buffer::collectRelatives(BufferSet & bufs) const
+{
+       bufs.insert(this);
+       if (parent())
+               parent()->collectRelatives(bufs);
+
+       // loop over children
+       Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+       Impl::BufferPositionMap::iterator end = d->children_positions.end();
+       for (; it != end; ++it)
+               bufs.insert(const_cast<Buffer *>(it->first));
+}
+
+
+std::vector<Buffer const *> Buffer::allRelatives() const
+{
+       BufferSet bufs;
+       collectRelatives(bufs);
+       BufferSet::iterator it = bufs.begin();
+       std::vector<Buffer const *> ret;
+       for (; it != bufs.end(); ++it)
+               ret.push_back(*it);
+       return ret;
+}
+
+
 Buffer const * Buffer::masterBuffer() const
 {
        if (!d->parent_buffer)
@@ -1703,6 +1732,16 @@ bool Buffer::isChild(Buffer * child) const
 }
 
 
+DocIterator Buffer::firstChildPosition(Buffer const * child)
+{
+       Impl::BufferPositionMap::iterator it;
+       it = d->children_positions.find(child);
+       if (it == d->children_positions.end())
+               return DocIterator();
+       return it->second;
+}
+
+
 template<typename M>
 typename M::iterator greatest_below(M & m, typename M::key_type const & x)
 {
index 57cf298e4f6530ca99cd6d63c87617bd00ff5a6f..697994c9854009feee0adb325348fa0894ab65fc 100644 (file)
@@ -26,6 +26,7 @@ namespace lyx {
 
 class BiblioInfo;
 class BufferParams;
+class BufferSet;
 class DocIterator;
 class ErrorItem;
 class ErrorList;
@@ -272,7 +273,10 @@ public:
 
        /// Set document's parent Buffer.
        void setParent(Buffer const *);
-       Buffer const * parent();
+       Buffer const * parent() const;
+
+       // Collect all relative buffer
+       std::vector<Buffer const *> allRelatives() const;
 
        /** Get the document's master (or \c this if this is not a
            child document)
@@ -359,6 +363,9 @@ public:
        ///
        ParConstIterator par_iterator_end() const;
 
+       // Position of the child buffer where it appears first in the master.
+       DocIterator firstChildPosition(Buffer const * child);
+
        /** \returns true only when the file is fully loaded.
         *  Used to prevent the premature generation of previews
         *  and by the citation inset.
@@ -482,6 +489,9 @@ private:
        void updateMacros(DocIterator & it,
                                     DocIterator & scope) const;
 
+       ///
+       void collectRelatives(BufferSet & bufs) const;
+
        ///
        bool readFileHelper(support::FileName const & s);
        ///
index c6d89d0691a766df38cc2488f8966d17c82e1219..01ee8fd0a5fb1e390cf336ac153a8b7c731ee8ab 100644 (file)
@@ -1074,16 +1074,14 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                docstring label = cmd.argument();
                if (label.empty()) {
                        InsetRef * inset =
-                               getInsetByCode<InsetRef>(d->cursor_,
-                                                        REF_CODE);
+                               getInsetByCode<InsetRef>(d->cursor_, REF_CODE);
                        if (inset) {
                                label = inset->getParam("reference");
                                // persistent=false: use temp_bookmark
                                saveBookmark(0);
                        }
                }
-
-               if (!label.empty())
+               if (!label.empty())
                        gotoLabel(label);
                break;
        }
@@ -1809,15 +1807,22 @@ bool BufferView::setCursorFromInset(Inset const * inset)
 
 void BufferView::gotoLabel(docstring const & label)
 {
-       Toc & toc = buffer().tocBackend().toc("label");
-       TocIterator toc_it = toc.begin();
-       TocIterator end = toc.end();
-       for (; toc_it != end; ++toc_it) {
-               if (label == toc_it->str())
-                       dispatch(toc_it->action());
+       std::vector<Buffer const *> bufs = buffer().allRelatives();
+       std::vector<Buffer const *>::iterator it = bufs.begin();
+       for (; it != bufs.end(); ++it) {
+               Buffer const * buf = *it;
+
+               // find label
+               Toc & toc = buf->tocBackend().toc("label");
+               TocIterator toc_it = toc.begin();
+               TocIterator end = toc.end();
+               for (; toc_it != end; ++toc_it) {
+                       if (label == toc_it->str()) {
+                               dispatch(toc_it->action());
+                               return;
+                       }
+               }
        }
-       //FIXME: We could do a bit more searching thanks to this:
-       //InsetLabel const * inset = buffer_.insetLabel(label);
 }