mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Move getCaptionInset() to InsetCollapsable, so it can be used in InsetListings.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30182 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
583e62836c
commit
3579d53108
@ -23,7 +23,9 @@
|
||||
#include "FloatList.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "InsetCaption.h"
|
||||
#include "InsetLayout.h"
|
||||
#include "InsetList.h"
|
||||
#include "Language.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "Lexer.h"
|
||||
@ -782,6 +784,24 @@ docstring InsetCollapsable::floatName(
|
||||
}
|
||||
|
||||
|
||||
InsetCaption const * InsetCollapsable::getCaptionInset() const
|
||||
{
|
||||
ParagraphList::const_iterator pit = paragraphs().begin();
|
||||
for (; pit != paragraphs().end(); ++pit) {
|
||||
InsetList::const_iterator it = pit->insetList().begin();
|
||||
for (; it != pit->insetList().end(); ++it) {
|
||||
Inset & inset = *it->inset;
|
||||
if (inset.lyxCode() == CAPTION_CODE) {
|
||||
InsetCaption const * ins =
|
||||
static_cast<InsetCaption const *>(it->inset);
|
||||
return ins;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
InsetLayout::InsetDecoration InsetCollapsable::decoration() const
|
||||
{
|
||||
if (!layout_)
|
||||
|
@ -23,6 +23,7 @@
|
||||
namespace lyx {
|
||||
|
||||
class CursorSlice;
|
||||
class InsetCaption;
|
||||
class InsetLayout;
|
||||
|
||||
namespace frontend { class Painter; }
|
||||
@ -180,6 +181,8 @@ protected:
|
||||
///
|
||||
virtual void resetParagraphsFont();
|
||||
///
|
||||
InsetCaption const * getCaptionInset() const;
|
||||
///
|
||||
mutable CollapseStatus status_;
|
||||
private:
|
||||
/// cache for the layout_. Make sure it is in sync with the document class!
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "FloatList.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "InsetList.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "Lexer.h"
|
||||
#include "OutputParams.h"
|
||||
@ -469,24 +468,6 @@ void InsetFloat::setNewLabel(BufferParams const & bp)
|
||||
}
|
||||
|
||||
|
||||
InsetCaption const * InsetFloat::getCaptionInset() const
|
||||
{
|
||||
ParagraphList::const_iterator pit = paragraphs().begin();
|
||||
for (; pit != paragraphs().end(); ++pit) {
|
||||
InsetList::const_iterator it = pit->insetList().begin();
|
||||
for (; it != pit->insetList().end(); ++it) {
|
||||
Inset & inset = *it->inset;
|
||||
if (inset.lyxCode() == CAPTION_CODE) {
|
||||
InsetCaption const * ins =
|
||||
static_cast<InsetCaption const *>(it->inset);
|
||||
return ins;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
docstring InsetFloat::getCaption(OutputParams const & runparams) const
|
||||
{
|
||||
if (paragraphs().empty())
|
||||
|
@ -18,8 +18,6 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class InsetCaption;
|
||||
|
||||
class InsetFloatParams {
|
||||
public:
|
||||
///
|
||||
@ -117,8 +115,6 @@ private:
|
||||
///
|
||||
docstring getCaptionHTML(OutputParams const &) const;
|
||||
///
|
||||
InsetCaption const * getCaptionInset() const;
|
||||
///
|
||||
InsetFloatParams params_;
|
||||
///
|
||||
docstring name_;
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "InsetCaption.h"
|
||||
#include "InsetList.h"
|
||||
#include "Language.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "output_latex.h"
|
||||
@ -434,37 +433,29 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const
|
||||
if (paragraphs().empty())
|
||||
return docstring();
|
||||
|
||||
ParagraphList::const_iterator pit = paragraphs().begin();
|
||||
for (; pit != paragraphs().end(); ++pit) {
|
||||
InsetList::const_iterator it = pit->insetList().begin();
|
||||
for (; it != pit->insetList().end(); ++it) {
|
||||
Inset & inset = *it->inset;
|
||||
if (inset.lyxCode() == CAPTION_CODE) {
|
||||
odocstringstream ods;
|
||||
InsetCaption * ins =
|
||||
static_cast<InsetCaption *>(it->inset);
|
||||
ins->getOptArg(ods, runparams);
|
||||
ins->getArgument(ods, runparams);
|
||||
// the caption may contain \label{} but the listings
|
||||
// package prefer caption={}, label={}
|
||||
docstring cap = ods.str();
|
||||
if (!contains(to_utf8(cap), "\\label{"))
|
||||
return cap;
|
||||
// convert from
|
||||
// blah1\label{blah2} blah3
|
||||
// to
|
||||
// blah1 blah3},label={blah2
|
||||
// to form options
|
||||
// caption={blah1 blah3},label={blah2}
|
||||
//
|
||||
// NOTE that } is not allowed in blah2.
|
||||
regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
|
||||
string const new_cap("\\1\\3},label={\\2");
|
||||
return from_utf8(regex_replace(to_utf8(cap), reg, new_cap));
|
||||
}
|
||||
}
|
||||
}
|
||||
return docstring();
|
||||
InsetCaption const * ins = getCaptionInset();
|
||||
if (ins == 0)
|
||||
return docstring();
|
||||
|
||||
odocstringstream ods;
|
||||
ins->getOptArg(ods, runparams);
|
||||
ins->getArgument(ods, runparams);
|
||||
// the caption may contain \label{} but the listings
|
||||
// package prefer caption={}, label={}
|
||||
docstring cap = ods.str();
|
||||
if (!contains(to_utf8(cap), "\\label{"))
|
||||
return cap;
|
||||
// convert from
|
||||
// blah1\label{blah2} blah3
|
||||
// to
|
||||
// blah1 blah3},label={blah2
|
||||
// to form options
|
||||
// caption={blah1 blah3},label={blah2}
|
||||
//
|
||||
// NOTE that } is not allowed in blah2.
|
||||
regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
|
||||
string const new_cap("\\1\\3},label={\\2");
|
||||
return from_utf8(regex_replace(to_utf8(cap), reg, new_cap));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user