]> git.lyx.org Git - features.git/commitdiff
Correctly handle environment sequences in TOC
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 15 Dec 2012 15:47:57 +0000 (16:47 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 15 Dec 2012 15:50:08 +0000 (16:50 +0100)
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
src/Text.h
src/Text3.cpp
src/TocBackend.cpp
src/insets/InsetText.cpp

index 390b69d7146da96eaf30dcf704caf07011df7fd7..48f8c82491fc40db4c3f867a5a52fb6e7a67848f 100644 (file)
@@ -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();
index c8c5876c23c1b265e52747c9d5a422f86902fc81..7ee76d232b5754c6975be75ffaef6332800e4ee7 100644 (file)
@@ -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;
index 1c7616ba4bca9de2d79f9cbadfae989ffe594875..421d8f428dc37255400d5a215f568a8a936aacb7 100644 (file)
@@ -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:
index 656f326e15c956aef9495823e5d6ef97f8261800..e3dcca1d0e59a201b268d397f91f9772561e2aa2 100644 (file)
@@ -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);
index ed2633b429dad7d29596470ea797a273a36964de..8b77149d8d9212e8d3f7e7340ea530f2de6ead04 100644 (file)
@@ -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;