Rewrite the label numbering code.

* buffer_funcs.cpp (updateLabels): new function taking a buffer and
	a ParIterator as arguments. This one is used to update labels
	into an InsetText. Cleanup the code to reset depth. Call setLabel
	for each paragraph, and then updateLabel on each inset it contains.
	(setCaptionLabels, setCaptions): removed.
	(setLabel): use Counters::current_float to make caption paragraphs
	labels.

	* insets/Inset.h (updateLabels): new virtual method, empty by
	default; this numbers the inset itself (if relevant) and then all
	the paragraphs it may contain.

	* insets/InsetText.cpp (updateLabels): basically calls
	lyx::updateLabels from buffer_func.cpp.

	* insets/InsetCaption.cpp (addToToc): use the label constructed by
	updateLabels.
	(computeFullLabel): removed.
	(metrics, plaintext): don't use computeFullLabel.
	(updateLabels): new method; set the label from
	Counters::current_float.

	* insets/InsetWrap.cpp (updateLabels):
	* insets/InsetFloat.cpp (updateLabel): new method; sets
	Counters::current_float to the float type.

	* insets/InsetBranch.cpp (updateLabels): new method; the numbering
	is reset afterwards if the branch is inactive. (bug 2671)

	* insets/InsetNote.cpp (updateLabels): new method; the numbering
	is reset after the underlying InsetText has been numbered.
	(bug 2671)

	* insets/InsetTabular.cpp (updateLabels): new method (also handles
	longtable)

	* insets/InsetListings.cpp (updateLabels): new method; mimics what
	is done for Floats (although Listings are not floats technically)

	* insets/InsetInclude.cpp (getScreenLabel): in the listings case,
	use the computed label.
	(updateLabels): new method; that either renumbers the child
	document or number the current listing.

	* LyXFunc.cpp (menuNew): do not updateLabels on empty documents
	(why do we do that at all?)


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19482 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2007-08-12 21:43:58 +00:00
parent f78fcc859e
commit 601a8e0192
22 changed files with 229 additions and 198 deletions

View File

@ -1995,7 +1995,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
Buffer * const b = newFile(filename, templname, !name.empty()); Buffer * const b = newFile(filename, templname, !name.empty());
if (b) { if (b) {
updateLabels(*b); //updateLabels(*b);
lyx_view_->setBuffer(b); lyx_view_->setBuffer(b);
} }
} }

View File

