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.
15 #include "BufferView.h"
16 #include "dispatchresult.h"
17 #include "funcrequest.h"
19 #include "LaTeXFeatures.h"
21 #include "frontends/LyXView.h"
23 #include "support/lstrings.h"
26 using lyx::support::escape;
32 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
33 : InsetCommand(p), isLatex(buf.isLatex())
37 InsetRef::InsetRef(InsetRef const & ir)
38 : InsetCommand(ir), isLatex(ir.isLatex)
45 InsetCommandMailer("ref", *this).hideDialog();
50 InsetRef::priv_dispatch(FuncRequest const & cmd,
51 idx_type & idx, pos_type & pos)
55 // Eventually trigger dialog with button 3 not 1
56 if (cmd.button() == mouse_button::button3)
58 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
60 InsetCommandMailer("ref", *this).showDialog(cmd.view());
64 return InsetCommand::priv_dispatch(cmd, idx, pos);
69 string const InsetRef::getScreenLabel(Buffer const &) const
72 for (int i = 0; !types[i].latex_name.empty(); ++ i)
73 if (getCmdName() == types[i].latex_name) {
74 temp = _(types[i].short_gui_name);
77 temp += getContents();
80 && !getOptions().empty()) {
88 int InsetRef::latex(Buffer const &, ostream & os,
89 LatexRunParams const &) const
91 if (getOptions().empty())
92 os << escape(getCommand());
94 InsetCommandParams p(getCmdName(), getContents(), "");
95 os << escape(p.getCommand());
101 int InsetRef::ascii(Buffer const &, ostream & os, int) const
103 os << '[' << getContents() << ']';
108 int InsetRef::linuxdoc(Buffer const &, ostream & os) const
110 os << "<ref id=\"" << getContents()
111 << "\" name=\"" << getOptions() << "\" >";
116 int InsetRef::docbook(Buffer const &, ostream & os, bool) const
118 if (getOptions().empty()) {
119 os << "<xref linkend=\"" << getContents() << "\">";
121 os << "<link linkend=\"" << getContents()
122 << "\">" << getOptions() << "</link>";
129 void InsetRef::validate(LaTeXFeatures & features) const
131 if (getCmdName() == "vref" || getCmdName() == "vpageref")
132 features.require("varioref");
133 else if (getCmdName() == "prettyref")
134 features.require("prettyref");
135 else if (getCmdName() == "eqref")
136 features.require("amsmath");
140 InsetRef::type_info InsetRef::types[] = {
141 { "ref", N_("Standard"), N_("Ref: ")},
142 { "eqref", N_("Equation"), N_("EqRef: ")},
143 { "pageref", N_("Page Number"), N_("Page: ")},
144 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
145 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
146 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
151 int InsetRef::getType(string const & name)
153 for (int i = 0; !types[i].latex_name.empty(); ++i)
154 if (name == types[i].latex_name)
160 string const & InsetRef::getName(int type)
162 return types[type].latex_name;