]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
ws changes only
[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 InsetUrl::localDispatch(FuncRequest const & cmd)
47 {
48         switch (cmd.action) {
49                 case LFUN_INSET_EDIT:
50                         InsetCommandMailer("url", *this).showDialog(cmd.view());
51                         return DISPATCHED;
52                 default:
53                         return InsetCommand::localDispatch(cmd);
54         }
55 }
56
57
58 string const InsetUrl::getScreenLabel(Buffer const &) const
59 {
60         string temp;
61         if (getCmdName() == "url")
62                 temp = _("Url: ");
63         else
64                 temp = _("HtmlUrl: ");
65
66         string url;
67
68         if (!getOptions().empty())
69                 url += getOptions();
70         else
71                 url += getContents();
72
73         // elide if long
74         if (url.length() > 30) {
75                 url = url.substr(0, 10) + "..."
76                         + url.substr(url.length() - 17, url.length());
77         }
78         return temp + url;
79 }
80
81
82 int InsetUrl::latex(Buffer const &, ostream & os,
83                     LatexRunParams const & runparams) const
84 {
85         if (!getOptions().empty())
86                 os << getOptions() + ' ';
87         if (runparams.moving_arg)
88                 os << "\\protect";
89         os << "\\url{" << getContents() << '}';
90         return 0;
91 }
92
93
94 int InsetUrl::ascii(Buffer const &, ostream & os, int) const
95 {
96         if (getOptions().empty())
97                 os << '[' << getContents() << ']';
98         else
99                 os << '[' << getContents() << "||" <<  getOptions() << ']';
100         return 0;
101 }
102
103
104 int InsetUrl::linuxdoc(Buffer const &, ostream & os) const
105 {
106         os << '<' << getCmdName()
107            << " url=\""  << getContents() << "\""
108            << " name=\"" << getOptions() << "\">";
109
110         return 0;
111 }
112
113
114 int InsetUrl::docbook(Buffer const &, ostream & os, bool) const
115 {
116         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
117            << "\">" << getOptions() << "</ulink>";
118         return 0;
119 }
120
121
122 void InsetUrl::validate(LaTeXFeatures & features) const
123 {
124         features.require("url");
125 }