@ -16,6 +16,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferList.h" #include "BufferList.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "debug.h"
#include "DocIterator.h" #include "DocIterator.h"
#include "Counters.h" #include "Counters.h"
#include "ErrorList.h" #include "ErrorList.h"
@ -42,6 +43,7 @@
#include "insets/InsetInclude.h" #include "insets/InsetInclude.h"
#include "insets/InsetTabular.h" #include "insets/InsetTabular.h"
#include "support/convert.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/fs_extras.h" #include "support/fs_extras.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
@ -402,84 +404,11 @@ bool needEnumCounterReset(ParIterator const & it)
} }
void setCaptionLabels(Inset & inset, string const & type,
docstring const label, Counters & counters)
{
Text * text = inset.getText(0);
if (!text)
return;
ParagraphList & pars = text->paragraphs();
if (pars.empty())
return;
docstring const counter = from_ascii(type);
ParagraphList::iterator p = pars.begin();
for (; p != pars.end(); ++p) {
InsetList::iterator it2 = p->insetlist.begin();
InsetList::iterator end2 = p->insetlist.end();
// Any caption within this float should have the same
// label prefix but different numbers.
for (; it2 != end2; ++it2) {
Inset & icap = *it2->inset;
// Look deeper just in case.
setCaptionLabels(icap, type, label, counters);
if (icap.lyxCode() == Inset::CAPTION_CODE) {
// We found a caption!
counters.step(counter);
int number = counters.value(counter);
InsetCaption & ic = static_cast<InsetCaption &>(icap);
ic.setType(type);
ic.setCount(number);
ic.setCustomLabel(label);
}
}
}
}
void setCaptions(Paragraph & par, TextClass const & textclass)
{
if (par.insetlist.empty())
return;
Counters & counters = textclass.counters();
InsetList::iterator it = par.insetlist.begin();
InsetList::iterator end = par.insetlist.end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == Inset::FLOAT_CODE
|| inset.lyxCode() == Inset::WRAP_CODE) {
docstring const name = inset.name();
if (name.empty())
continue;
Floating const & fl = textclass.floats().getType(to_ascii(name));
// FIXME UNICODE
string const & type = fl.type();
docstring const label = from_utf8(fl.name());
setCaptionLabels(inset, type, label, counters);
}
else if (inset.lyxCode() == Inset::TABULAR_CODE
&& static_cast<InsetTabular &>(inset).tabular.isLongTabular()) {
// FIXME: are "table" and "Table" the correct type and label?
setCaptionLabels(inset, "table", from_ascii("Table"), counters);
}
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);
}
}
// set the label of a paragraph. This includes the counters. // set the label of a paragraph. This includes the counters.
void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass) void setLabel(Buffer const & buf, ParIterator & it)
{ {
Paragraph & par = *it; TextClass const & textclass = buf.params().getTextClass();
Paragraph & par = it.paragraph();
Layout_ptr const & layout = par.layout(); Layout_ptr const & layout = par.layout();
Counters & counters = textclass.counters(); Counters & counters = textclass.counters();
@ -501,11 +430,6 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
par.params().labelWidthString(docstring()); par.params().labelWidthString(docstring());
} }
// Optimisation: setLabel() can be called for each for each
// paragraph of the document. So we make the string static to
// avoid the repeated instanciation.
static docstring itemlabel;
// is it a layout that has an automatic label? // is it a layout that has an automatic label?
if (layout->labeltype == LABEL_COUNTER) { if (layout->labeltype == LABEL_COUNTER) {
if (layout->toclevel <= buf.params().secnumdepth if (layout->toclevel <= buf.params().secnumdepth
@ -523,6 +447,7 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
// par.params().labelString( // par.params().labelString(
// buf.params().user_defined_bullet(par.itemdepth).getText()); // buf.params().user_defined_bullet(par.itemdepth).getText());
// for now, use a simple hardcoded label // for now, use a simple hardcoded label
docstring itemlabel;
switch (par.itemdepth) { switch (par.itemdepth) {
case 0: case 0:
itemlabel = char_type(0x2022); itemlabel = char_type(0x2022);
@ -600,40 +525,21 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
par.translateIfPossible(layout->labelstring(), buf.params())); par.translateIfPossible(layout->labelstring(), buf.params()));
// In biblio shouldn't be following counters but... // In biblio shouldn't be following counters but...
} else if (layout->labeltype == LABEL_SENSITIVE) { } else if (layout->labeltype == LABEL_SENSITIVE) {
// Search for the first float or wrap inset in the iterator string const & type = counters.current_float();
size_t i = it.depth(); docstring full_label;
Inset * in = 0; if (type.empty())
while (i > 0) { full_label = buf.B_("Senseless!!! ");
--i; else {
Inset::Code const code = it[i].inset().lyxCode(); docstring name = buf.B_(textclass.floats().getType(type).name());
if (code == Inset::FLOAT_CODE || if (counters.hasCounter(from_utf8(type))) {
code == Inset::WRAP_CODE) { counters.step(from_utf8(type));
in = &it[i].inset(); full_label = bformat(from_ascii("%1$s %2$s:"),
break; name,
} convert<docstring>(counters.value(from_utf8(type))));
} } else
// FIXME Can Inset::name() return an empty name for wide or full_label = bformat(from_ascii("%1$s #:"), name);
// float insets? If not we can put the definition of type
// inside the if (in) clause and use that instead of
// if (!type.empty()).
docstring type;
if (in)
type = in->name();
if (!type.empty()) {
Floating const & fl = textclass.floats().getType(to_ascii(type));
// FIXME UNICODE
counters.step(from_ascii(fl.type()));
// Doesn't work... yet.
par.params().labelString(par.translateIfPossible(
bformat(from_ascii("%1$s #:"), from_utf8(fl.name())),
buf.params()));
} else {
// par->SetLayout(0);
par.params().labelString(par.translateIfPossible(
layout->labelstring(), buf.params()));
} }
par.params().labelString(full_label);
} else if (layout->labeltype == LABEL_NO_LABEL) } else if (layout->labeltype == LABEL_NO_LABEL)
par.params().labelString(docstring()); par.params().labelString(docstring());
@ -644,6 +550,31 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
} // anon namespace } // anon namespace
void updateLabels(Buffer const & buf, ParIterator & parit)
{
BOOST_ASSERT(parit.pit() == 0);
depth_type maxdepth = 0;
pit_type const lastpit = parit.lastpit();
for ( ; parit.pit() <= lastpit ; ++parit.pit()) {
// reduce depth if necessary
parit->params().depth(min(parit->params().depth(), maxdepth));
maxdepth = parit->getMaxDepthAfter();
// set the counter for this paragraph
setLabel(buf, parit);
// Now the insets
InsetList::const_iterator iit = parit->insetlist.begin();
InsetList::const_iterator end = parit->insetlist.end();
for (; iit != end; ++iit) {
parit.pos() = iit->pos;
iit->inset->updateLabels(buf, parit);
}
}
}
void updateLabels(Buffer const & buf, bool childonly) void updateLabels(Buffer const & buf, bool childonly)
{ {
@ -662,34 +593,10 @@ void updateLabels(Buffer const & buf, bool childonly)
textclass.counters().reset(); textclass.counters().reset();
} }
ParIterator const end = par_iterator_end(buf.inset()); // do the real work
ParIterator parit = par_iterator_begin(buf.inset());
for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) { parit.forwardPos();
// reduce depth if necessary updateLabels(buf, parit);
if (it.pit()) {
Paragraph const & prevpar = it.plist()[it.pit() - 1];
it->params().depth(min(it->params().depth(),
prevpar.getMaxDepthAfter()));
} else
it->params().depth(0);
// set the counter for this paragraph
setLabel(buf, it, textclass);
// It is better to set the captions after setLabel because
// the caption number might need the section number in the
// future.
setCaptions(*it, textclass);
// Now included docs
InsetList::const_iterator iit = it->insetlist.begin();
InsetList::const_iterator end = it->insetlist.end();
for (; iit != end; ++iit) {
if (iit->inset->lyxCode() == Inset::INCLUDE_CODE)
static_cast<InsetInclude const *>(iit->inset)
->updateLabels(buf);
}
}
Buffer & cbuf = const_cast<Buffer &>(buf); Buffer & cbuf = const_cast<Buffer &>(buf);
cbuf.tocBackend().update(); cbuf.tocBackend().update();

