X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetRef.cpp;h=f0c45db39ce97d25d979eaea836263ae4b0a882a;hb=d6f1915684328c6e3fe61c6eef8846b5cabec334;hp=92db373c227af048b8e49e2f46192d7104124100;hpb=c8d00ed1272cd489041bed2115081008b6a26489;p=lyx.git diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 92db373c22..f0c45db39c 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -11,28 +11,28 @@ #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 lyx::support; +using namespace std; namespace lyx { -using support::escape; -using std::string; -using std::ostream; - - -InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf) +InsetRef::InsetRef(Buffer const & buf, InsetCommandParams const & p) : InsetCommand(p, "ref"), isLatex(buf.isLatex()) {} @@ -42,60 +42,47 @@ InsetRef::InsetRef(InsetRef const & ir) {} -void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd) -{ - switch (cmd.action) { - case LFUN_MOUSE_PRESS: - // 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; +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"; +} - case LFUN_MOUSE_RELEASE: - return; - default: - return InsetCommand::doDispatch(cur, cmd); +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_; } -docstring const InsetRef::getScreenLabel(Buffer const &) const +docstring InsetRef::screenLabel() const { - docstring temp; - for (int i = 0; !types[i].latex_name.empty(); ++i) { - if (getCmdName() == types[i].latex_name) { - temp = _(types[i].short_gui_name); - break; - } - } - temp += getParam("reference"); - - if (!isLatex && !getParam("name").empty()) { - temp += "||"; - temp += getParam("name"); - } - return temp; + return screen_label_; } -int InsetRef::latex(Buffer const &, odocstream & os, - OutputParams const &) const +int InsetRef::latex(odocstream & os, 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 +int InsetRef::plaintext(odocstream & os, OutputParams const &) const { docstring const str = getParam("reference"); os << '[' << str << ']'; @@ -103,24 +90,23 @@ int InsetRef::plaintext(Buffer const &, odocstream & os, } -int InsetRef::docbook(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const +int InsetRef::docbook(odocstream & os, OutputParams const & runparams) const { docstring const & name = getParam("name"); if (name.empty()) { if (runparams.flavor == OutputParams::XML) { - os << ""; } else { - os << ""; } } else { - os << "" + os << "" << getParam("name") << ""; } @@ -129,10 +115,44 @@ int InsetRef::docbook(Buffer const & buf, odocstream & os, } -int InsetRef::textString(Buffer const & buf, odocstream & os, - OutputParams const & op) const +void InsetRef::textString(odocstream & os) const { - return plaintext(buf, os, op); + plaintext(os, OutputParams(0)); +} + + +void InsetRef::updateLabels(ParIterator const & it) +{ + docstring const & label = getParam("reference"); + // register this inset into the buffer reference cache. + buffer().references(label).push_back(make_pair(this, it)); + + for (int i = 0; !types[i].latex_name.empty(); ++i) { + if (getCmdName() == types[i].latex_name) { + screen_label_ = _(types[i].short_gui_name); + break; + } + } + screen_label_ += getParam("reference"); + + if (!isLatex && !getParam("name").empty()) { + screen_label_ += "||"; + screen_label_ += getParam("name"); + } +} + + +void InsetRef::addToToc(DocIterator const & cpit) +{ + docstring const & label = getParam("reference"); + if (buffer().insetLabel(label)) + // This InsetRef has already been taken care of in InsetLabel::addToToc(). + return; + + // It seems that this reference does not point to any valid label. + screen_label_ = _("BROKEN: ") + screen_label_; + Toc & toc = buffer().tocBackend().toc("label"); + toc.push_back(TocItem(cpit, 0, screen_label_)); }