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()
122 TocList::const_iterator it = tocs().begin();
123 TocList::const_iterator end = tocs().end();
124 for (; it != end; ++it)
125 toc_models_.push_back(new TocModel(it->second));
129 TocList const & GuiToc::tocs() const
131 return buffer().getMasterBuffer()->tocBackend().tocs();
135 bool GuiToc::initialiseParams(string const & data)
137 InsetCommandMailer::string2params("toc", data, params_);
144 TocList const & tocs = buffer().getMasterBuffer()->
146 TocList::const_iterator it = tocs.begin();
147 TocList::const_iterator end = tocs.end();
148 for (; it != end; ++it) {
149 types_.push_back(it->first);
150 type_names_.push_back(guiName(it->first));
153 string selected_type ;
154 if (params_["type"].empty()) //Then plain toc...
155 selected_type = params_.getCmdName();
157 selected_type = to_ascii(params_["type"]);
159 for (size_t i = 0; i != types_.size(); ++i) {
160 if (selected_type == types_[i]) {
170 bool GuiToc::canOutline(int type) const
172 return types_[type] == "tableofcontents";
176 void GuiToc::outlineUp()
178 dispatch(FuncRequest(LFUN_OUTLINE_UP));
182 void GuiToc::outlineDown()
184 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
188 void GuiToc::outlineIn()
190 dispatch(FuncRequest(LFUN_OUTLINE_IN));
194 void GuiToc::outlineOut()
196 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
200 void GuiToc::updateBackend()
202 buffer().getMasterBuffer()->tocBackend().update();
203 buffer().structureChanged();
207 TocIterator GuiToc::currentTocItem(int type) const
209 BOOST_ASSERT(bufferview());
210 ParConstIterator it(bufferview()->cursor());
211 Buffer const * master = buffer().getMasterBuffer();
212 return master->tocBackend().item(types_[type], it);
216 docstring GuiToc::guiName(string const & type) const
218 if (type == "tableofcontents")
219 return _("Table of Contents");
221 FloatList const & floats = buffer().params().getTextClass().floats();
222 if (floats.typeExist(type))
223 return _(floats.getType(type).listName());
229 void GuiToc::dispatchParams()
232 InsetCommandMailer::params2string("toc", params_);
233 dispatch(FuncRequest(getLfun(), lfun));
237 Dialog * createGuiToc(LyXView & lv)
239 GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
241 // On Mac show as a drawer at the right
242 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
244 return new GuiToc(guiview);
249 } // namespace frontend
252 #include "GuiToc_moc.cpp"