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_CODE)
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().masterBuffer()->tocBackend().tocs();
137 bool GuiToc::initialiseParams(string const & data)
139 InsetCommandMailer::string2params("toc", data, params_);
144 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
145 TocList::const_iterator it = tocs.begin();
146 TocList::const_iterator end = tocs.end();
147 for (; it != end; ++it) {
148 types_.push_back(it->first);
149 type_names_.push_back(guiName(it->first));
150 toc_models_.push_back(new TocModel(it->second));
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]) {
171 bool GuiToc::canOutline(int type) const
173 return types_[type] == "tableofcontents";
177 void GuiToc::outlineUp()
179 dispatch(FuncRequest(LFUN_OUTLINE_UP));
183 void GuiToc::outlineDown()
185 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
189 void GuiToc::outlineIn()
191 dispatch(FuncRequest(LFUN_OUTLINE_IN));
195 void GuiToc::outlineOut()
197 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
201 void GuiToc::updateBackend()
203 buffer().masterBuffer()->tocBackend().update();
204 buffer().structureChanged();
208 TocIterator GuiToc::currentTocItem(int type) const
210 BOOST_ASSERT(bufferview());
211 ParConstIterator it(bufferview()->cursor());
212 return buffer().masterBuffer()->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"