3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
7 * \author Angus Leeming
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
18 #include "bufferparams.h"
19 #include "funcrequest.h"
21 #include "LyXAction.h"
22 #include "paragraph.h"
23 #include "pariterator.h"
32 void outline(OutlineOp mode, LCursor & cur)
34 Buffer * buf = & cur.buffer();
35 pit_type & pit = cur.pit();
36 ParagraphList & pars = buf->text().paragraphs();
37 ParagraphList::iterator bgn = pars.begin();
38 // The first paragraph of the area to be copied:
39 ParagraphList::iterator start = boost::next(bgn, pit);
40 // The final paragraph of area to be copied:
41 ParagraphList::iterator finish = start;
42 ParagraphList::iterator end = pars.end();
44 LyXTextClass::const_iterator lit =
45 buf->params().getLyXTextClass().begin();
46 LyXTextClass::const_iterator const lend =
47 buf->params().getLyXTextClass().end();
49 int const thistoclevel = start->layout()->toclevel;
53 // Move out (down) from this section header
56 // Seek the one (on same level) below
57 for (; finish != end; ++finish) {
58 toclevel = finish->layout()->toclevel;
59 if (toclevel != LyXLayout::NOT_IN_TOC
60 && toclevel <= thistoclevel) {
64 ParagraphList::iterator dest = start;
65 // Move out (up) from this header
70 // Search previous same-level header above
71 for (; dest != bgn; --dest) {
72 toclevel = dest->layout()->toclevel;
73 if (toclevel != LyXLayout::NOT_IN_TOC
74 && toclevel <= thistoclevel) {
78 // Not found; do nothing
81 pit_type const newpit = std::distance(bgn, dest);
82 pit_type const len = std::distance(start, finish);
84 pit = std::min(pit, cur.lastpit());
85 recordUndo(cur, Undo::ATOMIC, newpit, pit);
86 pars.insert(dest, start, finish);
87 start = boost::next(bgn, pit);
89 pars.erase(start, finish);
93 // Go down out of current header:
96 // Find next same-level header:
97 for (; finish != end; ++finish) {
98 toclevel = finish->layout()->toclevel;
99 if (toclevel != LyXLayout::NOT_IN_TOC
100 && toclevel <= thistoclevel) {
104 ParagraphList::iterator dest = finish;
105 // Go one down from *this* header:
110 // Go further down to find header to insert in front of:
111 for (; dest != end; ++dest) {
112 toclevel = dest->layout()->toclevel;
113 if (toclevel != LyXLayout::NOT_IN_TOC
114 && toclevel <= thistoclevel) {
118 // One such was found:
119 pit_type newpit = std::distance(bgn, dest);
120 pit_type const len = std::distance(start, finish);
121 recordUndo(cur, Undo::ATOMIC, pit, newpit -1);
122 pars.insert(dest, start, finish);
123 start = boost::next(bgn, pit);
125 pars.erase(start, finish);
130 for (; lit != lend; ++lit) {
131 if ((*lit)->toclevel == thistoclevel + 1 &&
132 start->layout()->labeltype == (*lit)->labeltype) {
133 start->layout((*lit));
140 for (; lit != lend; ++lit) {
141 if ((*lit)->toclevel == thistoclevel - 1 &&
142 start->layout()->labeltype == (*lit)->labeltype) {
143 start->layout((*lit));