]> git.lyx.org Git - features.git/commitdiff
Move getCaptionInset() to InsetCollapsable, so it can be used in InsetListings.
authorRichard Heck <rgheck@comcast.net>
Fri, 19 Jun 2009 13:12:02 +0000 (13:12 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 19 Jun 2009 13:12:02 +0000 (13:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30182 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetFloat.cpp
src/insets/InsetFloat.h
src/insets/InsetListings.cpp

index 46c155ea89b05ef3e024fc6ca63a6842a06233dd..ef9fba98c201c0d543f36ec051767ef0ce3bce2b 100644 (file)
@@ -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_)
index de432aa8fa01447ad1d3ae3d9d82f2307fef6168..a6213296bac8782c8ea0752ae1cf78451e83d72b 100644 (file)
@@ -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!
index 271090f1614778b41983d678d8214c6b59a22fb6..4cec685bd02ee73920cdcdbe9f72eac5e751eacd 100644 (file)
@@ -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())
index 65c306a93e076e9a04a22f36b0b1cdb50029f0a9..31ed0270845b9e53f3cf2af6f7b2f29861d8ee1c 100644 (file)
@@ -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_;
index 43f5eeed535e272c0033dc5d7084156dabcdad22..aa8a831a600a7e85a3d3a999788a5e6676aa93f4 100644 (file)
@@ -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));
 }