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 "frontends/LyXView.h"
36 #include "support/convert.h"
47 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
48 : DockView(parent, "toc", area, flags), params_(TOC_CODE)
50 widget_ = new TocWidget(*this);
52 setWindowTitle(widget_->windowTitle());
62 int GuiToc::getTocDepth(int type)
66 return toc_models_[type]->modelDepth();
70 QStandardItemModel * GuiToc::tocModel(int type)
75 if (toc_models_.empty()) {
76 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
81 << "GuiToc: type " << type
82 << " toc_models_.size() " << toc_models_.size()
85 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
86 return toc_models_[type];
90 QModelIndex GuiToc::currentIndex(int type) const
95 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
96 // This is because a proper ParConstIterator is not constructed in
97 // InsetCaption::addToToc()
101 return toc_models_[type]->modelIndex(currentTocItem(type));
105 void GuiToc::goTo(int type, QModelIndex const & index)
107 if (type < 0 || !index.isValid()
108 || index.model() != toc_models_[type]) {
110 << "GuiToc::goTo(): QModelIndex is invalid!"
115 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
117 TocIterator const it = toc_models_[type]->tocIterator(index);
119 LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
121 string const tmp = convert<string>(it->id());
122 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
126 void GuiToc::updateView()
128 widget_->updateView();
132 TocList const & GuiToc::tocs() const
134 return buffer().masterBuffer()->tocBackend().tocs();
138 bool GuiToc::initialiseParams(string const & data)
140 InsetCommandMailer::string2params("toc", data, params_);
145 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
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().masterBuffer()->tocBackend().update();
205 buffer().structureChanged();
209 TocIterator GuiToc::currentTocItem(int type) const
211 BOOST_ASSERT(bufferview());
212 ParConstIterator it(bufferview()->cursor());
213 return buffer().masterBuffer()->tocBackend().item(types_[type], it);
217 docstring GuiToc::guiName(string const & type) const
219 if (type == "tableofcontents")
220 return _("Table of Contents");
222 FloatList const & floats = buffer().params().getTextClass().floats();
223 if (floats.typeExist(type))
224 return _(floats.getType(type).listName());
230 void GuiToc::dispatchParams()
233 InsetCommandMailer::params2string("toc", params_);
234 dispatch(FuncRequest(getLfun(), lfun));
238 Dialog * createGuiToc(LyXView & lv)
240 GuiView & guiview = static_cast<GuiView &>(lv);
242 // On Mac show as a drawer at the right
243 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
245 return new GuiToc(guiview);
250 } // namespace frontend
253 #include "GuiToc_moc.cpp"