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
This commit is contained in:
Bo Peng 2007-05-24 14:10:35 +00:00
parent 7f9f6bce57
commit 1561aef0b5
3 changed files with 32 additions and 4 deletions

View File

@ -419,6 +419,10 @@ void setCaptions(Paragraph & par, TextClass const & textclass)
} }
else if (inset.lyxCode() == Inset::LISTINGS_CODE) else if (inset.lyxCode() == Inset::LISTINGS_CODE)
setCaptionLabels(inset, "listing", from_ascii("Listing"), counters); 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);
} }
} }

View File

@ -107,7 +107,7 @@ bool isListings(InsetCommandParams const & params)
InsetInclude::InsetInclude(InsetCommandParams const & p) InsetInclude::InsetInclude(InsetCommandParams const & p)
: params_(p), include_label(uniqueID()), : params_(p), include_label(uniqueID()),
preview_(new RenderMonitoredPreview(this)), preview_(new RenderMonitoredPreview(this)),
set_label_(false) set_label_(false), counter_(0)
{ {
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
} }
@ -118,7 +118,7 @@ InsetInclude::InsetInclude(InsetInclude const & other)
params_(other.params_), params_(other.params_),
include_label(other.include_label), include_label(other.include_label),
preview_(new RenderMonitoredPreview(this)), preview_(new RenderMonitoredPreview(this)),
set_label_(false) set_label_(false), counter_(0)
{ {
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
} }
@ -336,9 +336,13 @@ docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
case INCLUDE: case INCLUDE:
temp += buf.B_("Include"); temp += buf.B_("Include");
break; break;
case LISTINGS: case LISTINGS: {
temp += buf.B_("Program Listing"); if (counter_ > 0)
temp += buf.B_("Program Listing ") + convert<docstring>(counter_);
else
temp += buf.B_("Program Listing");
break; break;
}
} }
temp += ": "; 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"); string const InsetIncludeMailer::name_("include");
InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset) InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)

View File

@ -16,6 +16,7 @@
#include "InsetCommandParams.h" #include "InsetCommandParams.h"
#include "RenderButton.h" #include "RenderButton.h"
#include "MailInset.h" #include "MailInset.h"
#include "Counters.h"
#include "support/FileName.h" #include "support/FileName.h"
@ -99,6 +100,9 @@ public:
void updateLabels(Buffer const & buffer) const; void updateLabels(Buffer const & buffer) const;
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) 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: protected:
InsetInclude(InsetInclude const &); InsetInclude(InsetInclude const &);
/// ///
@ -133,6 +137,7 @@ private:
/// cache /// cache
mutable bool set_label_; mutable bool set_label_;
mutable RenderButton button_; mutable RenderButton button_;
int counter_;
}; };