]> git.lyx.org Git - features.git/commitdiff
Rewrite the label numbering code.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 12 Aug 2007 21:43:58 +0000 (21:43 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 12 Aug 2007 21:43:58 +0000 (21:43 +0000)
* 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

22 files changed:
src/LyXFunc.cpp
src/buffer_funcs.cpp
src/buffer_funcs.h
src/insets/Inset.h
src/insets/InsetBranch.cpp
src/insets/InsetBranch.h
src/insets/InsetCaption.cpp
src/insets/InsetCaption.h
src/insets/InsetFloat.cpp
src/insets/InsetFloat.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h
src/insets/InsetListings.cpp
src/insets/InsetListings.h
src/insets/InsetNote.cpp
src/insets/InsetNote.h
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h
src/insets/InsetText.cpp
src/insets/InsetText.h
src/insets/InsetWrap.cpp
src/insets/InsetWrap.h

index 19fd449c9d02918220d11c0d1da49175406915d7..94bd51cd6509087a126ff7ffb1399dad79484d27 100644 (file)
@@ -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);
        }
 }
index 1f1cd7917c1c6c8490b875be1af000d27d1e990f..502b8f35e512cb57d7e28b7c7d8851f2739a42d3 100644 (file)
@@ -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();
index 655d59bf34242a703dc17c5fb37bee55b504eff6..e059314b35d965fd25171dc1e83ec0607111d03a 100644 (file)
@@ -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 &);
 
index c50820289f0827c45139e539ae83d9b1533d9058..982d1306dba93a44ffa157ff8217777698d79729 100644 (file)
@@ -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, ...)
index 62f6a57dbca5944e9bb44445382871a831c82462..ce05c362c749d4608bdb801e62f530ebc44f0dcf 100644 (file)
@@ -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
 {
index 5df7b15d3280e209ea6db6b93a524d1fd2c264fa..586176b9b6e958d8ef8278d2f6a1c6da5069362e 100644 (file)
@@ -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 &);
index 7c986ea098a2bf8981ca66bdfd7c3566e036eacf..7c0121b864d48151566d0c12612f2bb1d33b2770 100644 (file)
@@ -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);
 }
 
 
index e13cf46319eebdedd66b05cb2964d20fe50de4ea..6a9d57e9b513715d280212046a538681fe4f4c94 100644 (file)
@@ -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_;
 };
 
index a60a4ddc3e1a62717b253d9234667f66f6ac91f7..9a91f0c6cfd8958f8d9c0c5106bf7544b4df7acf 100644 (file)
@@ -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';
index 21abf3be595e5fb734c58ff77116e9136f81491a..d56ededc5dcf09c4d5b22df5752f59d83345b8b1 100644 (file)
@@ -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:
index 16f46f7bb7235d499e20a1e6737e009984e512a6..6ab2324a2b3151ed2ef87858a6bb9ec52638be38 100644 (file)
@@ -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;
-
-       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");
+               }
        }
 }
 
index 7e981b9c83b8832829d8643ce2e62640aa267a13..2f834d4aa6e78a90f546e3e61bdd549f3ef2c21b 100644 (file)
@@ -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_;
 };
 
 
index e3f10b3f763ed1c1d6276dab18c397f4bbe62a11..e756d4fb7b5c462890aad16e0fa9709ca1a6d929 100644 (file)
@@ -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";
index af0676e4f4c93f0fa6a14bbd7db82b6d42f9e207..8fb21957d0f26323cec47c860460144f13a6c3ed 100644 (file)
@@ -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;
        ///
index 1406d0c6873d26340279730d7e140fd0fb230d00..9324af15e504b198aca4314d51fef3f46306a272 100644 (file)
@@ -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
index a17889aba4d173e8ac93e5b0f965a81bfe516f96..91d5771ca2069633d13d023c8e43058547ae4305 100644 (file)
@@ -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 &);
        ///
index 8ff702ef1ff3b0b7d902d8c35aca445fbc18ec1c..fb6b2c699fc60e494a84f5f664a9f3cdbe148941 100644 (file)
 #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)
index 32e1aa56e55080c9c31b6057387e21b74d1d93a7..16a469afd71142a7b91b5404de69cc904384761e 100644 (file)
@@ -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
index 8af5ada648e1673693c56958ce236de42a5da020..7439ae7659edefa00576ad661877ec35d7c01015 100644 (file)
@@ -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
index 6ffdead4d3bbd07904f01342439d0f998c2c84da..cb38e4d574fe9ab4546f3eaa2e31c00e3f57d527 100644 (file)
@@ -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:
        ///
index dd655c3603a18b4323381dfdb7a00efb53065b4c..bdfd1ff50dbe39e7d70f1b57cc4090801d9a723a 100644 (file)
@@ -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';
index d8f5acae931da6dc6f78566c0cdca06022196049..05da26566e7d6ab06fd57eb5d52e7bee70687f7c 100644 (file)
@@ -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);