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]) {
83 void ControlToc::goTo(TocItem const & item)
85 string const tmp = convert<string>(item.id());
86 kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
90 bool ControlToc::canOutline(size_t type) const
92 return types_[type] == "tableofcontents";
96 void ControlToc::outlineUp()
98 kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
102 void ControlToc::outlineDown()
104 kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
108 void ControlToc::outlineIn()
110 kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
114 void ControlToc::outlineOut()
116 kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
120 void ControlToc::updateBackend()
122 kernel().buffer().tocBackend().update();
126 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
128 BOOST_ASSERT(kernel().bufferview());
129 ParConstIterator it(kernel().bufferview()->cursor());
130 return kernel().buffer().tocBackend().item(types_[type], it);
134 docstring const ControlToc::getGuiName(string const & type) const
136 if (type == "tableofcontents")
137 return _("Table of Contents");
139 FloatList const & floats =
140 kernel().buffer().params().getLyXTextClass().floats();
141 if (floats.typeExist(type))
142 return from_utf8(floats.getType(type).name());
147 } // namespace frontend