+ return screen_label_;
+}
+
+
+void InsetLabel::updateBuffer(ParIterator const & par, UpdateType utype)
+{
+ docstring const & label = getParam("name");
+ if (buffer().insetLabel(label)) {
+ // Problem: We already have an InsetLabel with the same name!
+ screen_label_ = _("DUPLICATE: ") + label;
+ return;
+ }
+ buffer().setInsetLabel(label, this);
+ screen_label_ = label;
+
+ if (utype == OutputUpdate) {
+ // save info on the active counter
+ Counters const & cnts =
+ buffer().masterBuffer()->params().documentClass().counters();
+ active_counter_ = cnts.currentCounter();
+ Language const * lang = par->getParLanguage(buffer().params());
+ if (lang && !active_counter_.empty()) {
+ counter_value_ = cnts.theCounter(active_counter_, lang->code());
+ pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code());
+ } else {
+ counter_value_ = from_ascii("#");
+ pretty_counter_ = from_ascii("#");
+ }
+ }
+}
+
+
+void InsetLabel::addToToc(DocIterator const & cpit, bool output_active) const
+{
+ docstring const & label = getParam("name");
+ Toc & toc = buffer().tocBackend().toc("label");
+ if (buffer().insetLabel(label) != this) {
+ toc.push_back(TocItem(cpit, 0, screen_label_, output_active));
+ return;
+ }
+ toc.push_back(TocItem(cpit, 0, screen_label_, output_active));
+ Buffer::References const & refs = buffer().references(label);
+ Buffer::References::const_iterator it = refs.begin();
+ Buffer::References::const_iterator end = refs.end();
+ for (; it != end; ++it) {
+ DocIterator const ref_pit(it->second);
+ if (it->first->lyxCode() == MATH_REF_CODE)
+ toc.push_back(TocItem(ref_pit, 1,
+ it->first->asInsetMath()->asRefInset()->screenLabel(),
+ output_active));
+ else
+ toc.push_back(TocItem(ref_pit, 1,
+ static_cast<InsetRef *>(it->first)->getTOCString(),
+ output_active));
+ }
+}
+
+
+bool InsetLabel::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & status) const
+{
+ bool enabled;
+ switch (cmd.action()) {
+ case LFUN_LABEL_INSERT_AS_REFERENCE:
+ case LFUN_LABEL_COPY_AS_REFERENCE:
+ enabled = true;
+ break;
+ case LFUN_INSET_MODIFY:
+ if (cmd.getArg(0) == "changetype") {
+ // this is handled by InsetCommand,
+ // but not by InsetLabel.
+ enabled = false;
+ break;
+ }
+ default:
+ return InsetCommand::getStatus(cur, cmd, status);
+ }
+
+ status.setEnabled(enabled);
+ return true;