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
|
|
|
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();
|
2006-11-16 12:20:50 +00:00
|
|
|
// The first paragraph of the area to be copied:
|
|
|
|
ParagraphList::iterator start = boost::next(bgn, pit);
|
|
|
|
// The final paragraph of area to be copied:
|
|
|
|
ParagraphList::iterator finish = start;
|
2006-03-29 05:08:42 +00:00
|
|
|
ParagraphList::iterator end = pars.end();
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator lit =
|
|
|
|
buf->params().getLyXTextClass().begin();
|
|
|
|
LyXTextClass::const_iterator const lend =
|
|
|
|
buf->params().getLyXTextClass().end();
|
|
|
|
|
2006-11-16 12:20:50 +00:00
|
|
|
int const thistoclevel = start->layout()->toclevel;
|
2006-03-29 05:08:42 +00:00
|
|
|
int toclevel;
|
|
|
|
switch (mode) {
|
2006-04-28 07:28:10 +00:00
|
|
|
case Up: {
|
2006-11-16 12:20:50 +00:00
|
|
|
// Move out (down) from this section header
|
|
|
|
if (finish != end)
|
|
|
|
++finish;
|
|
|
|
// Seek the one (on same level) below
|
|
|
|
for (; finish != end; ++finish) {
|
|
|
|
toclevel = finish->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
|
|
|
}
|
|
|
|
}
|
2006-11-16 12:20:50 +00:00
|
|
|
ParagraphList::iterator dest = start;
|
|
|
|
// Move out (up) from this header
|
|
|
|
if (dest != bgn)
|
|
|
|
--dest;
|
2006-03-29 05:08:42 +00:00
|
|
|
else
|
|
|
|
break;
|
2006-11-16 12:20:50 +00:00
|
|
|
// Search previous same-level header above
|
|
|
|
for (; dest != bgn; --dest) {
|
|
|
|
toclevel = dest->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
|
|
|
}
|
|
|
|
}
|
2006-11-16 12:20:50 +00:00
|
|
|
// Not found; do nothing
|
|
|
|
if (dest == bgn)
|
|
|
|
break;
|
|
|
|
pit_type const newpit = std::distance(bgn, dest);
|
|
|
|
pit_type const len = std::distance(start, finish);
|
2006-03-29 05:08:42 +00:00
|
|
|
pit += len;
|
2006-11-16 12:20:50 +00:00
|
|
|
pit = std::min(pit, cur.lastpit());
|
|
|
|
recordUndo(cur, Undo::ATOMIC, newpit, pit);
|
|
|
|
pars.insert(dest, start, finish);
|
|
|
|
start = boost::next(bgn, pit);
|
2006-03-29 05:08:42 +00:00
|
|
|
pit = newpit;
|
2006-11-16 12:20:50 +00:00
|
|
|
pars.erase(start, finish);
|
2006-03-29 05:08:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-28 07:28:10 +00:00
|
|
|
case Down: {
|
2006-11-16 12:20:50 +00:00
|
|
|
// Go down out of current header:
|
|
|
|
if (finish != end)
|
|
|
|
++finish;
|
|
|
|
// Find next same-level header:
|
|
|
|
for (; finish != end; ++finish) {
|
|
|
|
toclevel = finish->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
|
|
|
}
|
|
|
|
}
|
2006-11-16 12:20:50 +00:00
|
|
|
ParagraphList::iterator dest = finish;
|
|
|
|
// Go one down from *this* header:
|
|
|
|
if (dest != end)
|
|
|
|
++dest;
|
2006-03-29 05:08:42 +00:00
|
|
|
else
|
|
|
|
break;
|
2006-11-16 12:20:50 +00:00
|
|
|
// Go further down to find header to insert in front of:
|
|
|
|
for (; dest != end; ++dest) {
|
|
|
|
toclevel = dest->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
|
|
|
}
|
|
|
|
}
|
2006-11-16 12:20:50 +00:00
|
|
|
// One such was found:
|
|
|
|
pit_type newpit = std::distance(bgn, dest);
|
|
|
|
pit_type const len = std::distance(start, finish);
|
|
|
|
recordUndo(cur, Undo::ATOMIC, pit, newpit -1);
|
|
|
|
pars.insert(dest, start, finish);
|
|
|
|
start = boost::next(bgn, pit);
|
2006-03-29 05:08:42 +00:00
|
|
|
pit = newpit - len;
|
2006-11-16 12:20:50 +00:00
|
|
|
pars.erase(start, finish);
|
2006-03-29 05:08:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-28 07:28:10 +00:00
|
|
|
case In:
|
2006-11-16 12:20:50 +00:00
|
|
|
recordUndo(cur);
|
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 &&
|
2006-11-16 12:20:50 +00:00
|
|
|
start->layout()->labeltype == (*lit)->labeltype) {
|
|
|
|
start->layout((*lit));
|
2006-03-29 05:08:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-04-28 07:28:10 +00:00
|
|
|
case Out:
|
2006-11-16 12:20:50 +00:00
|
|
|
recordUndo(cur);
|
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 &&
|
2006-11-16 12:20:50 +00:00
|
|
|
start->layout()->labeltype == (*lit)->labeltype) {
|
|
|
|
start->layout((*lit));
|
2006-03-29 05:08:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
} // namespace toc
|
2003-07-27 13:18:55 +00:00
|
|
|
} // namespace lyx
|