#include "InsetRef.h"
-#include "buffer.h"
-#include "cursor.h"
-#include "dispatchresult.h"
-#include "funcrequest.h"
-#include "gettext.h"
+#include "Buffer.h"
+#include "Cursor.h"
+#include "DispatchResult.h"
+#include "FuncRequest.h"
#include "LaTeXFeatures.h"
-#include "lyxfunc.h"
-#include "outputparams.h"
+#include "LyXFunc.h"
+#include "OutputParams.h"
+#include "ParIterator.h"
#include "sgml.h"
+#include "TocBackend.h"
+#include "support/docstream.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::escape;
-
-using std::string;
-using std::ostream;
-
InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
: InsetCommand(p, "ref"), isLatex(buf.isLatex())
{}
-void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd)
+bool InsetRef::isCompatibleCommand(string const & s) {
+ //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"
+ || s == "eqref";
+}
+
+
+ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
+{
+ static ParamInfo param_info_;
+ if (param_info_.empty()) {
+ param_info_.add("name", ParamInfo::LATEX_OPTIONAL);
+ param_info_.add("reference", ParamInfo::LATEX_REQUIRED);
+ }
+ return param_info_;
+}
+
+
+void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
- case LFUN_MOUSE_PRESS:
+ case LFUN_MOUSE_RELEASE:
// Eventually trigger dialog with button 3 not 1
if (cmd.button() == mouse_button::button3)
- lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getParam("reference")));
- else {
- InsetCommandMailer("ref", *this).showDialog(&cur.bv());
- cur.undispatched();
- }
- return;
-
- case LFUN_MOUSE_RELEASE:
- return;
+ lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
+ getParam("reference")));
+ else
+ InsetCommand::doDispatch(cur, cmd);
+ break;
default:
- return InsetCommand::doDispatch(cur, cmd);
+ InsetCommand::doDispatch(cur, cmd);
}
}
int InsetRef::latex(Buffer const &, odocstream & os,
- OutputParams const &) const
+ OutputParams const &) const
{
- // Don't output p_["name"], this is only used in docbook
- InsetCommandParams p(getCmdName());
+ // 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.
+ InsetCommandParams p(REF_CODE, getCmdName());
p["reference"] = getParam("reference");
os << escape(p.getCommand());
return 0;
int InsetRef::plaintext(Buffer const &, odocstream & os,
- OutputParams const &) const
+ OutputParams const &) const
{
docstring const str = getParam("reference");
os << '[' << str << ']';
int InsetRef::docbook(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
docstring const & name = getParam("name");
if (name.empty()) {
if (runparams.flavor == OutputParams::XML) {
- os << "<xref linkend=\""
- << sgml::cleanID(buf, runparams, getParam("reference"))
+ os << "<xref linkend=\""
+ << sgml::cleanID(buf, runparams, getParam("reference"))
<< "\" />";
} else {
- os << "<xref linkend=\""
- << sgml::cleanID(buf, runparams, getParam("reference"))
+ os << "<xref linkend=\""
+ << sgml::cleanID(buf, runparams, getParam("reference"))
<< "\">";
}
} else {
- os << "<link linkend=\""
+ os << "<link linkend=\""
<< sgml::cleanID(buf, runparams, getParam("reference"))
- << "\">"
+ << "\">"
<< getParam("name")
<< "</link>";
}
}
-int InsetRef::textString(Buffer const & buf, odocstream & os,
- OutputParams const & op) const
+void InsetRef::textString(Buffer const & buf, odocstream & os) const
+{
+ plaintext(buf, os, OutputParams(0));
+}
+
+
+void InsetRef::addToToc(Buffer const & buf,
+ ParConstIterator const & cpit) const
{
- return plaintext(buf, os, op);
+ docstring const & label = getParam("reference");
+ Toc & toc = buf.tocBackend().toc("label");
+ Toc::const_iterator it = toc.begin();
+ Toc::const_iterator end = toc.end();
+ for (; it != end; ++it) {
+ if (it->str() == label) {
+ ++it;
+ toc.insert(it, TocItem(cpit, 1, getScreenLabel(buf)));
+ break;
+ }
+ }
}