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 "funcrequest.h"
18 #include "LaTeXFeatures.h"
20 #include "frontends/LyXView.h"
22 #include "support/lstrings.h"
24 using lyx::support::escape;
29 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
30 : InsetCommand(p), isLatex(buf.isLatex())
34 InsetRef::InsetRef(InsetRef const & ir)
35 : InsetCommand(ir), isLatex(ir.isLatex)
42 InsetCommandMailer("ref", *this).hideDialog();
46 dispatch_result InsetRef::localDispatch(FuncRequest const & cmd)
50 // Eventually trigger dialog with button 3 not 1
51 if (cmd.button() == mouse_button::button3)
53 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
55 InsetCommandMailer("ref", *this).showDialog(cmd.view());
59 return InsetCommand::localDispatch(cmd);
64 string const InsetRef::getScreenLabel(Buffer const &) const
67 for (int i = 0; !types[i].latex_name.empty(); ++ i)
68 if (getCmdName() == types[i].latex_name) {
69 temp = _(types[i].short_gui_name);
72 temp += getContents();
75 && !getOptions().empty()) {
83 int InsetRef::latex(Buffer const &, ostream & os,
84 LatexRunParams const &) const
86 if (getOptions().empty())
87 os << escape(getCommand());
89 InsetCommandParams p(getCmdName(), getContents(), "");
90 os << escape(p.getCommand());
96 int InsetRef::ascii(Buffer const &, ostream & os, int) const
98 os << '[' << getContents() << ']';
103 int InsetRef::linuxdoc(Buffer const &, ostream & os) const
105 os << "<ref id=\"" << getContents()
106 << "\" name=\"" << getOptions() << "\" >";
111 int InsetRef::docbook(Buffer const &, ostream & os, bool) const
113 if (getOptions().empty()) {
114 os << "<xref linkend=\"" << getContents() << "\">";
116 os << "<link linkend=\"" << getContents()
117 << "\">" << getOptions() << "</link>";
124 void InsetRef::validate(LaTeXFeatures & features) const
126 if (getCmdName() == "vref" || getCmdName() == "vpageref")
127 features.require("varioref");
128 else if (getCmdName() == "prettyref")
129 features.require("prettyref");
130 else if (getCmdName() == "eqref")
131 features.require("amsmath");
135 InsetRef::type_info InsetRef::types[] = {
136 { "ref", N_("Standard"), N_("Ref: ")},
137 { "eqref", N_("Equation"), N_("EqRef: ")},
138 { "pageref", N_("Page Number"), N_("Page: ")},
139 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
140 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
141 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
146 int InsetRef::getType(string const & name)
148 for (int i = 0; !types[i].latex_name.empty(); ++i)
149 if (name == types[i].latex_name)
155 string const & InsetRef::getName(int type)
157 return types[type].latex_name;