3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
16 #include "ControlToc.h"
19 #include "BufferView.h"
20 #include "bufferparams.h"
22 #include "FloatList.h"
23 #include "funcrequest.h"
26 #include "frontends/LyXView.h"
28 #include "support/convert.h"
40 ControlToc::ControlToc(Dialog & d)
41 : ControlCommand(d, "tableofcontents", "toc")
46 TocList const & ControlToc::tocs() const
48 return kernel().buffer().tocBackend().tocs();
52 bool ControlToc::initialiseParams(string const & data)
54 if (!ControlCommand::initialiseParams(data))
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));
67 string selected_type ;
68 if(params()["type"].empty()) //Then plain toc...
69 selected_type = params().getCmdName();
71 selected_type = to_ascii(params()["type"]);
73 for (size_t i = 0; i != types_.size(); ++i) {
74 if (selected_type == types_[i]) {
84 void ControlToc::goTo(TocItem const & item)
86 string const tmp = convert<string>(item.id());
87 kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
91 bool ControlToc::canOutline(size_t type) const
93 BOOST_ASSERT(type >= 0 && type < int(types_.size()));
94 return types_[type] == "tableofcontents";
98 void ControlToc::outlineUp()
100 kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
104 void ControlToc::outlineDown()
106 kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
110 void ControlToc::outlineIn()
112 kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
116 void ControlToc::outlineOut()
118 kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
122 void ControlToc::updateBackend()
124 kernel().buffer().tocBackend().update();
128 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
130 BOOST_ASSERT(kernel().bufferview());
131 ParConstIterator it(kernel().bufferview()->cursor());
132 return kernel().buffer().tocBackend().item(types_[type], it);
136 docstring const ControlToc::getGuiName(string const & type) const
138 if (type == "tableofcontents")
139 return _("Table of Contents");
141 FloatList const & floats =
142 kernel().buffer().params().getLyXTextClass().floats();
143 if (floats.typeExist(type))
144 return from_utf8(floats.getType(type).name());
149 } // namespace frontend