2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathRef.cpp
|
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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-11-22 13:52:25 +00:00
|
|
|
#include "FuncStatus.h"
|
2010-01-25 15:14:41 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathFactory.h"
|
|
|
|
#include "MathSupport.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2010-01-28 17:37:22 +00:00
|
|
|
#include "ParIterator.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
#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
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2002-06-24 15:51:35 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathRef::InsetMathRef(Buffer * buf)
|
|
|
|
: CommandInset(buf, from_ascii("ref"), false)
|
2002-06-24 15:51:35 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data)
|
|
|
|
: CommandInset(buf, data, false)
|
2002-06-24 15:51:35 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathRef::clone() const
|
2002-06-24 15:51:35 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathRef(*this);
|
2002-06-24 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
void InsetMathRef::infoize(odocstream & os) const
|
2002-06-24 15:51:35 +00:00
|
|
|
{
|
|
|
|
os << "Ref: " << cell(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-06-24 15:51:35 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-10-17 18:01:15 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "ref") {
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
|
2010-12-08 09:24:04 +00:00
|
|
|
cur.recordUndo();
|
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: {
|
2010-10-29 00:42:40 +00:00
|
|
|
string const data = createDialogStr();
|
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:
|
2017-02-18 21:24:25 +00:00
|
|
|
if (cur.selection()) {
|
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
2003-10-17 18:01:15 +00:00
|
|
|
if (cmd.button() == mouse_button::button3) {
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
|
2010-01-25 15:14:41 +00:00
|
|
|
//FIXME: use DispatchResult argument
|
|
|
|
lyx::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
|
2010-10-29 00:42:40 +00:00
|
|
|
string const data = createDialogStr();
|
2007-11-18 00:39:15 +00:00
|
|
|
cur.bv().showDialog("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
|
|
|
|
2017-02-18 21:24:25 +00:00
|
|
|
case LFUN_MOUSE_PRESS: {
|
|
|
|
bool do_selection = cmd.button() == mouse_button::button1
|
|
|
|
&& cmd.modifier() == ShiftModifier;
|
|
|
|
// For some reason the cursor points inside the first cell, which is not
|
|
|
|
// active.
|
|
|
|
cur.leaveInset(*this);
|
|
|
|
cur.bv().mouseSetCursor(cur, do_selection);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MOUSE_DOUBLE:
|
|
|
|
case LFUN_MOUSE_TRIPLE:
|
2003-10-17 18:01:15 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2006-04-05 23:56:29 +00:00
|
|
|
FuncStatus & status) const
|
2005-11-22 13:52:25 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-11-22 13:52:25 +00:00
|
|
|
// we handle these
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2017-02-18 21:24:25 +00:00
|
|
|
case LFUN_MOUSE_DOUBLE:
|
|
|
|
case LFUN_MOUSE_TRIPLE:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2005-11-22 13:52:25 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return CommandInset::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
docstring const InsetMathRef::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
void InsetMathRef::validate(LaTeXFeatures & features) const
|
2002-06-24 15:51:35 +00:00
|
|
|
{
|
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");
|
2008-06-03 06:23:45 +00:00
|
|
|
else if (commandname() == "eqref")
|
|
|
|
features.require("amsmath");
|
2002-06-24 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetMathRef::docbook(odocstream & os, 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=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
<< sgml::cleanID(buffer(), 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=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
<< sgml::cleanID(buffer(), 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
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/)
|
2010-01-28 17:37:22 +00:00
|
|
|
{
|
|
|
|
if (!buffer_) {
|
2010-03-03 22:13:45 +00:00
|
|
|
LYXERR0("InsetMathRef::updateBuffer: no buffer_!");
|
2010-01-28 17:37:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// register this inset into the buffer reference cache.
|
2013-03-18 23:32:30 +00:00
|
|
|
buffer().addReference(getTarget(), this, it);
|
2010-01-28 17:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-29 00:42:40 +00:00
|
|
|
string const InsetMathRef::createDialogStr() const
|
2007-04-06 08:30:37 +00:00
|
|
|
{
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
|
2007-04-06 08:30:37 +00:00
|
|
|
icp["reference"] = asString(cell(0));
|
|
|
|
if (!cell(1).empty())
|
|
|
|
icp["name"] = asString(cell(1));
|
2010-10-29 00:25:28 +00:00
|
|
|
return InsetCommand::params2string(icp);
|
2007-04-06 08:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 17:37:22 +00:00
|
|
|
docstring const InsetMathRef::getTarget() const
|
|
|
|
{
|
|
|
|
return asString(cell(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathRef::changeTarget(docstring const & target)
|
|
|
|
{
|
|
|
|
InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
|
|
|
|
icp["reference"] = target;
|
|
|
|
if (!cell(1).empty())
|
|
|
|
icp["name"] = asString(cell(1));
|
|
|
|
MathData ar;
|
|
|
|
Buffer & buf = buffer();
|
|
|
|
if (createInsetMath_fromDialogStr(
|
2010-10-29 00:25:28 +00:00
|
|
|
from_utf8(InsetCommand::params2string(icp)), ar)) {
|
2010-01-28 17:37:22 +00:00
|
|
|
*this = *ar[0].nucleus()->asRefInset();
|
2010-07-09 14:37:00 +00:00
|
|
|
// FIXME audit setBuffer calls
|
2010-01-28 17:37:22 +00:00
|
|
|
setBuffer(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
InsetMathRef::ref_type_info InsetMathRef::types[] = {
|
2008-06-03 06:23:45 +00:00
|
|
|
{ from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
|
2006-10-22 10:15:23 +00:00
|
|
|
{ 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
|