2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathRef.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
#include <config.h>
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathRef.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-04-18 19:57:58 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2004-11-02 11:25:20 +00:00
|
|
|
|
#include "buffer.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "funcrequest.h"
|
2005-11-22 13:52:25 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "gettext.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathData.h"
|
|
|
|
|
#include "MathFactory.h"
|
|
|
|
|
#include "MathSupport.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "outputparams.h"
|
|
|
|
|
#include "sgml.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetCommand.h"
|
2007-04-06 08:30:37 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
using std::endl;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
|
|
RefInset::RefInset()
|
2006-10-22 10:15:23 +00:00
|
|
|
|
: CommandInset(from_ascii("ref"))
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
RefInset::RefInset(docstring const & data)
|
2002-06-24 15:51:35 +00:00
|
|
|
|
: CommandInset(data)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2005-02-23 12:01:50 +00:00
|
|
|
|
auto_ptr<InsetBase> RefInset::doClone() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new RefInset(*this));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void RefInset::infoize(odocstream & os) const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
|
|
|
|
os << "Ref: " << cell(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2002-08-12 09:53:04 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-10-17 18:01:15 +00:00
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
if (cmd.getArg(0) == "ref") {
|
|
|
|
|
MathArray ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
|
2004-04-03 08:37:12 +00:00
|
|
|
|
*this = *ar[0].nucleus()->asRefInset();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
2003-10-17 18:01:15 +00:00
|
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2005-11-22 13:52:25 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
|
|
|
|
string const data = createDialogStr("ref");
|
2006-09-19 13:36:20 +00:00
|
|
|
|
cur.bv().updateDialog("ref", data);
|
2005-11-22 13:52:25 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
if (cmd.button() == mouse_button::button3) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
lyxerr << "trying to goto ref '" << to_utf8(asString(cell(0))) << "'" << endl;
|
2005-05-08 10:02:38 +00:00
|
|
|
|
cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2003-10-17 18:01:15 +00:00
|
|
|
|
}
|
|
|
|
|
if (cmd.button() == mouse_button::button1) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// Eventually trigger dialog with button 3, not 1
|
2003-10-17 18:01:15 +00:00
|
|
|
|
string const data = createDialogStr("ref");
|
2006-09-19 13:36:20 +00:00
|
|
|
|
cur.bv().showInsetDialog("ref", data, this);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2003-10-17 18:01:15 +00:00
|
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
// eat other mouse commands
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
CommandInset::doDispatch(cur, cmd);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-11-22 13:52:25 +00:00
|
|
|
|
bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
FuncStatus & status) const
|
2005-11-22 13:52:25 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
// we handle these
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
status.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return CommandInset::getStatus(cur, cmd, status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const RefInset::screenLabel() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring str;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++i) {
|
2003-06-12 08:52:36 +00:00
|
|
|
|
if (commandname() == types[i].latex_name) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
str = _(to_utf8(types[i].short_gui_name));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-10-22 10:15:23 +00:00
|
|
|
|
}
|
|
|
|
|
str += asString(cell(0));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
|
|
//if (/* !isLatex && */ !cell(0).empty()) {
|
|
|
|
|
// str += "||";
|
|
|
|
|
// str += asString(cell(1));
|
|
|
|
|
//}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RefInset::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2003-06-12 08:52:36 +00:00
|
|
|
|
if (commandname() == "vref" || commandname() == "vpageref")
|
2002-06-24 15:51:35 +00:00
|
|
|
|
features.require("varioref");
|
2003-06-12 08:52:36 +00:00
|
|
|
|
else if (commandname() == "prettyref")
|
2002-06-24 15:51:35 +00:00
|
|
|
|
features.require("prettyref");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 11:00:04 +00:00
|
|
|
|
int RefInset::docbook(Buffer const & buf, odocstream & os,
|
2007-02-20 21:04:29 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (cell(1).empty()) {
|
2006-10-19 21:00:33 +00:00
|
|
|
|
os << "<xref linkend=\""
|
2006-10-22 11:00:04 +00:00
|
|
|
|
<< sgml::cleanID(buf, runparams, asString(cell(0)));
|
2004-11-24 21:58:42 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::XML)
|
2004-10-29 23:08:04 +00:00
|
|
|
|
os << "\"/>";
|
|
|
|
|
else
|
|
|
|
|
os << "\">";
|
2002-06-24 15:51:35 +00:00
|
|
|
|
} else {
|
2006-10-19 21:00:33 +00:00
|
|
|
|
os << "<link linkend=\""
|
2006-10-22 11:00:04 +00:00
|
|
|
|
<< sgml::cleanID(buf, runparams, asString(cell(0)))
|
2006-10-19 21:00:33 +00:00
|
|
|
|
<< "\">"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< asString(cell(1))
|
|
|
|
|
<< "</link>";
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2007-04-06 08:30:37 +00:00
|
|
|
|
string const RefInset::createDialogStr(string const & name) const
|
|
|
|
|
{
|
|
|
|
|
InsetCommandParams icp(to_ascii(commandname()));
|
|
|
|
|
icp["reference"] = asString(cell(0));
|
|
|
|
|
if (!cell(1).empty())
|
|
|
|
|
icp["name"] = asString(cell(1));
|
|
|
|
|
return InsetCommandMailer::params2string(name, icp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-13 08:12:51 +00:00
|
|
|
|
RefInset::ref_type_info RefInset::types[] = {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
{ from_ascii("ref"), from_ascii(N_("Standard")), from_ascii(N_("Ref: "))},
|
|
|
|
|
{ from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
|
|
|
|
|
{ from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
|
|
|
|
|
{ from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
|
|
|
|
|
{ from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
|
2007-02-12 02:15:04 +00:00
|
|
|
|
{ from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
|
2006-10-22 10:15:23 +00:00
|
|
|
|
{ from_ascii(""), from_ascii(""), from_ascii("") }
|
2002-06-24 15:51:35 +00:00
|
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|