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