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(GuiViewBase & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
47 : DockView(parent, "toc", area, flags), params_("toc")
49 widget_ = new TocWidget(*this);
51 setWindowTitle(widget_->windowTitle());
55 int GuiToc::getTocDepth(int type)
59 return toc_models_[type]->modelDepth();
63 QStandardItemModel * GuiToc::tocModel(int type)
68 if (toc_models_.empty()) {
69 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
74 << "GuiToc: type " << type
75 << " toc_models_.size() " << toc_models_.size()
78 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
79 return toc_models_[type];
83 QModelIndex GuiToc::currentIndex(int type) const
88 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
89 // This is because a proper ParConstIterator is not constructed in
90 // InsetCaption::addToToc()
94 return toc_models_[type]->modelIndex(currentTocItem(type));
98 void GuiToc::goTo(int type, QModelIndex const & index)
100 if (type < 0 || !index.isValid()
101 || index.model() != toc_models_[type]) {
103 << "GuiToc::goTo(): QModelIndex is invalid!"
108 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
110 TocIterator const it = toc_models_[type]->tocIterator(index);
112 LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
114 string const tmp = convert<string>(it->id());
115 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
119 void GuiToc::updateView()
121 widget_->updateView();
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_);
138 TocList const & tocs = buffer().getMasterBuffer()->
140 TocList::const_iterator it = tocs.begin();
141 TocList::const_iterator end = tocs.end();
142 for (; it != end; ++it) {
143 types_.push_back(it->first);
144 type_names_.push_back(guiName(it->first));
145 toc_models_.push_back(new TocModel(it->second));
148 string selected_type ;
149 if (params_["type"].empty()) //Then plain toc...
150 selected_type = params_.getCmdName();
152 selected_type = to_ascii(params_["type"]);
154 for (size_t i = 0; i != types_.size(); ++i) {
155 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 GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
240 return new GuiToc(guiview);
245 } // namespace frontend
248 #include "GuiToc_moc.cpp"