Changeset 27590

Show
Ignore:
Timestamp:
11/16/08 22:28:06 (2 months ago)
Author:
sts
Message:

* "Goto label" in reference dialog works with master and child documents

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lyx-devel/trunk/src/Buffer.cpp

    r27565 r27590  
    102102#include <iomanip> 
    103103#include <map> 
     104#include <set> 
    104105#include <sstream> 
    105106#include <stack> 
     
    124125 
    125126} // namespace anon 
     127 
     128class BufferSet : public std::set<Buffer const *> {}; 
    126129 
    127130class Buffer::Impl 
     
    16831686 
    16841687 
    1685 Buffer const * Buffer::parent() 
     1688Buffer const * Buffer::parent() const 
    16861689{ 
    16871690        return d->parent_buffer; 
     1691} 
     1692 
     1693 
     1694void Buffer::collectRelatives(BufferSet & bufs) const 
     1695{ 
     1696        bufs.insert(this); 
     1697        if (parent()) 
     1698                parent()->collectRelatives(bufs); 
     1699 
     1700        // loop over children 
     1701        Impl::BufferPositionMap::iterator it = d->children_positions.begin(); 
     1702        Impl::BufferPositionMap::iterator end = d->children_positions.end(); 
     1703        for (; it != end; ++it) 
     1704                bufs.insert(const_cast<Buffer *>(it->first)); 
     1705} 
     1706 
     1707 
     1708std::vector<Buffer const *> Buffer::allRelatives() const 
     1709{ 
     1710        BufferSet bufs; 
     1711        collectRelatives(bufs); 
     1712        BufferSet::iterator it = bufs.begin(); 
     1713        std::vector<Buffer const *> ret; 
     1714        for (; it != bufs.end(); ++it) 
     1715                ret.push_back(*it); 
     1716        return ret; 
    16881717} 
    16891718 
     
    17011730{ 
    17021731        return d->children_positions.find(child) != d->children_positions.end(); 
     1732} 
     1733 
     1734 
     1735DocIterator Buffer::firstChildPosition(Buffer const * child) 
     1736{ 
     1737        Impl::BufferPositionMap::iterator it; 
     1738        it = d->children_positions.find(child); 
     1739        if (it == d->children_positions.end()) 
     1740                return DocIterator(); 
     1741        return it->second; 
    17031742} 
    17041743 
  • lyx-devel/trunk/src/Buffer.h

    r27565 r27590  
    2727class BiblioInfo; 
    2828class BufferParams; 
     29class BufferSet; 
    2930class DocIterator; 
    3031class ErrorItem; 
     
    273274        /// Set document's parent Buffer. 
    274275        void setParent(Buffer const *); 
    275         Buffer const * parent(); 
     276        Buffer const * parent() const; 
     277 
     278        // Collect all relative buffer 
     279        std::vector<Buffer const *> allRelatives() const; 
    276280 
    277281        /** Get the document's master (or \c this if this is not a 
     
    359363        /// 
    360364        ParConstIterator par_iterator_end() const; 
     365 
     366        // Position of the child buffer where it appears first in the master. 
     367        DocIterator firstChildPosition(Buffer const * child); 
    361368 
    362369        /** \returns true only when the file is fully loaded. 
     
    484491 
    485492        /// 
     493        void collectRelatives(BufferSet & bufs) const; 
     494 
     495        /// 
    486496        bool readFileHelper(support::FileName const & s); 
    487497        /// 
  • lyx-devel/trunk/src/BufferView.cpp

    r27578 r27590  
    10751075                if (label.empty()) { 
    10761076                        InsetRef * inset = 
    1077                                 getInsetByCode<InsetRef>(d->cursor_, 
    1078                                                          REF_CODE); 
     1077                                getInsetByCode<InsetRef>(d->cursor_, REF_CODE); 
    10791078                        if (inset) { 
    10801079                                label = inset->getParam("reference"); 
     
    10831082                        } 
    10841083                } 
    1085  
    1086                 if (!label.empty()) 
     1084                if (!label.empty()) 
    10871085                        gotoLabel(label); 
    10881086                break; 
     
    18101808void BufferView::gotoLabel(docstring const & label) 
    18111809{ 
    1812         Toc & toc = buffer().tocBackend().toc("label"); 
    1813         TocIterator toc_it = toc.begin(); 
    1814         TocIterator end = toc.end(); 
    1815         for (; toc_it != end; ++toc_it) { 
    1816                 if (label == toc_it->str()) 
    1817                         dispatch(toc_it->action()); 
    1818         } 
    1819         //FIXME: We could do a bit more searching thanks to this: 
    1820         //InsetLabel const * inset = buffer_.insetLabel(label); 
     1810        std::vector<Buffer const *> bufs = buffer().allRelatives(); 
     1811        std::vector<Buffer const *>::iterator it = bufs.begin(); 
     1812        for (; it != bufs.end(); ++it) { 
     1813                Buffer const * buf = *it; 
     1814 
     1815                // find label 
     1816                Toc & toc = buf->tocBackend().toc("label"); 
     1817                TocIterator toc_it = toc.begin(); 
     1818                TocIterator end = toc.end(); 
     1819                for (; toc_it != end; ++toc_it) { 
     1820                        if (label == toc_it->str()) { 
     1821                                dispatch(toc_it->action()); 
     1822                                return; 
     1823                        } 
     1824                } 
     1825        } 
    18211826} 
    18221827