]> git.lyx.org Git - features.git/commitdiff
This patch solves this crash (due to an assertion):
authorAbdelrazak Younes <younes@lyx.org>
Thu, 17 May 2007 19:19:37 +0000 (19:19 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 17 May 2007 19:19:37 +0000 (19:19 +0000)
1) Open EmbeddedObject.lyx
2) Open Toc
3) Click on section 7.2.2 which is in the second child document
4) assertion.

This commit adds proper support for multi-part documents. With this each child document has access to the _full_ TOC tree (including LOT and LOF). This enables to switch between master and child document using the TOC.

* buffer_funcs.cpp:
  - updateLabels(): do not emit Buffer::structureChanged() signal for child document
  - checkBufferStructure(): update the structure of the master document.

* ControlToc.cpp: always use the TocBackend of the master document.

* LyXView::connectBuffer(): connect structureChanged() of master document.

* TocBackend:
  - TocItem: get rid of child_ member.
  - TocBackend::item(): only compare items from the same document.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18386 a592a061-630c-0410-9148-cb99ea01b6c8

src/TocBackend.cpp
src/TocBackend.h
src/buffer_funcs.cpp
src/frontends/LyXView.cpp
src/frontends/controllers/ControlToc.cpp

index 074624c86ad995bfdca24d1bb12bb13120b8abb4..103721213ae5e278139cacf2b59d14bdd0cc3ea5 100644 (file)
@@ -37,8 +37,8 @@ using std::string;
 // TocItem implementation
 
 TocItem::TocItem(ParConstIterator const & par_it, int d,
-               docstring const & s, bool child)
-               : par_it_(par_it), depth_(d), str_(s), child_(child)
+               docstring const & s)
+               : par_it_(par_it), depth_(d), str_(s)
 {
 /*
        if (!uid_.empty())
@@ -170,9 +170,6 @@ void TocBackend::update()
        BufferParams const & bufparams = buffer_->params();
        const int min_toclevel = bufparams.getTextClass().min_toclevel();
 
-       // Is this a child document?
-       bool const child_document = buffer_->getMasterBuffer() != buffer_;
-
        Toc & toc = tocs_["tableofcontents"];
        ParConstIterator pit = buffer_->par_iterator_begin();
        ParConstIterator end = buffer_->par_iterator_end();
@@ -212,14 +209,14 @@ void TocBackend::update()
                        if (tocstring.empty())
                                tocstring = pit->asString(*buffer_, true);
                        toc.push_back(TocItem(pit, toclevel - min_toclevel,
-                               tocstring, child_document));
+                               tocstring));
                }
        }
 }
 
 
-TocIterator const TocBackend::item(
-       std::string const & type, ParConstIterator const & par_it) const
+TocIterator const TocBackend::item(std::string const & type,
+               ParConstIterator const & par_it) const
 {
        TocList::const_iterator toclist_it = tocs_.find(type);
        // Is the type supported?
@@ -242,7 +239,10 @@ TocIterator const TocBackend::item(
                        par_it_text.backwardPos();
 
        for (; it != last; --it) {
-               if (it->child_)
+               // We verify that we don't compare contents of two
+               // different document. This happens when you
+               // have parent and child documents.
+               if (&it->par_it_[0].inset() != &par_it_text[0].inset())
                        continue;
                if (it->par_it_ <= par_it_text)
                        return it;
index f25fc83399f8e46cd68cca8f2bedaa4de11f290e..ca69b09237331f495de21956e670b995f0e3d3c0 100644 (file)
@@ -41,8 +41,7 @@ public:
        ///
        TocItem(ParConstIterator const & par_it = ParConstIterator(),
                int d = -1,
-               docstring const & s = docstring(),
-               bool child = false
+               docstring const & s = docstring()
                );
        ///
        ~TocItem() {}
@@ -69,9 +68,6 @@ protected:
 
        /// Full item string
        docstring str_;
-
-       /// Set to true if the item comes from a child document.
-       bool child_;
 };
 
 
@@ -110,7 +106,10 @@ public:
        ///
        Toc const & toc(std::string const & type) const;
        /// Return the first Toc Item before the cursor
-       TocIterator const item(std::string const & type, ParConstIterator const &) const;
+       TocIterator const item(
+               std::string const & type, ///< Type of Toc.
+               ParConstIterator const & ///< The cursor location in the document.
+               ) const;
 
        void writePlaintextTocList(std::string const & type, odocstream & os) const;
 
index 6527018748ae4f21737c42a8cfdcfd30bb5085b6..7a8618cc1564d3ebf30557a68dfcabacd507ba5f 100644 (file)
@@ -698,7 +698,8 @@ void updateLabels(Buffer const & buf, bool childonly)
 
        Buffer & cbuf = const_cast<Buffer &>(buf);
        cbuf.tocBackend().update();
-       cbuf.structureChanged();
+       if (!childonly)
+               cbuf.structureChanged();
 }
 
 
@@ -706,8 +707,9 @@ void checkBufferStructure(Buffer & buffer, ParIterator const & par_it)
 {
        if (par_it->layout()->labeltype == LABEL_COUNTER
                && par_it->layout()->toclevel != Layout::NOT_IN_TOC) {
-               buffer.tocBackend().updateItem(par_it);
-               buffer.structureChanged();
+               Buffer * master = buffer.getMasterBuffer();
+               master->tocBackend().updateItem(par_it);
+               master->structureChanged();
        }
 }
 
index 2342882247e88fcb4f65bf3337e0a7eaefe1b00c..6c358ae01470d99cabece1da3f8d3c2409fea682 100644 (file)
@@ -196,7 +196,7 @@ void LyXView::connectBuffer(Buffer & buf)
                        boost::bind(&WorkArea::redraw, work_area_));
 
        bufferStructureChangedConnection_ =
-               buf.structureChanged.connect(
+               buf.getMasterBuffer()->structureChanged.connect(
                        boost::bind(&LyXView::updateToc, this));
 
        errorsConnection_ =
index d1cee72ecc1df722be1635c72b5cc691c2f361b8..ad3c8d3c6422344ca51f225ca1f314c451c5ec18 100644 (file)
@@ -42,7 +42,7 @@ ControlToc::ControlToc(Dialog & d)
 
 TocList const & ControlToc::tocs() const
 {
-       return kernel().buffer().tocBackend().tocs();
+       return kernel().buffer().getMasterBuffer()->tocBackend().tocs();
 }
 
 
@@ -53,7 +53,8 @@ bool ControlToc::initialiseParams(string const & data)
 
        types_.clear();
        type_names_.clear();
-       TocList const & tocs = kernel().buffer().tocBackend().tocs();
+       TocList const & tocs = kernel().buffer().getMasterBuffer()->
+               tocBackend().tocs();
        TocList::const_iterator it = tocs.begin();
        TocList::const_iterator end = tocs.end();
        for (; it != end; ++it) {
@@ -116,7 +117,7 @@ void ControlToc::outlineOut()
 
 void ControlToc::updateBackend()
 {
-       kernel().buffer().tocBackend().update();
+       kernel().buffer().getMasterBuffer()->tocBackend().update();
        kernel().buffer().structureChanged();
 }
 
@@ -125,7 +126,8 @@ TocIterator const ControlToc::getCurrentTocItem(size_t type) const
 {
        BOOST_ASSERT(kernel().bufferview());
        ParConstIterator it(kernel().bufferview()->cursor());
-       return kernel().buffer().tocBackend().item(types_[type], it);
+       Buffer const * master = kernel().buffer().getMasterBuffer();
+       return master->tocBackend().item(types_[type], it);
 }