]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
First step towards unified insets...
[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 void InsetUrl::edit(BufferView * bv, int, int, mouse_button::state)
31 {
32         bv->owner()->getDialogs().showUrl(this);
33 }
34
35
36 void InsetUrl::edit(BufferView * bv, bool)
37 {
38         edit(bv, 0, 0, mouse_button::none);
39 }
40
41
42 string const InsetUrl::getScreenLabel(Buffer const *) const
43 {
44         string temp;
45         if (getCmdName() == "url")
46                 temp = _("Url: ");
47         else
48                 temp = _("HtmlUrl: ");
49
50         string url;
51
52         if (!getOptions().empty())
53                 url += getOptions();
54         else
55                 url += getContents();
56
57         // elide if long
58         if (url.length() > 30) {
59                 url = url.substr(0, 10) + "..."
60                         + url.substr(url.length() - 17, url.length());
61         }
62         return temp + url;
63 }
64
65
66 int InsetUrl::latex(Buffer const *, ostream & os,
67                     bool fragile, bool /*free_spc*/) const
68 {
69         if (!getOptions().empty())
70                 os << getOptions() + ' ';
71         if (fragile)
72                 os << "\\protect";
73         os << "\\url{" << getContents() << '}';
74         return 0;
75 }
76
77
78 int InsetUrl::ascii(Buffer const *, ostream & os, int) const
79 {
80         if (getOptions().empty())
81                 os << '[' << getContents() << ']';
82         else
83                 os << '[' << getContents() << "||" <<  getOptions() << ']';
84         return 0;
85 }
86
87
88 int InsetUrl::linuxdoc(Buffer const *, ostream & os) const
89 {
90         os << '<' << getCmdName()
91            << " url=\""  << getContents() << "\""
92            << " name=\"" << getOptions() << "\">";
93
94         return 0;
95 }
96
97
98 int InsetUrl::docbook(Buffer const *, ostream & os, bool) const
99 {
100         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
101            << "\">" << getOptions() << "</ulink>";
102         return 0;
103 }
104
105
106 void InsetUrl::validate(LaTeXFeatures & features) const
107 {
108         features.require("url");
109 }