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 "DocIterator.h"
16 #include "TocBackend.h"
18 #include "support/lassert.h"
27 TocBuilder::TocBuilder(shared_ptr<Toc> toc)
28 : toc_(toc ? toc : make_shared<Toc>()),
34 void TocBuilder::pushItem(DocIterator const & dit, docstring const & s,
35 bool output_active, bool is_captioned)
37 toc_->push_back(TocItem(dit, stack_.size(), s, output_active));
39 toc_->size() - 1, //pos
40 is_captioned, //is_captioned
45 void TocBuilder::captionItem(DocIterator const & dit, docstring const & s,
48 // first show the float before moving to the caption
49 docstring arg = "paragraph-goto " + dit.paragraphGotoArgument();
51 arg = "paragraph-goto " +
52 (*toc_)[stack_.top().pos].dit().paragraphGotoArgument() + ";" + arg;
53 FuncRequest func(LFUN_COMMAND_SEQUENCE, arg);
55 if (!stack_.empty() && !stack_.top().is_captioned) {
56 // The float we entered has not yet been assigned a caption.
57 // Assign the caption string to it.
58 TocItem & captionable = (*toc_)[stack_.top().pos];
60 captionable.setAction(func);
61 stack_.top().is_captioned = true;
63 // This is a new entry.
65 // the dit is at the float's level, e.g. for the contextual menu of
67 DocIterator captionable_dit = dit;
68 captionable_dit.pop_back();
69 pushItem(captionable_dit, s, output_active, true);
70 (*toc_)[stack_.top().pos].setAction(func);
74 void TocBuilder::argumentItem(docstring const & arg_str)
76 if (stack_.empty() || arg_str.empty())
78 TocItem & item = (*toc_)[stack_.top().pos];
79 docstring const & str = item.str();
80 string const & delim =
81 (str.empty() || !stack_.top().is_captioned) ? "" : ", ";
82 item.str(str + from_ascii(delim) + arg_str);
83 stack_.top().is_captioned = true;
86 void TocBuilder::pop()