]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBibitem.cpp
The last commit was, uhh, not what I intended.
[lyx.git] / src / insets / InsetBibitem.cpp
index a05cbd45b0144dc7d4a33e84d53a36e35307cc40..1f5b9159483bd406a7d73a692cb7505d727b89c3 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <config.h>
+#include <algorithm>
 
 #include "InsetBibitem.h"
 
 
 #include "frontends/alert.h"
 
-#include "support/lstrings.h"
+#include "support/convert.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
-#include "support/convert.h"
-
-#include <ostream>
+#include "support/lstrings.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -46,14 +45,23 @@ int InsetBibitem::key_counter = 0;
 docstring const key_prefix = from_ascii("key-");
 
 
-InsetBibitem::InsetBibitem(InsetCommandParams const & p)
+InsetBibitem::InsetBibitem(Buffer const & buf, InsetCommandParams const & p)
        : InsetCommand(p, "bibitem")
 {
+       Inset::setBuffer(const_cast<Buffer &>(buf));
+       buffer_->invalidateBibinfoCache();
        if (getParam("key").empty())
                setParam("key", key_prefix + convert<docstring>(++key_counter));
 }
 
 
+InsetBibitem::~InsetBibitem()
+{
+       if (isBufferValid())
+               buffer_->invalidateBibinfoCache();
+}
+
+
 void InsetBibitem::initView()
 {
        updateCommand(getParam("key"));
@@ -65,9 +73,7 @@ void InsetBibitem::updateCommand(docstring const & new_key, bool)
        docstring const old_key = getParam("key");
        docstring key = new_key;
 
-       BiblioInfo keys;
-       keys.fillWithBibKeys(&buffer());
-       vector<docstring> bibkeys = keys.getKeys();
+       vector<docstring> bibkeys = buffer().masterBibInfo().getKeys();
 
        int i = 1;
 
@@ -105,17 +111,20 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p(BIBITEM_CODE);
-               InsetCommandMailer::string2params("bibitem", to_utf8(cmd.argument()), p);
+               InsetCommand::string2params("bibitem", to_utf8(cmd.argument()), p);
                if (p.getCmdName().empty()) {
                        cur.noUpdate();
                        break;
                }
-               docstring old_key = params()["key"];
+               docstring const & old_key = params()["key"];
                setParam("label", p["label"]);
-               updateCommand(p["key"]);
-               if (params()["key"] != old_key)
+               if (p["key"] != old_key) {
+                       updateCommand(p["key"]);
                        cur.bv().buffer().changeRefsIfUnique(old_key,
                                params()["key"], CITE_CODE);
+               }
+               buffer_->invalidateBibinfoCache();
+               break;
        }
 
        default:
@@ -162,7 +171,7 @@ int InsetBibitem::plaintext(odocstream & os, OutputParams const &) const
 
 
 // ale070405
-docstring const bibitemWidest(Buffer const & buffer)
+docstring bibitemWidest(Buffer const & buffer)
 {
        int w = 0;
 
@@ -233,7 +242,7 @@ void InsetBibitem::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it)
        keyvalmap[from_ascii("label")] = getParam("label");
        DocIterator doc_it(it); 
        doc_it.forwardPos();
-       keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString(false);
+       keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString();
        keys[key] = keyvalmap;
 }