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