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.
This commit is contained in:
Juergen Spitzmueller 2012-12-15 16:47:57 +01:00
parent 9f7c8be6d7
commit dcaab11b09
5 changed files with 25 additions and 12 deletions

View 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();

View 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;

View 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:

View 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);

View 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;