Jose,

This patch solves this crash (due to an assertion):
1) Open EmbeddedObject.lyx
2) Open Toc
3) Click on section 7.2.2 which is in the second child document
4) assertion.

Besides that, this patch 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.

I think this should go in before beta3. So?

Abdel.
Index: buffer_funcs.cpp
===================================================================
--- buffer_funcs.cpp    (revision 18366)
+++ buffer_funcs.cpp    (working copy)
@@ -698,7 +698,8 @@
 
        Buffer & cbuf = const_cast<Buffer &>(buf);
        cbuf.tocBackend().update();
-       cbuf.structureChanged();
+       if (!childonly)
+               cbuf.structureChanged();
 }
 
 
@@ -706,8 +707,12 @@
 {
        if (par_it->layout()->labeltype == LABEL_COUNTER
                && par_it->layout()->toclevel != Layout::NOT_IN_TOC) {
-               buffer.tocBackend().updateItem(par_it);
-               buffer.structureChanged();
+               //buffer.tocBackend().updateItem(par_it);
+               Buffer * master = buffer.getMasterBuffer();
+               master->tocBackend().updateItem(par_it);
+               //if (master != &buffer)
+               //      master->tocBackend().update();
+               master->structureChanged();
        }
 }
 
Index: frontends/controllers/ControlToc.cpp
===================================================================
--- frontends/controllers/ControlToc.cpp        (revision 18366)
+++ frontends/controllers/ControlToc.cpp        (working copy)
@@ -42,7 +42,7 @@
 
 TocList const & ControlToc::tocs() const
 {
-       return kernel().buffer().tocBackend().tocs();
+       return kernel().buffer().getMasterBuffer()->tocBackend().tocs();
 }
 
 
@@ -53,7 +53,8 @@
 
        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::updateBackend()
 {
-       kernel().buffer().tocBackend().update();
+       kernel().buffer().getMasterBuffer()->tocBackend().update();
        kernel().buffer().structureChanged();
 }
 
@@ -125,7 +126,8 @@
 {
        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);
 }
 
 
Index: frontends/LyXView.cpp
===================================================================
--- frontends/LyXView.cpp       (revision 18366)
+++ frontends/LyXView.cpp       (working copy)
@@ -196,7 +196,7 @@
                        boost::bind(&WorkArea::redraw, work_area_));
 
        bufferStructureChangedConnection_ =
-               buf.structureChanged.connect(
+               buf.getMasterBuffer()->structureChanged.connect(
                        boost::bind(&LyXView::updateToc, this));
 
        errorsConnection_ =
Index: TocBackend.cpp
===================================================================
--- TocBackend.cpp      (revision 18370)
+++ TocBackend.cpp      (working copy)
@@ -37,8 +37,8 @@
 // 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())
@@ -131,7 +131,7 @@
        BufferParams const & bufparams = buffer_->params();
        const int min_toclevel = bufparams.getTextClass().min_toclevel();
 
-       TocIterator toc_item = item("tableofcontents", par_it);
+       TocIterator toc_item = item("tableofcontents", par_it, false);
 
        docstring tocstring;
 
@@ -170,9 +170,6 @@
        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 @@
                        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 @@
                        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: TocBackend.h
===================================================================
--- TocBackend.h        (revision 18370)
+++ TocBackend.h        (working copy)
@@ -69,9 +69,6 @@
 
        /// Full item string
        docstring str_;
-
-       /// Set to true if the item comes from a child document.
-       bool child_;
 };
 
 
@@ -110,7 +107,10 @@
        ///
        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;
 

Reply via email to