Inset * inset = itemInset();
FuncRequest tmpcmd(cmd);
+ QModelIndex const & index = tocTV->currentIndex();
+ TocItem const & item =
+ gui_view_.tocModels().currentItem(current_type_, index);
+
switch (cmd.action)
{
case LFUN_CHANGE_ACCEPT:
status.setEnabled(true);
return true;
+ case LFUN_LABEL_COPY_AS_REF: {
+ // For labels in math, we need to supply the label as a string
+ FuncRequest label_copy(LFUN_LABEL_COPY_AS_REF, item.asString());
+ if (inset)
+ return inset->getStatus(cur, label_copy, status);
+ }
+
default:
if (inset)
return inset->getStatus(cur, tmpcmd, status);
dispatch(item.action());
cur.dispatch(tmpcmd);
break;
+
+ case LFUN_LABEL_COPY_AS_REF: {
+ // For labels in math, we need to supply the label as a string
+ FuncRequest label_copy(LFUN_LABEL_COPY_AS_REF, item.asString());
+ if (inset)
+ inset->dispatch(cur, label_copy);
+ break;
+ }
case LFUN_OUTLINE_UP:
case LFUN_OUTLINE_DOWN:
}
case LFUN_LABEL_COPY_AS_REF: {
- row_type const row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+ row_type row;
+ if (cmd.argument().empty() && &cur.inset() == this)
+ // if there is no argument and we're inside math, we retrieve
+ // the row number from the cursor position.
+ row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+ else {
+ // if there is an argument, find the corresponding label, else
+ // check whether there is at least one label.
+ for (row = 0; row != nrows(); ++row)
+ if (!nonum_[row] && label_[row]
+ && (cmd.argument().empty() || label(row) == cmd.argument()))
+ break;
+ }
+
+ if (row == nrows())
+ break;
+
InsetCommandParams p(REF_CODE, "ref");
p["reference"] = label(row);
cap::clearSelection();
return true;
case LFUN_LABEL_COPY_AS_REF: {
- row_type const row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
- status.setEnabled(numberedType() && label_[row] && !nonum_[row]);
+ bool enabled = false;
+ row_type row;
+ if (cmd.argument().empty() && &cur.inset() == this) {
+ // if there is no argument and we're inside math, we retrieve
+ // the row number from the cursor position.
+ row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+ enabled = numberedType() && label_[row] && !nonum_[row];
+ } else {
+ // if there is an argument, find the corresponding label, else
+ // check whether there is at least one label.
+ for (row_type row = 0; row != nrows(); ++row) {
+ if (!nonum_[row] && label_[row] &&
+ (cmd.argument().empty() || label(row) == cmd.argument())) {
+ enabled = true;
+ break;
+ }
+ }
+ }
+ status.setEnabled(enabled);
return true;
}