mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Implement IsTocCaption for InsetArgument
Shows the title of Sweave, Knitr chunks in the Navigate menu.
This commit is contained in:
parent
28dfc48fb2
commit
5e20713769
@ -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())
|
||||
|
@ -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(){}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user