]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
ec996776aebed6753a716172a85658b57ad04107
[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 "latexrunparams.h"
18 #include "LaTeXFeatures.h"
19 #include "gettext.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)
33 {}
34
35
36 // InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
37 //              : InsetCommand(p, false)
38 // {}
39
40
41 InsetUrl::~InsetUrl()
42 {
43         InsetCommandMailer("url", *this).hideDialog();
44 }
45
46
47 DispatchResult
48 InsetUrl::priv_dispatch(FuncRequest const & cmd,
49                         idx_type & idx, pos_type & pos)
50 {
51         switch (cmd.action) {
52                 case LFUN_MOUSE_PRESS:
53                         InsetCommandMailer("url", *this).showDialog(cmd.view());
54                         return DispatchResult(true, true);
55                 default:
56                         return InsetCommand::priv_dispatch(cmd, idx, pos);
57         }
58 }
59
60
61 string const InsetUrl::getScreenLabel(Buffer const &) const
62 {
63         string temp;
64         if (getCmdName() == "url")
65                 temp = _("Url: ");
66         else
67                 temp = _("HtmlUrl: ");
68
69         string url;
70
71         if (!getOptions().empty())
72                 url += getOptions();
73         else
74                 url += getContents();
75
76         // elide if long
77         if (url.length() > 30) {
78                 url = url.substr(0, 10) + "..."
79                         + url.substr(url.length() - 17, url.length());
80         }
81         return temp + url;
82 }
83
84
85 int InsetUrl::latex(Buffer const &, ostream & os,
86                     LatexRunParams const & runparams) const
87 {
88         if (!getOptions().empty())
89                 os << getOptions() + ' ';
90         if (runparams.moving_arg)
91                 os << "\\protect";
92         os << "\\url{" << getContents() << '}';
93         return 0;
94 }
95
96
97 int InsetUrl::ascii(Buffer const &, ostream & os,
98                     LatexRunParams const &) const
99 {
100         if (getOptions().empty())
101                 os << '[' << getContents() << ']';
102         else
103                 os << '[' << getContents() << "||" <<  getOptions() << ']';
104         return 0;
105 }
106
107
108 int InsetUrl::linuxdoc(Buffer const &, ostream & os,
109                        LatexRunParams const &) const
110 {
111         os << '<' << getCmdName()
112            << " url=\""  << getContents() << "\""
113            << " name=\"" << getOptions() << "\">";
114
115         return 0;
116 }
117
118
119 int InsetUrl::docbook(Buffer const &, ostream & os,
120                       LatexRunParams const &) const
121 {
122         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
123            << "\">" << getOptions() << "</ulink>";
124         return 0;
125 }
126
127
128 void InsetUrl::validate(LaTeXFeatures & features) const
129 {
130         features.require("url");
131 }