From 1561aef0b5ce07703960001aa4ab353bd2c1d18b Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Thu, 24 May 2007 14:10:35 +0000 Subject: [PATCH] Increase listings counter for InsetInclude with lstinputlisting and a caption, fix bug 3708 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18486 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer_funcs.cpp | 4 ++++ src/insets/InsetInclude.cpp | 27 +++++++++++++++++++++++---- src/insets/InsetInclude.h | 5 +++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 7a8618cc15..e53f897805 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -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(inset).updateCounter(counters); } } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index eca2ff60cd..df6043fee7 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -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(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) diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index fcbfb9526f..b1a4e48568 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -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_; };