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