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