commit 5e2071376972a3c16d0874f18cf31e329e4f773c
Author: Guillaume Munch <[email protected]>
Date: Sun Jan 8 19:17:57 2017 +0100
Implement IsTocCaption for InsetArgument
Shows the title of Sweave, Knitr chunks in the Navigate menu.
---
src/TocBackend.cpp | 14 +++++++++++++-
src/TocBackend.h | 8 +++++---
src/insets/InsetArgument.cpp | 22 ++++++++++++++++++++++
src/insets/InsetArgument.h | 5 +++++
src/insets/InsetFlex.cpp | 12 +++++-------
5 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
index 3992784..f490c35 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 eaa1ce9..b851d68 100644
--- a/src/TocBackend.h
+++ b/src/TocBackend.h
@@ -120,13 +120,15 @@ class TocBuilder
{
public:
TocBuilder(std::shared_ptr<Toc> 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 6ba49c7..605286c 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 fb7e290..0ccdc41 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 18f3417..05cbb29 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<InsetFlex &>(*this)));
- docstring str;
- str = getLabel();
+ b.pushItem(pit, getLabel(), output_active);
+ // Proceed with the rest of the inset.
+ InsetCollapsable::addToToc(cpit, output_active, utype);
if (layout.isTocCaption()) {
- if (!str.empty())
- str += ": ";
+ docstring str;
text().forOutliner(str, TOC_ENTRY_LENGTH);
+ b.argumentItem(str);
}
- b.pushItem(pit, str, output_active);
- // Proceed with the rest of the inset.
- InsetCollapsable::addToToc(cpit, output_active, utype);
b.pop();
} else
InsetCollapsable::addToToc(cpit, output_active, utype);