2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2002 The LyX Team.
9 * ======================================================
12 * \author Angus Leeming <a.leeming@ic.ac.uk>
13 * \author Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
20 #include "LyXAction.h"
21 #include "paragraph.h"
23 #include "iterators.h"
25 #include "insets/insetfloat.h"
26 #include "insets/insetwrap.h"
28 #include "support/tostr.h"
30 #include "frontends/LyXView.h"
40 string const TocItem::asString() const
42 return string(4 * depth, ' ') + str;
46 void TocItem::goTo(LyXView & lv_) const
48 string const tmp = tostr(id_);
49 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
53 int TocItem::action() const
55 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
60 string const getType(string const & cmdName)
63 if (cmdName == "tableofcontents")
70 TocList const getTocList(Buffer const * buf)
76 LyXTextClass const & textclass = buf->params.getLyXTextClass();
78 ParConstIterator pit = buf->par_iterator_begin();
79 ParConstIterator end = buf->par_iterator_end();
80 for (; pit != end; ++pit) {
82 #warning bogus type (Lgb)
84 char const labeltype = pit->layout()->labeltype;
86 if (labeltype >= LABEL_COUNTER_CHAPTER
87 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
88 // insert this into the table of contents
89 const int depth = max(0, labeltype - textclass.maxcounter());
90 TocItem const item(pit->id(), depth,
91 pit->asString(buf, true));
92 toclist["TOC"].push_back(item);
95 // For each paragraph, traverse its insets and look for
96 // FLOAT_CODE or WRAP_CODE
97 InsetList::const_iterator it = pit->insetlist.begin();
98 InsetList::const_iterator end = pit->insetlist.end();
99 for (; it != end; ++it) {
100 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
102 static_cast<InsetFloat*>(it->inset);
103 il->addToToc(toclist, buf);
104 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
106 static_cast<InsetWrap*>(it->inset);
108 il->addToToc(toclist, buf);
116 vector<string> const getTypes(Buffer const * buffer)
118 vector<string> types;
120 TocList const tmp = getTocList(buffer);
122 TocList::const_iterator cit = tmp.begin();
123 TocList::const_iterator end = tmp.end();
125 for (; cit != end; ++cit) {
126 types.push_back(cit->first);
133 void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
135 TocList const toc_list = getTocList(buffer);
136 TocList::const_iterator cit = toc_list.find(type);
137 if (cit != toc_list.end()) {
138 Toc::const_iterator ccit = cit->second.begin();
139 Toc::const_iterator end = cit->second.end();
140 for (; ccit != end; ++ccit)
141 os << ccit->asString() << '\n';