From 3579d53108a65e7164612b15b4cb64de9cea8cf6 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 19 Jun 2009 13:12:02 +0000 Subject: [PATCH] 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 --- src/insets/InsetCollapsable.cpp | 20 ++++++++++++ src/insets/InsetCollapsable.h | 3 ++ src/insets/InsetFloat.cpp | 19 ------------ src/insets/InsetFloat.h | 4 --- src/insets/InsetListings.cpp | 55 ++++++++++++++------------------- 5 files changed, 46 insertions(+), 55 deletions(-) diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 46c155ea89..ef9fba98c2 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -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(it->inset); + return ins; + } + } + } + return 0; +} + + InsetLayout::InsetDecoration InsetCollapsable::decoration() const { if (!layout_) diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index de432aa8fa..a6213296ba 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -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! diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 271090f161..4cec685bd0 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -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(it->inset); - return ins; - } - } - } - return 0; -} - - docstring InsetFloat::getCaption(OutputParams const & runparams) const { if (paragraphs().empty()) diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index 65c306a93e..31ed027084 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -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_; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 43f5eeed53..aa8a831a60 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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(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)); } -- 2.39.2