]> git.lyx.org Git - lyx.git/blob - src/toc.C
Extend the navigate menu to child docs
[lyx.git] / src / toc.C
1 /**
2  * \file toc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jean-Marc Lasgouttes
7  * \author Angus Leeming
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "toc.h"
16
17 #include "buffer.h"
18 #include "bufferparams.h"
19 #include "funcrequest.h"
20 #include "lyxtext.h"
21 #include "LyXAction.h"
22 #include "paragraph.h"
23 #include "pariterator.h"
24 #include "cursor.h"
25 #include "debug.h"
26 #include "undo.h"
27
28
29 namespace lyx {
30 namespace toc {
31
32 void outline(OutlineOp mode,  LCursor & cur)
33 {
34         recordUndo(cur);
35         Buffer * buf = & cur.buffer();
36         pit_type & pit = cur.pit();
37         ParagraphList & pars = buf->text().paragraphs();
38         ParagraphList::iterator bgn = pars.begin();
39         ParagraphList::iterator s = boost::next(bgn, pit);
40         ParagraphList::iterator p = s;
41         ParagraphList::iterator end = pars.end();
42
43         LyXTextClass::const_iterator lit =
44                 buf->params().getLyXTextClass().begin();
45         LyXTextClass::const_iterator const lend =
46                 buf->params().getLyXTextClass().end();
47
48         int const thistoclevel = s->layout()->toclevel;
49         int toclevel;
50         switch (mode) {
51                 case Up: {
52                         if (p != end)
53                                 ++p;
54                         for (; p != end; ++p) {
55                                 toclevel = p->layout()->toclevel;
56                                 if (toclevel != LyXLayout::NOT_IN_TOC
57                                     && toclevel <= thistoclevel) {
58                                         break;
59                                 }
60                         }
61                         ParagraphList::iterator q = s;
62                         if (q != bgn)
63                                 --q;
64                         else
65                                 break;
66                         for (; q != bgn; --q) {
67                                 toclevel = q->layout()->toclevel;
68                                 if (toclevel != LyXLayout::NOT_IN_TOC
69                                     && toclevel <= thistoclevel) {
70                                         break;
71                                 }
72                         }
73                         pit_type const newpit = std::distance(pars.begin(), q);
74                         pit_type const len = std::distance(s, p);
75                         pit += len;
76                         pars.insert(q, s, p);
77                         s = boost::next(pars.begin(), pit);
78                         ParagraphList::iterator t = boost::next(s, len);
79                         pit = newpit;
80                         pars.erase(s, t);
81                 break;
82                 }
83                 case Down: {
84                            if (p != end)
85                                 ++p;
86                         for (; p != end; ++p) {
87                                 toclevel = p->layout()->toclevel;
88                                 if (toclevel != LyXLayout::NOT_IN_TOC
89                                     && toclevel <= thistoclevel) {
90                                         break;
91                                 }
92                         }
93                         ParagraphList::iterator q = p;
94                         if (q != end)
95                                 ++q;
96                         else
97                                 break;
98                         for (; q != end; ++q) {
99                                 toclevel = q->layout()->toclevel;
100                                 if (toclevel != LyXLayout::NOT_IN_TOC
101                                     && toclevel <= thistoclevel) {
102                                         break;
103                                 }
104                         }
105                         pit_type const newpit = std::distance(pars.begin(), q);
106                         pit_type const len = std::distance(s, p);
107                         pars.insert(q, s, p);
108                         s = boost::next(pars.begin(), pit);
109                         ParagraphList::iterator t = boost::next(s, len);
110                         pit = newpit - len;
111                         pars.erase(s, t);
112                 break;
113                 }
114                 case In:
115                         for (; lit != lend; ++lit) {
116                                 if ((*lit)->toclevel == thistoclevel + 1 &&
117                                     s->layout()->labeltype == (*lit)->labeltype) {
118                                         s->layout((*lit));
119                                         break;
120                                 }
121                         }
122                 break;
123                 case Out:
124                         for (; lit != lend; ++lit) {
125                                 if ((*lit)->toclevel == thistoclevel - 1 &&
126                                     s->layout()->labeltype == (*lit)->labeltype) {
127                                         s->layout((*lit));
128                                         break;
129                                 }
130                         }
131                 break;
132                 default:
133                 break;
134         }
135 }
136
137
138 } // namespace toc
139 } // namespace lyx