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"
29 #include "insets/insetwrap.h"
31 #include "iterators.h"
41 string const TocItem::asString() const
43 return string(4 * depth, ' ') + str;
47 void TocItem::goTo(LyXView & lv_) const
49 string const tmp = tostr(par->id());
50 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
54 int TocItem::action() const
56 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
61 string const getType(string const & cmdName)
64 if (cmdName == "tableofcontents")
71 TocList const getTocList(Buffer const * buf)
77 LyXTextClass const & textclass = buf->params.getLyXTextClass();
79 ParConstIterator pit = buf->par_iterator_begin();
80 ParConstIterator end = buf->par_iterator_end();
81 for (; pit != end; ++pit) {
82 Paragraph const * par = *pit;
85 #warning bogus type (Lgb)
87 char const labeltype = par->layout()->labeltype;
89 if (labeltype >= LABEL_COUNTER_CHAPTER
90 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
91 // insert this into the table of contents
92 const int depth = max(0, labeltype - textclass.maxcounter());
93 TocItem const item(par, depth,
94 par->asString(buf, true));
95 toclist["TOC"].push_back(item);
98 // For each paragraph, traverse its insets and look for
99 // FLOAT_CODE or WRAP_CODE
100 InsetList::iterator it = par->insetlist.begin();
101 InsetList::iterator end = par->insetlist.end();
102 for (; it != end; ++it) {
103 if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) {
105 static_cast<InsetFloat*>(it.getInset());
106 il->addToToc(toclist, buf);
107 } else if (it.getInset()->lyxCode() == Inset::WRAP_CODE) {
109 static_cast<InsetWrap*>(it.getInset());
110 il->addToToc(toclist, buf);
118 vector<string> const getTypes(Buffer const * buffer)
120 vector<string> types;
122 TocList const tmp = getTocList(buffer);
124 TocList::const_iterator cit = tmp.begin();
125 TocList::const_iterator end = tmp.end();
127 for (; cit != end; ++cit) {
128 types.push_back(cit->first);
135 void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
137 TocList const toc_list = getTocList(buffer);
138 TocList::const_iterator cit = toc_list.find(type);
139 if (cit != toc_list.end()) {
140 Toc::const_iterator ccit = cit->second.begin();
141 Toc::const_iterator end = cit->second.end();
142 for (; ccit != end; ++ccit)
143 os << ccit->asString() << '\n';