]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathRef.cpp
Removed unused private variable
[lyx.git] / src / mathed / InsetMathRef.cpp
index 61d05b2eac23fd8a3d10b88dee988c6e9c44587a..42151209e733d43ca222b926c2a58d078f8ad37f 100644 (file)
@@ -38,12 +38,12 @@ using namespace std;
 namespace lyx {
 
 InsetMathRef::InsetMathRef(Buffer * buf)
-       : CommandInset(buf, from_ascii("ref"), false)
+       : InsetMathCommand(buf, from_ascii("ref"), false)
 {}
 
 
 InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data)
-       : CommandInset(buf, data, false)
+       : InsetMathCommand(buf, data, false)
 {}
 
 
@@ -61,11 +61,12 @@ void InsetMathRef::infoize(odocstream & os) const
 
 void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
        case LFUN_INSET_MODIFY:
                if (cmd.getArg(0) == "ref") {
                        MathData ar;
                        if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
+                               cur.recordUndo();
                                *this = *ar[0].nucleus()->asRefInset();
                                break;
                        }
@@ -74,12 +75,16 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_INSET_DIALOG_UPDATE: {
-               string const data = createDialogStr("ref");
+               string const data = createDialogStr();
                cur.bv().updateDialog("ref", data);
                break;
        }
 
        case LFUN_MOUSE_RELEASE:
+               if (cur.selection()) {
+                       cur.undispatched();
+                       break;
+               }
                if (cmd.button() == mouse_button::button3) {
                        LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
                        //FIXME: use DispatchResult argument
@@ -88,20 +93,30 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                if (cmd.button() == mouse_button::button1) {
                        // Eventually trigger dialog with button 3, not 1
-                       string const data = createDialogStr("ref");
+                       string const data = createDialogStr();
                        cur.bv().showDialog("ref", data, this);
                        break;
                }
                cur.undispatched();
                break;
 
-       case LFUN_MOUSE_PRESS:
-       case LFUN_MOUSE_MOTION:
+       case LFUN_MOUSE_PRESS: {
+               bool do_selection = cmd.button() == mouse_button::button1
+                       && cmd.modifier() == ShiftModifier;
+               // For some reason the cursor points inside the first cell, which is not
+               // active.
+               cur.leaveInset(*this);
+               cur.bv().mouseSetCursor(cur, do_selection);
+               break;
+       }
+
+       case LFUN_MOUSE_DOUBLE:
+       case LFUN_MOUSE_TRIPLE:
                // eat other mouse commands
                break;
 
        default:
-               CommandInset::doDispatch(cur, cmd);
+               InsetMathCommand::doDispatch(cur, cmd);
                break;
        }
 }
@@ -110,17 +125,18 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
                         FuncStatus & status) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
        // we handle these
        case LFUN_INSET_MODIFY:
        case LFUN_INSET_DIALOG_UPDATE:
        case LFUN_MOUSE_RELEASE:
        case LFUN_MOUSE_PRESS:
-       case LFUN_MOUSE_MOTION:
+       case LFUN_MOUSE_DOUBLE:
+       case LFUN_MOUSE_TRIPLE:
                status.setEnabled(true);
                return true;
        default:
-               return CommandInset::getStatus(cur, cmd, status);
+               return InsetMathCommand::getStatus(cur, cmd, status);
        }
 }
 
@@ -176,24 +192,24 @@ int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
 }
 
 
-void InsetMathRef::updateLabels(ParIterator const & it, UpdateType /*utype*/)
+void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/)
 {
        if (!buffer_) {
-               LYXERR0("InsetMathRef::updateLabels: no buffer_!");
+               LYXERR0("InsetMathRef::updateBuffer: no buffer_!");
                return;
        }
        // register this inset into the buffer reference cache.
-       buffer().references(getTarget()).push_back(make_pair(this, it));
+       buffer().addReference(getTarget(), this, it);
 }
 
 
-string const InsetMathRef::createDialogStr(string const & name) const
+string const InsetMathRef::createDialogStr() const
 {
        InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
        icp["reference"] = asString(cell(0));
        if (!cell(1).empty())
                icp["name"] = asString(cell(1));
-       return InsetCommand::params2string(name, icp);
+       return InsetCommand::params2string(icp);
 }
 
 
@@ -212,9 +228,9 @@ void InsetMathRef::changeTarget(docstring const & target)
        MathData ar;
        Buffer & buf = buffer();
        if (createInsetMath_fromDialogStr(
-           from_utf8(InsetCommand::params2string("ref", icp)), ar)) {
+           from_utf8(InsetCommand::params2string(icp)), ar)) {
                *this = *ar[0].nucleus()->asRefInset();
-               // FIXME audit setBuffer/updateLabels calls
+               // FIXME audit setBuffer calls
                setBuffer(buf);
        }
 }