]> 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 3ba161071f64de38c45de6fc67c82062cd98ce9d..b773b088c637a25884c938f94f35685ebe8ebc78 100644 (file)
@@ -46,6 +46,7 @@
 
 #include "insets/RenderPreview.h"
 #include "insets/InsetLabel.h"
+#include "insets/InsetRef.h"
 
 #include "graphics/PreviewImage.h"
 #include "graphics/PreviewLoader.h"
@@ -1227,6 +1228,31 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_LABEL_COPY_AS_REF: {
+               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();
+               cap::copyInset(cur, new InsetRef(*cur.buffer(), p), label(row));
+               break;
+       }
+
        case LFUN_WORD_DELETE_FORWARD:
        case LFUN_CHAR_DELETE_FORWARD:
                if (col(cur.idx()) + 1 == ncols()
@@ -1330,37 +1356,71 @@ 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?
                status.setEnabled(display());
                status.setOnOff(numberedType());
                return true;
+
        case LFUN_MATH_NUMBER_LINE_TOGGLE: {
                // FIXME: what is the right test, this or the one of
                // 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;
        }
+
        case LFUN_LABEL_INSERT:
                status.setEnabled(type_ != hullSimple);
                return true;
+
+       case LFUN_LABEL_COPY_AS_REF: {
+               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;
+       }
+
        case LFUN_INSET_INSERT:
                if (cmd.getArg(0) == "label") {
                        status.setEnabled(type_ != hullSimple);
                        return true;
                }
                return InsetMathGrid::getStatus(cur, cmd, status);
+
        case LFUN_TABULAR_FEATURE: {
                istringstream is(to_utf8(cmd.argument()));
                string s;
@@ -1410,6 +1470,7 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
                }
                return InsetMathGrid::getStatus(cur, cmd, status);
        }
+
        default:
                return InsetMathGrid::getStatus(cur, cmd, status);
        }