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"
38 string const TocItem::asString() const
40 return string(4 * depth, ' ') + str;
44 void TocItem::goTo(LyXView & lv_) const
46 string const tmp = tostr(id_);
47 lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
51 FuncRequest TocItem::action() const
53 return FuncRequest(LFUN_GOTO_PARAGRAPH, tostr(id_));
57 string const getType(string const & cmdName)
60 if (cmdName == "tableofcontents")
67 TocList const getTocList(Buffer const & buf)
71 BufferParams const & bufparams = buf.params();
73 ParConstIterator pit = buf.par_iterator_begin();
74 ParConstIterator end = buf.par_iterator_end();
75 for (; pit != end; ++pit) {
77 int const toclevel = pit->layout()->toclevel;
78 if (toclevel > 0 && toclevel <= bufparams.tocdepth) {
79 // insert this into the table of contents
80 TocItem const item(pit->id(), toclevel - 1, pit->asString(buf, true));
81 toclist["TOC"].push_back(item);
84 // For each paragraph, traverse its insets and look for
85 // FLOAT_CODE or WRAP_CODE
86 InsetList::const_iterator it = pit->insetlist.begin();
87 InsetList::const_iterator end = pit->insetlist.end();
88 for (; it != end; ++it) {
89 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
91 static_cast<InsetFloat*>(it->inset);
92 il->addToToc(toclist, buf);
93 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
95 static_cast<InsetWrap*>(it->inset);
97 il->addToToc(toclist, buf);
105 vector<string> const getTypes(Buffer const & buffer)
107 vector<string> types;
109 TocList const tmp = getTocList(buffer);
111 TocList::const_iterator cit = tmp.begin();
112 TocList::const_iterator end = tmp.end();
114 for (; cit != end; ++cit) {
115 types.push_back(cit->first);
122 void asciiTocList(string const & type, Buffer const & buffer, ostream & os)
124 TocList const toc_list = getTocList(buffer);
125 TocList::const_iterator cit = toc_list.find(type);
126 if (cit != toc_list.end()) {
127 Toc::const_iterator ccit = cit->second.begin();
128 Toc::const_iterator end = cit->second.end();
129 for (; ccit != end; ++ccit)
130 os << ccit->asString() << '\n';