]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
A little cleanup of the layout files.
[lyx.git] / src / mathed / InsetMathHull.cpp
index b41fd82dd429637f9465444594ba6905ee7434e2..b773b088c637a25884c938f94f35685ebe8ebc78 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();
@@ -1340,12 +1356,18 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_DOWN:
        case LFUN_NEWLINE_INSERT:
        case LFUN_MATH_EXTERN:
-       case LFUN_MATH_MUTATE:
        case LFUN_MATH_DISPLAY:
                // we handle these
                status.setEnabled(true);
                return true;
 
+       case LFUN_MATH_MUTATE: {
+               HullType ht = hullType(cmd.argument());
+               status.setOnOff(type_ == ht);
+               status.setEnabled(true);
+               return true;
+       }
+
        case LFUN_MATH_NUMBER_TOGGLE:
                // FIXME: what is the right test, this or the one of
                // LABEL_INSERT?
@@ -1358,10 +1380,10 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
                // LABEL_INSERT?
                bool const enable = (type_ == hullMultline)
                        ? (nrows() - 1 == cur.row())
-                       : display() != Inline;
+                       : display() != Inline && nrows() > 1;
                row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
                status.setEnabled(enable);
-               status.setOnOff(numbered(r));
+               status.setOnOff(enable && numbered(r));
                return true;
        }
 
@@ -1370,8 +1392,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;
        }