From c99463ebfc858450ae0bf5ffd185bdb29597861b Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 3 Jun 2008 11:12:45 +0000 Subject: [PATCH] Fix bug http://bugzilla.lyx.org/show_bug.cgi?id=4910 by creating InsetText::addToToc(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25096 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/TocBackend.cpp | 52 ++---------------------------------- src/insets/InsetText.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ src/insets/InsetText.h | 2 ++ 3 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 1ec56700e8..17de467d14 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -151,56 +151,8 @@ void TocBackend::updateItem(DocIterator const & dit) void TocBackend::update() { tocs_.clear(); - - BufferParams const & bufparams = buffer_->params(); - const int min_toclevel = bufparams.documentClass().min_toclevel(); - - Toc & toc = tocs_["tableofcontents"]; - ParConstIterator pit = buffer_->par_iterator_begin(); - ParConstIterator end = buffer_->par_iterator_end(); - for (; pit != end; ++pit) { - - // the string that goes to the toc (could be the optarg) - docstring tocstring; - - // For each paragraph, traverse its insets and let them add - // their toc items - InsetList::const_iterator it = pit->insetList().begin(); - InsetList::const_iterator end = pit->insetList().end(); - for (; it != end; ++it) { - Inset & inset = *it->inset; - pit.pos() = it->pos; - //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; - inset.addToToc(pit); - switch (inset.lyxCode()) { - case OPTARG_CODE: { - if (!tocstring.empty()) - break; - pit.pos() = 0; - Paragraph const & par = - *static_cast(inset).paragraphs().begin(); - if (!pit->labelString().empty()) - tocstring = pit->labelString() + ' '; - tocstring += par.asString(); - break; - } - default: - break; - } - } - - /// now the toc entry for the paragraph - int const toclevel = pit->layout().toclevel; - if (toclevel != Layout::NOT_IN_TOC - && toclevel >= min_toclevel) { - pit.pos() = 0; - // insert this into the table of contents - if (tocstring.empty()) - tocstring = pit->asString(AS_STR_LABEL); - toc.push_back(TocItem(pit, toclevel - min_toclevel, - tocstring)); - } - } + DocIterator dit; + buffer_->inset().addToToc(dit); } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 8231d2cb38..89216ba1c9 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -12,6 +12,8 @@ #include "InsetText.h" +#include "insets/InsetOptArg.h" + #include "buffer_funcs.h" #include "Buffer.h" #include "BufferParams.h" @@ -43,6 +45,7 @@ #include "TextClass.h" #include "Text.h" #include "TextMetrics.h" +#include "TocBackend.h" #include "frontends/alert.h" #include "frontends/Painter.h" @@ -444,6 +447,60 @@ void InsetText::updateLabels(ParIterator const & it) } +void InsetText::addToToc(DocIterator const & cdit) +{ + DocIterator dit = cdit; + dit.push_back(CursorSlice(*this)); + Toc & toc = buffer().tocBackend().toc("tableofcontents"); + + BufferParams const & bufparams = buffer_->params(); + const int min_toclevel = bufparams.documentClass().min_toclevel(); + + // For each paragraph, traverse its insets and let them add + // their toc items + ParagraphList & pars = paragraphs(); + pit_type pend = paragraphs().size(); + for (pit_type pit = 0; pit != pend; ++pit) { + Paragraph const & par = pars[pit]; + dit.pit() = pit; + // the string that goes to the toc (could be the optarg) + docstring tocstring; + InsetList::const_iterator it = par.insetList().begin(); + InsetList::const_iterator end = par.insetList().end(); + for (; it != end; ++it) { + Inset & inset = *it->inset; + dit.pos() = it->pos; + //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; + inset.addToToc(dit); + switch (inset.lyxCode()) { + case OPTARG_CODE: { + if (!tocstring.empty()) + break; + dit.pos() = 0; + Paragraph const & insetpar = + *static_cast(inset).paragraphs().begin(); + if (!par.labelString().empty()) + tocstring = par.labelString() + ' '; + tocstring += insetpar.asString(); + break; + } + default: + break; + } + } + /// now the toc entry for the paragraph + int const toclevel = par.layout().toclevel; + if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) { + dit.pos() = 0; + // insert this into the table of contents + if (tocstring.empty()) + tocstring = par.asString(AS_STR_LABEL); + toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring)); + } + } +} + + bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur) { if (cur.buffer().isClean()) diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index afb874a442..33c5b474b3 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -137,6 +137,8 @@ public: // Update the counters of this inset and of its contents void updateLabels(ParIterator const &); /// + void addToToc(DocIterator const &); + /// Inset * clone() const { return new InsetText(*this); } /// bool notifyCursorLeaves(Cursor const & old, Cursor & cur); -- 2.39.2