3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
18 #include "TocWidget.h"
19 #include "FuncRequest.h"
20 #include "insets/InsetCommand.h"
23 #include "qt_helpers.h"
26 #include "BufferView.h"
27 #include "BufferParams.h"
29 #include "FloatList.h"
30 #include "FuncRequest.h"
33 #include "frontends/LyXView.h"
35 #include "support/convert.h"
46 GuiToc::GuiToc(Dialog & dialog)
47 : Controller(dialog), params_("toc")
51 int GuiToc::getTocDepth(int type)
55 return toc_models_[type]->modelDepth();
59 QStandardItemModel * GuiToc::tocModel(int type)
64 if (toc_models_.empty()) {
65 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
70 << "GuiToc: type " << type
71 << " toc_models_.size() " << toc_models_.size()
74 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
75 return toc_models_[type];
79 QModelIndex GuiToc::currentIndex(int type) const
84 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
85 // This is because a proper ParConstIterator is not constructed in
86 // InsetCaption::addToToc()
90 return toc_models_[type]->modelIndex(currentTocItem(type));
94 void GuiToc::goTo(int type, QModelIndex const & index)
96 if (type < 0 || !index.isValid()
97 || index.model() != toc_models_[type]) {
99 << "GuiToc::goTo(): QModelIndex is invalid!"
104 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
106 TocIterator const it = toc_models_[type]->tocIterator(index);
108 LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
110 string const tmp = convert<string>(it->id());
111 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
115 void GuiToc::updateView()
118 TocList::const_iterator it = tocs().begin();
119 TocList::const_iterator end = tocs().end();
120 for (; it != end; ++it)
121 toc_models_.push_back(new TocModel(it->second));
125 TocList const & GuiToc::tocs() const
127 return buffer().getMasterBuffer()->tocBackend().tocs();
131 bool GuiToc::initialiseParams(string const & data)
133 InsetCommandMailer::string2params("toc", data, params_);
140 TocList const & tocs = buffer().getMasterBuffer()->
142 TocList::const_iterator it = tocs.begin();
143 TocList::const_iterator end = tocs.end();
144 for (; it != end; ++it) {
145 types_.push_back(it->first);
146 type_names_.push_back(guiName(it->first));
149 string selected_type ;
150 if (params_["type"].empty()) //Then plain toc...
151 selected_type = params_.getCmdName();
153 selected_type = to_ascii(params_["type"]);
155 for (size_t i = 0; i != types_.size(); ++i) {
156 if (selected_type == types_[i]) {
166 bool GuiToc::canOutline(int type) const
168 return types_[type] == "tableofcontents";
172 void GuiToc::outlineUp()
174 dispatch(FuncRequest(LFUN_OUTLINE_UP));
178 void GuiToc::outlineDown()
180 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
184 void GuiToc::outlineIn()
186 dispatch(FuncRequest(LFUN_OUTLINE_IN));
190 void GuiToc::outlineOut()
192 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
196 void GuiToc::updateBackend()
198 buffer().getMasterBuffer()->tocBackend().update();
199 buffer().structureChanged();
203 TocIterator GuiToc::currentTocItem(int type) const
205 BOOST_ASSERT(bufferview());
206 ParConstIterator it(bufferview()->cursor());
207 Buffer const * master = buffer().getMasterBuffer();
208 return master->tocBackend().item(types_[type], it);
212 docstring GuiToc::guiName(string const & type) const
214 if (type == "tableofcontents")
215 return _("Table of Contents");
217 FloatList const & floats = buffer().params().getTextClass().floats();
218 if (floats.typeExist(type))
219 return _(floats.getType(type).listName());
225 void GuiToc::dispatchParams()
228 InsetCommandMailer::params2string("toc", params_);
229 dispatch(FuncRequest(getLfun(), lfun));
233 Dialog * createGuiToc(LyXView & lv)
235 GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
237 // On Mac show as a drawer at the right
238 return new DockView<GuiToc, TocWidget>(guiview, "toc",
239 Qt::RightDockWidgetArea, Qt::Drawer);
241 return new DockView<GuiToc, TocWidget>(guiview, "toc");
246 } // namespace frontend
249 #include "GuiToc_moc.cpp"