]> git.lyx.org Git - features.git/blobdiff - src/mathed/InsetMathRef.cpp
s/updateLabels/updateBuffer/g, per a suggestion of Abdel's.
[features.git] / src / mathed / InsetMathRef.cpp
index 36a678ae06ac03d28e25a30e92b7910839524f9c..859845faaa2cccc4d4266c5278a2255096b9ba90 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "InsetMathRef.h"
 
 #include "BufferView.h"
-#include "LaTeXFeatures.h"
 #include "Buffer.h"
 #include "Cursor.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "LaTeXFeatures.h"
+#include "LyX.h"
 #include "MathData.h"
 #include "MathFactory.h"
 #include "MathSupport.h"
 #include "OutputParams.h"
+#include "ParIterator.h"
 #include "sgml.h"
 
 #include "insets/InsetCommand.h"
@@ -35,13 +37,13 @@ using namespace std;
 
 namespace lyx {
 
-InsetMathRef::InsetMathRef()
-       : CommandInset(from_ascii("ref"))
+InsetMathRef::InsetMathRef(Buffer * buf)
+       : CommandInset(buf, from_ascii("ref"), false)
 {}
 
 
-InsetMathRef::InsetMathRef(docstring const & data)
-       : CommandInset(data)
+InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data)
+       : CommandInset(buf, data, false)
 {}
 
 
@@ -80,7 +82,8 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3) {
                        LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
-                       cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
+                       //FIXME: use DispatchResult argument
+                       lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
                        break;
                }
                if (cmd.button() == mouse_button::button1) {
@@ -147,6 +150,8 @@ void InsetMathRef::validate(LaTeXFeatures & features) const
                features.require("varioref");
        else if (commandname() == "prettyref")
                features.require("prettyref");
+       else if (commandname() == "eqref")
+               features.require("amsmath");
 }
 
 
@@ -171,6 +176,17 @@ int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
 }
 
 
+void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/)
+{
+       if (!buffer_) {
+               LYXERR0("InsetMathRef::updateBuffer: no buffer_!");
+               return;
+       }
+       // register this inset into the buffer reference cache.
+       buffer().references(getTarget()).push_back(make_pair(this, it));
+}
+
+
 string const InsetMathRef::createDialogStr(string const & name) const
 {
        InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
@@ -181,8 +197,31 @@ string const InsetMathRef::createDialogStr(string const & name) const
 }
 
 
+docstring const InsetMathRef::getTarget() const
+{
+       return asString(cell(0));
+}
+
+
+void InsetMathRef::changeTarget(docstring const & target)
+{
+       InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
+       icp["reference"] = target;
+       if (!cell(1).empty())
+               icp["name"] = asString(cell(1));
+       MathData ar;
+       Buffer & buf = buffer();
+       if (createInsetMath_fromDialogStr(
+           from_utf8(InsetCommand::params2string("ref", icp)), ar)) {
+               *this = *ar[0].nucleus()->asRefInset();
+               // FIXME audit setBuffer/updateBuffer calls
+               setBuffer(buf);
+       }
+}
+
+
 InsetMathRef::ref_type_info InsetMathRef::types[] = {
-       { from_ascii("ref"),       from_ascii(N_("Standard[[mathref]]")),              from_ascii(N_("Ref: "))},
+       { from_ascii("ref"),       from_ascii(N_("Standard[[mathref]]")),   from_ascii(N_("Ref: "))},
        { from_ascii("eqref"),     from_ascii(N_("Equation")),              from_ascii(N_("EqRef: "))},
        { from_ascii("pageref"),   from_ascii(N_("Page Number")),           from_ascii(N_("Page: "))},
        { from_ascii("vpageref"),  from_ascii(N_("Textual Page Number")),   from_ascii(N_("TextPage: "))},