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"
32 #include "TextClass.h"
34 #include "support/convert.h"
45 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
46 : DockView(parent, "toc", area, flags), params_(TOC_CODE)
48 widget_ = new TocWidget(*this);
50 setWindowTitle(widget_->windowTitle());
60 int GuiToc::getTocDepth(int type)
64 return toc_models_[type]->modelDepth();
68 QStandardItemModel * GuiToc::tocModel(int type)
73 if (toc_models_.empty()) {
74 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
79 << "GuiToc: type " << type
80 << " toc_models_.size() " << toc_models_.size()
83 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
84 return toc_models_[type];
88 QModelIndex GuiToc::currentIndex(int type) const
93 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
94 // This is because a proper ParConstIterator is not constructed in
95 // InsetCaption::addToToc()
99 return toc_models_[type]->modelIndex(currentTocItem(type));
103 void GuiToc::goTo(int type, QModelIndex const & index)
105 if (type < 0 || !index.isValid()
106 || index.model() != toc_models_[type]) {
108 << "GuiToc::goTo(): QModelIndex is invalid!"
113 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
115 TocIterator const it = toc_models_[type]->tocIterator(index);
117 LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
119 string const tmp = convert<string>(it->id());
120 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
124 void GuiToc::updateView()
126 widget_->updateView();
130 TocList const & GuiToc::tocs() const
132 return buffer().masterBuffer()->tocBackend().tocs();
136 bool GuiToc::initialiseParams(string const & data)
138 InsetCommandMailer::string2params("toc", data, params_);
143 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
144 TocList::const_iterator it = tocs.begin();
145 TocList::const_iterator end = tocs.end();
146 for (; it != end; ++it) {
147 types_.push_back(it->first);
148 type_names_.push_back(guiName(it->first));
149 toc_models_.push_back(new TocModel(it->second));
152 string selected_type ;
153 if (params_["type"].empty()) //Then plain toc...
154 selected_type = params_.getCmdName();
156 selected_type = to_ascii(params_["type"]);
158 for (size_t i = 0; i != types_.size(); ++i) {
159 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().masterBuffer()->tocBackend().update();
203 buffer().structureChanged();
207 TocIterator GuiToc::currentTocItem(int type) const
209 BOOST_ASSERT(bufferview());
210 ParConstIterator it(bufferview()->cursor());
211 return buffer().masterBuffer()->tocBackend().item(types_[type], it);
215 docstring GuiToc::guiName(string const & type) const
217 if (type == "tableofcontents")
218 return _("Table of Contents");
220 FloatList const & floats = buffer().params().getTextClass().floats();
221 if (floats.typeExist(type))
222 return _(floats.getType(type).listName());
228 void GuiToc::dispatchParams()
231 InsetCommandMailer::params2string("toc", params_);
232 dispatch(FuncRequest(getLfun(), lfun));
236 Dialog * createGuiToc(LyXView & lv)
238 GuiView & guiview = static_cast<GuiView &>(lv);
240 // On Mac show as a drawer at the right
241 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
243 return new GuiToc(guiview);
248 } // namespace frontend
251 #include "GuiToc_moc.cpp"