View File

@ -65,6 +65,9 @@ int countWords(DocIterator const & from, DocIterator const & to);
/// updates all counters /// updates all counters
void updateLabels(Buffer const &, bool childonly = false); void updateLabels(Buffer const &, bool childonly = false);
///
void updateLabels(Buffer const &, ParIterator &);
/// ///
void checkBufferStructure(Buffer &, ParIterator const &); void checkBufferStructure(Buffer &, ParIterator const &);

View File

@ -28,6 +28,7 @@ namespace lyx {
class Buffer; class Buffer;
class BufferParams; class BufferParams;
class BufferView; class BufferView;
class ParIterator;
class ParConstIterator; class ParConstIterator;
class CursorSlice; class CursorSlice;
class FuncRequest; class FuncRequest;
@ -433,6 +434,8 @@ public:
/// Add an entry to the TocList /// Add an entry to the TocList
/// pit is the ParConstIterator of the paragraph containing the inset /// pit is the ParConstIterator of the paragraph containing the inset
virtual void addToToc(TocList &, Buffer const &, ParConstIterator const &) const {} virtual void addToToc(TocList &, Buffer const &, ParConstIterator const &) const {}
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &) {}
public: public:
/// returns LyX code associated with the inset. Used for TOC, ...) /// returns LyX code associated with the inset. Used for TOC, ...)

