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, bool)
27 : InsetCommand(p), isLatex(buf.isLatex())
31 void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button)
33 // FuncRequestually trigger dialog with button 3 not 1
34 if (button == mouse_button::button3)
35 bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
36 else if (button == mouse_button::button1)
37 bv->owner()->getDialogs().showRef(this);
41 void InsetRef::edit(BufferView *, bool)
45 string const InsetRef::getScreenLabel(Buffer const *) const
48 for (int i = 0; !types[i].latex_name.empty(); ++ i)
49 if (getCmdName() == types[i].latex_name) {
50 temp = _(types[i].short_gui_name);
53 temp += getContents();
56 && !getOptions().empty()) {
64 int InsetRef::latex(Buffer const *, ostream & os,
65 bool /*fragile*/, bool /*fs*/) const
67 if (getOptions().empty())
68 os << escape(getCommand());
70 InsetCommandParams p(getCmdName(), getContents(), "");
71 os << escape(p.getCommand());
77 int InsetRef::ascii(Buffer const *, ostream & os, int) const
79 os << '[' << getContents() << ']';
84 int InsetRef::linuxdoc(Buffer const *, ostream & os) const
86 os << "<ref id=\"" << getContents()
87 << "\" name=\"" << getOptions() << "\" >";
92 int InsetRef::docbook(Buffer const *, ostream & os, bool) const
94 if (getOptions().empty()) {
95 os << "<xref linkend=\"" << getContents() << "\">";
97 os << "<link linkend=\"" << getContents()
98 << "\">" << getOptions() << "</link>";
105 void InsetRef::validate(LaTeXFeatures & features) const
107 if (getCmdName() == "vref" || getCmdName() == "vpageref")
108 features.require("varioref");
109 else if (getCmdName() == "prettyref")
110 features.require("prettyref");
114 InsetRef::type_info InsetRef::types[] = {
115 { "ref", N_("Standard"), N_("Ref: ")},
116 { "pageref", N_("Page Number"), N_("Page: ")},
117 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
118 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
119 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
124 int InsetRef::getType(string const & name)
126 for (int i = 0; !types[i].latex_name.empty(); ++i)
127 if (name == types[i].latex_name)
133 string const & InsetRef::getName(int type)
135 return types[type].latex_name;