2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetRef.cpp
|
2002-09-25 14:26:13 +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 José Matos
|
2002-09-25 14:26:13 +00:00
|
|
|
*
|
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>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetRef.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
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 "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2010-01-20 19:03:17 +00:00
|
|
|
#include "InsetLabel.h"
|
2000-05-19 16:46:01 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2009-11-14 14:12:37 +00:00
|
|
|
#include "output_xhtml.h"
|
2008-02-27 16:23:27 +00:00
|
|
|
#include "ParIterator.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
#include "sgml.h"
|
2008-02-27 16:23:27 +00:00
|
|
|
#include "TocBackend.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-27 16:23:27 +00:00
|
|
|
#include "support/gettext.h"
|
2001-06-27 14:10:35 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2008-03-02 15:27:35 +00:00
|
|
|
using namespace std;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetRef::InsetRef(Buffer * buf, InsetCommandParams const & p)
|
2009-11-08 16:10:34 +00:00
|
|
|
: InsetCommand(buf, 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
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
bool InsetRef::isCompatibleCommand(string const & s) {
|
2007-10-25 04:13:56 +00:00
|
|
|
//FIXME This is likely not the best way to handle this.
|
|
|
|
//But this stuff is hardcoded elsewhere already.
|
|
|
|
return s == "ref"
|
|
|
|
|| s == "pageref"
|
|
|
|
|| s == "vref"
|
|
|
|
|| s == "vpageref"
|
|
|
|
|| s == "prettyref"
|
2010-07-13 03:23:29 +00:00
|
|
|
|| s == "eqref"
|
|
|
|
|| s == "nameref"
|
|
|
|
|| s == "Nameref";
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
param_info_.add("name", ParamInfo::LATEX_OPTIONAL);
|
2010-02-13 13:08:32 +00:00
|
|
|
param_info_.add("reference", ParamInfo::LATEX_REQUIRED,
|
|
|
|
ParamInfo::HANDLING_ESCAPE);
|
2008-02-23 22:01:02 +00:00
|
|
|
}
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-13 13:08:32 +00:00
|
|
|
int InsetRef::latex(odocstream & os, OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-09-27 18:24:18 +00:00
|
|
|
// We don't want to output p_["name"], since that is only used
|
|
|
|
// in docbook. So we construct new params, without it, and use that.
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(REF_CODE, getCmdName());
|
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
|
|
|
p["reference"] = getParam("reference");
|
2010-02-13 13:08:32 +00:00
|
|
|
os << p.getCommand(runparams);
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetRef::plaintext(odocstream & os, OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2007-02-24 14:35:38 +00:00
|
|
|
docstring const str = getParam("reference");
|
2007-02-15 23:28:31 +00:00
|
|
|
os << '[' << str << ']';
|
|
|
|
return 2 + str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetRef::docbook(odocstream & os, 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) {
|
2007-05-28 22:27:45 +00:00
|
|
|
os << "<xref linkend=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
<< sgml::cleanID(buffer(), runparams, getParam("reference"))
|
2006-10-20 16:12:49 +00:00
|
|
|
<< "\" />";
|
|
|
|
} else {
|
2007-05-28 22:27:45 +00:00
|
|
|
os << "<xref linkend=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
<< sgml::cleanID(buffer(), runparams, getParam("reference"))
|
2006-10-20 16:12:49 +00:00
|
|
|
<< "\">";
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
} else {
|
2007-05-28 22:27:45 +00:00
|
|
|
os << "<link linkend=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
<< sgml::cleanID(buffer(), runparams, getParam("reference"))
|
2007-05-28 22:27:45 +00:00
|
|
|
<< "\">"
|
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
|
|
|
|
2009-11-28 21:37:47 +00:00
|
|
|
docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-11-14 14:12:37 +00:00
|
|
|
{
|
2010-01-20 19:03:17 +00:00
|
|
|
docstring const & ref = getParam("reference");
|
|
|
|
InsetLabel const * il = buffer().insetLabel(ref);
|
|
|
|
string const & cmd = params().getCmdName();
|
|
|
|
docstring display_string;
|
|
|
|
|
|
|
|
if (il && !il->counterValue().empty()) {
|
|
|
|
// Try to construct a label from the InsetLabel we reference.
|
|
|
|
docstring const & value = il->counterValue();
|
|
|
|
if (cmd == "ref")
|
|
|
|
display_string = value;
|
|
|
|
else if (cmd == "vref")
|
2010-01-20 20:33:36 +00:00
|
|
|
// normally, would be "ref on page #", but we have no pages
|
|
|
|
display_string = value;
|
2010-01-20 19:03:17 +00:00
|
|
|
else if (cmd == "pageref" || cmd == "vpageref")
|
2010-01-20 20:33:36 +00:00
|
|
|
// normally would be "on page #", but we have no pages
|
|
|
|
display_string = _("elsewhere");
|
2010-01-20 19:03:17 +00:00
|
|
|
else if (cmd == "eqref")
|
|
|
|
display_string = bformat(from_ascii("equation (%1$s)"), value);
|
2010-07-13 03:23:29 +00:00
|
|
|
else if (cmd == "prettyref"
|
|
|
|
// we don't really have the ability to handle these
|
|
|
|
// properly in XHTML output
|
|
|
|
|| cmd == "nameref" || cmd == "Nameref")
|
2010-01-20 20:33:36 +00:00
|
|
|
display_string = il->prettyCounter();
|
2010-01-20 19:03:17 +00:00
|
|
|
} else
|
|
|
|
display_string = ref;
|
|
|
|
|
2009-11-14 14:12:37 +00:00
|
|
|
// FIXME What we'd really like to do is to be able to output some
|
|
|
|
// appropriate sort of text here. But to do that, we need to associate
|
|
|
|
// some sort of counter with the label, and we don't have that yet.
|
2010-01-20 19:03:17 +00:00
|
|
|
string const attr = "href=\"#" + html::cleanAttr(to_utf8(ref)) + "\"";
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::StartTag("a", attr);
|
2010-01-20 19:03:17 +00:00
|
|
|
xs << display_string;
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::EndTag("a");
|
2009-11-14 14:12:37 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2009-12-31 15:52:16 +00:00
|
|
|
|
2008-11-10 22:45:14 +00:00
|
|
|
void InsetRef::tocString(odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
plaintext(os, OutputParams(0));
|
2005-11-25 14:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
|
2008-02-27 16:23:27 +00:00
|
|
|
{
|
2010-02-26 20:16:12 +00:00
|
|
|
docstring const & ref = getParam("reference");
|
2008-03-03 17:58:26 +00:00
|
|
|
// register this inset into the buffer reference cache.
|
2010-02-26 20:16:12 +00:00
|
|
|
buffer().references(ref).push_back(make_pair(this, it));
|
2008-03-03 17:58:26 +00:00
|
|
|
|
2010-02-26 20:16:12 +00:00
|
|
|
docstring label;
|
2008-03-03 17:58:26 +00:00
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++i) {
|
|
|
|
if (getCmdName() == types[i].latex_name) {
|
2010-02-26 20:16:12 +00:00
|
|
|
label = _(types[i].short_gui_name);
|
2008-03-03 17:58:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-26 20:16:12 +00:00
|
|
|
label += ref;
|
2008-03-03 17:58:26 +00:00
|
|
|
|
|
|
|
if (!isLatex && !getParam("name").empty()) {
|
2010-02-26 20:16:12 +00:00
|
|
|
label += "||";
|
|
|
|
label += getParam("name");
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_label_ = label;
|
|
|
|
bool shortened = false;
|
|
|
|
unsigned int const maxLabelChars = 24;
|
|
|
|
if (screen_label_.size() > maxLabelChars) {
|
|
|
|
screen_label_.erase(maxLabelChars - 3);
|
|
|
|
screen_label_ += "...";
|
|
|
|
shortened = true;
|
2008-03-03 17:58:26 +00:00
|
|
|
}
|
2010-02-26 20:16:12 +00:00
|
|
|
if (shortened)
|
|
|
|
tooltip_ = label;
|
|
|
|
else
|
|
|
|
tooltip_ = from_ascii("");
|
2008-03-02 15:27:35 +00:00
|
|
|
}
|
2008-02-27 16:44:57 +00:00
|
|
|
|
2008-03-02 15:27:35 +00:00
|
|
|
|
2008-05-13 08:23:44 +00:00
|
|
|
void InsetRef::addToToc(DocIterator const & cpit)
|
2008-03-02 15:27:35 +00:00
|
|
|
{
|
|
|
|
docstring const & label = getParam("reference");
|
|
|
|
if (buffer().insetLabel(label))
|
|
|
|
// This InsetRef has already been taken care of in InsetLabel::addToToc().
|
2008-02-27 16:44:57 +00:00
|
|
|
return;
|
|
|
|
|
2008-03-03 17:58:26 +00:00
|
|
|
// It seems that this reference does not point to any valid label.
|
|
|
|
screen_label_ = _("BROKEN: ") + screen_label_;
|
2008-03-02 15:27:35 +00:00
|
|
|
Toc & toc = buffer().tocBackend().toc("label");
|
2008-03-03 17:58:26 +00:00
|
|
|
toc.push_back(TocItem(cpit, 0, screen_label_));
|
2008-02-27 16:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetRef::validate(LaTeXFeatures & features) const
|
2000-05-19 16:46:01 +00:00
|
|
|
{
|
2010-07-13 03:23:29 +00:00
|
|
|
string const cmd = getCmdName();
|
|
|
|
if (cmd == "vref" || cmd == "vpageref")
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("varioref");
|
2010-07-13 03:23:29 +00:00
|
|
|
else if (cmd == "prettyref")
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("prettyref");
|
2010-07-13 03:23:29 +00:00
|
|
|
else if (cmd == "eqref")
|
2003-08-18 17:41:30 +00:00
|
|
|
features.require("amsmath");
|
2010-07-13 03:23:29 +00:00
|
|
|
else if (cmd == "nameref" || cmd == "Nameref")
|
|
|
|
features.require("nameref");
|
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: ")},
|
2010-02-26 20:16:12 +00:00
|
|
|
{ "prettyref", N_("PrettyRef"), N_("FrmtRef: ")},
|
2010-07-13 03:23:29 +00:00
|
|
|
{ "nameref", N_("Reference to Name"), N_("NameRef:")},
|
|
|
|
{ "Nameref", N_("Name+Textual Page"), N_("NamePgRef:")},
|
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
|