]> git.lyx.org Git - lyx.git/commitdiff
Fix the copy label as ref for equations from the context menu.
authorVincent van Ravesteijn <vfr@lyx.org>
Wed, 20 May 2009 23:58:29 +0000 (23:58 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Wed, 20 May 2009 23:58:29 +0000 (23:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29754 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/TocWidget.cpp
src/mathed/InsetMathHull.cpp

index a5850f5c3634cf5b4c7a4d4f89c53d96388d3425..361971e3547c884f8c113c59943c12c16b44b5bb 100644 (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:
index b41fd82dd429637f9465444594ba6905ee7434e2..31e0bb2880b5459e5fbd894dd9e6c9aa356b4807 100644 (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;
        }