2 * \file InsetMathRef.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathRef.h"
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
19 #include "support/debug.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
22 #include "support/gettext.h"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "OutputParams.h"
29 #include "insets/InsetCommand.h"
37 InsetMathRef::InsetMathRef()
38 : CommandInset(from_ascii("ref"))
42 InsetMathRef::InsetMathRef(docstring const & data)
47 Inset * InsetMathRef::clone() const
49 return new InsetMathRef(*this);
53 void InsetMathRef::infoize(odocstream & os) const
55 os << "Ref: " << cell(0);
59 void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
62 case LFUN_INSET_MODIFY:
63 if (cmd.getArg(0) == "ref") {
65 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
66 *this = *ar[0].nucleus()->asRefInset();
73 case LFUN_INSET_DIALOG_UPDATE: {
74 string const data = createDialogStr("ref");
75 cur.bv().updateDialog("ref", data);
79 case LFUN_MOUSE_RELEASE:
80 if (cmd.button() == mouse_button::button3) {
81 LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
82 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
85 if (cmd.button() == mouse_button::button1) {
86 // Eventually trigger dialog with button 3, not 1
87 string const data = createDialogStr("ref");
88 cur.bv().showDialog("ref", data, this);
94 case LFUN_MOUSE_PRESS:
95 case LFUN_MOUSE_MOTION:
96 // eat other mouse commands
100 CommandInset::doDispatch(cur, cmd);
106 bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
107 FuncStatus & status) const
109 switch (cmd.action) {
111 case LFUN_INSET_MODIFY:
112 case LFUN_INSET_DIALOG_UPDATE:
113 case LFUN_MOUSE_RELEASE:
114 case LFUN_MOUSE_PRESS:
115 case LFUN_MOUSE_MOTION:
116 status.enabled(true);
119 return CommandInset::getStatus(cur, cmd, status);
124 docstring const InsetMathRef::screenLabel() const
127 for (int i = 0; !types[i].latex_name.empty(); ++i) {
128 if (commandname() == types[i].latex_name) {
129 str = _(to_utf8(types[i].short_gui_name));
133 str += asString(cell(0));
135 //if (/* !isLatex && */ !cell(0).empty()) {
137 // str += asString(cell(1));
143 void InsetMathRef::validate(LaTeXFeatures & features) const
145 if (commandname() == "vref" || commandname() == "vpageref")
146 features.require("varioref");
147 else if (commandname() == "prettyref")
148 features.require("prettyref");
152 int InsetMathRef::docbook(Buffer const & buf, odocstream & os,
153 OutputParams const & runparams) const
155 if (cell(1).empty()) {
156 os << "<xref linkend=\""
157 << sgml::cleanID(buf, runparams, asString(cell(0)));
158 if (runparams.flavor == OutputParams::XML)
163 os << "<link linkend=\""
164 << sgml::cleanID(buf, runparams, asString(cell(0)))
174 string const InsetMathRef::createDialogStr(string const & name) const
176 InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
177 icp["reference"] = asString(cell(0));
178 if (!cell(1).empty())
179 icp["name"] = asString(cell(1));
180 return InsetCommandMailer::params2string(name, icp);
184 InsetMathRef::ref_type_info InsetMathRef::types[] = {
185 { from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
186 { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
187 { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
188 { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
189 { from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
190 { from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
191 { from_ascii(""), from_ascii(""), from_ascii("") }