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