X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetRef.cpp;h=f0c45db39ce97d25d979eaea836263ae4b0a882a;hb=d6f1915684328c6e3fe61c6eef8846b5cabec334;hp=84a602e8648a0e63da8f0bd713a2445851fd94ee;hpb=aede435746e2e3844666c2dd24cccf6a8b09ff8c;p=lyx.git diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 84a602e864..f0c45db39c 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -26,13 +26,13 @@ #include "support/gettext.h" #include "support/lstrings.h" -using namespace std; using namespace lyx::support; +using namespace std; namespace lyx { -InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf) +InsetRef::InsetRef(Buffer const & buf, InsetCommandParams const & p) : InsetCommand(p, "ref"), isLatex(buf.isLatex()) {} @@ -65,45 +65,13 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */) } -void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd) +docstring InsetRef::screenLabel() const { - switch (cmd.action) { - 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 - InsetCommand::doDispatch(cur, cmd); - break; - - default: - InsetCommand::doDispatch(cur, cmd); - } + return screen_label_; } -docstring const InsetRef::getScreenLabel(Buffer const &) 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; -} - - -int InsetRef::latex(Buffer const &, odocstream & os, - OutputParams const &) const +int InsetRef::latex(odocstream & os, OutputParams const &) const { // 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. @@ -114,8 +82,7 @@ int InsetRef::latex(Buffer const &, odocstream & os, } -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 << ']'; @@ -123,23 +90,22 @@ 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 << "" << getParam("name") << ""; @@ -149,39 +115,44 @@ int InsetRef::docbook(Buffer const & buf, odocstream & os, } -void InsetRef::textString(Buffer const & buf, odocstream & os) const +void InsetRef::textString(odocstream & os) const { - plaintext(buf, os, OutputParams(0)); + plaintext(os, OutputParams(0)); } -void InsetRef::addToToc(Buffer const & buf, - ParConstIterator const & cpit) const +void InsetRef::updateLabels(ParIterator const & it) { docstring const & label = getParam("reference"); - Toc & toc = buf.tocBackend().toc("label"); - Toc::iterator it = toc.begin(); - Toc::iterator end = toc.end(); - for (; it != end; ++it) { - if (it->str() == label) + // 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"); - docstring const reflabel = getScreenLabel(buf); - if (it == end) { - // This label has not been parsed yet so we just add it temporarily. - // InsetLabel::addTocToc() will fix that later. - toc.push_back(TocItem(cpit, 0, label)); - toc.push_back(TocItem(cpit, 1, reflabel)); - return; + 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; - // The Toc item for this label already exists so let's add - // this inset to this node. - ++it; - while (it != end && it->str() == reflabel) - ++it; - toc.insert(it, TocItem(cpit, 1, reflabel)); + // 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_)); }