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