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"
34 ControlToc::ControlToc(Dialog & d)
35 : ControlCommand(d, "toc")
40 TocList const & ControlToc::tocs() const
42 return buffer().getMasterBuffer()->tocBackend().tocs();
46 bool ControlToc::initialiseParams(string const & data)
48 if (!ControlCommand::initialiseParams(data))
53 TocList const & tocs = buffer().getMasterBuffer()->
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));
62 string selected_type ;
63 if(params()["type"].empty()) //Then plain toc...
64 selected_type = params().getCmdName();
66 selected_type = to_ascii(params()["type"]);
68 for (size_t i = 0; i != types_.size(); ++i) {
69 if (selected_type == types_[i]) {
79 void ControlToc::goTo(TocItem const & item)
81 string const tmp = convert<string>(item.id());
82 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
86 bool ControlToc::canOutline(size_t type) const
88 return types_[type] == "tableofcontents";
92 void ControlToc::outlineUp()
94 dispatch(FuncRequest(LFUN_OUTLINE_UP));
98 void ControlToc::outlineDown()
100 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
104 void ControlToc::outlineIn()
106 dispatch(FuncRequest(LFUN_OUTLINE_IN));
110 void ControlToc::outlineOut()
112 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
116 void ControlToc::updateBackend()
118 buffer().getMasterBuffer()->tocBackend().update();
119 buffer().structureChanged();
123 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
125 BOOST_ASSERT(bufferview());
126 ParConstIterator it(bufferview()->cursor());
127 Buffer const * master = buffer().getMasterBuffer();
128 return master->tocBackend().item(types_[type], it);
132 docstring const ControlToc::getGuiName(string const & type) const
134 if (type == "tableofcontents")
135 return _("Table of Contents");
137 FloatList const & floats = buffer().params().getTextClass().floats();
138 if (floats.typeExist(type))
139 return _(floats.getType(type).listName());
144 } // namespace frontend