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 int const toclevel = pit->layout()->toclevel;
79 if (toclevel > 0 && toclevel <= bufparams.tocdepth) {
80 // insert this into the table of contents
81 TocItem const item(pit->id(), toclevel - 1, pit->asString(buf, true));
82 toclist["TOC"].push_back(item);
85 // For each paragraph, traverse its insets and look for
86 // FLOAT_CODE or WRAP_CODE
87 InsetList::const_iterator it = pit->insetlist.begin();
88 InsetList::const_iterator end = pit->insetlist.end();
89 for (; it != end; ++it) {
90 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
92 static_cast<InsetFloat*>(it->inset);
93 il->addToToc(toclist, buf);
94 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
96 static_cast<InsetWrap*>(it->inset);
98 il->addToToc(toclist, buf);
106 vector<string> const getTypes(Buffer const & buffer)
108 vector<string> types;
110 TocList const tmp = getTocList(buffer);
112 TocList::const_iterator cit = tmp.begin();
113 TocList::const_iterator end = tmp.end();
115 for (; cit != end; ++cit) {
116 types.push_back(cit->first);
123 void asciiTocList(string const & type, Buffer const & buffer, ostream & os)
125 TocList const toc_list = getTocList(buffer);
126 TocList::const_iterator cit = toc_list.find(type);
127 if (cit != toc_list.end()) {
128 Toc::const_iterator ccit = cit->second.begin();
129 Toc::const_iterator end = cit->second.end();
130 for (; ccit != end; ++ccit)
131 os << ccit->asString() << '\n';