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 "lyxtextclasslist.h"
30 #include "insets/insetfloat.h"
38 extern LyXAction lyxaction;
43 string const TocItem::asString() const
45 return string(4 * depth, ' ') + str;
49 void TocItem::goTo(LyXView & lv_) const
51 string const tmp = tostr(par->id());
52 lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp, false);
56 int TocItem::action() const
58 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
63 string const getType(string const & cmdName)
66 if (cmdName == "tableofcontents")
73 TocList const getTocList(Buffer const * buf)
76 Paragraph * par = buf->paragraph;
78 LyXTextClass const & textclass = textclasslist[buf->params.textclass];
79 bool found = textclass.hasLayout("Caption");
80 string const layout("Caption");
84 #warning bogus type (Lgb)
86 char const labeltype = par->layout()->labeltype;
88 if (labeltype >= LABEL_COUNTER_CHAPTER
89 && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
90 // insert this into the table of contents
91 const int depth = max(0, labeltype - textclass.maxcounter());
92 TocItem const item(par, depth,
93 par->asString(buf, true));
94 toclist["TOC"].push_back(item);
96 // For each paragraph, traverse its insets and look for
100 Paragraph::inset_iterator it =
101 par->inset_iterator_begin();
102 Paragraph::inset_iterator end =
103 par->inset_iterator_end();
105 for (; it != end; ++it) {
106 if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
108 static_cast<InsetFloat*>(*it);
110 string const type = il->type();
112 // Now find the caption in the float...
113 // We now tranverse the paragraphs of
115 Paragraph * tmp = il->inset.paragraph();
117 if (tmp->layout()->name() == layout) {
119 tostr(toclist[type].size()+1) + ". " + tmp->asString(buf, false);
120 TocItem const item(tmp, 0 , str);
121 toclist[type].push_back(item);
128 lyxerr << "Caption not found" << endl;
137 vector<string> const getTypes(Buffer const * buffer)
139 vector<string> types;
141 TocList const tmp = getTocList(buffer);
143 TocList::const_iterator cit = tmp.begin();
144 TocList::const_iterator end = tmp.end();
146 for (; cit != end; ++cit) {
147 types.push_back(cit->first);
154 void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
156 TocList const toc_list = getTocList(buffer);
157 TocList::const_iterator cit = toc_list.find(type);
158 if (cit != toc_list.end()) {
159 Toc::const_iterator ccit = cit->second.begin();
160 Toc::const_iterator end = cit->second.end();
161 for (; ccit != end; ++ccit)
162 os << ccit->asString() << '\n';