Fix the copy label as ref for equations from the context menu.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29754 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-05-20 23:58:29 +00:00
parent 9173fe2c5e
commit 60b26d1aac
2 changed files with 55 additions and 3 deletions

View File

@ -132,6 +132,10 @@ bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
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:
@ -144,6 +148,13 @@ bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
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);
@ -170,6 +181,14 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
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:

View File

@ -1229,7 +1229,23 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
}
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();
@ -1370,8 +1386,25 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
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;
}