]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
make dispatch_result_t ctor of DispatchResult explicit
[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_INSET_EDIT:
53                         InsetCommandMailer("url", *this).showDialog(cmd.view());
54                         return DispatchResult(DISPATCHED);
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, int) const
98 {
99         if (getOptions().empty())
100                 os << '[' << getContents() << ']';
101         else
102                 os << '[' << getContents() << "||" <<  getOptions() << ']';
103         return 0;
104 }
105
106
107 int InsetUrl::linuxdoc(Buffer const &, ostream & os) const
108 {
109         os << '<' << getCmdName()
110            << " url=\""  << getContents() << "\""
111            << " name=\"" << getOptions() << "\">";
112
113         return 0;
114 }
115
116
117 int InsetUrl::docbook(Buffer const &, ostream & os, bool) const
118 {
119         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
120            << "\">" << getOptions() << "</ulink>";
121         return 0;
122 }
123
124
125 void InsetUrl::validate(LaTeXFeatures & features) const
126 {
127         features.require("url");
128 }