]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
The markDirty() and fitCursor() changes
[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 #include <config.h>
11
12
13 #include "inseturl.h"
14 #include "BufferView.h"
15 #include "LaTeXFeatures.h"
16 #include "frontends/LyXView.h"
17 #include "debug.h"
18 #include "frontends/Dialogs.h"
19 #include "support/lstrings.h"
20 #include "gettext.h"
21
22 using std::ostream;
23
24
25 InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
26                 : InsetCommand(p)
27 {}
28
29
30 InsetUrl::~InsetUrl()
31 {
32         InsetCommandMailer mailer("url", *this);
33         mailer.hideDialog();
34 }
35
36
37 void InsetUrl::edit(BufferView * bv, int, int, mouse_button::state)
38 {
39         InsetCommandMailer mailer("url", *this);
40         mailer.showDialog(bv);
41 }
42
43
44 void InsetUrl::edit(BufferView * bv, bool)
45 {
46         edit(bv, 0, 0, mouse_button::none);
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                     bool fragile, bool /*free_spc*/) const
76 {
77         if (!getOptions().empty())
78                 os << getOptions() + ' ';
79         if (fragile)
80                 os << "\\protect";
81         os << "\\url{" << getContents() << '}';
82         return 0;
83 }
84
85
86 int InsetUrl::ascii(Buffer const *, ostream & os, int) const
87 {
88         if (getOptions().empty())
89                 os << '[' << getContents() << ']';
90         else
91                 os << '[' << getContents() << "||" <<  getOptions() << ']';
92         return 0;
93 }
94
95
96 int InsetUrl::linuxdoc(Buffer const *, ostream & os) const
97 {
98         os << '<' << getCmdName()
99            << " url=\""  << getContents() << "\""
100            << " name=\"" << getOptions() << "\">";
101
102         return 0;
103 }
104
105
106 int InsetUrl::docbook(Buffer const *, ostream & os, bool) const
107 {
108         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
109            << "\">" << getOptions() << "</ulink>";
110         return 0;
111 }
112
113
114 void InsetUrl::validate(LaTeXFeatures & features) const
115 {
116         features.require("url");
117 }