View File

@ -15,6 +15,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BranchList.h" #include "BranchList.h"
#include "Counters.h"
#include "Cursor.h" #include "Cursor.h"
#include "DispatchResult.h" #include "DispatchResult.h"
#include "FuncRequest.h" #include "FuncRequest.h"
@ -231,6 +232,19 @@ bool InsetBranch::isBranchSelected(Buffer const & buffer) const
} }
void InsetBranch::updateLabels(Buffer const & buf, ParIterator const & it)
{
if (isBranchSelected(buf))
InsetCollapsable::updateLabels(buf, it);
else {
TextClass const & tclass = buf.params().getTextClass();
Counters savecnt = tclass.counters();
InsetCollapsable::updateLabels(buf, it);
tclass.counters() = savecnt;
}
}
int InsetBranch::latex(Buffer const & buf, odocstream & os, int InsetBranch::latex(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {

View File

@ -80,7 +80,8 @@ public:
bool isBranchSelected(Buffer const & buffer) const; bool isBranchSelected(Buffer const & buffer) const;
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
//
virtual void updateLabels(Buffer const &, ParIterator const &);
protected: protected:
/// ///
InsetBranch(InsetBranch const &); InsetBranch(InsetBranch const &);

View File

@ -123,8 +123,7 @@ void InsetCaption::addToToc(TocList & toclist, Buffer const & buf, ParConstItera
ParConstIterator pit = par_const_iterator_begin(*this); ParConstIterator pit = par_const_iterator_begin(*this);
Toc & toc = toclist[type_]; Toc & toc = toclist[type_];
docstring const str = convert<docstring>(counter_) docstring const str = full_label_ + ". " + pit->asString(buf, false);
+ ". " + pit->asString(buf, false);
toc.push_back(TocItem(pit, 0, str)); toc.push_back(TocItem(pit, 0, str));
} }
@ -134,8 +133,6 @@ bool InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
int const width_offset = TEXT_TO_INSET_OFFSET / 2; int const width_offset = TEXT_TO_INSET_OFFSET / 2;
mi.base.textwidth -= width_offset; mi.base.textwidth -= width_offset;
computeFullLabel(*mi.base.bv->buffer());
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_); labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
// add some space to separate the label from the inset text // add some space to separate the label from the inset text
labelwidth_ += 2 * TEXT_TO_INSET_OFFSET; labelwidth_ += 2 * TEXT_TO_INSET_OFFSET;
@ -257,8 +254,6 @@ int InsetCaption::latex(Buffer const & buf, odocstream & os,
int InsetCaption::plaintext(Buffer const & buf, odocstream & os, int InsetCaption::plaintext(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
computeFullLabel(buf);
os << '[' << full_label_ << "\n"; os << '[' << full_label_ << "\n";
InsetText::plaintext(buf, os, runparams); InsetText::plaintext(buf, os, runparams);
os << "\n]"; os << "\n]";
@ -292,15 +287,32 @@ int InsetCaption::getOptArg(Buffer const & buf, odocstream & os,
} }
void InsetCaption::computeFullLabel(Buffer const & buf) const void InsetCaption::updateLabels(Buffer const & buf, ParIterator const & it)
{ {
if (type_.empty()) TextClass const & tclass = buf.params().getTextClass();
Counters & cnts = tclass.counters();
string const & type = cnts.current_float();
if (type.empty())
full_label_ = buf.B_("Senseless!!! "); full_label_ = buf.B_("Senseless!!! ");
else { else {
docstring const number = convert<docstring>(counter_); // FIXME: life would be _much_ simpler if listings was
docstring label = custom_label_.empty()? buf.B_(type_): custom_label_; // listed in Floating.
full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number); docstring name;
if (type == "listing")
name = buf.B_("Listing");
else
name = buf.B_(tclass.floats().getType(type).name());
if (cnts.hasCounter(from_utf8(type))) {
cnts.step(from_utf8(type));
full_label_ = bformat(from_ascii("%1$s %2$s:"),
name,
convert<docstring>(cnts.value(from_utf8(type))));
} else
full_label_ = bformat(from_ascii("%1$s #:"), name);
} }
// Do the real work now.
InsetText::updateLabels(buf, it);
} }

View File

@ -58,6 +58,8 @@ public:
bool insetAllowed(Inset::Code code) const; bool insetAllowed(Inset::Code code) const;
/// ///
virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
/// ///
virtual bool wide() const { return false; } virtual bool wide() const { return false; }
/// ///
@ -76,8 +78,6 @@ public:
int getOptArg(Buffer const & buf, odocstream & os, int getOptArg(Buffer const & buf, odocstream & os,
OutputParams const &) const; OutputParams const &) const;
/// ///
void setCount(int c) { counter_ = c; }
///
std::string const & type() const { return type_; } std::string const & type() const { return type_; }
/// ///
void setType(std::string const & type) { type_ = type; } void setType(std::string const & type) { type_ = type; }
@ -89,8 +89,6 @@ public:
bool forceDefaultParagraphs(idx_type) const { return true; } bool forceDefaultParagraphs(idx_type) const { return true; }
private: private:
///
void computeFullLabel(Buffer const & buf) const;
/// ///
virtual std::auto_ptr<Inset> doClone() const; virtual std::auto_ptr<Inset> doClone() const;
/// ///
@ -102,8 +100,6 @@ private:
/// ///
docstring custom_label_; docstring custom_label_;
/// ///
int counter_;
///
TextClass const & textclass_; TextClass const & textclass_;
}; };

