From dcaab11b09d9be2c7b561f9028d30d5a624ecbb9 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 15 Dec 2012 16:47:57 +0100 Subject: [PATCH] Correctly handle environment sequences in TOC Only the first paragraph in those sequences goes into the TOC, since the environment is merged. This is needed to handle the forthcoming beamer environments properly in the outliner. --- src/Text.cpp | 11 +++++++++++ src/Text.h | 2 ++ src/Text3.cpp | 18 +++++++++--------- src/TocBackend.cpp | 4 ++-- src/insets/InsetText.cpp | 2 +- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index 390b69d714..48f8c82491 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -265,6 +265,17 @@ bool Text::isFirstInSequence(pit_type par_offset) const } +int Text::getTocLevel(pit_type par_offset) const +{ + Paragraph const & par = pars_[par_offset]; + + if (par.layout().isEnvironment() && !isFirstInSequence(par_offset)) + return Layout::NOT_IN_TOC; + + return par.layout().toclevel; +} + + Font const Text::outerFont(pit_type par_offset) const { depth_type par_depth = pars_[par_offset].getDepth(); diff --git a/src/Text.h b/src/Text.h index c8c5876c23..7ee76d232b 100644 --- a/src/Text.h +++ b/src/Text.h @@ -334,6 +334,8 @@ public: pit_type outerHook(pit_type par) const; /// Is it the first par with same depth and layout? bool isFirstInSequence(pit_type par) const; + /// Is this paragraph in the table of contents? + int getTocLevel(pit_type par) const; /// Get the font of the "environment" of paragraph \p par_offset in \p pars. /// All font changes of the paragraph are relative to this font. Font const outerFont(pit_type par_offset) const; diff --git a/src/Text3.cpp b/src/Text3.cpp index 1c7616ba4b..421d8f428d 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -344,7 +344,7 @@ static void outline(OutlineOp mode, Cursor & cur) DocumentClass const & tc = buf.params().documentClass(); - int const thistoclevel = start->layout().toclevel; + int const thistoclevel = buf.text().getTocLevel(distance(bgn, start)); int toclevel; // Move out (down) from this section header @@ -353,7 +353,7 @@ static void outline(OutlineOp mode, Cursor & cur) // Seek the one (on same level) below for (; finish != end; ++finish) { - toclevel = finish->layout().toclevel; + toclevel = buf.text().getTocLevel(distance(bgn, finish)); if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) break; } @@ -370,7 +370,7 @@ static void outline(OutlineOp mode, Cursor & cur) // Search previous same-level header above do { --dest; - toclevel = dest->layout().toclevel; + toclevel = buf.text().getTocLevel(distance(bgn, dest)); } while(dest != bgn && (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)); @@ -393,7 +393,7 @@ static void outline(OutlineOp mode, Cursor & cur) ParagraphList::iterator dest = boost::next(finish, 1); // Go further down to find header to insert in front of: for (; dest != end; ++dest) { - toclevel = dest->layout().toclevel; + toclevel = buf.text().getTocLevel(distance(bgn, dest)); if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) break; @@ -410,7 +410,7 @@ static void outline(OutlineOp mode, Cursor & cur) pit_type const len = distance(start, finish); buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1); for (; start != finish; ++start) { - toclevel = start->layout().toclevel; + toclevel = buf.text().getTocLevel(distance(bgn, start)); if (toclevel == Layout::NOT_IN_TOC) continue; DocumentClass::const_iterator lit = tc.begin(); @@ -429,7 +429,7 @@ static void outline(OutlineOp mode, Cursor & cur) pit_type const len = distance(start, finish); buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1); for (; start != finish; ++start) { - toclevel = start->layout().toclevel; + toclevel = buf.text().getTocLevel(distance(bgn, start)); if (toclevel == Layout::NOT_IN_TOC) continue; DocumentClass::const_iterator lit = tc.begin(); @@ -798,7 +798,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) ParagraphList::iterator finish = start; ParagraphList::iterator end = pars.end(); - int const thistoclevel = start->layout().toclevel; + int const thistoclevel = buf.text().getTocLevel(distance(bgn, start)); if (thistoclevel == Layout::NOT_IN_TOC) break; @@ -812,7 +812,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // Seek the one (on same level) below for (; finish != end; ++finish, ++cur.pit()) { - int const toclevel = finish->layout().toclevel; + int const toclevel = buf.text().getTocLevel(distance(bgn, finish)); if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) break; } @@ -2770,7 +2770,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_OUTLINE_OUT: // FIXME: LyX is not ready for outlining within inset. enable = isMainText() - && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC; + && cur.buffer()->text().getTocLevel(cur.pit()) != Layout::NOT_IN_TOC; break; case LFUN_NEWLINE_INSERT: diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 656f326e15..e3dcca1d0e 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -118,7 +118,7 @@ Toc & TocBackend::toc(string const & type) bool TocBackend::updateItem(DocIterator const & dit) { - if (dit.paragraph().layout().toclevel == Layout::NOT_IN_TOC) + if (dit.text()->getTocLevel(dit.pit()) == Layout::NOT_IN_TOC) return false; if (toc("tableofcontents").empty()) { @@ -154,7 +154,7 @@ bool TocBackend::updateItem(DocIterator const & dit) } } - int const toclevel = par.layout().toclevel; + int const toclevel = toc_item->dit_.text()->getTocLevel(toc_item->dit_.pit()); if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel && tocstring.empty()) tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS); diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index ed2633b429..8b77149d8d 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -821,7 +821,7 @@ void InsetText::addToToc(DocIterator const & cdit) const arginset = inset.asInsetText(); } // now the toc entry for the paragraph - int const toclevel = par.layout().toclevel; + int const toclevel = text().getTocLevel(pit); if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) { // insert this into the table of contents docstring tocstring; -- 2.39.2