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"
26 #include "ParIterator.h"
29 #include "insets/InsetCommand.h"
31 #include "support/debug.h"
32 #include "support/gettext.h"
40 InsetMathRef::InsetMathRef(Buffer * buf)
41 : CommandInset(buf, from_ascii("ref"), false)
45 InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data)
46 : CommandInset(buf, data, false)
50 Inset * InsetMathRef::clone() const
52 return new InsetMathRef(*this);
56 void InsetMathRef::infoize(odocstream & os) const
58 os << "Ref: " << cell(0);
62 void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
65 case LFUN_INSET_MODIFY:
66 if (cmd.getArg(0) == "ref") {
68 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
69 *this = *ar[0].nucleus()->asRefInset();
76 case LFUN_INSET_DIALOG_UPDATE: {
77 string const data = createDialogStr("ref");
78 cur.bv().updateDialog("ref", data);
82 case LFUN_MOUSE_RELEASE:
83 if (cmd.button() == mouse_button::button3) {
84 LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
85 //FIXME: use DispatchResult argument
86 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
89 if (cmd.button() == mouse_button::button1) {
90 // Eventually trigger dialog with button 3, not 1
91 string const data = createDialogStr("ref");
92 cur.bv().showDialog("ref", data, this);
98 case LFUN_MOUSE_PRESS:
99 case LFUN_MOUSE_MOTION:
100 // eat other mouse commands
104 CommandInset::doDispatch(cur, cmd);
110 bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
111 FuncStatus & status) const
113 switch (cmd.action) {
115 case LFUN_INSET_MODIFY:
116 case LFUN_INSET_DIALOG_UPDATE:
117 case LFUN_MOUSE_RELEASE:
118 case LFUN_MOUSE_PRESS:
119 case LFUN_MOUSE_MOTION:
120 status.setEnabled(true);
123 return CommandInset::getStatus(cur, cmd, status);
128 docstring const InsetMathRef::screenLabel() const
131 for (int i = 0; !types[i].latex_name.empty(); ++i) {
132 if (commandname() == types[i].latex_name) {
133 str = _(to_utf8(types[i].short_gui_name));
137 str += asString(cell(0));
139 //if (/* !isLatex && */ !cell(0).empty()) {
141 // str += asString(cell(1));
147 void InsetMathRef::validate(LaTeXFeatures & features) const
149 if (commandname() == "vref" || commandname() == "vpageref")
150 features.require("varioref");
151 else if (commandname() == "prettyref")
152 features.require("prettyref");
153 else if (commandname() == "eqref")
154 features.require("amsmath");
158 int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
160 if (cell(1).empty()) {
161 os << "<xref linkend=\""
162 << sgml::cleanID(buffer(), runparams, asString(cell(0)));
163 if (runparams.flavor == OutputParams::XML)
168 os << "<link linkend=\""
169 << sgml::cleanID(buffer(), runparams, asString(cell(0)))
179 void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/)
182 LYXERR0("InsetMathRef::updateBuffer: no buffer_!");
185 // register this inset into the buffer reference cache.
186 buffer().references(getTarget()).push_back(make_pair(this, it));
190 string const InsetMathRef::createDialogStr(string const & name) const
192 InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
193 icp["reference"] = asString(cell(0));
194 if (!cell(1).empty())
195 icp["name"] = asString(cell(1));
196 return InsetCommand::params2string(name, icp);
200 docstring const InsetMathRef::getTarget() const
202 return asString(cell(0));
206 void InsetMathRef::changeTarget(docstring const & target)
208 InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
209 icp["reference"] = target;
210 if (!cell(1).empty())
211 icp["name"] = asString(cell(1));
213 Buffer & buf = buffer();
214 if (createInsetMath_fromDialogStr(
215 from_utf8(InsetCommand::params2string("ref", icp)), ar)) {
216 *this = *ar[0].nucleus()->asRefInset();
217 // FIXME audit setBuffer/updateBuffer calls
223 InsetMathRef::ref_type_info InsetMathRef::types[] = {
224 { from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
225 { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
226 { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
227 { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
228 { from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
229 { from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
230 { from_ascii(""), from_ascii(""), from_ascii("") }