]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[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
26 namespace lyx {
27
28 using support::subst;
29
30 using std::string;
31 using std::ostream;
32
33
34 InsetUrl::InsetUrl(InsetCommandParams const & p)
35         : InsetCommand(p, "url")
36 {}
37
38
39 docstring const InsetUrl::getScreenLabel(Buffer const &) const
40 {
41         docstring const temp =
42                 (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
43
44         docstring url;
45
46         if (!getParam("name").empty())
47                 url += getParam("name");
48         else
49                 url += getParam("target");
50
51         // elide if long
52         if (url.length() > 30) {
53                 url = url.substr(0, 10) + "..."
54                         + url.substr(url.length() - 17, url.length());
55         }
56         return temp + url;
57 }
58
59
60 int InsetUrl::latex(Buffer const &, odocstream & os,
61                     OutputParams const & runparams) const
62 {
63         docstring const & name = getParam("name");
64         if (!name.empty())
65                 os << name + ' ';
66         if (runparams.moving_arg)
67                 os << "\\protect";
68         os << "\\url{" << getParam("target") << '}';
69         return 0;
70 }
71
72
73 int InsetUrl::plaintext(Buffer const &, odocstream & os,
74                     OutputParams const &) const
75 {
76         os << '[' << getParam("target");
77         if (getParam("name").empty())
78                 os << ']';
79         else
80                 os << "||" << getParam("name") << ']';
81         return 0;
82 }
83
84
85 int InsetUrl::docbook(Buffer const &, odocstream & os,
86                       OutputParams const &) const
87 {
88         os << "<ulink url=\"" 
89            << subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
90            << "\">" 
91            << getParam("name")
92            << "</ulink>";
93         return 0;
94 }
95
96
97 int InsetUrl::textString(Buffer const & buf, odocstream & os,
98                        OutputParams const & op) const
99 {
100         return plaintext(buf, os, op);
101 }
102
103
104 void InsetUrl::validate(LaTeXFeatures & features) const
105 {
106         features.require("url");
107 }
108
109
110 } // namespace lyx