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) {
83 Paragraph const * par = *pit;
86 #warning bogus type (Lgb)
88 char const labeltype = par->layout()->labeltype;
90 if (labeltype >= LABEL_COUNTER_CHAPTER
91 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
92 // insert this into the table of contents
93 const int depth = max(0, labeltype - textclass.maxcounter());
94 TocItem const item(par, depth,
95 par->asString(buf, true));
96 toclist["TOC"].push_back(item);
99 // For each paragraph, traverse its insets and look for
100 // FLOAT_CODE or WRAP_CODE
101 InsetList::iterator it = par->insetlist.begin();
102 InsetList::iterator end = par->insetlist.end();
103 for (; it != end; ++it) {
104 if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) {
106 static_cast<InsetFloat*>(it.getInset());
107 il->addToToc(toclist, buf);
108 } else if (it.getInset()->lyxCode() == Inset::WRAP_CODE) {
110 static_cast<InsetWrap*>(it.getInset());
111 il->addToToc(toclist, buf);
119 vector<string> const getTypes(Buffer const * buffer)
121 vector<string> types;
123 TocList const tmp = getTocList(buffer);
125 TocList::const_iterator cit = tmp.begin();
126 TocList::const_iterator end = tmp.end();
128 for (; cit != end; ++cit) {
129 types.push_back(cit->first);
136 void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
138 TocList const toc_list = getTocList(buffer);
139 TocList::const_iterator cit = toc_list.find(type);
140 if (cit != toc_list.end()) {
141 Toc::const_iterator ccit = cit->second.begin();
142 Toc::const_iterator end = cit->second.end();
143 for (; ccit != end; ++ccit)
144 os << ccit->asString() << '\n';