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 "funcrequest.h"
18 #include "LaTeXFeatures.h"
19 #include "frontends/LyXView.h"
20 #include "frontends/Dialogs.h"
21 #include "BufferView.h"
22 #include "support/lstrings.h"
26 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
27 : InsetCommand(p), isLatex(buf.isLatex())
31 InsetRef::InsetRef(InsetRef const & ir)
32 : InsetCommand(ir), isLatex(ir.isLatex)
39 InsetCommandMailer("ref", *this).hideDialog();
43 dispatch_result InsetRef::localDispatch(FuncRequest const & cmd)
47 // Eventually trigger dialog with button 3 not 1
48 if (cmd.button() == mouse_button::button3)
50 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
51 if (cmd.button() == mouse_button::button1)
52 InsetCommandMailer("ref", *this).showDialog(cmd.view());
56 return InsetCommand::localDispatch(cmd);
61 string const InsetRef::getScreenLabel(Buffer const *) const
64 for (int i = 0; !types[i].latex_name.empty(); ++ i)
65 if (getCmdName() == types[i].latex_name) {
66 temp = _(types[i].short_gui_name);
69 temp += getContents();
72 && !getOptions().empty()) {
80 int InsetRef::latex(Buffer const *, ostream & os,
81 LatexRunParams const &) const
83 if (getOptions().empty())
84 os << escape(getCommand());
86 InsetCommandParams p(getCmdName(), getContents(), "");
87 os << escape(p.getCommand());
93 int InsetRef::ascii(Buffer const *, ostream & os, int) const
95 os << '[' << getContents() << ']';
100 int InsetRef::linuxdoc(Buffer const *, ostream & os) const
102 os << "<ref id=\"" << getContents()
103 << "\" name=\"" << getOptions() << "\" >";
108 int InsetRef::docbook(Buffer const *, ostream & os, bool) const
110 if (getOptions().empty()) {
111 os << "<xref linkend=\"" << getContents() << "\">";
113 os << "<link linkend=\"" << getContents()
114 << "\">" << getOptions() << "</link>";
121 void InsetRef::validate(LaTeXFeatures & features) const
123 if (getCmdName() == "vref" || getCmdName() == "vpageref")
124 features.require("varioref");
125 else if (getCmdName() == "prettyref")
126 features.require("prettyref");
130 InsetRef::type_info InsetRef::types[] = {
131 { "ref", N_("Standard"), N_("Ref: ")},
132 { "eqref", N_("Equation"), N_("EqRef: ")},
133 { "pageref", N_("Page Number"), N_("Page: ")},
134 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
135 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
136 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
141 int InsetRef::getType(string const & name)
143 for (int i = 0; !types[i].latex_name.empty(); ++i)
144 if (name == types[i].latex_name)
150 string const & InsetRef::getName(int type)
152 return types[type].latex_name;