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 "LyXAction.h"
17 #include "paragraph.h"
19 #include "iterators.h"
21 #include "insets/insetfloat.h"
22 #include "insets/insetwrap.h"
24 #include "support/tostr.h"
26 #include "frontends/LyXView.h"
36 string const TocItem::asString() const
38 return string(4 * depth, ' ') + str;
42 void TocItem::goTo(LyXView & lv_) const
44 string const tmp = tostr(id_);
45 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
49 int TocItem::action() const
51 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
56 string const getType(string const & cmdName)
59 if (cmdName == "tableofcontents")
66 TocList const getTocList(Buffer const & buf)
70 LyXTextClass const & textclass = buf.params.getLyXTextClass();
72 ParConstIterator pit = buf.par_iterator_begin();
73 ParConstIterator end = buf.par_iterator_end();
74 for (; pit != end; ++pit) {
76 #warning bogus type (Lgb)
78 char const labeltype = pit->layout()->labeltype;
80 if (labeltype >= LABEL_COUNTER_CHAPTER
81 && labeltype <= LABEL_COUNTER_CHAPTER + buf.params.tocdepth) {
82 // insert this into the table of contents
83 const int depth = max(0, labeltype - textclass.maxcounter());
84 TocItem const item(pit->id(), depth,
85 pit->asString(buf, true));
86 toclist["TOC"].push_back(item);
89 // For each paragraph, traverse its insets and look for
90 // FLOAT_CODE or WRAP_CODE
91 InsetList::const_iterator it = pit->insetlist.begin();
92 InsetList::const_iterator end = pit->insetlist.end();
93 for (; it != end; ++it) {
94 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
96 static_cast<InsetFloat*>(it->inset);
97 il->addToToc(toclist, buf);
98 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
100 static_cast<InsetWrap*>(it->inset);
102 il->addToToc(toclist, buf);
110 vector<string> const getTypes(Buffer const & buffer)
112 vector<string> types;
114 TocList const tmp = getTocList(buffer);
116 TocList::const_iterator cit = tmp.begin();
117 TocList::const_iterator end = tmp.end();
119 for (; cit != end; ++cit) {
120 types.push_back(cit->first);
127 void asciiTocList(string const & type, Buffer const & buffer, ostream & os)
129 TocList const toc_list = getTocList(buffer);
130 TocList::const_iterator cit = toc_list.find(type);
131 if (cit != toc_list.end()) {
132 Toc::const_iterator ccit = cit->second.begin();
133 Toc::const_iterator end = cit->second.end();
134 for (; ccit != end; ++ccit)
135 os << ccit->asString() << '\n';