3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
17 #include "bufferparams.h"
18 #include "funcrequest.h"
19 #include "iterators.h"
20 #include "LyXAction.h"
21 #include "paragraph.h"
23 #include "frontends/LyXView.h"
25 #include "insets/insetfloat.h"
26 #include "insets/insetwrap.h"
28 #include "support/tostr.h"
37 string const TocItem::asString() const
39 return string(4 * depth, ' ') + str;
43 void TocItem::goTo(LyXView & lv_) const
45 string const tmp = tostr(id_);
46 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
50 int TocItem::action() const
52 return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
57 string const getType(string const & cmdName)
60 if (cmdName == "tableofcontents")
67 TocList const getTocList(Buffer const & buf)
71 BufferParams const & bufparams = buf.params();
72 LyXTextClass const & textclass = bufparams.getLyXTextClass();
74 ParConstIterator pit = buf.par_iterator_begin();
75 ParConstIterator end = buf.par_iterator_end();
76 for (; pit != end; ++pit) {
78 #warning bogus type (Lgb)
80 char const labeltype = pit->layout()->labeltype;
82 if (labeltype >= LABEL_COUNTER_CHAPTER
83 && labeltype <= LABEL_COUNTER_CHAPTER + bufparams.tocdepth) {
84 // insert this into the table of contents
85 const int depth = max(0, labeltype - textclass.maxcounter());
86 TocItem const item(pit->id(), depth,
87 pit->asString(buf, true));
88 toclist["TOC"].push_back(item);
91 // For each paragraph, traverse its insets and look for
92 // FLOAT_CODE or WRAP_CODE
93 InsetList::const_iterator it = pit->insetlist.begin();
94 InsetList::const_iterator end = pit->insetlist.end();
95 for (; it != end; ++it) {
96 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
98 static_cast<InsetFloat*>(it->inset);
99 il->addToToc(toclist, buf);
100 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
102 static_cast<InsetWrap*>(it->inset);
104 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';