2002-09-11 08:26:02 +00:00
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
#include <config.h>
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
#include "ref_inset.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
#include "math_factory.h"
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
#include "BufferView.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "funcrequest.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
|
|
|
#include "support/LOstream.h"
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
RefInset::RefInset()
|
|
|
|
: CommandInset("ref")
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
RefInset::RefInset(string const & data)
|
|
|
|
: CommandInset(data)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * RefInset::clone() const
|
|
|
|
{
|
|
|
|
return new RefInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RefInset::infoize(std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << "Ref: " << cell(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-18 11:47:16 +00:00
|
|
|
dispatch_result
|
2002-08-19 10:11:13 +00:00
|
|
|
RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
|
2002-06-24 15:51:35 +00:00
|
|
|
{
|
2002-08-12 09:53:04 +00:00
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2002-08-19 10:11:13 +00:00
|
|
|
if (cmd.button() == mouse_button::button3) {
|
2002-08-12 09:53:04 +00:00
|
|
|
lyxerr << "trying to goto ref" << cell(0) << "\n";
|
2002-08-13 17:43:40 +00:00
|
|
|
cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
|
|
|
|
return DISPATCHED;
|
2002-08-12 09:53:04 +00:00
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
if (cmd.button() == mouse_button::button1) {
|
2003-02-25 14:51:38 +00:00
|
|
|
// Eventually trigger dialog with button 3
|
|
|
|
// not 1
|
2003-03-04 16:39:13 +00:00
|
|
|
string const data = createDialogStr("ref");
|
2003-02-25 14:51:38 +00:00
|
|
|
cmd.view()->owner()->getDialogs().
|
2003-03-04 16:39:13 +00:00
|
|
|
show("ref", data, this);
|
2002-08-13 17:43:40 +00:00
|
|
|
return DISPATCHED;
|
2002-08-12 09:53:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-11-27 10:30:28 +00:00
|
|
|
case LFUN_MOUSE_PRESS:
|
2002-08-12 09:53:04 +00:00
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
// eat other mouse commands
|
2002-08-13 17:43:40 +00:00
|
|
|
return DISPATCHED;
|
2002-08-12 09:53:04 +00:00
|
|
|
default:
|
2002-08-19 10:11:13 +00:00
|
|
|
return CommandInset::dispatch(cmd, idx, pos);
|
2002-06-24 15:51:35 +00:00
|
|
|
}
|
2002-08-12 09:53:04 +00:00
|
|
|
// not our business
|
2002-08-13 17:43:40 +00:00
|
|
|
return UNDISPATCHED;
|
2002-06-24 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string RefInset::screenLabel() const
|
|
|
|
{
|
|
|
|
string str;
|
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++i)
|
|
|
|
if (name_ == types[i].latex_name) {
|
|
|
|
str = _(types[i].short_gui_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str += asString(cell(0));
|
|
|
|
|
|
|
|
//if (/* !isLatex && */ !cell(0).empty()) {
|
|
|
|
// str += "||";
|
|
|
|
// str += asString(cell(1));
|
|
|
|
//}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RefInset::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
if (name_ == "vref" || name_ == "vpageref")
|
|
|
|
features.require("varioref");
|
|
|
|
else if (name_ == "prettyref")
|
|
|
|
features.require("prettyref");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RefInset::ascii(std::ostream & os, int) const
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '[' << asString(cell(0)) << ']';
|
2002-06-24 15:51:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RefInset::linuxdoc(std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << "<ref id=\"" << asString(cell(0))
|
|
|
|
<< "\" name=\"" << asString(cell(1)) << "\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RefInset::docbook(std::ostream & os, bool) const
|
|
|
|
{
|
|
|
|
if (cell(1).empty()) {
|
|
|
|
os << "<xref linkend=\"" << asString(cell(0)) << "\">";
|
|
|
|
} else {
|
|
|
|
os << "<link linkend=\"" << asString(cell(0))
|
|
|
|
<< "\">" << asString(cell(1)) << "</link>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2003-02-26 11:37:53 +00:00
|
|
|
dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
|
|
|
|
{
|
2003-03-04 14:31:04 +00:00
|
|
|
if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
|
2003-02-26 19:28:38 +00:00
|
|
|
return UNDISPATCHED;
|
|
|
|
|
2003-02-26 11:37:53 +00:00
|
|
|
MathArray ar;
|
2003-03-04 16:39:13 +00:00
|
|
|
if (!createMathInset_fromDialogStr(cmd.argument, ar))
|
2003-02-26 11:37:53 +00:00
|
|
|
return UNDISPATCHED;
|
|
|
|
|
|
|
|
*this = *ar[0].nucleus()->asRefInset();
|
2003-02-26 19:28:38 +00:00
|
|
|
// if (cmd.view())
|
|
|
|
// // This does not compile because updateInset expects
|
|
|
|
// // an Inset* and 'this' isn't.
|
2003-03-19 14:45:22 +00:00
|
|
|
// cmd.view()->updateInset(this);
|
2003-02-26 11:37:53 +00:00
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-13 08:12:51 +00:00
|
|
|
RefInset::ref_type_info RefInset::types[] = {
|
2003-04-24 12:16:56 +00:00
|
|
|
{ "ref", N_("Standard"), N_("Ref: ")},
|
|
|
|
{ "eqref", N_("Equation"), N_("EqRef: ")},
|
|
|
|
{ "pageref", N_("Page Number"), N_("Page: ")},
|
|
|
|
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
|
|
|
|
{ "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
|
|
|
|
{ "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
|
2002-06-24 15:51:35 +00:00
|
|
|
{ "", "", "" }
|
|
|
|
};
|