]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
Enable convertDefault.sh to run even if its executable bit is not set.
[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
13 #include "insetref.h"
14 #include "buffer.h"
15 #include "funcrequest.h"
16 #include "debug.h"
17 #include "gettext.h"
18 #include "LaTeXFeatures.h"
19 #include "frontends/LyXView.h"
20 #include "frontends/Dialogs.h"
21 #include "BufferView.h"
22 #include "support/lstrings.h"
23
24 using namespace lyx::support;
25
26 using std::ostream;
27
28 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
29         : InsetCommand(p), isLatex(buf.isLatex())
30 {}
31
32
33 InsetRef::InsetRef(InsetRef const & ir)
34         : InsetCommand(ir), isLatex(ir.isLatex)
35 {
36 }
37
38
39 InsetRef::~InsetRef()
40 {
41         InsetCommandMailer("ref", *this).hideDialog();
42 }
43
44
45 dispatch_result InsetRef::localDispatch(FuncRequest const & cmd)
46 {
47         switch (cmd.action) {
48         case LFUN_INSET_EDIT:
49                 // Eventually trigger dialog with button 3 not 1
50                 if (cmd.button() == mouse_button::button3)
51                         cmd.view()->owner()->
52                                 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
53                 else
54                         InsetCommandMailer("ref", *this).showDialog(cmd.view());
55                 return DISPATCHED;
56
57         default:
58                 return InsetCommand::localDispatch(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         temp += getContents();
72
73         if (!isLatex
74            && !getOptions().empty()) {
75                 temp += "||";
76                 temp += getOptions();
77         }
78         return temp;
79 }
80
81
82 int InsetRef::latex(Buffer const &, ostream & os,
83                     LatexRunParams 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::ascii(Buffer const &, ostream & os, int) const
96 {
97         os << '[' << getContents() << ']';
98         return 0;
99 }
100
101
102 int InsetRef::linuxdoc(Buffer const &, ostream & os) const
103 {
104         os << "<ref id=\"" << getContents()
105            << "\" name=\"" << getOptions() << "\" >";
106         return 0;
107 }
108
109
110 int InsetRef::docbook(Buffer const &, ostream & os, bool) const
111 {
112         if (getOptions().empty()) {
113                 os << "<xref linkend=\"" << getContents() << "\">";
114         } else {
115                 os << "<link linkend=\"" << getContents()
116                    << "\">" << getOptions() << "</link>";
117         }
118
119         return 0;
120 }
121
122
123 void InsetRef::validate(LaTeXFeatures & features) const
124 {
125         if (getCmdName() == "vref" || getCmdName() == "vpageref")
126                 features.require("varioref");
127         else if (getCmdName() == "prettyref")
128                 features.require("prettyref");
129         else if (getCmdName() == "eqref")
130                 features.require("amsmath");
131 }
132
133
134 InsetRef::type_info InsetRef::types[] = {
135         { "ref",       N_("Standard"),              N_("Ref: ")},
136         { "eqref",     N_("Equation"),              N_("EqRef: ")},
137         { "pageref",   N_("Page Number"),           N_("Page: ")},
138         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
139         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
140         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
141         { "", "", "" }
142 };
143
144
145 int InsetRef::getType(string const & name)
146 {
147         for (int i = 0; !types[i].latex_name.empty(); ++i)
148                 if (name == types[i].latex_name)
149                         return i;
150         return 0;
151 }
152
153
154 string const & InsetRef::getName(int type)
155 {
156         return types[type].latex_name;
157 }