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>
19 #pragma implementation
22 #include "support/lstrings.h"
25 #include "frontends/LyXView.h"
27 #include "LyXAction.h"
28 #include "paragraph.h"
29 #include "insets/insetfloat.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(par->id());
49 lv_.getLyXFunc()->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)
75 Paragraph * par = &*(buf->paragraphs.begin());
77 LyXTextClass const & textclass = buf->params.getLyXTextClass();
81 #warning bogus type (Lgb)
83 char const labeltype = par->layout()->labeltype;
85 if (labeltype >= LABEL_COUNTER_CHAPTER
86 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
87 // insert this into the table of contents
88 const int depth = max(0, labeltype - textclass.maxcounter());
89 TocItem const item(par, depth,
90 par->asString(buf, true));
91 toclist["TOC"].push_back(item);
94 // For each paragraph, traverse its insets and look for
96 InsetList::iterator it = par->insetlist.begin();
97 InsetList::iterator end = par->insetlist.end();
98 for (; it != end; ++it) {
99 if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) {
101 static_cast<InsetFloat*>(it.getInset());
102 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';