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"
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "LaTeXFeatures.h"
23 #include "MathFactory.h"
24 #include "MathSupport.h"
25 #include "OutputParams.h"
28 #include "insets/InsetCommand.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
39 InsetMathRef::InsetMathRef(Buffer * buf)
40 : CommandInset(buf, from_ascii("ref"), false)
44 InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data)
45 : CommandInset(buf, data, false)
49 Inset * InsetMathRef::clone() const
51 return new InsetMathRef(*this);
55 void InsetMathRef::infoize(odocstream & os) const
57 os << "Ref: " << cell(0);
61 void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
64 case LFUN_INSET_MODIFY:
65 if (cmd.getArg(0) == "ref") {
67 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
68 *this = *ar[0].nucleus()->asRefInset();
75 case LFUN_INSET_DIALOG_UPDATE: {
76 string const data = createDialogStr("ref");
77 cur.bv().updateDialog("ref", data);
81 case LFUN_MOUSE_RELEASE:
82 if (cmd.button() == mouse_button::button3) {
83 LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
84 //FIXME: use DispatchResult argument
85 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
88 if (cmd.button() == mouse_button::button1) {
89 // Eventually trigger dialog with button 3, not 1
90 string const data = createDialogStr("ref");
91 cur.bv().showDialog("ref", data, this);
97 case LFUN_MOUSE_PRESS:
98 case LFUN_MOUSE_MOTION:
99 // eat other mouse commands
103 CommandInset::doDispatch(cur, cmd);
109 bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
110 FuncStatus & status) const
112 switch (cmd.action) {
114 case LFUN_INSET_MODIFY:
115 case LFUN_INSET_DIALOG_UPDATE:
116 case LFUN_MOUSE_RELEASE:
117 case LFUN_MOUSE_PRESS:
118 case LFUN_MOUSE_MOTION:
119 status.setEnabled(true);
122 return CommandInset::getStatus(cur, cmd, status);
127 docstring const InsetMathRef::screenLabel() const
130 for (int i = 0; !types[i].latex_name.empty(); ++i) {
131 if (commandname() == types[i].latex_name) {
132 str = _(to_utf8(types[i].short_gui_name));
136 str += asString(cell(0));
138 //if (/* !isLatex && */ !cell(0).empty()) {
140 // str += asString(cell(1));
146 void InsetMathRef::validate(LaTeXFeatures & features) const
148 if (commandname() == "vref" || commandname() == "vpageref")
149 features.require("varioref");
150 else if (commandname() == "prettyref")
151 features.require("prettyref");
152 else if (commandname() == "eqref")
153 features.require("amsmath");
157 int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
159 if (cell(1).empty()) {
160 os << "<xref linkend=\""
161 << sgml::cleanID(buffer(), runparams, asString(cell(0)));
162 if (runparams.flavor == OutputParams::XML)
167 os << "<link linkend=\""
168 << sgml::cleanID(buffer(), runparams, asString(cell(0)))
178 string const InsetMathRef::createDialogStr(string const & name) const
180 InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
181 icp["reference"] = asString(cell(0));
182 if (!cell(1).empty())
183 icp["name"] = asString(cell(1));
184 return InsetCommand::params2string(name, icp);
188 InsetMathRef::ref_type_info InsetMathRef::types[] = {
189 { from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
190 { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
191 { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
192 { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
193 { from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
194 { from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
195 { from_ascii(""), from_ascii(""), from_ascii("") }