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"
25 using lyx::support::escape;
31 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
32 : InsetCommand(p), isLatex(buf.isLatex())
36 InsetRef::InsetRef(InsetRef const & ir)
37 : InsetCommand(ir), isLatex(ir.isLatex)
44 InsetCommandMailer("ref", *this).hideDialog();
48 dispatch_result InsetRef::localDispatch(FuncRequest const & cmd)
52 // Eventually trigger dialog with button 3 not 1
53 if (cmd.button() == mouse_button::button3)
55 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
57 InsetCommandMailer("ref", *this).showDialog(cmd.view());
61 return InsetCommand::localDispatch(cmd);
66 string const InsetRef::getScreenLabel(Buffer const &) const
69 for (int i = 0; !types[i].latex_name.empty(); ++ i)
70 if (getCmdName() == types[i].latex_name) {
71 temp = _(types[i].short_gui_name);
74 temp += getContents();
77 && !getOptions().empty()) {
85 int InsetRef::latex(Buffer const &, ostream & os,
86 LatexRunParams const &) const
88 if (getOptions().empty())
89 os << escape(getCommand());
91 InsetCommandParams p(getCmdName(), getContents(), "");
92 os << escape(p.getCommand());
98 int InsetRef::ascii(Buffer const &, ostream & os, int) const
100 os << '[' << getContents() << ']';
105 int InsetRef::linuxdoc(Buffer const &, ostream & os) const
107 os << "<ref id=\"" << getContents()
108 << "\" name=\"" << getOptions() << "\" >";
113 int InsetRef::docbook(Buffer const &, ostream & os, bool) const
115 if (getOptions().empty()) {
116 os << "<xref linkend=\"" << getContents() << "\">";
118 os << "<link linkend=\"" << getContents()
119 << "\">" << getOptions() << "</link>";
126 void InsetRef::validate(LaTeXFeatures & features) const
128 if (getCmdName() == "vref" || getCmdName() == "vpageref")
129 features.require("varioref");
130 else if (getCmdName() == "prettyref")
131 features.require("prettyref");
132 else if (getCmdName() == "eqref")
133 features.require("amsmath");
137 InsetRef::type_info InsetRef::types[] = {
138 { "ref", N_("Standard"), N_("Ref: ")},
139 { "eqref", N_("Equation"), N_("EqRef: ")},
140 { "pageref", N_("Page Number"), N_("Page: ")},
141 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
142 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
143 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
148 int InsetRef::getType(string const & name)
150 for (int i = 0; !types[i].latex_name.empty(); ++i)
151 if (name == types[i].latex_name)
157 string const & InsetRef::getName(int type)
159 return types[type].latex_name;