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().getMasterBuffer()->tocBackend().tocs();
49 bool ControlToc::initialiseParams(string const & data)
51 if (!ControlCommand::initialiseParams(data))
56 TocList const & tocs = kernel().buffer().getMasterBuffer()->
58 TocList::const_iterator it = tocs.begin();
59 TocList::const_iterator end = tocs.end();
60 for (; it != end; ++it) {
61 types_.push_back(it->first);
62 type_names_.push_back(getGuiName(it->first));
65 string selected_type ;
66 if(params()["type"].empty()) //Then plain toc...
67 selected_type = params().getCmdName();
69 selected_type = to_ascii(params()["type"]);
71 for (size_t i = 0; i != types_.size(); ++i) {
72 if (selected_type == types_[i]) {
81 void ControlToc::goTo(TocItem const & item)
83 string const tmp = convert<string>(item.id());
84 kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
88 bool ControlToc::canOutline(size_t type) const
90 return types_[type] == "tableofcontents";
94 void ControlToc::outlineUp()
96 kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
100 void ControlToc::outlineDown()
102 kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
106 void ControlToc::outlineIn()
108 kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
112 void ControlToc::outlineOut()
114 kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
118 void ControlToc::updateBackend()
120 kernel().buffer().getMasterBuffer()->tocBackend().update();
121 kernel().buffer().structureChanged();
125 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
127 BOOST_ASSERT(kernel().bufferview());
128 ParConstIterator it(kernel().bufferview()->cursor());
129 Buffer const * master = kernel().buffer().getMasterBuffer();
130 return master->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().getTextClass().floats();
141 if (floats.typeExist(type))
142 return _(floats.getType(type).listName());
147 } // namespace frontend