]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
Use the new InsetCommandParams interface (inset part), from Ugras and me
[lyx.git] / src / insets / inseturl.C
1 /**
2  * \file inseturl.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author José Matos
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "inseturl.h"
14
15 #include "dispatchresult.h"
16 #include "funcrequest.h"
17 #include "LaTeXFeatures.h"
18 #include "gettext.h"
19 #include "outputparams.h"
20
21 #include "support/lstrings.h"
22
23 #include "support/std_ostream.h"
24
25 using lyx::docstring;
26 using lyx::odocstream;
27 using lyx::support::subst;
28
29 using std::string;
30 using std::ostream;
31
32
33 InsetUrl::InsetUrl(InsetCommandParams const & p)
34         : InsetCommand(p, "url")
35 {}
36
37
38 docstring const InsetUrl::getScreenLabel(Buffer const &) const
39 {
40         docstring const temp =
41                 (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
42
43         docstring url;
44
45         if (!getParam("name").empty())
46                 url += getParam("name");
47         else
48                 url += getParam("target");
49
50         // elide if long
51         if (url.length() > 30) {
52                 url = url.substr(0, 10) + "..."
53                         + url.substr(url.length() - 17, url.length());
54         }
55         return temp + url;
56 }
57
58
59 int InsetUrl::latex(Buffer const &, odocstream & os,
60                     OutputParams const & runparams) const
61 {
62         docstring const & name = getParam("name");
63         if (!name.empty())
64                 os << name + ' ';
65         if (runparams.moving_arg)
66                 os << "\\protect";
67         os << "\\url{" << getParam("target") << '}';
68         return 0;
69 }
70
71
72 int InsetUrl::plaintext(Buffer const &, odocstream & os,
73                     OutputParams const &) const
74 {
75         os << '[' << getParam("target");
76         if (getParam("name").empty())
77                 os << ']';
78         else
79                 os << "||" << getParam("name") << ']';
80         return 0;
81 }
82
83
84 int InsetUrl::docbook(Buffer const &, odocstream & os,
85                       OutputParams const &) const
86 {
87         os << "<ulink url=\"" 
88            << subst(getParam("target"), lyx::from_ascii("&"), lyx::from_ascii("&amp;"))
89            << "\">" 
90            << getParam("name")
91            << "</ulink>";
92         return 0;
93 }
94
95
96 int InsetUrl::textString(Buffer const & buf, odocstream & os,
97                        OutputParams const & op) const
98 {
99         return plaintext(buf, os, op);
100 }
101
102
103 void InsetUrl::validate(LaTeXFeatures & features) const
104 {
105         features.require("url");
106 }