// check for duplicates
InsetCommand & lab = static_cast<InsetCommand &>(*it);
docstring const oldname = lab.getParam("name");
- lab.update(oldname, false);
+ lab.updateCommand(oldname, false);
docstring const newname = lab.getParam("name");
if (oldname != newname) {
// adapt the references
break;
}
+ case BIBITEM_CODE: {
+ // check for duplicates
+ InsetCommand & bib = static_cast<InsetCommand &>(*it);
+ docstring const oldkey = bib.getParam("key");
+ bib.updateCommand(oldkey, false);
+ docstring const newkey = bib.getParam("key");
+ if (oldkey != newkey) {
+ // adapt the references
+ for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
+ if (itt->lyxCode() == CITE_CODE) {
+ InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
+ if (ref.getParam("key") == oldkey)
+ ref.setParam("key", newkey);
+ }
+ }
+ }
+ break;
+ }
+
default:
break; // nothing
}
#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:
public:
///
InsetBibitem(InsetCommandParams const &);
+ /// verify label and update references.
+ /**
+ * Overloaded from Inset::initView.
+ **/
+ void initView();
///
void read(Lexer & lex);
///
///
static bool isCompatibleCommand(std::string const & s)
{ return s == "bibitem"; }
+ ///
+ void updateCommand(docstring const & new_key, bool dummy = false);
protected:
///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
/// Whether this is a command this inset can represent.
/// Not implemented here. Must be implemented in derived class.
static bool isCompatibleCommand(std::string const & cmd);
- /// update label and references. Currently used by InsetLabel.
- virtual void update(docstring const &, bool) {};
+ /// update label and references.
+ virtual void updateCommand(docstring const &, bool) {};
protected:
///
void InsetLabel::initView()
{
- update(getParam("name"));
+ updateCommand(getParam("name"));
}
-void InsetLabel::update(docstring const & new_label, bool updaterefs)
+void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
{
docstring const old_label = getParam("name");
docstring label = new_label;
cur.noUpdate();
break;
}
- update(p["name"]);
+ updateCommand(p["name"]);
break;
}
///
void addToToc(ParConstIterator const &) const;
///
- void update(docstring const & new_label, bool updaterefs = true);
+ void updateCommand(docstring const & new_label, bool updaterefs = true);
protected:
///
void doDispatch(Cursor & cur, FuncRequest & cmd);