View File

@ -16,6 +16,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "Counters.h"
#include "Cursor.h" #include "Cursor.h"
#include "debug.h" #include "debug.h"
#include "DispatchResult.h" #include "DispatchResult.h"
@ -183,6 +184,21 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
void InsetFloat::updateLabels(Buffer const & buf, ParIterator const & it)
{
Counters & cnts = buf.params().getTextClass().counters();
string const saveflt = cnts.current_float();
// Tell to captions what the current float is
cnts.current_float(params().type);
InsetCollapsable::updateLabels(buf, it);
//reset afterwards
cnts.current_float(saveflt);
}
void InsetFloatParams::write(ostream & os) const void InsetFloatParams::write(ostream & os) const
{ {
os << "Float " << type << '\n'; os << "Float " << type << '\n';

View File

@ -87,6 +87,8 @@ public:
InsetFloatParams const & params() const { return params_; } InsetFloatParams const & params() const { return params_; }
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
protected: protected:
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
private: private:

View File

@ -111,7 +111,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), counter_(0) set_label_(false)
{ {
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
} }
@ -122,7 +122,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), counter_(0) set_label_(false)
{ {
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
} }
@ -336,23 +336,19 @@ docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
switch (type(params_)) { switch (type(params_)) {
case INPUT: case INPUT:
temp += buf.B_("Input"); temp = buf.B_("Input");
break; break;
case VERB: case VERB:
temp += buf.B_("Verbatim Input"); temp = buf.B_("Verbatim Input");
break; break;
case VERBAST: case VERBAST:
temp += buf.B_("Verbatim Input*"); temp = buf.B_("Verbatim Input*");
break; break;
case INCLUDE: case INCLUDE:
temp += buf.B_("Include"); temp = buf.B_("Include");
break; break;
case LISTINGS: { case LISTINGS: {
if (counter_ > 0) temp = listings_label_;
temp += buf.B_("Program Listing ") + convert<docstring>(counter_);
else
temp += buf.B_("Program Listing");
break;
} }
} }
@ -925,27 +921,25 @@ void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer, ParConstIt
} }
void InsetInclude::updateLabels(Buffer const & buffer) const void InsetInclude::updateLabels(Buffer const & buffer,
ParIterator const &) const
{ {
Buffer const * const childbuffer = getChildBuffer(buffer, params_); Buffer const * const childbuffer = getChildBuffer(buffer, params_);
if (!childbuffer) if (childbuffer)
return; lyx::updateLabels(*childbuffer, true);
else if (isListings(params_)) {
lyx::updateLabels(*childbuffer, true); InsetListingsParams const par = params_.getOptions();
} if (par.getParamValue("caption").empty())
listings_label_.clear();
else {
void InsetInclude::updateCounter(Counters & counters) Counters & counters = buffer.params().getTextClass().counters();
{ docstring const cnt = from_ascii("listing");
if (!isListings(params_)) if (counters.hasCounter(cnt)) {
return; counters.step(cnt);
listings_label_ = buffer.B_("Program Listing ") + convert<docstring>(counters.value(cnt));
InsetListingsParams const par = params_.getOptions(); } else
if (par.getParamValue("caption").empty()) listings_label_ = buffer.B_("Program Listing");
counter_ = 0; }
else {
counters.step(from_ascii("listing"));
counter_ = counters.value(from_ascii("listing"));
} }
} }

