#include "InsetBibitem.h"
+#include "BiblioInfo.h"
#include "Buffer.h"
+#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Counters.h"
#include "ParagraphList.h"
#include "TextClass.h"
+#include "frontends/alert.h"
+
#include "support/lstrings.h"
#include "support/docstream.h"
+#include "support/gettext.h"
#include "support/convert.h"
#include <ostream>
}
+void InsetBibitem::initView()
+{
+ updateCommand(getParam("key"));
+}
+
+
+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();
+
+ int i = 1;
+
+ if (find(bibkeys.begin(), bibkeys.end(), key) != bibkeys.end()) {
+ // generate unique label
+ key = new_key + '-' + convert<docstring>(i);
+ while (find(bibkeys.begin(), bibkeys.end(), key) != bibkeys.end()) {
+ ++i;
+ key = new_key + '-' + convert<docstring>(i);
+ }
+ frontend::Alert::warning(_("Keys must be unique!"),
+ bformat(_("The key %1$s already exists,\n"
+ "it will be changed to %2$s."), new_key, key));
+ }
+ setParam("key", key);
+
+ lyx::updateLabels(buffer());
+}
+
+
ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */)
{
static ParamInfo param_info_;
cur.noUpdate();
break;
}
- if (p["key"] != params()["key"])
- cur.bv().buffer().changeRefsIfUnique(params()["key"],
- p["key"], CITE_CODE);
- setParams(p);
+ docstring old_key = params()["key"];
+ setParam("label", p["label"]);
+ updateCommand(p["key"]);
+ if (params()["key"] != old_key)
+ cur.bv().buffer().changeRefsIfUnique(old_key,
+ params()["key"], CITE_CODE);
}
default: