]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
another fix
[lyx.git] / src / insets / inseturl.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "inseturl.h"
8 #include "BufferView.h"
9 #include "LaTeXFeatures.h"
10 #include "frontends/LyXView.h"
11 #include "debug.h"
12 #include "frontends/Dialogs.h"
13 #include "support/lstrings.h"
14 #include "gettext.h"
15
16 using std::ostream;
17
18
19 InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
20                 : InsetCommand(p)
21 {}
22
23
24 void InsetUrl::edit(BufferView * bv, int, int, mouse_button::state)
25 {
26         bv->owner()->getDialogs().showUrl(this);
27 }
28
29
30 void InsetUrl::edit(BufferView * bv, bool)
31 {
32         edit(bv, 0, 0, mouse_button::none);
33 }
34
35
36 string const InsetUrl::getScreenLabel(Buffer const *) const
37 {
38         string temp;
39         if (getCmdName() == "url")
40                 temp = _("Url: ");
41         else
42                 temp = _("HtmlUrl: ");
43
44         string url;
45  
46         if (!getOptions().empty())
47                 url += getOptions();
48         else
49                 url += getContents();
50
51         // elide if long
52         if (url.length() > 30) {
53                 url = url.substr(0, 10) + "..."
54                         + url.substr(url.length() - 17, url.length());
55         }
56         return temp + url;
57 }
58
59
60 int InsetUrl::latex(Buffer const *, ostream & os,
61                     bool fragile, bool /*free_spc*/) const
62 {
63         if (!getOptions().empty())
64                 os << getOptions() + ' ';
65         if (fragile)
66                 os << "\\protect";
67         os << "\\url{" << getContents() << '}';
68         return 0;
69 }
70
71
72 int InsetUrl::ascii(Buffer const *, ostream & os, int) const
73 {
74         if (getOptions().empty())
75                 os << "[" << getContents() << "]";
76         else
77                 os << "[" << getContents() << "||" <<  getOptions() << "]";
78         return 0;
79 }
80
81
82 int InsetUrl::linuxdoc(Buffer const *, ostream & os) const
83 {
84         os << "<" << getCmdName()
85            << " url=\""  << getContents() << "\""
86            << " name=\"" << getOptions() << "\">";
87
88         return 0;
89 }
90
91
92 int InsetUrl::docbook(Buffer const *, ostream & os, bool) const
93 {
94         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
95            << "\">" << getOptions() << "</ulink>";
96         return 0;
97 }
98
99
100 void InsetUrl::validate(LaTeXFeatures & features) const
101 {
102         features.require("url");
103 }