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