View File

@ -97,12 +97,9 @@ public:
/// ///
void addToToc(TocList &, Buffer const &, ParConstIterator const &) const; void addToToc(TocList &, Buffer const &, ParConstIterator const &) 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 updateLabels(Buffer const & buffer, ParIterator const &) const;
void updateCounter(Counters & counters);
protected: protected:
InsetInclude(InsetInclude const &); InsetInclude(InsetInclude const &);
/// ///
@ -137,7 +134,7 @@ private:
/// cache /// cache
mutable bool set_label_; mutable bool set_label_;
mutable RenderButton button_; mutable RenderButton button_;
int counter_; mutable docstring listings_label_;
}; };

View File

@ -14,6 +14,9 @@
#include "InsetListings.h" #include "InsetListings.h"
#include "InsetCaption.h" #include "InsetCaption.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "Counters.h"
#include "Language.h" #include "Language.h"
#include "gettext.h" #include "gettext.h"
#include "DispatchResult.h" #include "DispatchResult.h"
@ -84,6 +87,21 @@ Inset::DisplayType InsetListings::display() const
} }
void InsetListings::updateLabels(Buffer const & buf, ParIterator const & it)
{
Counters & cnts = buf.params().getTextClass().counters();
string const saveflt = cnts.current_float();
// Tell to captions what the current float is
cnts.current_float("listing");
InsetCollapsable::updateLabels(buf, it);
//reset afterwards
cnts.current_float(saveflt);
}
void InsetListings::write(Buffer const & buf, ostream & os) const void InsetListings::write(Buffer const & buf, ostream & os) const
{ {
os << "listings" << "\n"; os << "listings" << "\n";

View File

@ -36,6 +36,8 @@ public:
virtual DisplayType display() const; virtual DisplayType display() const;
/// ///
docstring name() const { return from_ascii("Listings"); } docstring name() const { return from_ascii("Listings"); }
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
/// ///
void write(Buffer const & buf, std::ostream & os) const; void write(Buffer const & buf, std::ostream & os) const;
/// ///

View File

@ -15,7 +15,9 @@
#include "InsetNote.h" #include "InsetNote.h"
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "Counters.h"
#include "Cursor.h" #include "Cursor.h"
#include "debug.h" #include "debug.h"
#include "DispatchResult.h" #include "DispatchResult.h"
@ -280,6 +282,14 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
} }
void InsetNote::updateLabels(Buffer const & buf, ParIterator const & it)
{
TextClass const & tclass = buf.params().getTextClass();
Counters savecnt = tclass.counters();
InsetCollapsable::updateLabels(buf, it);
tclass.counters() = savecnt;
}
int InsetNote::latex(Buffer const & buf, odocstream & os, int InsetNote::latex(Buffer const & buf, odocstream & os,
OutputParams const & runparams_in) const OutputParams const & runparams_in) const

View File

@ -77,6 +77,8 @@ public:
InsetNoteParams const & params() const { return params_; } InsetNoteParams const & params() const { return params_; }
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
protected: protected:
InsetNote(InsetNote const &); InsetNote(InsetNote const &);
/// ///

View File

