Get rid of some magic booleans in updateLabels() and related routines.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33110 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-01-20 19:42:12 +00:00
parent bd95cdb734
commit caa4e94bf0
33 changed files with 82 additions and 77 deletions

View File

@ -1498,7 +1498,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
{
LaTeXFeatures features(*this, params(), runparams);
validate(features);
updateLabels(UpdateMaster, true);
updateLabels(UpdateMaster, OutputUpdate);
checkBibInfoCache();
d->bibinfo_.makeCitationLabels(*this);
updateMacros();
@ -3500,7 +3500,7 @@ void Buffer::setBuffersForInsets() const
}
void Buffer::updateLabels(UpdateScope scope, bool out) const
void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
{
// Use the master text class also for child documents
Buffer const * const master = masterBuffer();
@ -3518,7 +3518,7 @@ void Buffer::updateLabels(UpdateScope scope, bool out) const
// If this is a child document start with the master
if (master != this) {
bufToUpdate.insert(this);
master->updateLabels(UpdateMaster, out);
master->updateLabels(UpdateMaster, utype);
// Do this here in case the master has no gui associated with it. Then,
// the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
if (!master->gui_)
@ -3546,7 +3546,7 @@ void Buffer::updateLabels(UpdateScope scope, bool out) const
// do the real work
ParIterator parit = cbuf.par_iterator_begin();
updateLabels(parit, out);
updateLabels(parit, utype);
if (master != this)
// TocBackend update will be done later.
@ -3628,7 +3628,7 @@ static bool needEnumCounterReset(ParIterator const & it)
// set the label of a paragraph. This includes the counters.
void Buffer::setLabel(ParIterator & it, bool for_output) const
void Buffer::setLabel(ParIterator & it, UpdateType utype) const
{
BufferParams const & bp = this->masterBuffer()->params();
DocumentClass const & textclass = bp.documentClass();
@ -3660,7 +3660,7 @@ void Buffer::setLabel(ParIterator & it, bool for_output) const
if (layout.toclevel <= bp.secnumdepth
&& (layout.latextype != LATEX_ENVIRONMENT
|| it.text()->isFirstInSequence(it.pit()))) {
counters.step(layout.counter, for_output);
counters.step(layout.counter, utype);
par.params().labelString(
par.expandLabel(layout, bp));
} else
@ -3714,7 +3714,7 @@ void Buffer::setLabel(ParIterator & it, bool for_output) const
// Maybe we have to reset the enumeration counter.
if (needEnumCounterReset(it))
counters.reset(enumcounter);
counters.step(enumcounter, for_output);
counters.step(enumcounter, utype);
string const & lang = par.getParLanguage(bp)->code();
par.params().labelString(counters.theCounter(enumcounter, lang));
@ -3731,7 +3731,7 @@ void Buffer::setLabel(ParIterator & it, bool for_output) const
docstring name = this->B_(textclass.floats().getType(type).name());
if (counters.hasCounter(from_utf8(type))) {
string const & lang = par.getParLanguage(bp)->code();
counters.step(from_utf8(type), for_output);
counters.step(from_utf8(type), utype);
full_label = bformat(from_ascii("%1$s %2$s:"),
name,
counters.theCounter(from_utf8(type), lang));
@ -3757,7 +3757,7 @@ void Buffer::setLabel(ParIterator & it, bool for_output) const
}
void Buffer::updateLabels(ParIterator & parit, bool out) const
void Buffer::updateLabels(ParIterator & parit, UpdateType utype) const
{
LASSERT(parit.pit() == 0, /**/);
@ -3774,7 +3774,7 @@ void Buffer::updateLabels(ParIterator & parit, bool out) const
parit->params().depth(min(parit->params().depth(), maxdepth));
maxdepth = parit->getMaxDepthAfter();
if (out) {
if (utype == OutputUpdate) {
// track the active counters
// we have to do this for the master buffer, since the local
// buffer isn't tracking anything.
@ -3783,14 +3783,14 @@ void Buffer::updateLabels(ParIterator & parit, bool out) const
}
// set the counter for this paragraph
setLabel(parit, out);
setLabel(parit, utype);
// 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(parit, out);
iit->inset->updateLabels(parit, utype);
}
}
}

View File

@ -12,6 +12,7 @@
#ifndef BUFFER_H
#define BUFFER_H
#include "OutputEnums.h"
#include "update_flags.h"
#include "insets/InsetCode.h"
@ -552,13 +553,13 @@ public:
/// Updates screen labels and some other information associated with
/// insets and paragraphs. Actually, it's more like a general "recurse
/// through the Buffer" routine, that visits all the insets and paragraphs.
void updateLabels() const { updateLabels(UpdateMaster, false); }
void updateLabels() const { updateLabels(UpdateMaster, InternalUpdate); }
/// \param scope: whether to start with the master document or just
/// do this one.
/// \param output: whether we are preparing for output.
void updateLabels(UpdateScope scope, bool output) const;
void updateLabels(UpdateScope scope, UpdateType utype) const;
///
void updateLabels(ParIterator & parit, bool output) const;
void updateLabels(ParIterator & parit, UpdateType utype) const;
/// Spellcheck starting from \p from.
/// \p from initial position, will then points to the next misspelled
@ -579,7 +580,7 @@ private:
void updateMacros(DocIterator & it,
DocIterator & scope) const;
///
void setLabel(ParIterator & it) const;
void setLabel(ParIterator & it, UpdateType utype) const;
///
void collectRelatives(BufferSet & bufs) const;

View File

@ -227,7 +227,7 @@ int Counters::value(docstring const & ctr) const
}
void Counters::step(docstring const & ctr, bool track_counters)
void Counters::step(docstring const & ctr, UpdateType utype)
{
CounterList::iterator it = counterList_.find(ctr);
if (it == counterList_.end()) {
@ -237,7 +237,7 @@ void Counters::step(docstring const & ctr, bool track_counters)
}
it->second.step();
if (track_counters) {
if (utype == OutputUpdate) {
LASSERT(!counter_stack_.empty(), /* */);
counter_stack_.pop_back();
counter_stack_.push_back(ctr);

View File

@ -15,6 +15,8 @@
#ifndef COUNTERS_H
#define COUNTERS_H
#include "OutputEnums.h"
#include "support/docstring.h"
#include <map>
@ -116,7 +118,7 @@ public:
/// Sub-slaves are not zeroed! That happens at slave's first
/// step 0->1. Seems to be sufficient.
/// \param for_output: whether to track the counters
void step(docstring const & ctr, bool track_counters = false);
void step(docstring const & ctr, UpdateType = InternalUpdate);
/// Reset all counters.
void reset();
/// Reset counters matched by match string.

View File

@ -18,6 +18,7 @@
#include "ColorCode.h"
#include "InsetCode.h"
#include "Layout.h"
#include "OutputEnums.h"
#include "support/strfwd.h"
#include "support/types.h"
@ -472,7 +473,7 @@ public:
/// Update the counters of this inset and of its contents.
/// The boolean indicates whether we are preparing for output, e.g.,
/// of XHTML.
virtual void updateLabels(ParIterator const &, bool) {}
virtual void updateLabels(ParIterator const &, UpdateType) {}
/// Updates the inset's dialog
virtual Buffer const * updateFrontend() const;

View File

@ -254,13 +254,13 @@ void InsetBibitem::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it)
// Update the counters of this inset and of its contents
void InsetBibitem::updateLabels(ParIterator const & it, bool)
void InsetBibitem::updateLabels(ParIterator const & it, UpdateType utype)
{
BufferParams const & bp = buffer().masterBuffer()->params();
Counters & counters = bp.documentClass().counters();
docstring const bibitem = from_ascii("bibitem");
if (counters.hasCounter(bibitem) && getParam("label").empty()) {
counters.step(bibitem);
counters.step(bibitem, utype);
string const & lang = it.paragraph().getParLanguage(bp)->code();
autolabel_ = counters.theCounter(bibitem, lang);
} else {

View File

@ -65,7 +65,7 @@ private:
///
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
/// Update the counter of this inset
virtual void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
void updateCommand(docstring const & new_key, bool dummy = false);
///

View File

@ -307,14 +307,14 @@ docstring InsetCaption::getCaptionAsHTML(XHTMLStream & xs,
}
void InsetCaption::updateLabels(ParIterator const & it, bool out)
void InsetCaption::updateLabels(ParIterator const & it, UpdateType utype)
{
Buffer const & master = *buffer().masterBuffer();
DocumentClass const & tclass = master.params().documentClass();
string const & lang = it.paragraph().getParLanguage(master.params())->code();
Counters & cnts = tclass.counters();
string const & type = cnts.current_float();
if (out) {
if (utype == OutputUpdate) {
// counters are local to the caption
cnts.saveLastCounter();
}
@ -337,7 +337,7 @@ void InsetCaption::updateLabels(ParIterator const & it, bool out)
master.B_(tclass.floats().getType(type).name()));
}
if (cnts.hasCounter(counter)) {
cnts.step(counter, out);
cnts.step(counter, utype);
full_label_ = bformat(from_ascii("%1$s %2$s:"),
name,
cnts.theCounter(counter, lang));
@ -346,8 +346,8 @@ void InsetCaption::updateLabels(ParIterator const & it, bool out)
}
// Do the real work now.
InsetText::updateLabels(it, out);
if (out)
InsetText::updateLabels(it, utype);
if (utype == OutputUpdate)
cnts.restoreLastCounter();
}

View File

@ -64,7 +64,7 @@ private:
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
int latex(odocstream & os, OutputParams const &) const;
///

View File

@ -457,7 +457,7 @@ docstring InsetCitation::screenLabel() const
}
void InsetCitation::updateLabels(ParIterator const &, bool)
void InsetCitation::updateLabels(ParIterator const &, UpdateType utype)
{
CiteEngine const engine = buffer().params().citeEngine();
if (cache.params == params() && cache.engine == engine)

View File

@ -56,7 +56,7 @@ public:
///
void validate(LaTeXFeatures &) const;
///
void updateLabels(ParIterator const & it, bool);
void updateLabels(ParIterator const & it, UpdateType);
///
void addToToc(DocIterator const &);

View File

@ -195,11 +195,11 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
}
void InsetFloat::updateLabels(ParIterator const & it, bool out)
void InsetFloat::updateLabels(ParIterator const & it, UpdateType utype)
{
Counters & cnts =
buffer().masterBuffer()->params().documentClass().counters();
if (out) {
if (utype == OutputUpdate) {
// counters are local to the float
cnts.saveLastCounter();
}
@ -217,11 +217,11 @@ void InsetFloat::updateLabels(ParIterator const & it, bool out)
cnts.current_float(params().type);
cnts.isSubfloat(subflt);
InsetCollapsable::updateLabels(it, out);
InsetCollapsable::updateLabels(it, utype);
//reset afterwards
cnts.current_float(saveflt);
if (out)
if (utype == OutputUpdate)
cnts.restoreLastCounter();
cnts.isSubfloat(savesubflt);
}

View File

@ -101,7 +101,7 @@ private:
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///

View File

@ -36,11 +36,11 @@ InsetFoot::InsetFoot(Buffer * buf)
{}
void InsetFoot::updateLabels(ParIterator const & it, bool out)
void InsetFoot::updateLabels(ParIterator const & it, UpdateType utype)
{
BufferParams const & bp = buffer().masterBuffer()->params();
Counters & cnts = bp.documentClass().counters();
if (out) {
if (utype == OutputUpdate) {
// the footnote counter is local to this inset
cnts.saveLastCounter();
}
@ -48,13 +48,13 @@ void InsetFoot::updateLabels(ParIterator const & it, bool out)
InsetLayout const & il = getLayout();
docstring const & count = il.counter();
if (!outer.layout().intitle && cnts.hasCounter(count)) {
cnts.step(count, out);
cnts.step(count, utype);
custom_label_= translateIfPossible(il.labelstring())
+ ' ' + cnts.theCounter(count, outer.getParLanguage(bp)->code());
setLabel(custom_label_);
}
InsetCollapsable::updateLabels(it, out);
if (out)
InsetCollapsable::updateLabels(it, utype);
if (utype == OutputUpdate)
cnts.restoreLastCounter();
}

View File

@ -38,7 +38,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
/// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
void addToToc(DocIterator const &);
///

View File

@ -1047,18 +1047,18 @@ void InsetInclude::updateCommand()
setParams(p);
}
void InsetInclude::updateLabels(ParIterator const & it, bool out)
void InsetInclude::updateLabels(ParIterator const & it, UpdateType utype)
{
Buffer const * const childbuffer = getChildBuffer();
if (childbuffer) {
childbuffer->updateLabels(Buffer::UpdateChildOnly, out);
childbuffer->updateLabels(Buffer::UpdateChildOnly, utype);
return;
}
if (!isListings(params()))
return;
if (label_)
label_->updateLabels(it, out);
label_->updateLabels(it, utype);
InsetListingsParams const par(to_utf8(params()["lstparams"]));
if (par.getParamValue("caption").empty()) {
@ -1070,7 +1070,7 @@ void InsetInclude::updateLabels(ParIterator const & it, bool out)
docstring const cnt = from_ascii("listing");
listings_label_ = master.B_("Program Listing");
if (counters.hasCounter(cnt)) {
counters.step(cnt);
counters.step(cnt, utype);
listings_label_ += " " + convert<docstring>(counters.value(cnt));
}
}

View File

@ -94,7 +94,7 @@ public:
///
void updateCommand();
///
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
static ParamInfo const & findInfo(std::string const &);
///

View File

@ -108,7 +108,7 @@ docstring InsetLabel::screenLabel() const
}
void InsetLabel::updateLabels(ParIterator const & par, bool out)
void InsetLabel::updateLabels(ParIterator const & par, UpdateType utype)
{
docstring const & label = getParam("name");
if (buffer().insetLabel(label)) {
@ -119,7 +119,7 @@ void InsetLabel::updateLabels(ParIterator const & par, bool out)
buffer().setInsetLabel(label, this);
screen_label_ = label;
if (out) {
if (utype) {
// save info on the active counter
Counters const & cnts =
buffer().masterBuffer()->params().documentClass().counters();

View File

@ -55,7 +55,7 @@ public:
static bool isCompatibleCommand(std::string const & s)
{ return s == "label"; }
///
void updateLabels(ParIterator const & it, bool);
void updateLabels(ParIterator const & it, UpdateType);
///
void addToToc(DocIterator const &);
///

View File

@ -71,7 +71,7 @@ Inset::DisplayType InsetListings::display() const
}
void InsetListings::updateLabels(ParIterator const & it, bool out)
void InsetListings::updateLabels(ParIterator const & it, UpdateType utype)
{
Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
string const saveflt = cnts.current_float();
@ -79,7 +79,7 @@ void InsetListings::updateLabels(ParIterator const & it, bool out)
// Tell to captions what the current float is
cnts.current_float("listing");
InsetCollapsable::updateLabels(it, out);
InsetCollapsable::updateLabels(it, utype);
//reset afterwards
cnts.current_float(saveflt);

View File

@ -48,7 +48,7 @@ private:
///
docstring name() const { return from_ascii("Listings"); }
// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
void write(std::ostream & os) const;
///

View File

@ -161,7 +161,7 @@ void InsetRef::tocString(odocstream & os) const
}
void InsetRef::updateLabels(ParIterator const & it, bool)
void InsetRef::updateLabels(ParIterator const & it, UpdateType)
{
docstring const & label = getParam("reference");
// register this inset into the buffer reference cache.

View File

@ -67,7 +67,7 @@ public:
///
static bool isCompatibleCommand(std::string const & s);
///
void updateLabels(ParIterator const & it, bool);
void updateLabels(ParIterator const & it, UpdateType);
///
void addToToc(DocIterator const &);
protected:

View File

@ -3398,7 +3398,7 @@ void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
}
void InsetTabular::updateLabels(ParIterator const & it, bool out)
void InsetTabular::updateLabels(ParIterator const & it, UpdateType utype)
{
// In a longtable, tell captions what the current float is
Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
@ -3410,7 +3410,7 @@ void InsetTabular::updateLabels(ParIterator const & it, bool out)
it2.forwardPos();
size_t const end = it2.nargs();
for ( ; it2.idx() < end; it2.top().forwardIdx())
buffer().updateLabels(it2, out);
buffer().updateLabels(it2, utype);
//reset afterwards
if (tabular.is_long_tabular)

View File

@ -836,7 +836,7 @@ public:
/// can we go further down on mouse click?
bool descendable(BufferView const &) const { return true; }
// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
bool completionSupported(Cursor const &) const;

View File

@ -504,7 +504,7 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & runpara
if ((opts & WriteLabel) && !il.counter().empty()) {
BufferParams const & bp = buffer().masterBuffer()->params();
Counters & cntrs = bp.documentClass().counters();
cntrs.step(il.counter(), true);
cntrs.step(il.counter(), OutputUpdate);
// FIXME: translate to paragraph language
if (!il.htmllabel().empty()) {
docstring const lbl =
@ -648,23 +648,21 @@ ParagraphList & InsetText::paragraphs()
}
void InsetText::updateLabels(ParIterator const & it, bool out)
void InsetText::updateLabels(ParIterator const & it, UpdateType utype)
{
ParIterator it2 = it;
it2.forwardPos();
LASSERT(&it2.inset() == this && it2.pit() == 0, return);
if (producesOutput()) {
// FIXME We only want to do this, in fact, for some insets.
// But we'll need layout info for that.
InsetLayout const & il = getLayout();
bool const save_layouts = out && il.htmlisblock();
bool const save_layouts = utype == OutputUpdate && il.htmlisblock();
Counters & cnt = buffer().masterBuffer()->params().documentClass().counters();
if (save_layouts) {
// LYXERR0("Entering " << name());
cnt.clearLastLayout();
// FIXME cnt.saveLastCounter()?
}
buffer().updateLabels(it2, out);
buffer().updateLabels(it2, utype);
if (save_layouts) {
// LYXERR0("Exiting " << name());
cnt.restoreLastLayout();
@ -676,7 +674,7 @@ void InsetText::updateLabels(ParIterator const & it, bool out)
// tclass.counters().clearLastLayout()
// since we are saving and restoring the existing counters, etc.
Counters const savecnt = tclass.counters();
buffer().updateLabels(it2, out);
buffer().updateLabels(it2, utype);
tclass.counters() = savecnt;
}
}

View File

@ -164,7 +164,7 @@ public:
{ return getLayout().allowParagraphCustomization(); }
/// Update the counters of this inset and of its contents
virtual void updateLabels(ParIterator const &, bool);
virtual void updateLabels(ParIterator const &, UpdateType);
/// the string that is passed to the TOC
void tocString(odocstream &) const;
///

View File

@ -114,12 +114,12 @@ bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
}
void InsetWrap::updateLabels(ParIterator const & it, bool out)
void InsetWrap::updateLabels(ParIterator const & it, UpdateType utype)
{
setLabel(_("wrap: ") + floatName(params_.type));
Counters & cnts =
buffer().masterBuffer()->params().documentClass().counters();
if (out) {
if (utype == OutputUpdate) {
// counters are local to the wrap
cnts.saveLastCounter();
}
@ -128,11 +128,11 @@ void InsetWrap::updateLabels(ParIterator const & it, bool out)
// Tell to captions what the current float is
cnts.current_float(params().type);
InsetCollapsable::updateLabels(it, out);
InsetCollapsable::updateLabels(it, utype);
// reset afterwards
cnts.current_float(saveflt);
if (out)
if (utype == OutputUpdate)
cnts.restoreLastCounter();
}

View File

@ -79,7 +79,7 @@ private:
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
/// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///

View File

@ -213,7 +213,7 @@ void InsetMathHull::setBuffer(Buffer & buffer)
}
void InsetMathHull::updateLabels(ParIterator const & it, bool out)
void InsetMathHull::updateLabels(ParIterator const & it, UpdateType utype)
{
if (!buffer_) {
//FIXME: buffer_ should be set at creation for this inset! Problem is
@ -223,7 +223,7 @@ void InsetMathHull::updateLabels(ParIterator const & it, bool out)
}
for (size_t i = 0; i != label_.size(); ++i) {
if (label_[i])
label_[i]->updateLabels(it, out);
label_[i]->updateLabels(it, utype);
}
}

View File

@ -14,6 +14,8 @@
#include "InsetMathGrid.h"
#include "OutputEnums.h"
#include <boost/scoped_ptr.hpp>
@ -36,7 +38,7 @@ public:
///
void setBuffer(Buffer &);
///
void updateLabels(ParIterator const &, bool);
void updateLabels(ParIterator const &, UpdateType);
///
void addToToc(DocIterator const &);
///

View File

@ -573,7 +573,7 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
for (; par != pend; ++par) {
Layout const & lay = par->layout();
if (!lay.counter.empty())
buf.params().documentClass().counters().step(lay.counter);
buf.params().documentClass().counters().step(lay.counter, OutputUpdate);
// FIXME We should see if there's a label to be output and
// do something with it.
if (par != pbegin)
@ -674,7 +674,7 @@ ParagraphList::const_iterator makeEnvironmentHtml(Buffer const & buf,
&& (par == pbegin || !isNormalEnv(style))
&& cnts.hasCounter(cntr)
)
cnts.step(cntr);
cnts.step(cntr, OutputUpdate);
ParagraphList::const_iterator send;
// this will be positive, if we want to skip the initial word
// (if it's been taken for the label).
@ -786,7 +786,7 @@ void makeCommand(Buffer const & buf,
{
Layout const & style = pbegin->layout();
if (!style.counter.empty())
buf.params().documentClass().counters().step(style.counter);
buf.params().documentClass().counters().step(style.counter, OutputUpdate);
openTag(xs, style);

View File

@ -220,6 +220,7 @@ void sgml::openTag(Buffer const & buf, odocstream & os,
if (param.find('#') != string::npos) {
// FIXME UNICODE
if (!style.counter.empty())
// NOTE This could use OutputUpdate and track the counters.
counters.step(style.counter);
else
counters.step(from_ascii(name));