3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Guillaume Munch
8 * Full author contact details are available in file CREDITS.
13 #include "TocBuilder.h"
15 #include "TocBackend.h"
17 #include "support/lassert.h"
26 TocBuilder::TocBuilder(shared_ptr<Toc> toc)
27 : toc_(toc ? toc : make_shared<Toc>()),
33 void TocBuilder::pushItem(DocIterator const & dit, docstring const & s,
34 bool output_active, bool is_captioned)
36 toc_->push_back(TocItem(dit, stack_.size(), s, output_active));
38 toc_->size() - 1, //pos
39 is_captioned, //is_captioned
44 void TocBuilder::captionItem(DocIterator const & dit, docstring const & s,
47 // first show the float before moving to the caption
48 docstring arg = "paragraph-goto " + dit.paragraphGotoArgument();
50 arg = "paragraph-goto " +
51 (*toc_)[stack_.top().pos].dit().paragraphGotoArgument() + ";" + arg;
52 FuncRequest func(LFUN_COMMAND_SEQUENCE, arg);
54 if (!stack_.empty() && !stack_.top().is_captioned) {
55 // The float we entered has not yet been assigned a caption.
56 // Assign the caption string to it.
57 TocItem & captionable = (*toc_)[stack_.top().pos];
59 captionable.setAction(func);
60 stack_.top().is_captioned = true;
62 // This is a new entry.
64 // the dit is at the float's level, e.g. for the contextual menu of
66 DocIterator captionable_dit = dit;
67 captionable_dit.pop_back();
68 pushItem(captionable_dit, s, output_active, true);
69 (*toc_)[stack_.top().pos].setAction(func);
73 void TocBuilder::argumentItem(docstring const & arg_str)
75 if (stack_.empty() || arg_str.empty())
77 TocItem & item = (*toc_)[stack_.top().pos];
78 docstring const & str = item.str();
79 string const & delim =
80 (str.empty() || !stack_.top().is_captioned) ? "" : ", ";
81 item.str(str + from_ascii(delim) + arg_str);
82 stack_.top().is_captioned = true;
85 void TocBuilder::pop()