@ -21,8 +21,10 @@
#include "InsetTabular.h" #include "InsetTabular.h"
#include "Buffer.h" #include "Buffer.h"
#include "buffer_funcs.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "Counters.h"
#include "Cursor.h" #include "Cursor.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "CoordCache.h" #include "CoordCache.h"
@ -41,6 +43,7 @@
#include "Paragraph.h" #include "Paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "ParIterator.h"
#include "Undo.h" #include "Undo.h"
#include "support/convert.h" #include "support/convert.h"
@ -3181,6 +3184,25 @@ void InsetTabular::edit(Cursor & cur, bool left)
} }
void InsetTabular::updateLabels(Buffer const & buf, ParIterator const & it)
{
// In a longtable, tell captions what the current float is
Counters & cnts = buf.params().getTextClass().counters();
string const saveflt = cnts.current_float();
if (tabular.isLongTabular())
cnts.current_float("table");
ParIterator it2 = it;
it2.forwardPos();
for ( ; it2.idx() <= it2.lastidx() ; it2.forwardIdx())
lyx::updateLabels(buf, it2);
//reset afterwards
if (tabular.isLongTabular())
cnts.current_float(saveflt);
}
void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
{ {
LYXERR(Debug::DEBUG) << "# InsetTabular::doDispatch: cmd: " << cmd LYXERR(Debug::DEBUG) << "# InsetTabular::doDispatch: cmd: " << cmd
@ -4792,7 +4814,6 @@ bool InsetTabular::tablemode(Cursor & cur) const
string const InsetTabularMailer::name_("tabular"); string const InsetTabularMailer::name_("tabular");
InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset) InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)

View File

@ -758,6 +758,8 @@ public:
Inset * editXY(Cursor & cur, int x, int y); Inset * editXY(Cursor & cur, int x, int y);
/// can we go further down on mouse click? /// can we go further down on mouse click?
bool descendable() const { return true; } bool descendable() const { return true; }
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
// //
// Public structures and variables // Public structures and variables

View File

@ -14,6 +14,7 @@
#include "InsetNewline.h" #include "InsetNewline.h"
#include "Buffer.h" #include "Buffer.h"
#include "buffer_funcs.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "CoordCache.h" #include "CoordCache.h"
@ -38,6 +39,7 @@
#include "Paragraph.h" #include "Paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "ParIterator.h"
#include "rowpainter.h" #include "rowpainter.h"
#include "Row.h" #include "Row.h"
#include "sgml.h" #include "sgml.h"
@ -461,4 +463,13 @@ ParagraphList & InsetText::paragraphs()
} }
void InsetText::updateLabels(Buffer const & buf, ParIterator const & it)
{
ParIterator it2 = it;
it2.forwardPos();
BOOST_ASSERT(&it2.inset() == this && it2.pit() == 0);
lyx::updateLabels(buf, it2);
}
} // namespace lyx } // namespace lyx

View File

@ -138,6 +138,8 @@ public:
virtual bool wide() const { return wide_inset_; } virtual bool wide() const { return wide_inset_; }
/// ///
void setWide(bool wide_inset) { wide_inset_ = wide_inset; } void setWide(bool wide_inset) { wide_inset_ = wide_inset; }
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
protected: protected:
/// ///

View File

@ -15,6 +15,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "Counters.h"
#include "Cursor.h" #include "Cursor.h"
#include "debug.h" #include "debug.h"
#include "DispatchResult.h" #include "DispatchResult.h"
@ -108,6 +109,21 @@ bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
void InsetWrap::updateLabels(Buffer const & buf, ParIterator const & it)
{
Counters & cnts = buf.params().getTextClass().counters();
string const saveflt = cnts.current_float();
// Tell to captions what the current float is
cnts.current_float(params().type);
InsetCollapsable::updateLabels(buf, it);
//reset afterwards
cnts.current_float(saveflt);
}
void InsetWrapParams::write(ostream & os) const void InsetWrapParams::write(ostream & os) const
{ {
os << "Wrap " << type << '\n'; os << "Wrap " << type << '\n';

View File

@ -71,6 +71,8 @@ public:
InsetWrapParams const & params() const { return params_; } InsetWrapParams const & params() const { return params_; }
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
protected: protected:
/// ///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);