X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetBibitem.cpp;h=f65899d89d7f390af33bdef273e2aafa0a092d10;hb=f756c0232943ed0f760b78eb6f3a53d16227ce2f;hp=8c9410b2b1fc725148940959acae7baf3b584d89;hpb=5bb22d9498da67b2cc279b9c07271fb4c033ca39;p=lyx.git diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index 8c9410b2b1..f65899d89d 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -12,9 +12,13 @@ #include "InsetBibitem.h" +#include "debug.h" + #include "Biblio.h" #include "Buffer.h" +#include "BufferParams.h" #include "BufferView.h" +#include "Counters.h" #include "DispatchResult.h" #include "FuncRequest.h" #include "Font.h" @@ -41,7 +45,7 @@ int InsetBibitem::key_counter = 0; docstring const key_prefix = from_ascii("key-"); InsetBibitem::InsetBibitem(InsetCommandParams const & p) - : InsetCommand(p, "bibitem"), counter(1) + : InsetCommand(p, "bibitem") { if (getParam("key").empty()) setParam("key", key_prefix + convert(++key_counter)); @@ -51,7 +55,7 @@ InsetBibitem::InsetBibitem(InsetCommandParams const & p) auto_ptr InsetBibitem::doClone() const { auto_ptr b(new InsetBibitem(params())); - b->setCounter(counter); + b->autolabel_ = autolabel_; return auto_ptr(b); } @@ -80,12 +84,6 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd) } -void InsetBibitem::setCounter(int c) -{ - counter = c; -} - - void InsetBibitem::read(Buffer const & buf, Lexer & lex) { InsetCommand::read(buf, lex); @@ -100,7 +98,7 @@ void InsetBibitem::read(Buffer const & buf, Lexer & lex) docstring const InsetBibitem::getBibLabel() const { docstring const & label = getParam("label"); - return label.empty() ? convert(counter) : label; + return label.empty() ? autolabel_ : label; } @@ -114,7 +112,7 @@ int InsetBibitem::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { odocstringstream oss; - oss << '[' << getCounter() << "] "; + oss << '[' << getBibLabel() << "] "; docstring const str = oss.str(); os << str; @@ -199,4 +197,20 @@ void InsetBibitem::fillWithBibKeys(Buffer const & buf, keys[key] = keyvalmap; } + +/// Update the counters of this inset and of its contents +void InsetBibitem::updateLabels(Buffer const &buf, ParIterator const & pit) +{ + lyxerr << "update! " << to_utf8(getParam("key")) << std::endl; + Counters & counters = buf.params().getTextClass().counters(); + docstring const bibitem = from_ascii("bibitem"); + if (counters.hasCounter(bibitem) && getParam("label").empty()) { + counters.step(bibitem); + autolabel_ = counters.theCounter(bibitem); + } else + autolabel_ = from_ascii("??"); + refresh(); +} + + } // namespace lyx