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());
61 int GuiToc::getTocDepth(int type)
65 return toc_models_[type]->modelDepth();
69 QStandardItemModel * GuiToc::tocModel(int type)
74 if (toc_models_.empty()) {
75 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
80 << "GuiToc: type " << type
81 << " toc_models_.size() " << toc_models_.size()
84 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
85 return toc_models_[type];
89 QModelIndex GuiToc::currentIndex(int type) const
94 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
95 // This is because a proper ParConstIterator is not constructed in
96 // InsetCaption::addToToc()
100 return toc_models_[type]->modelIndex(currentTocItem(type));
104 void GuiToc::goTo(int type, QModelIndex const & index)
106 if (type < 0 || !index.isValid()
107 || index.model() != toc_models_[type]) {
109 << "GuiToc::goTo(): QModelIndex is invalid!"
114 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
116 TocIterator const it = toc_models_[type]->tocIterator(index);
118 LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
120 string const tmp = convert<string>(it->id());
121 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
125 void GuiToc::updateView()
127 widget_->updateView();
131 TocList const & GuiToc::tocs() const
133 return buffer().getMasterBuffer()->tocBackend().tocs();
137 bool GuiToc::initialiseParams(string const & data)
139 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));
151 toc_models_.push_back(new TocModel(it->second));
154 string selected_type ;
155 if (params_["type"].empty()) //Then plain toc...
156 selected_type = params_.getCmdName();
158 selected_type = to_ascii(params_["type"]);
160 for (size_t i = 0; i != types_.size(); ++i) {
161 if (selected_type == types_[i]) {
172 bool GuiToc::canOutline(int type) const
174 return types_[type] == "tableofcontents";
178 void GuiToc::outlineUp()
180 dispatch(FuncRequest(LFUN_OUTLINE_UP));
184 void GuiToc::outlineDown()
186 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
190 void GuiToc::outlineIn()
192 dispatch(FuncRequest(LFUN_OUTLINE_IN));
196 void GuiToc::outlineOut()
198 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
202 void GuiToc::updateBackend()
204 buffer().getMasterBuffer()->tocBackend().update();
205 buffer().structureChanged();
209 TocIterator GuiToc::currentTocItem(int type) const
211 BOOST_ASSERT(bufferview());
212 ParConstIterator it(bufferview()->cursor());
213 Buffer const * master = buffer().getMasterBuffer();
214 return master->tocBackend().item(types_[type], it);
218 docstring GuiToc::guiName(string const & type) const
220 if (type == "tableofcontents")
221 return _("Table of Contents");
223 FloatList const & floats = buffer().params().getTextClass().floats();
224 if (floats.typeExist(type))
225 return _(floats.getType(type).listName());
231 void GuiToc::dispatchParams()
234 InsetCommandMailer::params2string("toc", params_);
235 dispatch(FuncRequest(getLfun(), lfun));
239 Dialog * createGuiToc(LyXView & lv)
241 GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
243 // On Mac show as a drawer at the right
244 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
246 return new GuiToc(guiview);
251 } // namespace frontend
254 #include "GuiToc_moc.cpp"