]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetref.C
Final touch 'inset display()'; fix 'is a bit silly' bug
[lyx.git] / src / insets / insetref.C
index ef0da4aa727f18185ce5c9c1e23f7a96f0ed018b..959f3e903ce9182c52bba1e7e9b114db7253e30c 100644 (file)
@@ -1,44 +1,70 @@
+/**
+ * \file insetref.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author José Matos
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "insetref.h"
+
 #include "buffer.h"
-#include "commandtags.h"
-#include "debug.h"
+#include "BufferView.h"
+#include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "LyXView.h"
-#include "frontends/Dialogs.h"
-#include "lyxfunc.h"
-#include "BufferView.h"
+
+#include "frontends/LyXView.h"
+
 #include "support/lstrings.h"
 
+
+using lyx::support::escape;
+
+using std::string;
 using std::ostream;
 
-InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool)
+
+InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
        : InsetCommand(p), isLatex(buf.isLatex())
 {}
 
-void InsetRef::edit(BufferView * bv, int, int, unsigned int button)
+
+InsetRef::InsetRef(InsetRef const & ir)
+       : InsetCommand(ir), isLatex(ir.isLatex)
+{
+}
+
+
+InsetRef::~InsetRef()
 {
-       // Eventually trigger dialog with button 3 not 1
-       if (button == 3 )
-               bv->owner()->getLyXFunc()->
-                       dispatch(LFUN_REF_GOTO, getContents());
-       else if (button == 1 )
-               bv->owner()->getDialogs()->showRef( this );
+       InsetCommandMailer("ref", *this).hideDialog();
 }
 
 
-void InsetRef::edit(BufferView *, bool)
+dispatch_result
+InsetRef::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
 {
+       switch (cmd.action) {
+       case LFUN_INSET_EDIT:
+               // Eventually trigger dialog with button 3 not 1
+               if (cmd.button() == mouse_button::button3)
+                       cmd.view()->owner()->
+                               dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
+               else
+                       InsetCommandMailer("ref", *this).showDialog(cmd.view());
+               return DISPATCHED;
+
+       default:
+               return InsetCommand::priv_dispatch(cmd, idx, pos);
+       }
 }
 
 
-string const InsetRef::getScreenLabel() const
+string const InsetRef::getScreenLabel(Buffer const &) const
 {
        string temp;
        for (int i = 0; !types[i].latex_name.empty(); ++ i)
@@ -57,27 +83,27 @@ string const InsetRef::getScreenLabel() const
 }
 
 
-int InsetRef::latex(Buffer const *, ostream & os,
-                   bool /*fragile*/, bool /*fs*/) const
+int InsetRef::latex(Buffer const &, ostream & os,
+                   LatexRunParams const &) const
 {
        if (getOptions().empty())
                os << escape(getCommand());
        else {
-               InsetCommandParams p( getCmdName(), getContents(), "" );
+               InsetCommandParams p(getCmdName(), getContents(), "");
                os << escape(p.getCommand());
        }
        return 0;
 }
 
 
-int InsetRef::ascii(Buffer const *, ostream & os, int) const
+int InsetRef::ascii(Buffer const &, ostream & os, int) const
 {
-       os << "[" << getContents() << "]";
+       os << '[' << getContents() << ']';
        return 0;
 }
 
 
-int InsetRef::linuxdoc(Buffer const *, ostream & os) const
+int InsetRef::linuxdoc(Buffer const &, ostream & os) const
 {
        os << "<ref id=\"" << getContents()
           << "\" name=\"" << getOptions() << "\" >";
@@ -85,10 +111,10 @@ int InsetRef::linuxdoc(Buffer const *, ostream & os) const
 }
 
 
-int InsetRef::docBook(Buffer const *, ostream & os) const
+int InsetRef::docbook(Buffer const &, ostream & os, bool) const
 {
        if (getOptions().empty()) {
-               os << "<xref linkend=\"" << getContents() << "\"/>";
+               os << "<xref linkend=\"" << getContents() << "\">";
        } else {
                os << "<link linkend=\"" << getContents()
                   << "\">" << getOptions() << "</link>";
@@ -101,17 +127,21 @@ int InsetRef::docBook(Buffer const *, ostream & os) const
 void InsetRef::validate(LaTeXFeatures & features) const
 {
        if (getCmdName() == "vref" || getCmdName() == "vpageref")
-               features.varioref = true;
+               features.require("varioref");
        else if (getCmdName() == "prettyref")
-               features.prettyref = true;
+               features.require("prettyref");
+       else if (getCmdName() == "eqref")
+               features.require("amsmath");
 }
 
+
 InsetRef::type_info InsetRef::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: ")},
+       { "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: ")},
        { "", "", "" }
 };