Buffer * const b = newFile(filename, templname, !name.empty());
if (b) {
- updateLabels(*b);
+ //updateLabels(*b);
lyx_view_->setBuffer(b);
}
}
#include "Buffer.h"
#include "BufferList.h"
#include "BufferParams.h"
+#include "debug.h"
#include "DocIterator.h"
#include "Counters.h"
#include "ErrorList.h"
#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"
}
-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();
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
// 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);
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());
} // 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)
{
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();
/// updates all counters
void updateLabels(Buffer const &, bool childonly = false);
+///
+void updateLabels(Buffer const &, ParIterator &);
+
///
void checkBufferStructure(Buffer &, ParIterator const &);
class Buffer;
class BufferParams;
class BufferView;
+class ParIterator;
class ParConstIterator;
class CursorSlice;
class FuncRequest;
/// 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, ...)
#include "Buffer.h"
#include "BufferParams.h"
#include "BranchList.h"
+#include "Counters.h"
#include "Cursor.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
}
+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
{
bool isBranchSelected(Buffer const & buffer) const;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
-
+ //
+ virtual void updateLabels(Buffer const &, ParIterator const &);
protected:
///
InsetBranch(InsetBranch const &);
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));
}
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;
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]";
}
-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);
}
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; }
///
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; }
bool forceDefaultParagraphs(idx_type) const { return true; }
private:
- ///
- void computeFullLabel(Buffer const & buf) const;
///
virtual std::auto_ptr<Inset> doClone() const;
///
///
docstring custom_label_;
///
- int counter_;
- ///
TextClass const & textclass_;
};
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
+#include "Counters.h"
#include "Cursor.h"
#include "debug.h"
#include "DispatchResult.h"
}
+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';
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:
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));
}
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));
}
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_;
}
}
}
-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;
-
- lyx::updateLabels(*childbuffer, true);
-}
-
-
-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"));
+ if (childbuffer)
+ lyx::updateLabels(*childbuffer, true);
+ else if (isListings(params_)) {
+ InsetListingsParams const par = params_.getOptions();
+ if (par.getParamValue("caption").empty())
+ listings_label_.clear();
+ else {
+ 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");
+ }
}
}
///
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 &);
///
/// cache
mutable bool set_label_;
mutable RenderButton button_;
- int counter_;
+ mutable docstring listings_label_;
};
#include "InsetListings.h"
#include "InsetCaption.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "Counters.h"
#include "Language.h"
#include "gettext.h"
#include "DispatchResult.h"
}
+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";
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;
///
#include "InsetNote.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "BufferView.h"
+#include "Counters.h"
#include "Cursor.h"
#include "debug.h"
#include "DispatchResult.h"
}
}
+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
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 &);
///
#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"
#include "Paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
+#include "ParIterator.h"
#include "Undo.h"
#include "support/convert.h"
}
+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
-
string const InsetTabularMailer::name_("tabular");
InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
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
#include "InsetNewline.h"
#include "Buffer.h"
+#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "CoordCache.h"
#include "Paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
+#include "ParIterator.h"
#include "rowpainter.h"
#include "Row.h"
#include "sgml.h"
}
+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
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:
///
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
+#include "Counters.h"
#include "Cursor.h"
#include "debug.h"
#include "DispatchResult.h"
}
+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';
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);