2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetref.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Jos<EFBFBD> Matos
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetref.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "BufferView.h"
|
2002-08-07 08:11:41 +00:00
|
|
|
|
#include "funcrequest.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "gettext.h"
|
2000-05-19 16:46:01 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2002-05-23 12:08:47 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::escape;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
|
2000-10-10 11:50:43 +00:00
|
|
|
|
: InsetCommand(p), isLatex(buf.isLatex())
|
2000-08-08 13:55:26 +00:00
|
|
|
|
{}
|
|
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
|
InsetRef::InsetRef(InsetRef const & ir)
|
|
|
|
|
: InsetCommand(ir), isLatex(ir.isLatex)
|
|
|
|
|
{
|
|
|
|
|
}
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetRef::~InsetRef()
|
|
|
|
|
{
|
2003-05-16 07:44:00 +00:00
|
|
|
|
InsetCommandMailer("ref", *this).hideDialog();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
dispatch_result InsetRef::localDispatch(FuncRequest const & cmd)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-05-16 07:44:00 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-05-26 09:13:55 +00:00
|
|
|
|
case LFUN_INSET_EDIT:
|
2003-05-16 07:44:00 +00:00
|
|
|
|
// Eventually trigger dialog with button 3 not 1
|
|
|
|
|
if (cmd.button() == mouse_button::button3)
|
|
|
|
|
cmd.view()->owner()->
|
|
|
|
|
dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
|
2003-06-11 21:46:42 +00:00
|
|
|
|
else
|
2003-05-16 07:44:00 +00:00
|
|
|
|
InsetCommandMailer("ref", *this).showDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
default:
|
2003-05-28 16:36:55 +00:00
|
|
|
|
return InsetCommand::localDispatch(cmd);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-08 13:55:26 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string const InsetRef::getScreenLabel(Buffer const &) const
|
2000-05-19 16:46:01 +00:00
|
|
|
|
{
|
2000-08-08 13:55:26 +00:00
|
|
|
|
string temp;
|
2001-01-21 21:41:35 +00:00
|
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++ i)
|
|
|
|
|
if (getCmdName() == types[i].latex_name) {
|
|
|
|
|
temp = _(types[i].short_gui_name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-08-08 13:55:26 +00:00
|
|
|
|
temp += getContents();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!isLatex
|
1999-11-04 01:40:20 +00:00
|
|
|
|
&& !getOptions().empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
temp += "||";
|
|
|
|
|
temp += getOptions();
|
|
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetRef::latex(Buffer const &, ostream & os,
|
2003-05-23 08:59:47 +00:00
|
|
|
|
LatexRunParams const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (getOptions().empty())
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << escape(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
InsetCommandParams p(getCmdName(), getContents(), "");
|
2000-08-04 13:12:30 +00:00
|
|
|
|
os << escape(p.getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetRef::ascii(Buffer const &, ostream & os, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << getContents() << ']';
|
2000-04-24 20:58:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetRef::linuxdoc(Buffer const &, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
os << "<ref id=\"" << getContents()
|
|
|
|
|
<< "\" name=\"" << getOptions() << "\" >";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetRef::docbook(Buffer const &, ostream & os, bool) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (getOptions().empty()) {
|
2001-10-23 09:42:14 +00:00
|
|
|
|
os << "<xref linkend=\"" << getContents() << "\">";
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
os << "<link linkend=\"" << getContents()
|
|
|
|
|
<< "\">" << getOptions() << "</link>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetRef::validate(LaTeXFeatures & features) const
|
2000-05-19 16:46:01 +00:00
|
|
|
|
{
|
2000-08-08 13:55:26 +00:00
|
|
|
|
if (getCmdName() == "vref" || getCmdName() == "vpageref")
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("varioref");
|
2000-11-04 10:00:12 +00:00
|
|
|
|
else if (getCmdName() == "prettyref")
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("prettyref");
|
2003-08-18 17:41:30 +00:00
|
|
|
|
else if (getCmdName() == "eqref")
|
|
|
|
|
features.require("amsmath");
|
2000-08-04 13:12:30 +00:00
|
|
|
|
}
|
2001-01-21 21:41:35 +00:00
|
|
|
|
|
2002-06-24 17:26:15 +00:00
|
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
|
InsetRef::type_info InsetRef::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: ")},
|
2001-01-21 21:41:35 +00:00
|
|
|
|
{ "", "", "" }
|
|
|
|
|
};
|
2001-01-26 17:11:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetRef::getType(string const & name)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++i)
|
|
|
|
|
if (name == types[i].latex_name)
|
|
|
|
|
return i;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & InsetRef::getName(int type)
|
|
|
|
|
{
|
|
|
|
|
return types[type].latex_name;
|
|
|
|
|
}
|