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"
26 #include "LyXAction.h"
27 #include "paragraph.h"
28 #include "insets/insetfloat.h"
39 string const TocItem::asString() const
41 return string(4 * depth, ' ') + str;
45 void TocItem::goTo(LyXView & lv_) const
47 string const tmp = tostr(par->id());
48 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
52 int TocItem::action() const
54 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
59 string const getType(string const & cmdName)
62 if (cmdName == "tableofcontents")
69 TocList const getTocList(Buffer const * buf)
74 Paragraph * par = &*(buf->paragraphs.begin());
76 LyXTextClass const & textclass = buf->params.getLyXTextClass();
80 #warning bogus type (Lgb)
82 char const labeltype = par->layout()->labeltype;
84 if (labeltype >= LABEL_COUNTER_CHAPTER
85 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
86 // insert this into the table of contents
87 const int depth = max(0, labeltype - textclass.maxcounter());
88 TocItem const item(par, depth,
89 par->asString(buf, true));
90 toclist["TOC"].push_back(item);
93 // For each paragraph, traverse its insets and look for
95 InsetList::iterator it = par->insetlist.begin();
96 InsetList::iterator end = par->insetlist.end();
97 for (; it != end; ++it) {
98 if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) {
100 static_cast<InsetFloat*>(it.getInset());
101 il->addToToc(toclist, buf);
111 vector<string> const getTypes(Buffer const * buffer)
113 vector<string> types;
115 TocList const tmp = getTocList(buffer);
117 TocList::const_iterator cit = tmp.begin();
118 TocList::const_iterator end = tmp.end();
120 for (; cit != end; ++cit) {
121 types.push_back(cit->first);
128 void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
130 TocList const toc_list = getTocList(buffer);
131 TocList::const_iterator cit = toc_list.find(type);
132 if (cit != toc_list.end()) {
133 Toc::const_iterator ccit = cit->second.begin();
134 Toc::const_iterator end = cit->second.end();
135 for (; ccit != end; ++ccit)
136 os << ccit->asString() << '\n';