3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
16 #include "funcrequest.h"
17 #include "LyXAction.h"
18 #include "iterators.h"
20 #include "insets/insetfloat.h"
21 #include "insets/insetwrap.h"
23 #include "support/tostr.h"
25 #include "frontends/LyXView.h"
35 string const TocItem::asString() const
37 return string(4 * depth, ' ') + str;
41 void TocItem::goTo(LyXView & lv_) const
43 string const tmp = tostr(id_);
44 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
48 int TocItem::action() const
50 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
55 string const getType(string const & cmdName)
58 if (cmdName == "tableofcontents")
65 TocList const getTocList(Buffer const & buf)
69 LyXTextClass const & textclass = buf.params.getLyXTextClass();
71 ParConstIterator pit = buf.par_iterator_begin();
72 ParConstIterator end = buf.par_iterator_end();
73 for (; pit != end; ++pit) {
75 #warning bogus type (Lgb)
77 char const labeltype = pit->layout()->labeltype;
79 if (labeltype >= LABEL_COUNTER_CHAPTER
80 && labeltype <= LABEL_COUNTER_CHAPTER + buf.params.tocdepth) {
81 // insert this into the table of contents
82 const int depth = max(0, labeltype - textclass.maxcounter());
83 TocItem const item(pit->id(), depth,
84 pit->asString(buf, true));
85 toclist["TOC"].push_back(item);
88 // For each paragraph, traverse its insets and look for
89 // FLOAT_CODE or WRAP_CODE
90 InsetList::const_iterator it = pit->insetlist.begin();
91 InsetList::const_iterator end = pit->insetlist.end();
92 for (; it != end; ++it) {
93 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
95 static_cast<InsetFloat*>(it->inset);
96 il->addToToc(toclist, buf);
97 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
99 static_cast<InsetWrap*>(it->inset);
101 il->addToToc(toclist, buf);
109 vector<string> const getTypes(Buffer const & buffer)
111 vector<string> types;
113 TocList const tmp = getTocList(buffer);
115 TocList::const_iterator cit = tmp.begin();
116 TocList::const_iterator end = tmp.end();
118 for (; cit != end; ++cit) {
119 types.push_back(cit->first);
126 void asciiTocList(string const & type, Buffer const & buffer, ostream & os)
128 TocList const toc_list = getTocList(buffer);
129 TocList::const_iterator cit = toc_list.find(type);
130 if (cit != toc_list.end()) {
131 Toc::const_iterator ccit = cit->second.begin();
132 Toc::const_iterator end = cit->second.end();
133 for (; ccit != end; ++ccit)
134 os << ccit->asString() << '\n';