]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
Purely mechanical: move fragile into LatexRunParams.
[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,
76                     bool /*free_spc*/) const
77 {
78         if (!getOptions().empty())
79                 os << getOptions() + ' ';
80         if (runparams.fragile)
81                 os << "\\protect";
82         os << "\\url{" << getContents() << '}';
83         return 0;
84 }
85
86
87 int InsetUrl::ascii(Buffer const *, ostream & os, int) const
88 {
89         if (getOptions().empty())
90                 os << '[' << getContents() << ']';
91         else
92                 os << '[' << getContents() << "||" <<  getOptions() << ']';
93         return 0;
94 }
95
96
97 int InsetUrl::linuxdoc(Buffer const *, ostream & os) const
98 {
99         os << '<' << getCmdName()
100            << " url=\""  << getContents() << "\""
101            << " name=\"" << getOptions() << "\">";
102
103         return 0;
104 }
105
106
107 int InsetUrl::docbook(Buffer const *, ostream & os, bool) const
108 {
109         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
110            << "\">" << getOptions() << "</ulink>";
111         return 0;
112 }
113
114
115 void InsetUrl::validate(LaTeXFeatures & features) const
116 {
117         features.require("url");
118 }