]> git.lyx.org Git - lyx.git/blobdiff - src/insets/inseturl.C
Final touch 'inset display()'; fix 'is a bit silly' bug
[lyx.git] / src / insets / inseturl.C
index ab8aec39dfe7aad63de0b2eb7b83c5e014461046..13a25dd3fa7d8a095cdee4b30a71e6bf0022ae4d 100644 (file)
@@ -1,16 +1,29 @@
-#include <config.h>
+/**
+ * \file inseturl.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.
+ */
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include <config.h>
 
 #include "inseturl.h"
-#include "BufferView.h"
+
+#include "funcrequest.h"
+#include "latexrunparams.h"
 #include "LaTeXFeatures.h"
-#include "LyXView.h"
-#include "debug.h"
-#include "frontends/Dialogs.h"
+#include "gettext.h"
+
+#include "support/lstrings.h"
 
+#include "support/std_ostream.h"
+
+using lyx::support::subst;
+
+using std::string;
 using std::ostream;
 
 
@@ -19,54 +32,80 @@ InsetUrl::InsetUrl(InsetCommandParams const & p)
 {}
 
 
-void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
+// InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
+//             : InsetCommand(p, false)
+// {}
+
+
+InsetUrl::~InsetUrl()
 {
-       bv->owner()->getDialogs()->showUrl( this );
+       InsetCommandMailer("url", *this).hideDialog();
 }
 
 
-string const InsetUrl::getScreenLabel() const
+dispatch_result
+InsetUrl::priv_dispatch(FuncRequest const & cmd,
+                       idx_type & idx, pos_type & pos)
+{
+       switch (cmd.action) {
+               case LFUN_INSET_EDIT:
+                       InsetCommandMailer("url", *this).showDialog(cmd.view());
+                       return DISPATCHED;
+               default:
+                       return InsetCommand::priv_dispatch(cmd, idx, pos);
+       }
+}
+
+
+string const InsetUrl::getScreenLabel(Buffer const &) const
 {
        string temp;
-       if( getCmdName() == "url" )
+       if (getCmdName() == "url")
                temp = _("Url: ");
-       else 
+       else
                temp = _("HtmlUrl: ");
 
-       if(!getOptions().empty())
-               temp += getOptions();
-       else
-               temp += getContents();
+       string url;
 
-       return temp;
+       if (!getOptions().empty())
+               url += getOptions();
+       else
+               url += getContents();
+
+       // elide if long
+       if (url.length() > 30) {
+               url = url.substr(0, 10) + "..."
+                       + url.substr(url.length() - 17, url.length());
+       }
+       return temp + url;
 }
 
 
-int InsetUrl::Latex(Buffer const *, ostream & os,
-                   bool fragile, bool /*free_spc*/) const
+int InsetUrl::latex(Buffer const &, ostream & os,
+                   LatexRunParams const & runparams) const
 {
        if (!getOptions().empty())
                os << getOptions() + ' ';
-       if (fragile)
+       if (runparams.moving_arg)
                os << "\\protect";
        os << "\\url{" << getContents() << '}';
        return 0;
 }
 
 
-int InsetUrl::Ascii(Buffer const *, ostream & os, int linelen) const
+int InsetUrl::ascii(Buffer const &, ostream & os, int) const
 {
        if (getOptions().empty())
-               os << "[" << getContents() << "]";
+               os << '[' << getContents() << ']';
        else
-               os << "[" << getContents() << "||" <<  getOptions() << "]";
+               os << '[' << getContents() << "||" <<  getOptions() << ']';
        return 0;
 }
 
 
-int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
+int InsetUrl::linuxdoc(Buffer const &, ostream & os) const
 {
-       os << "<" << getCmdName()
+       os << '<' << getCmdName()
           << " url=\""  << getContents() << "\""
           << " name=\"" << getOptions() << "\">";
 
@@ -74,15 +113,15 @@ int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
 }
 
 
-int InsetUrl::DocBook(Buffer const *, ostream & os) const
+int InsetUrl::docbook(Buffer const &, ostream & os, bool) const
 {
-       os << "<ulink url=\"" << getContents() << "\">"
-          << getOptions() << "</ulink>";
+       os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
+          << "\">" << getOptions() << "</ulink>";
        return 0;
 }
 
 
-void InsetUrl::Validate(LaTeXFeatures & features) const
+void InsetUrl::validate(LaTeXFeatures & features) const
 {
-       features.url = true;
+       features.require("url");
 }