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.
16 #include "funcrequest.h"
17 #include "LyXAction.h"
18 #include "paragraph.h"
20 #include "iterators.h"
22 #include "insets/insetfloat.h"
23 #include "insets/insetwrap.h"
25 #include "support/tostr.h"
27 #include "frontends/LyXView.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 LyXTextClass const & textclass = buf.params.getLyXTextClass();
73 ParConstIterator pit = buf.par_iterator_begin();
74 ParConstIterator end = buf.par_iterator_end();
75 for (; pit != end; ++pit) {
77 #warning bogus type (Lgb)
79 char const labeltype = pit->layout()->labeltype;
81 if (labeltype >= LABEL_COUNTER_CHAPTER
82 && labeltype <= LABEL_COUNTER_CHAPTER + buf.params.tocdepth) {
83 // insert this into the table of contents
84 const int depth = max(0, labeltype - textclass.maxcounter());
85 TocItem const item(pit->id(), depth,
86 pit->asString(buf, true));
87 toclist["TOC"].push_back(item);
90 // For each paragraph, traverse its insets and look for
91 // FLOAT_CODE or WRAP_CODE
92 InsetList::const_iterator it = pit->insetlist.begin();
93 InsetList::const_iterator end = pit->insetlist.end();
94 for (; it != end; ++it) {
95 if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
97 static_cast<InsetFloat*>(it->inset);
98 il->addToToc(toclist, buf);
99 } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
101 static_cast<InsetWrap*>(it->inset);
103 il->addToToc(toclist, buf);
111 vector<string> const getTypes(Buffer const & buffer)
113 vector<string> types;
115 TocList const tmp = getTocList(buffer);
117 TocList::const_iterator cit = tmp.begin();
118 TocList::const_iterator end = tmp.end();
120 for (; cit != end; ++cit) {
121 types.push_back(cit->first);
128 void asciiTocList(string const & type, Buffer const & buffer, ostream & os)
130 TocList const toc_list = getTocList(buffer);
131 TocList::const_iterator cit = toc_list.find(type);
132 if (cit != toc_list.end()) {
133 Toc::const_iterator ccit = cit->second.begin();
134 Toc::const_iterator end = cit->second.end();
135 for (; ccit != end; ++ccit)
136 os << ccit->asString() << '\n';