2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file toc.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* 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
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "FuncRequest.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
#include "Text.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "LyXAction.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "ParIterator.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2006-04-19 14:48:22 +00:00
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +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
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void outline(OutlineOp mode, Cursor & cur)
|
2006-03-29 05:08:42 +00:00
|
|
|
{
|
2007-08-21 13:03:55 +00:00
|
|
|
Buffer & buf = cur.buffer();
|
2006-04-26 17:43:03 +00:00
|
|
|
pit_type & pit = cur.pit();
|
2007-08-21 13:03:55 +00:00
|
|
|
ParagraphList & pars = buf.text().paragraphs();
|
2006-03-29 05:08:42 +00:00
|
|
|
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();
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
TextClass::const_iterator lit =
|
2007-08-21 13:03:55 +00:00
|
|
|
buf.params().getTextClass().begin();
|
2007-04-29 19:53:54 +00:00
|
|
|
TextClass::const_iterator const lend =
|
2007-08-21 13:03:55 +00:00
|
|
|
buf.params().getTextClass().end();
|
2006-03-29 05:08:42 +00:00
|
|
|
|
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;
|
2007-04-29 18:58:28 +00:00
|
|
|
if (toclevel != Layout::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
|
2007-03-27 05:53:14 +00:00
|
|
|
if (dest == bgn)
|
2006-03-29 05:08:42 +00:00
|
|
|
break;
|
2006-11-16 12:20:50 +00:00
|
|
|
// Search previous same-level header above
|
2007-03-27 05:53:14 +00:00
|
|
|
do {
|
|
|
|
--dest;
|
2006-11-16 12:20:50 +00:00
|
|
|
toclevel = dest->layout()->toclevel;
|
2007-03-27 05:58:10 +00:00
|
|
|
} while(dest != bgn
|
2007-04-29 18:58:28 +00:00
|
|
|
&& (toclevel == Layout::NOT_IN_TOC
|
2007-03-27 05:58:10 +00:00
|
|
|
|| toclevel > thistoclevel));
|
2006-11-16 12:20:50 +00:00
|
|
|
// Not found; do nothing
|
2007-04-29 18:58:28 +00:00
|
|
|
if (toclevel == Layout::NOT_IN_TOC
|
2007-03-27 05:58:10 +00:00
|
|
|
|| toclevel > thistoclevel)
|
2006-11-16 12:20:50 +00:00
|
|
|
break;
|
|
|
|
pit_type const newpit = std::distance(bgn, dest);
|
|
|
|
pit_type const len = std::distance(start, finish);
|
2007-03-05 13:16:55 +00:00
|
|
|
pit_type const deletepit = pit + len;
|
|
|
|
recordUndo(cur, Undo::ATOMIC, newpit, deletepit - 1);
|
2006-11-16 12:20:50 +00:00
|
|
|
pars.insert(dest, start, finish);
|
2007-03-27 05:53:14 +00:00
|
|
|
start = boost::next(pars.begin(), deletepit);
|
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:
|
2007-05-28 22:27:45 +00:00
|
|
|
if (finish != end)
|
2006-11-16 12:20:50 +00:00
|
|
|
++finish;
|
|
|
|
// Find next same-level header:
|
|
|
|
for (; finish != end; ++finish) {
|
|
|
|
toclevel = finish->layout()->toclevel;
|
2007-04-29 18:58:28 +00:00
|
|
|
if (toclevel != Layout::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;
|
2007-04-29 18:58:28 +00:00
|
|
|
if (toclevel != Layout::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);
|
2007-03-27 05:53:14 +00:00
|
|
|
recordUndo(cur, Undo::ATOMIC, pit, newpit - 1);
|
2006-11-16 12:20:50 +00:00
|
|
|
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
|