diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 399278456d..f490c3534a 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -27,7 +27,7 @@ #include "ParIterator.h" #include "TextClass.h" -#include "insets/InsetArgument.h" +#include "insets/InsetText.h" #include "support/convert.h" #include "support/debug.h" @@ -193,6 +193,18 @@ void TocBuilder::captionItem(DocIterator const & dit, docstring const & s, } } +void TocBuilder::argumentItem(docstring const & arg_str) +{ + if (stack_.empty() || arg_str.empty()) + return; + TocItem & item = (*toc_)[stack_.top().pos]; + docstring const & str = item.str(); + string const & delim = + str.empty() ? "" : stack_.top().is_captioned ? ", " : ": "; + item.str(str + from_ascii(delim) + arg_str); + stack_.top().is_captioned = true; +} + void TocBuilder::pop() { if (!stack_.empty()) diff --git a/src/TocBackend.h b/src/TocBackend.h index eaa1ce99e2..b851d68546 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -120,13 +120,15 @@ class TocBuilder { public: TocBuilder(std::shared_ptr const toc); - /// When entering a float + /// When entering a float or flex (AddToToc) void pushItem(DocIterator const & dit, docstring const & s, bool output_active, bool is_captioned = false); - /// When encountering a caption + /// When encountering a float caption void captionItem(DocIterator const & dit, docstring const & s, bool output_active); - /// When exiting a float + /// When encountering an argument (isTocCaption) + void argumentItem(docstring const & arg_str); + /// When exiting a float or flex void pop(); private: TocBuilder(){} diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 6ba49c7aef..605286ca20 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -26,6 +26,7 @@ #include "ParIterator.h" #include "TexRow.h" #include "texstream.h" +#include "TocBackend.h" #include "support/convert.h" #include "support/debug.h" @@ -106,6 +107,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) } } Layout::LaTeXArgMap::const_iterator const lait = args.find(name_); + caption_of_toc_ = string(); if (lait != args.end()) { docstring label = translateIfPossible((*lait).second.labelstring); docstring striplabel; @@ -117,6 +119,12 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) decoration_ = (*lait).second.decoration; pass_thru_chars_ = (*lait).second.pass_thru_chars; pass_thru_local_ = false; + if (lait->second.is_toc_caption) + // empty if AddToToc is not set + caption_of_toc_ = insetlayout + ? it.inset().getLayout().tocType() + : it.paragraph().layout().tocType(); + switch ((*lait).second.passthru) { case PT_INHERITED: pass_thru_ = pass_thru_context_; @@ -309,4 +317,18 @@ void InsetArgument::latexArgument(otexstream & os, } + +void InsetArgument::addToToc(DocIterator const & dit, bool output_active, + UpdateType utype) const +{ + if (!caption_of_toc_.empty()) { + docstring str; + text().forOutliner(str, TOC_ENTRY_LENGTH); + buffer().tocBackend().builder(caption_of_toc_).argumentItem(str); + } + // Proceed with the rest of the inset. + InsetText::addToToc(dit, output_active, utype); +} + + } // namespace lyx diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index fb7e290aeb..0ccdc41bc0 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -81,6 +81,9 @@ public: /// void setButtonLabel(); //@} + /// + void addToToc(DocIterator const & dit, bool output_active, + UpdateType utype) const; //override private: /// @@ -105,6 +108,8 @@ private: bool pass_thru_; /// docstring pass_thru_chars_; + /// The type of Toc this is the caption of, empty otherwise. + std::string caption_of_toc_; protected: /// \name Protected functions inherited from Inset class diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 18f341789b..05cbb298b2 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -175,16 +175,14 @@ void InsetFlex::addToToc(DocIterator const & cpit, bool output_active, // Cursor inside the inset DocIterator pit = cpit; pit.push_back(CursorSlice(const_cast(*this))); - docstring str; - str = getLabel(); - if (layout.isTocCaption()) { - if (!str.empty()) - str += ": "; - text().forOutliner(str, TOC_ENTRY_LENGTH); - } - b.pushItem(pit, str, output_active); + b.pushItem(pit, getLabel(), output_active); // Proceed with the rest of the inset. InsetCollapsable::addToToc(cpit, output_active, utype); + if (layout.isTocCaption()) { + docstring str; + text().forOutliner(str, TOC_ENTRY_LENGTH); + b.argumentItem(str); + } b.pop(); } else InsetCollapsable::addToToc(cpit, output_active, utype);