]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlToc.C
* ControlToc:
[features.git] / src / frontends / controllers / ControlToc.C
1 /**
2  * \file ControlToc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <sstream>
12
13 #include <config.h>
14
15 #include "ControlToc.h"
16 #include "buffer.h"
17 #include "BufferView.h"
18 #include "bufferparams.h"
19 #include "debug.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23
24 #include "frontends/LyXView.h"
25
26 #include "support/convert.h"
27
28 using std::vector;
29 using std::string;
30
31
32 class Buffer;
33
34 namespace lyx {
35 namespace frontend {
36
37
38 ControlToc::ControlToc(Dialog & d)
39         : ControlCommand(d, "tableofcontents", "toc")
40 {
41 }
42
43
44 bool ControlToc::initialiseParams(string const & data)
45 {
46         update();
47         return ControlCommand::initialiseParams(data);
48 }
49
50 void ControlToc::goTo(TocItem const & item)
51 {
52         string const tmp = convert<string>(item.id());
53         kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
54 }
55
56
57 bool ControlToc::canOutline(string const & type)
58 {
59         return type == "tableofcontents";
60 }
61
62
63 void ControlToc::outlineUp()
64 {
65         kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
66 }
67
68
69 void ControlToc::outlineDown()
70 {
71         kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
72 }
73
74
75 void ControlToc::outlineIn()
76 {
77         kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
78 }
79
80
81 void ControlToc::outlineOut()
82 {
83         kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
84 }
85
86
87 vector<string> const & ControlToc::getTypes() const
88 {
89         return kernel().buffer().tocBackend().types();
90 }
91
92
93 void ControlToc::updateBackend()
94 {
95         kernel().buffer().tocBackend().update();
96 }
97
98
99 TocIterator const ControlToc::getCurrentTocItem(
100         string const & type) const
101 {
102         BOOST_ASSERT(kernel().bufferview());
103
104         ParConstIterator it(kernel().bufferview()->cursor());
105         return kernel().buffer().tocBackend().item(type, it);
106 }
107
108
109 docstring const ControlToc::getGuiName(string const & type) const
110 {
111         if (type == "tableofcontents")
112                 return _("Table of Contents");
113
114         FloatList const & floats =
115                 kernel().buffer().params().getLyXTextClass().floats();
116         if (floats.typeExist(type))
117                 return from_utf8(floats.getType(type).name());
118         else
119                 return _(type);
120 }
121
122
123 Toc const empty_list;
124
125 Toc const & ControlToc::getContents(string const & type) const
126 {
127         // This shouldn't be possible...
128         if (!kernel().isBufferAvailable()) {
129                 return empty_list;
130         }
131
132         return kernel().buffer().tocBackend().toc(type);
133 }
134
135 } // namespace frontend
136 } // namespace lyx