]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/ref_inset.C
Always use std::endl with lyxerr.
[lyx.git] / src / mathed / ref_inset.C
index 33d8c48601745ac78fc82be80be1b4912112c40e..58638c3afcddc501a60a235ac5ba15371bf08d3c 100644 (file)
@@ -1,16 +1,21 @@
 #include <config.h>
 
 #include "ref_inset.h"
-#include "funcrequest.h"
-#include "formulabase.h"
+#include "math_factory.h"
+
 #include "BufferView.h"
-#include "frontends/LyXView.h"
-#include "frontends/Painter.h"
-#include "frontends/Dialogs.h"
-#include "lyxfunc.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "math_support.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "debug.h"
+
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+
+#include "support/LOstream.h"
+
+using std::auto_ptr;
 
 
 RefInset::RefInset()
@@ -23,9 +28,9 @@ RefInset::RefInset(string const & data)
 {}
 
 
-MathInset * RefInset::clone() const
+auto_ptr<InsetBase> RefInset::clone() const
 {
-       return new RefInset(*this);
+       return auto_ptr<InsetBase>(new RefInset(*this));
 }
 
 
@@ -35,7 +40,7 @@ void RefInset::infoize(std::ostream & os) const
 }
 
 
-MathInset::result_type
+dispatch_result
 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
 {
        switch (cmd.action) {
@@ -46,13 +51,15 @@ RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
                                return DISPATCHED;
                        }
                        if (cmd.button() == mouse_button::button1) {
-                               lyxerr << "trying to open ref" << cell(0) << "\n";
-                               // Eventually trigger dialog with button 3 not 1
-               //      cmd.view()->owner()->getDialogs()->showRef(this);
+                               // Eventually trigger dialog with button 3
+                               // not 1
+                               string const data = createDialogStr("ref");
+                               cmd.view()->owner()->getDialogs().
+                                       show("ref", data, this);
                                return DISPATCHED;
                        }
                        break;
-               case LFUN_MOUSE_PRESS:  
+               case LFUN_MOUSE_PRESS:
                case LFUN_MOUSE_MOTION:
                        // eat other mouse commands
                        return DISPATCHED;
@@ -64,11 +71,11 @@ RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
 }
 
 
-string RefInset::screenLabel() const
+string const RefInset::screenLabel() const
 {
        string str;
        for (int i = 0; !types[i].latex_name.empty(); ++i)
-               if (name_ == types[i].latex_name) {
+               if (commandname() == types[i].latex_name) {
                        str = _(types[i].short_gui_name);
                        break;
                }
@@ -84,16 +91,16 @@ string RefInset::screenLabel() const
 
 void RefInset::validate(LaTeXFeatures & features) const
 {
-       if (name_ == "vref" || name_ == "vpageref")
+       if (commandname() == "vref" || commandname() == "vpageref")
                features.require("varioref");
-       else if (name_ == "prettyref")
+       else if (commandname() == "prettyref")
                features.require("prettyref");
 }
 
 
 int RefInset::ascii(std::ostream & os, int) const
 {
-       os << "[" << asString(cell(0)) << "]";
+       os << '[' << asString(cell(0)) << ']';
        return 0;
 }
 
@@ -119,11 +126,30 @@ int RefInset::docbook(std::ostream & os, bool) const
 }
 
 
-RefInset::type_info RefInset::types[] = {
-       { "ref",        N_("Standard"),                 N_("Ref: ")},
-       { "pageref",    N_("Page Number"),              N_("Page: ")},
-       { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
-       { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
-       { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
+dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
+{
+       if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
+               return UNDISPATCHED;
+
+       MathArray ar;
+       if (!createMathInset_fromDialogStr(cmd.argument, ar))
+               return UNDISPATCHED;
+
+       *this = *ar[0].nucleus()->asRefInset();
+//     if (cmd.view())
+//                 // This does not compile because updateInset expects
+//                 // an Inset* and 'this' isn't.
+//             cmd.view()->updateInset(this);
+       return DISPATCHED;
+}
+
+
+RefInset::ref_type_info RefInset::types[] = {
+       { "ref",       N_("Standard"),              N_("Ref: ")},
+       { "eqref",     N_("Equation"),              N_("EqRef: ")},
+       { "pageref",   N_("Page Number"),           N_("Page: ")},
+       { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
+       { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
+       { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
        { "", "", "" }
 };