From: Vincent van Ravesteijn Date: Wed, 20 May 2009 23:58:29 +0000 (+0000) Subject: Fix the copy label as ref for equations from the context menu. X-Git-Tag: 2.0.0~6510 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=60b26d1aac16e6d41404ec37a8f22fd164f131e0;p=lyx.git 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 --- diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index a5850f5c36..361971e354 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -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: diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index b41fd82dd4..31e0bb2880 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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; }