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