]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlToc.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[features.git] / src / frontends / controllers / ControlToc.C
1 /**
2  * \file ControlToc.cpp
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  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlToc.h"
15
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::string;
29
30
31 class Buffer;
32
33 namespace lyx {
34 namespace frontend {
35
36
37 ControlToc::ControlToc(Dialog & d)
38         : ControlCommand(d, "tableofcontents", "toc")
39 {
40 }
41
42
43 TocList const & ControlToc::tocs() const
44 {
45         return kernel().buffer().tocBackend().tocs();
46 }
47
48
49 bool ControlToc::initialiseParams(string const & data)
50 {
51         if (!ControlCommand::initialiseParams(data))
52                 return false;
53
54         types_.clear();
55         type_names_.clear();
56         TocList const & tocs = kernel().buffer().tocBackend().tocs();
57         TocList::const_iterator it = tocs.begin();
58         TocList::const_iterator end = tocs.end();
59         for (; it != end; ++it) {
60                 types_.push_back(it->first);
61                 type_names_.push_back(getGuiName(it->first));
62         }
63
64         string selected_type ;
65         if(params()["type"].empty()) //Then plain toc...
66                 selected_type = params().getCmdName();
67         else
68                 selected_type = to_ascii(params()["type"]);
69         selected_type_ = -1;
70         for (size_t i = 0;  i != types_.size(); ++i) {
71                 if (selected_type == types_[i]) {
72                         selected_type_ = i;
73                         break;
74                 }
75         }
76
77         return true;
78 }
79
80 void ControlToc::goTo(TocItem const & item)
81 {
82         string const tmp = convert<string>(item.id());
83         kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
84 }
85
86
87 bool ControlToc::canOutline(size_t type) const
88 {
89         return types_[type] == "tableofcontents";
90 }
91
92
93 void ControlToc::outlineUp()
94 {
95         kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
96 }
97
98
99 void ControlToc::outlineDown()
100 {
101         kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
102 }
103
104
105 void ControlToc::outlineIn()
106 {
107         kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
108 }
109
110
111 void ControlToc::outlineOut()
112 {
113         kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
114 }
115
116
117 void ControlToc::updateBackend()
118 {
119         kernel().buffer().tocBackend().update();
120 }
121
122
123 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
124 {
125         BOOST_ASSERT(kernel().bufferview());
126         ParConstIterator it(kernel().bufferview()->cursor());
127         return kernel().buffer().tocBackend().item(types_[type], it);
128 }
129
130
131 docstring const ControlToc::getGuiName(string const & type) const
132 {
133         if (type == "tableofcontents")
134                 return _("Table of Contents");
135
136         FloatList const & floats =
137                 kernel().buffer().params().getLyXTextClass().floats();
138         if (floats.typeExist(type))
139                 return from_utf8(floats.getType(type).name());
140         else
141                 return _(type);
142 }
143
144 } // namespace frontend
145 } // namespace lyx