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)
72 LyXTextClass const & textclass = buf->params.getLyXTextClass();
74 ParConstIterator pit = buf->par_iterator_begin();
75 ParConstIterator end = buf->par_iterator_end();
76 for (; pit != end; ++pit) {
78 #warning bogus type (Lgb)
80 char const labeltype = pit->layout()->labeltype;
82 if (labeltype >= LABEL_COUNTER_CHAPTER
83 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
84 // insert this into the table of contents
85 const int depth = max(0, labeltype - textclass.maxcounter());
86 TocItem const item(pit->id(), depth,
87 pit->asString(buf, true));
88 toclist["TOC"].push_back(item);
91 // For each paragraph, traverse its insets and look for
92 // FLOAT_CODE or WRAP_CODE
93 InsetList::const_iterator it = pit->insetlist.begin();
94 InsetList::const_iterator end = pit->insetlist.end();
95 for (; it != end; ++it) {
96 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
98 static_cast<InsetFloat*>(it->inset);
99 il->addToToc(toclist, buf);
100 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
102 static_cast<InsetWrap*>(it->inset);
104 il->addToToc(toclist, buf);
112 vector<string> const getTypes(Buffer const * buffer)
114 vector<string> types;
116 TocList const tmp = getTocList(buffer);
118 TocList::const_iterator cit = tmp.begin();
119 TocList::const_iterator end = tmp.end();
121 for (; cit != end; ++cit) {
122 types.push_back(cit->first);
129 void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
131 TocList const toc_list = getTocList(buffer);
132 TocList::const_iterator cit = toc_list.find(type);
133 if (cit != toc_list.end()) {
134 Toc::const_iterator ccit = cit->second.begin();
135 Toc::const_iterator end = cit->second.end();
136 for (; ccit != end; ++ccit)
137 os << ccit->asString() << '\n';