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"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "cursor.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.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"
|
2006-09-29 22:06:28 +00:00
|
|
|
|
#include "lyxfunc.h"
|
2004-09-25 12:26:07 +00:00
|
|
|
|
#include "outputparams.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "sgml.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
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using 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)
|
2003-12-11 15:23:15 +00:00
|
|
|
|
: InsetCommand(p, "ref"), 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-12-11 15:23:15 +00:00
|
|
|
|
{}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-05-16 07:44:00 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-11-04 12:36:59 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2003-05-16 07:44:00 +00:00
|
|
|
|
// Eventually trigger dialog with button 3 not 1
|
|
|
|
|
if (cmd.button() == mouse_button::button3)
|
2006-10-20 16:12:49 +00:00
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getParam("reference")));
|
2006-04-15 15:10:03 +00:00
|
|
|
|
else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetCommandMailer("ref", *this).showDialog(&cur.bv());
|
2006-04-15 15:10:03 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
return;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
return;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
return InsetCommand::doDispatch(cur, 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
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const InsetRef::getScreenLabel(Buffer const &) const
|
2000-05-19 16:46:01 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring temp;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++i) {
|
2001-01-21 21:41:35 +00:00
|
|
|
|
if (getCmdName() == types[i].latex_name) {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
temp = _(types[i].short_gui_name);
|
2001-01-21 21:41:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 11:05:29 +00:00
|
|
|
|
}
|
2006-10-20 16:12:49 +00:00
|
|
|
|
temp += getParam("reference");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
if (!isLatex && !getParam("name").empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
temp += "||";
|
2006-10-20 16:12:49 +00:00
|
|
|
|
temp += getParam("name");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetRef::latex(Buffer const &, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
|
// Don't output p_["name"], this is only used in docbook
|
|
|
|
|
InsetCommandParams p(getCmdName());
|
|
|
|
|
p["reference"] = getParam("reference");
|
|
|
|
|
os << escape(p.getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetRef::plaintext(Buffer const &, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
|
os << '[' << getParam("reference") << ']';
|
2000-04-24 20:58:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetRef::docbook(Buffer const & buf, odocstream & os,
|
2004-09-25 12:26:07 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
|
docstring const & name = getParam("name");
|
|
|
|
|
if (name.empty()) {
|
|
|
|
|
if (runparams.flavor == OutputParams::XML) {
|
|
|
|
|
os << "<xref linkend=\""
|
2006-10-22 11:00:04 +00:00
|
|
|
|
<< sgml::cleanID(buf, runparams, getParam("reference"))
|
2006-10-20 16:12:49 +00:00
|
|
|
|
<< "\" />";
|
|
|
|
|
} else {
|
|
|
|
|
os << "<xref linkend=\""
|
2006-10-22 11:00:04 +00:00
|
|
|
|
<< sgml::cleanID(buf, runparams, getParam("reference"))
|
2006-10-20 16:12:49 +00:00
|
|
|
|
<< "\">";
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
2006-10-20 16:12:49 +00:00
|
|
|
|
os << "<link linkend=\""
|
2006-10-22 11:00:04 +00:00
|
|
|
|
<< sgml::cleanID(buf, runparams, getParam("reference"))
|
2006-10-20 16:12:49 +00:00
|
|
|
|
<< "\">"
|
|
|
|
|
<< getParam("name")
|
|
|
|
|
<< "</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
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetRef::textString(Buffer const & buf, odocstream & os,
|
2005-11-25 14:40:34 +00:00
|
|
|
|
OutputParams const & op) const
|
|
|
|
|
{
|
|
|
|
|
return plaintext(buf, os, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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: ")},
|
2007-02-12 02:15:04 +00:00
|
|
|
|
{ "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
|
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;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|