]> git.lyx.org Git - features.git/commitdiff
Increase listings counter for InsetInclude with lstinputlisting and a caption, fix...
authorBo Peng <bpeng@lyx.org>
Thu, 24 May 2007 14:10:35 +0000 (14:10 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 24 May 2007 14:10:35 +0000 (14:10 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18486 a592a061-630c-0410-9148-cb99ea01b6c8

src/buffer_funcs.cpp
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h

index 7a8618cc1564d3ebf30557a68dfcabacd507ba5f..e53f89780548988fcf6ec64f7a2cf4004efa4bb2 100644 (file)
@@ -419,6 +419,10 @@ void setCaptions(Paragraph & par, TextClass const & textclass)
                }
                else if (inset.lyxCode() == Inset::LISTINGS_CODE)
                        setCaptionLabels(inset, "listing", from_ascii("Listing"), counters);
+               else if (inset.lyxCode() == Inset::INCLUDE_CODE)
+                       // if this include inset contains lstinputlisting, and has a caption
+                       // it will increase the 'listing' counter by one
+                       static_cast<InsetInclude &>(inset).updateCounter(counters);
        }
 }
 
index eca2ff60cd9eafb193c5f1f19101e859b1db2370..df6043fee71ffc4b70b19ae5645e9bcef2a13900 100644 (file)
@@ -107,7 +107,7 @@ bool isListings(InsetCommandParams const & params)
 InsetInclude::InsetInclude(InsetCommandParams const & p)
        : params_(p), include_label(uniqueID()),
          preview_(new RenderMonitoredPreview(this)),
-         set_label_(false)
+         set_label_(false), counter_(0)
 {
        preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
 }
@@ -118,7 +118,7 @@ InsetInclude::InsetInclude(InsetInclude const & other)
          params_(other.params_),
          include_label(other.include_label),
          preview_(new RenderMonitoredPreview(this)),
-         set_label_(false)
+         set_label_(false), counter_(0)
 {
        preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
 }
@@ -336,9 +336,13 @@ docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
                case INCLUDE:
                        temp += buf.B_("Include");
                        break;
-               case LISTINGS:
-                       temp += buf.B_("Program Listing");
+               case LISTINGS: {
+                       if (counter_ > 0)
+                               temp += buf.B_("Program Listing ") + convert<docstring>(counter_);
+                       else
+                               temp += buf.B_("Program Listing");
                        break;
+               }
        }
 
        temp += ": ";
@@ -882,6 +886,21 @@ void InsetInclude::updateLabels(Buffer const & buffer) const
 }
 
 
+void InsetInclude::updateCounter(Counters & counters)
+{
+       if (!isListings(params_))
+               return;
+
+       InsetListingsParams const par = params_.getOptions();
+       if (par.getParamValue("caption").empty())
+               counter_ = 0;
+       else {
+               counters.step(from_ascii("listing"));
+               counter_ = counters.value(from_ascii("listing"));
+       }
+}
+
+
 string const InsetIncludeMailer::name_("include");
 
 InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
index fcbfb9526f9d9ce0db1700629f854e87de445573..b1a4e48568fe6bd92a4c95f61611639a6ad1ff41 100644 (file)
@@ -16,6 +16,7 @@
 #include "InsetCommandParams.h"
 #include "RenderButton.h"
 #include "MailInset.h"
+#include "Counters.h"
 
 #include "support/FileName.h"
 
@@ -99,6 +100,9 @@ public:
        void updateLabels(Buffer const & buffer) const;
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
+       /// if this inset contains lstinputlisting and has a caption, 
+       /// update internal counter and passed counter
+       void updateCounter(Counters & counters);
 protected:
        InsetInclude(InsetInclude const &);
        ///
@@ -133,6 +137,7 @@ private:
        /// cache
        mutable bool set_label_;
        mutable RenderButton button_;
+       int counter_;
 };