+void InsetLabel::initView()
+{
+ updateCommand(getParam("name"));
+}
+
+
+void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
+{
+ docstring const old_label = getParam("name");
+ docstring label = new_label;
+ int i = 1;
+ while (buffer().insetLabel(label)) {
+ label = new_label + '-' + convert<docstring>(i);
+ ++i;
+ }
+
+ if (label != new_label) {
+ // Warn the user that the label has been changed to something else.
+ frontend::Alert::warning(_("Label names must be unique!"),
+ bformat(_("The label %1$s already exists,\n"
+ "it will be changed to %2$s."), new_label, label));
+ }
+
+ buffer().undo().beginUndoGroup();
+ setParam("name", label);
+
+ if (updaterefs) {
+ Buffer::References & refs = buffer().references(old_label);
+ Buffer::References::iterator it = refs.begin();
+ Buffer::References::iterator end = refs.end();
+ for (; it != end; ++it) {
+ buffer().undo().recordUndo(it->second);
+ it->first->setParam("reference", label);
+ }
+ }
+ buffer().undo().endUndoGroup();
+
+ // We need an update of the Buffer reference cache. This is achieved by
+ // updateLabel().
+ lyx::updateLabels(buffer());
+}
+
+
+ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)