]> git.lyx.org Git - lyx.git/blobdiff - src/insets/inseturl.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / inseturl.C
index 161fe59fa9ca3ef5bec001c92026a10ad77d808b..4bd7f5765a8d581e512c828af431d7aafdd426ab 100644 (file)
-#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 "dispatchresult.h"
+#include "funcrequest.h"
 #include "LaTeXFeatures.h"
-#include "LyXView.h"
-#include "debug.h"
-#include "frontends/Dialogs.h"
+#include "gettext.h"
+#include "outputparams.h"
+
+#include "support/lstrings.h"
+
+#include "support/std_ostream.h"
+
+
+namespace lyx {
+
+using support::subst;
 
+using std::string;
 using std::ostream;
 
 
 InsetUrl::InsetUrl(InsetCommandParams const & p)
-               : InsetCommand(p)
+       : InsetCommand(p, "url")
 {}
 
 
-void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
+docstring const InsetUrl::getScreenLabel(Buffer const &) const
 {
-       bv->owner()->getDialogs()->showUrl( this );
-}
+       docstring const temp =
+               (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
 
+       docstring url;
 
-string const InsetUrl::getScreenLabel() const
-{
-       string temp;
-       if( getCmdName() == "url" )
-               temp = _("Url: ");
-       else 
-               temp = _("HtmlUrl: ");
-
-       if(!getOptions().empty())
-               temp += getOptions();
+       if (!getParam("name").empty())
+               url += getParam("name");
        else
-               temp += getContents();
-
-       return temp;
+               url += getParam("target");
+
+       // 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 &, odocstream & os,
+                   OutputParams const & runparams) const
 {
-       if (!getOptions().empty())
-               os << getOptions() + ' ';
-       if (fragile)
+       docstring const & name = getParam("name");
+       if (!name.empty())
+               os << name + ' ';
+       if (runparams.moving_arg)
                os << "\\protect";
-       os << "\\url{" << getContents() << '}';
+       os << "\\url{" << getParam("target") << '}';
        return 0;
 }
 
 
-int InsetUrl::Ascii(Buffer const *, ostream & os) const
+int InsetUrl::plaintext(Buffer const &, odocstream & os,
+                   OutputParams const &) const
 {
-       if (getOptions().empty())
-               os << "[" << getContents() << "]";
+       os << '[' << getParam("target");
+       if (getParam("name").empty())
+               os << ']';
        else
-               os << "[" << getContents() << "||" <<  getOptions() << "]";
+               os << "||" << getParam("name") << ']';
        return 0;
 }
 
 
-int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
+int InsetUrl::docbook(Buffer const &, odocstream & os,
+                     OutputParams const &) const
 {
-       os << "<" << getCmdName()
-          << " url=\""  << getContents() << "\""
-          << " name=\"" << getOptions() << "\">";
-
+       os << "<ulink url=\"" 
+          << subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
+          << "\">" 
+          << getParam("name")
+          << "</ulink>";
        return 0;
 }
 
 
-int InsetUrl::DocBook(Buffer const *, ostream & os) const
+int InsetUrl::textString(Buffer const & buf, odocstream & os,
+                      OutputParams const & op) const
 {
-       os << "<ulink url=\"" << getContents() << "\">"
-          << getOptions() << "</ulink>";
-       return 0;
+       return plaintext(buf, os, op);
 }
 
 
-void InsetUrl::Validate(LaTeXFeatures & features) const
+void InsetUrl::validate(LaTeXFeatures & features) const
 {
-       features.url = true;
+       features.require("url");
 }
+
+
+} // namespace lyx