]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
fix reading the author field.
[lyx.git] / src / insets / insetref.C
1 /**
2  * \file insetref.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 #include "insetref.h"
13
14 #include "buffer.h"
15 #include "cursor.h"
16 #include "BufferView.h"
17 #include "dispatchresult.h"
18 #include "funcrequest.h"
19 #include "gettext.h"
20 #include "LaTeXFeatures.h"
21
22 #include "frontends/LyXView.h"
23
24 #include "support/lstrings.h"
25
26
27 using lyx::support::escape;
28
29 using std::string;
30 using std::ostream;
31
32
33 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
34         : InsetCommand(p, "ref"), isLatex(buf.isLatex())
35 {}
36
37
38 InsetRef::InsetRef(InsetRef const & ir)
39         : InsetCommand(ir), isLatex(ir.isLatex)
40 {}
41
42
43 void InsetRef::priv_dispatch(LCursor & cur, FuncRequest & cmd)
44 {
45         switch (cmd.action) {
46         case LFUN_MOUSE_PRESS:
47                 // Eventually trigger dialog with button 3 not 1
48                 if (cmd.button() == mouse_button::button3)
49                         cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
50                 else
51                         InsetCommandMailer("ref", *this).showDialog(&cur.bv());
52                 return;
53
54         case LFUN_MOUSE_RELEASE:
55                 return;
56
57         default:
58                 return InsetCommand::priv_dispatch(cur, cmd);
59         }
60 }
61
62
63 string const InsetRef::getScreenLabel(Buffer const &) const
64 {
65         string temp;
66         for (int i = 0; !types[i].latex_name.empty(); ++i) {
67                 if (getCmdName() == types[i].latex_name) {
68                         temp = _(types[i].short_gui_name);
69                         break;
70                 }
71         }
72         temp += getContents();
73
74         if (!isLatex && !getOptions().empty()) {
75                 temp += "||";
76                 temp += getOptions();
77         }
78         return temp;
79 }
80
81
82 int InsetRef::latex(Buffer const &, ostream & os,
83                     OutputParams const &) const
84 {
85         if (getOptions().empty())
86                 os << escape(getCommand());
87         else {
88                 InsetCommandParams p(getCmdName(), getContents(), "");
89                 os << escape(p.getCommand());
90         }
91         return 0;
92 }
93
94
95 int InsetRef::plaintext(Buffer const &, ostream & os,
96                     OutputParams const &) const
97 {
98         os << '[' << getContents() << ']';
99         return 0;
100 }
101
102
103 int InsetRef::linuxdoc(Buffer const &, ostream & os,
104                        OutputParams const &) const
105 {
106         os << "<ref id=\"" << getContents()
107            << "\" name=\"" << getOptions() << "\" >";
108         return 0;
109 }
110
111
112 int InsetRef::docbook(Buffer const &, ostream & os,
113                       OutputParams const &) const
114 {
115         if (getOptions().empty()) {
116                 os << "<xref linkend=\"" << getContents() << "\">";
117         } else {
118                 os << "<link linkend=\"" << getContents()
119                    << "\">" << getOptions() << "</link>";
120         }
121
122         return 0;
123 }
124
125
126 void InsetRef::validate(LaTeXFeatures & features) const
127 {
128         if (getCmdName() == "vref" || getCmdName() == "vpageref")
129                 features.require("varioref");
130         else if (getCmdName() == "prettyref")
131                 features.require("prettyref");
132         else if (getCmdName() == "eqref")
133                 features.require("amsmath");
134 }
135
136
137 InsetRef::type_info InsetRef::types[] = {
138         { "ref",       N_("Standard"),              N_("Ref: ")},
139         { "eqref",     N_("Equation"),              N_("EqRef: ")},
140         { "pageref",   N_("Page Number"),           N_("Page: ")},
141         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
142         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
143         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
144         { "", "", "" }
145 };
146
147
148 int InsetRef::getType(string const & name)
149 {
150         for (int i = 0; !types[i].latex_name.empty(); ++i)
151                 if (name == types[i].latex_name)
152                         return i;
153         return 0;
154 }
155
156
157 string const & InsetRef::getName(int type)
158 {
159         return types[type].latex_name;
160 }