From 9092bffc32c3a9206818f82265ff9a6db4bc7fbe Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 17 May 2007 19:19:37 +0000 Subject: [PATCH] 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. 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 | 18 +++++++++--------- src/TocBackend.h | 11 +++++------ src/buffer_funcs.cpp | 8 +++++--- src/frontends/LyXView.cpp | 2 +- src/frontends/controllers/ControlToc.cpp | 10 ++++++---- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 074624c86a..103721213a 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -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; diff --git a/src/TocBackend.h b/src/TocBackend.h index f25fc83399..ca69b09237 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -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; diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 6527018748..7a8618cc15 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -698,7 +698,8 @@ void updateLabels(Buffer const & buf, bool childonly) Buffer & cbuf = const_cast(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(); } } diff --git a/src/frontends/LyXView.cpp b/src/frontends/LyXView.cpp index 2342882247..6c358ae014 100644 --- a/src/frontends/LyXView.cpp +++ b/src/frontends/LyXView.cpp @@ -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_ = diff --git a/src/frontends/controllers/ControlToc.cpp b/src/frontends/controllers/ControlToc.cpp index d1cee72ecc..ad3c8d3c64 100644 --- a/src/frontends/controllers/ControlToc.cpp +++ b/src/frontends/controllers/ControlToc.cpp @@ -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); }