2003-08-23 00:17:00 +00:00
|
|
|
/**
|
|
|
|
* \file toc.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-07-21 15:51:07 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
2006-04-19 14:48:22 +00:00
|
|
|
* \author Abdelrazak Younes
|
2002-07-21 15:51:07 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-07-21 15:51:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "toc.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "funcrequest.h"
|
2006-11-09 18:21:51 +00:00
|
|
|
#include "lyxtext.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "LyXAction.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
#include "paragraph.h"
|
2006-11-09 18:21:51 +00:00
|
|
|
#include "pariterator.h"
|
2006-04-19 14:48:22 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "debug.h"
|
2006-04-26 17:43:03 +00:00
|
|
|
#include "undo.h"
|
2002-07-21 15:51:07 +00:00
|
|
|
|
|
|
|
|
2003-07-27 13:18:55 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace toc {
|
2002-07-21 15:51:07 +00:00
|
|
|
|
2006-04-26 17:43:03 +00:00
|
|
|
void outline(OutlineOp mode, LCursor & cur)
|
2006-03-29 05:08:42 +00:00
|
|
|
{
|
2006-04-26 17:43:03 +00:00
|
|
|
recordUndo(cur);
|
|
|
|
Buffer * buf = & cur.buffer();
|
|
|
|
pit_type & pit = cur.pit();
|
2006-03-29 05:08:42 +00:00
|
|
|
ParagraphList & pars = buf->text().paragraphs();
|
|
|
|
ParagraphList::iterator bgn = pars.begin();
|
|
|
|
ParagraphList::iterator s = boost::next(bgn, pit);
|
|
|
|
ParagraphList::iterator p = s;
|
|
|
|
ParagraphList::iterator end = pars.end();
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator lit =
|
|
|
|
buf->params().getLyXTextClass().begin();
|
|
|
|
LyXTextClass::const_iterator const lend =
|
|
|
|
buf->params().getLyXTextClass().end();
|
|
|
|
|
|
|
|
int const thistoclevel = s->layout()->toclevel;
|
|
|
|
int toclevel;
|
|
|
|
switch (mode) {
|
2006-04-28 07:28:10 +00:00
|
|
|
case Up: {
|
2006-03-29 05:08:42 +00:00
|
|
|
if (p != end)
|
|
|
|
++p;
|
|
|
|
for (; p != end; ++p) {
|
|
|
|
toclevel = p->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ParagraphList::iterator q = s;
|
|
|
|
if (q != bgn)
|
|
|
|
--q;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
for (; q != bgn; --q) {
|
|
|
|
toclevel = q->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pit_type const newpit = std::distance(pars.begin(), q);
|
|
|
|
pit_type const len = std::distance(s, p);
|
|
|
|
pit += len;
|
|
|
|
pars.insert(q, s, p);
|
|
|
|
s = boost::next(pars.begin(), pit);
|
|
|
|
ParagraphList::iterator t = boost::next(s, len);
|
|
|
|
pit = newpit;
|
|
|
|
pars.erase(s, t);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-28 07:28:10 +00:00
|
|
|
case Down: {
|
2006-04-05 23:56:29 +00:00
|
|
|
if (p != end)
|
2006-03-29 05:08:42 +00:00
|
|
|
++p;
|
|
|
|
for (; p != end; ++p) {
|
|
|
|
toclevel = p->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ParagraphList::iterator q = p;
|
|
|
|
if (q != end)
|
|
|
|
++q;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
for (; q != end; ++q) {
|
|
|
|
toclevel = q->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pit_type const newpit = std::distance(pars.begin(), q);
|
|
|
|
pit_type const len = std::distance(s, p);
|
|
|
|
pars.insert(q, s, p);
|
|
|
|
s = boost::next(pars.begin(), pit);
|
|
|
|
ParagraphList::iterator t = boost::next(s, len);
|
|
|
|
pit = newpit - len;
|
|
|
|
pars.erase(s, t);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-28 07:28:10 +00:00
|
|
|
case In:
|
2006-03-29 05:08:42 +00:00
|
|
|
for (; lit != lend; ++lit) {
|
2006-04-26 17:43:03 +00:00
|
|
|
if ((*lit)->toclevel == thistoclevel + 1 &&
|
|
|
|
s->layout()->labeltype == (*lit)->labeltype) {
|
2006-03-29 05:08:42 +00:00
|
|
|
s->layout((*lit));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-04-28 07:28:10 +00:00
|
|
|
case Out:
|
2006-03-29 05:08:42 +00:00
|
|
|
for (; lit != lend; ++lit) {
|
2006-04-26 17:43:03 +00:00
|
|
|
if ((*lit)->toclevel == thistoclevel - 1 &&
|
|
|
|
s->layout()->labeltype == (*lit)->labeltype) {
|
2006-03-29 05:08:42 +00:00
|
|
|
s->layout((*lit));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
} // namespace toc
|
2003-07-27 13:18:55 +00:00
|
|
|
} // namespace lyx
|