mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
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:
parent
f78fcc859e
commit
601a8e0192
@ -1995,7 +1995,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
|
||||
|
||||
Buffer * const b = newFile(filename, templname, !name.empty());
|
||||
if (b) {
|
||||
updateLabels(*b);
|
||||
//updateLabels(*b);
|
||||
lyx_view_->setBuffer(b);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "BufferList.h"
|
||||
#include "BufferParams.h"
|
||||
#include "debug.h"
|
||||
#include "DocIterator.h"
|
||||
#include "Counters.h"
|
||||
#include "ErrorList.h"
|
||||
@ -42,6 +43,7 @@
|
||||
#include "insets/InsetInclude.h"
|
||||
#include "insets/InsetTabular.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.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.
|
||||
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();
|
||||
Counters & counters = textclass.counters();
|
||||
|
||||
@ -501,11 +430,6 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
|
||||
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?
|
||||
if (layout->labeltype == LABEL_COUNTER) {
|
||||
if (layout->toclevel <= buf.params().secnumdepth
|
||||
@ -523,6 +447,7 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
|
||||
// par.params().labelString(
|
||||
// buf.params().user_defined_bullet(par.itemdepth).getText());
|
||||
// for now, use a simple hardcoded label
|
||||
docstring itemlabel;
|
||||
switch (par.itemdepth) {
|
||||
case 0:
|
||||
itemlabel = char_type(0x2022);
|
||||
@ -600,40 +525,21 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
|
||||
par.translateIfPossible(layout->labelstring(), buf.params()));
|
||||
// In biblio shouldn't be following counters but...
|
||||
} else if (layout->labeltype == LABEL_SENSITIVE) {
|
||||
// Search for the first float or wrap inset in the iterator
|
||||
size_t i = it.depth();
|
||||
Inset * in = 0;
|
||||
while (i > 0) {
|
||||
--i;
|
||||
Inset::Code const code = it[i].inset().lyxCode();
|
||||
if (code == Inset::FLOAT_CODE ||
|
||||
code == Inset::WRAP_CODE) {
|
||||
in = &it[i].inset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// FIXME Can Inset::name() return an empty name for wide or
|
||||
// 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()));
|
||||
string const & type = counters.current_float();
|
||||
docstring full_label;
|
||||
if (type.empty())
|
||||
full_label = buf.B_("Senseless!!! ");
|
||||
else {
|
||||
docstring name = buf.B_(textclass.floats().getType(type).name());
|
||||
if (counters.hasCounter(from_utf8(type))) {
|
||||
counters.step(from_utf8(type));
|
||||
full_label = bformat(from_ascii("%1$s %2$s:"),
|
||||
name,
|
||||
convert<docstring>(counters.value(from_utf8(type))));
|
||||
} else
|
||||
full_label = bformat(from_ascii("%1$s #:"), name);
|
||||
}
|
||||
par.params().labelString(full_label);
|
||||
|
||||
} else if (layout->labeltype == LABEL_NO_LABEL)
|
||||
par.params().labelString(docstring());
|
||||
@ -644,6 +550,31 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
|
||||
|
||||
} // 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)
|
||||
{
|
||||
@ -662,34 +593,10 @@ void updateLabels(Buffer const & buf, bool childonly)
|
||||
textclass.counters().reset();
|
||||
}
|
||||
|
||||
ParIterator const end = par_iterator_end(buf.inset());
|
||||
|
||||
for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) {
|
||||
// reduce depth if necessary
|
||||
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);
|
||||
}
|
||||
}
|
||||
// do the real work
|
||||
ParIterator parit = par_iterator_begin(buf.inset());
|
||||
parit.forwardPos();
|
||||
updateLabels(buf, parit);
|
||||
|
||||
Buffer & cbuf = const_cast<Buffer &>(buf);
|
||||
cbuf.tocBackend().update();
|
||||
|
@ -65,6 +65,9 @@ int countWords(DocIterator const & from, DocIterator const & to);
|
||||
/// updates all counters
|
||||
void updateLabels(Buffer const &, bool childonly = false);
|
||||
|
||||
///
|
||||
void updateLabels(Buffer const &, ParIterator &);
|
||||
|
||||
///
|
||||
void checkBufferStructure(Buffer &, ParIterator const &);
|
||||
|
||||
|
@ -28,6 +28,7 @@ namespace lyx {
|
||||
class Buffer;
|
||||
class BufferParams;
|
||||
class BufferView;
|
||||
class ParIterator;
|
||||
class ParConstIterator;
|
||||
class CursorSlice;
|
||||
class FuncRequest;
|
||||
@ -433,6 +434,8 @@ public:
|
||||
/// Add an entry to the TocList
|
||||
/// pit is the ParConstIterator of the paragraph containing the inset
|
||||
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:
|
||||
/// returns LyX code associated with the inset. Used for TOC, ...)
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BranchList.h"
|
||||
#include "Counters.h"
|
||||
#include "Cursor.h"
|
||||
#include "DispatchResult.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,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
|
@ -80,7 +80,8 @@ public:
|
||||
bool isBranchSelected(Buffer const & buffer) const;
|
||||
///
|
||||
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
|
||||
|
||||
//
|
||||
virtual void updateLabels(Buffer const &, ParIterator const &);
|
||||
protected:
|
||||
///
|
||||
InsetBranch(InsetBranch const &);
|
||||
|
@ -123,8 +123,7 @@ void InsetCaption::addToToc(TocList & toclist, Buffer const & buf, ParConstItera
|
||||
ParConstIterator pit = par_const_iterator_begin(*this);
|
||||
|
||||
Toc & toc = toclist[type_];
|
||||
docstring const str = convert<docstring>(counter_)
|
||||
+ ". " + pit->asString(buf, false);
|
||||
docstring const str = full_label_ + ". " + pit->asString(buf, false);
|
||||
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;
|
||||
mi.base.textwidth -= width_offset;
|
||||
|
||||
computeFullLabel(*mi.base.bv->buffer());
|
||||
|
||||
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
|
||||
// add some space to separate the label from the inset text
|
||||
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,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
computeFullLabel(buf);
|
||||
|
||||
os << '[' << full_label_ << "\n";
|
||||
InsetText::plaintext(buf, os, runparams);
|
||||
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!!! ");
|
||||
else {
|
||||
docstring const number = convert<docstring>(counter_);
|
||||
docstring label = custom_label_.empty()? buf.B_(type_): custom_label_;
|
||||
full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number);
|
||||
// FIXME: life would be _much_ simpler if listings was
|
||||
// listed in Floating.
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,6 +58,8 @@ public:
|
||||
bool insetAllowed(Inset::Code code) 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; }
|
||||
///
|
||||
@ -76,8 +78,6 @@ public:
|
||||
int getOptArg(Buffer const & buf, odocstream & os,
|
||||
OutputParams const &) const;
|
||||
///
|
||||
void setCount(int c) { counter_ = c; }
|
||||
///
|
||||
std::string const & type() const { return type_; }
|
||||
///
|
||||
void setType(std::string const & type) { type_ = type; }
|
||||
@ -89,8 +89,6 @@ public:
|
||||
bool forceDefaultParagraphs(idx_type) const { return true; }
|
||||
|
||||
private:
|
||||
///
|
||||
void computeFullLabel(Buffer const & buf) const;
|
||||
///
|
||||
virtual std::auto_ptr<Inset> doClone() const;
|
||||
///
|
||||
@ -102,8 +100,6 @@ private:
|
||||
///
|
||||
docstring custom_label_;
|
||||
///
|
||||
int counter_;
|
||||
///
|
||||
TextClass const & textclass_;
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Counters.h"
|
||||
#include "Cursor.h"
|
||||
#include "debug.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
|
||||
{
|
||||
os << "Float " << type << '\n';
|
||||
|
@ -87,6 +87,8 @@ public:
|
||||
InsetFloatParams const & params() const { return params_; }
|
||||
///
|
||||
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:
|
||||
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||
private:
|
||||
|
@ -111,7 +111,7 @@ bool isListings(InsetCommandParams const & params)
|
||||
InsetInclude::InsetInclude(InsetCommandParams const & p)
|
||||
: params_(p), include_label(uniqueID()),
|
||||
preview_(new RenderMonitoredPreview(this)),
|
||||
set_label_(false), counter_(0)
|
||||
set_label_(false)
|
||||
{
|
||||
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
||||
}
|
||||
@ -122,7 +122,7 @@ InsetInclude::InsetInclude(InsetInclude const & other)
|
||||
params_(other.params_),
|
||||
include_label(other.include_label),
|
||||
preview_(new RenderMonitoredPreview(this)),
|
||||
set_label_(false), counter_(0)
|
||||
set_label_(false)
|
||||
{
|
||||
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
||||
}
|
||||
@ -336,23 +336,19 @@ docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
|
||||
|
||||
switch (type(params_)) {
|
||||
case INPUT:
|
||||
temp += buf.B_("Input");
|
||||
temp = buf.B_("Input");
|
||||
break;
|
||||
case VERB:
|
||||
temp += buf.B_("Verbatim Input");
|
||||
temp = buf.B_("Verbatim Input");
|
||||
break;
|
||||
case VERBAST:
|
||||
temp += buf.B_("Verbatim Input*");
|
||||
temp = buf.B_("Verbatim Input*");
|
||||
break;
|
||||
case INCLUDE:
|
||||
temp += buf.B_("Include");
|
||||
temp = buf.B_("Include");
|
||||
break;
|
||||
case LISTINGS: {
|
||||
if (counter_ > 0)
|
||||
temp += buf.B_("Program Listing ") + convert<docstring>(counter_);
|
||||
else
|
||||
temp += buf.B_("Program Listing");
|
||||
break;
|
||||
temp = listings_label_;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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_);
|
||||
if (!childbuffer)
|
||||
return;
|
||||
|
||||
if (childbuffer)
|
||||
lyx::updateLabels(*childbuffer, true);
|
||||
}
|
||||
|
||||
|
||||
void InsetInclude::updateCounter(Counters & counters)
|
||||
{
|
||||
if (!isListings(params_))
|
||||
return;
|
||||
|
||||
else if (isListings(params_)) {
|
||||
InsetListingsParams const par = params_.getOptions();
|
||||
if (par.getParamValue("caption").empty())
|
||||
counter_ = 0;
|
||||
listings_label_.clear();
|
||||
else {
|
||||
counters.step(from_ascii("listing"));
|
||||
counter_ = counters.value(from_ascii("listing"));
|
||||
Counters & counters = buffer.params().getTextClass().counters();
|
||||
docstring const cnt = from_ascii("listing");
|
||||
if (counters.hasCounter(cnt)) {
|
||||
counters.step(cnt);
|
||||
listings_label_ = buffer.B_("Program Listing ") + convert<docstring>(counters.value(cnt));
|
||||
} else
|
||||
listings_label_ = buffer.B_("Program Listing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,12 +97,9 @@ public:
|
||||
///
|
||||
void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
|
||||
///
|
||||
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);
|
||||
///
|
||||
void updateLabels(Buffer const & buffer, ParIterator const &) const;
|
||||
protected:
|
||||
InsetInclude(InsetInclude const &);
|
||||
///
|
||||
@ -137,7 +134,7 @@ private:
|
||||
/// cache
|
||||
mutable bool set_label_;
|
||||
mutable RenderButton button_;
|
||||
int counter_;
|
||||
mutable docstring listings_label_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -14,6 +14,9 @@
|
||||
#include "InsetListings.h"
|
||||
#include "InsetCaption.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "Counters.h"
|
||||
#include "Language.h"
|
||||
#include "gettext.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
|
||||
{
|
||||
os << "listings" << "\n";
|
||||
|
@ -36,6 +36,8 @@ public:
|
||||
virtual DisplayType display() const;
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -15,7 +15,9 @@
|
||||
#include "InsetNote.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Counters.h"
|
||||
#include "Cursor.h"
|
||||
#include "debug.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,
|
||||
OutputParams const & runparams_in) const
|
||||
|
@ -77,6 +77,8 @@ public:
|
||||
InsetNoteParams const & params() const { return params_; }
|
||||
///
|
||||
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:
|
||||
InsetNote(InsetNote const &);
|
||||
///
|
||||
|
@ -21,8 +21,10 @@
|
||||
#include "InsetTabular.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Counters.h"
|
||||
#include "Cursor.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "CoordCache.h"
|
||||
@ -41,6 +43,7 @@
|
||||
#include "Paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "ParIterator.h"
|
||||
#include "Undo.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)
|
||||
{
|
||||
LYXERR(Debug::DEBUG) << "# InsetTabular::doDispatch: cmd: " << cmd
|
||||
@ -4792,7 +4814,6 @@ bool InsetTabular::tablemode(Cursor & cur) const
|
||||
|
||||
|
||||
|
||||
|
||||
string const InsetTabularMailer::name_("tabular");
|
||||
|
||||
InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
|
||||
|
@ -758,6 +758,8 @@ public:
|
||||
Inset * editXY(Cursor & cur, int x, int y);
|
||||
/// can we go further down on mouse click?
|
||||
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
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "InsetNewline.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "CoordCache.h"
|
||||
@ -38,6 +39,7 @@
|
||||
#include "Paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "ParIterator.h"
|
||||
#include "rowpainter.h"
|
||||
#include "Row.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
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
virtual bool wide() const { return 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:
|
||||
///
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Counters.h"
|
||||
#include "Cursor.h"
|
||||
#include "debug.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
|
||||
{
|
||||
os << "Wrap " << type << '\n';
|
||||
|
@ -71,6 +71,8 @@ public:
|
||||
InsetWrapParams const & params() const { return params_; }
|
||||
///
|
||||
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:
|
||||
///
|
||||
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||
|
Loading…
Reference in New Issue
Block a user