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"
28 #include "FloatList.h"
29 #include "FuncRequest.h"
30 #include "TextClass.h"
32 #include "support/convert.h"
33 #include "support/debug.h"
34 #include "support/gettext.h"
43 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
44 : DockView(parent, "toc", qt_("Outline"), area, flags)
46 widget_ = new TocWidget(*this, &parent);
58 void GuiToc::clearTocModels()
60 const unsigned int size = toc_models_.size();
61 for (unsigned int i = 0; i < size; ++i) {
62 delete toc_models_[i];
68 int GuiToc::getTocDepth(int type)
72 return toc_models_[type]->modelDepth();
76 QStandardItemModel * GuiToc::tocModel(int type)
81 if (toc_models_.empty()) {
82 LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
86 LYXERR(Debug::GUI, "GuiToc: type " << type
87 << " toc_models_.size() " << toc_models_.size());
89 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
90 return toc_models_[type];
94 QModelIndex GuiToc::currentIndex(int type) const
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]) {
107 LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
111 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
113 TocIterator const it = toc_models_[type]->tocIterator(index);
115 LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
117 string const tmp = convert<string>(it->id());
118 dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
122 void GuiToc::updateView()
124 widget_->updateView();
128 TocList const & GuiToc::tocs() const
130 return buffer().masterBuffer()->tocBackend().tocs();
134 bool GuiToc::initialiseParams(string const & data)
136 LYXERR(Debug::GUI, data);
137 QString str = QString::fromUtf8(data.c_str());
139 if (str.contains("tableofcontents"))
140 new_type = "tableofcontents";
141 else if (str.contains("floatlist")) {
142 if (str.contains("\"figure"))
144 else if (str.contains("\"table"))
146 else if (str.contains("\"algorithm"))
147 new_type = "algorithm";
149 new_type = toqstr(data);
154 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
155 TocList::const_iterator it = tocs.begin();
156 TocList::const_iterator end = tocs.end();
157 for (; it != end; ++it) {
158 types_.push_back(toqstr(it->first));
159 type_names_.push_back(toqstr(guiName(it->first)));
160 toc_models_.push_back(new TocModel(it->second));
163 int selected_type = -1;
164 for (int i = 0; i != types_.size(); ++i) {
165 if (new_type == types_[i]) {
170 widget_->updateGui(selected_type);
176 bool GuiToc::canOutline(int type) const
178 return types_[type] == "tableofcontents";
182 void GuiToc::outlineUp()
184 dispatch(FuncRequest(LFUN_OUTLINE_UP));
188 void GuiToc::outlineDown()
190 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
194 void GuiToc::outlineIn()
196 dispatch(FuncRequest(LFUN_OUTLINE_IN));
200 void GuiToc::outlineOut()
202 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
206 void GuiToc::updateBackend()
208 buffer().masterBuffer()->tocBackend().update();
209 buffer().structureChanged();
213 TocIterator GuiToc::currentTocItem(int type) const
215 BOOST_ASSERT(bufferview());
216 ParConstIterator it(bufferview()->cursor());
217 return buffer().masterBuffer()->tocBackend().item(fromqstr(types_[type]), it);
221 docstring GuiToc::guiName(string const & type) const
223 if (type == "tableofcontents")
224 return _("Table of Contents");
226 return _("Child Documents");
227 if (type == "embedded")
228 return _("Embedded Files");
229 if (type == "graphics")
230 return _("List of Graphics");
231 if (type == "equation")
232 return _("List of Equations");
233 if (type == "footnote")
234 return _("List of Foot notes");
235 if (type == "listing")
236 return _("List of Listings");
238 return _("List of Indexes");
239 if (type == "marginalnote")
240 return _("List of Marginal notes");
242 return _("List of Notes");
243 if (type == "citation")
244 return _("List of Citations");
246 return _("Labels and References");
248 FloatList const & floats = buffer().params().documentClass().floats();
249 if (floats.typeExist(type))
250 return _(floats.getType(type).listName());
256 void GuiToc::dispatchParams()
261 Dialog * createGuiToc(GuiView & lv)
263 GuiView & guiview = static_cast<GuiView &>(lv);
265 // On Mac show as a drawer at the right
266 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
268 return new GuiToc(guiview);
273 } // namespace frontend
276 #include "GuiToc_moc.cpp"