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.
14 #include "ControlToc.h"
17 #include "BufferView.h"
18 #include "bufferparams.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
24 #include "frontends/LyXView.h"
26 #include "support/convert.h"
37 ControlToc::ControlToc(Dialog & d)
38 : ControlCommand(d, "tableofcontents", "toc")
43 TocList const & ControlToc::tocs() const
45 return kernel().buffer().tocBackend().tocs();
49 bool ControlToc::initialiseParams(string const & data)
51 if (!ControlCommand::initialiseParams(data))
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));
64 string selected_type ;
65 if(params()["type"].empty()) //Then plain toc...
66 selected_type = params().getCmdName();
68 selected_type = to_ascii(params()["type"]);
70 for (size_t i = 0; i != types_.size(); ++i) {
71 if (selected_type == types_[i]) {
80 void ControlToc::goTo(TocItem const & item)
82 string const tmp = convert<string>(item.id());
83 kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
87 bool ControlToc::canOutline(size_t type) const
89 return types_[type] == "tableofcontents";
93 void ControlToc::outlineUp()
95 kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
99 void ControlToc::outlineDown()
101 kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
105 void ControlToc::outlineIn()
107 kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
111 void ControlToc::outlineOut()
113 kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
117 void ControlToc::updateBackend()
119 kernel().buffer().tocBackend().update();
123 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
125 BOOST_ASSERT(kernel().bufferview());
126 ParConstIterator it(kernel().bufferview()->cursor());
127 return kernel().buffer().tocBackend().item(types_[type], it);
131 docstring const ControlToc::getGuiName(string const & type) const
133 if (type == "tableofcontents")
134 return _("Table of Contents");
136 FloatList const & floats =
137 kernel().buffer().params().getLyXTextClass().floats();
138 if (floats.typeExist(type))
139 return from_utf8(floats.getType(type).name());
144 } // namespace frontend