X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathRef.cpp;h=22807f15b533a5be5eb829e192d0089ff0a125ad;hb=28be7d552f62cc02fa86d7f79201d089bfb2d7b5;hp=e66aa89f2d2d3bdcd09818a9ad132db95f1ba18f;hpb=42123ab8a71080b6d15fca4e0c43ae76abf00a1e;p=lyx.git diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp index e66aa89f2d..22807f15b5 100644 --- a/src/mathed/InsetMathRef.cpp +++ b/src/mathed/InsetMathRef.cpp @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ @@ -13,58 +13,60 @@ #include "InsetMathRef.h" #include "BufferView.h" -#include "LaTeXFeatures.h" #include "Buffer.h" #include "Cursor.h" -#include "debug.h" #include "FuncRequest.h" #include "FuncStatus.h" -#include "gettext.h" -#include "MathArray.h" +#include "LaTeXFeatures.h" +#include "LyX.h" +#include "MathData.h" #include "MathFactory.h" #include "MathSupport.h" #include "OutputParams.h" +#include "ParIterator.h" #include "sgml.h" #include "insets/InsetCommand.h" +#include "support/debug.h" +#include "support/gettext.h" -namespace lyx { +#include -using std::string; -using std::auto_ptr; -using std::endl; +using namespace std; +namespace lyx { -RefInset::RefInset() - : CommandInset(from_ascii("ref")) +InsetMathRef::InsetMathRef(Buffer * buf) + : CommandInset(buf, from_ascii("ref"), false) {} -RefInset::RefInset(docstring const & data) - : CommandInset(data) +InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data) + : CommandInset(buf, data, false) {} -auto_ptr RefInset::doClone() const +Inset * InsetMathRef::clone() const { - return auto_ptr(new RefInset(*this)); + return new InsetMathRef(*this); } -void RefInset::infoize(odocstream & os) const +void InsetMathRef::infoize(odocstream & os) const { os << "Ref: " << cell(0); } -void RefInset::doDispatch(Cursor & cur, FuncRequest & cmd) +void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd) { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "ref") { - MathArray ar; + MathData ar; if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { + cur.recordUndo(); *this = *ar[0].nucleus()->asRefInset(); break; } @@ -73,28 +75,43 @@ void RefInset::doDispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_INSET_DIALOG_UPDATE: { - string const data = createDialogStr("ref"); + string const data = createDialogStr(); cur.bv().updateDialog("ref", data); break; } case LFUN_MOUSE_RELEASE: + if (cur.selection()) { + cur.undispatched(); + break; + } if (cmd.button() == mouse_button::button3) { - lyxerr << "trying to goto ref '" << to_utf8(asString(cell(0))) << "'" << endl; - cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0)))); + LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'"); + //FIXME: use DispatchResult argument + lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0)))); break; } if (cmd.button() == mouse_button::button1) { // Eventually trigger dialog with button 3, not 1 - string const data = createDialogStr("ref"); - cur.bv().showInsetDialog("ref", data, this); + string const data = createDialogStr(); + cur.bv().showDialog("ref", data, this); break; } cur.undispatched(); break; - case LFUN_MOUSE_PRESS: - case LFUN_MOUSE_MOTION: + case LFUN_MOUSE_PRESS: { + bool do_selection = cmd.button() == mouse_button::button1 + && cmd.modifier() == ShiftModifier; + // For some reason the cursor points inside the first cell, which is not + // active. + cur.leaveInset(*this); + cur.bv().mouseSetCursor(cur, do_selection); + break; + } + + case LFUN_MOUSE_DOUBLE: + case LFUN_MOUSE_TRIPLE: // eat other mouse commands break; @@ -105,17 +122,18 @@ void RefInset::doDispatch(Cursor & cur, FuncRequest & cmd) } -bool RefInset::getStatus(Cursor & cur, FuncRequest const & cmd, +bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { - switch (cmd.action) { + switch (cmd.action()) { // we handle these case LFUN_INSET_MODIFY: case LFUN_INSET_DIALOG_UPDATE: case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_PRESS: - case LFUN_MOUSE_MOTION: - status.enabled(true); + case LFUN_MOUSE_DOUBLE: + case LFUN_MOUSE_TRIPLE: + status.setEnabled(true); return true; default: return CommandInset::getStatus(cur, cmd, status); @@ -123,7 +141,7 @@ bool RefInset::getStatus(Cursor & cur, FuncRequest const & cmd, } -docstring const RefInset::screenLabel() const +docstring const InsetMathRef::screenLabel() const { docstring str; for (int i = 0; !types[i].latex_name.empty(); ++i) { @@ -142,28 +160,29 @@ docstring const RefInset::screenLabel() const } -void RefInset::validate(LaTeXFeatures & features) const +void InsetMathRef::validate(LaTeXFeatures & features) const { if (commandname() == "vref" || commandname() == "vpageref") features.require("varioref"); else if (commandname() == "prettyref") features.require("prettyref"); + else if (commandname() == "eqref") + features.require("amsmath"); } -int RefInset::docbook(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const +int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const { if (cell(1).empty()) { os << ""; else os << "\">"; } else { os << "" << asString(cell(1)) << ""; @@ -173,18 +192,52 @@ int RefInset::docbook(Buffer const & buf, odocstream & os, } -string const RefInset::createDialogStr(string const & name) const +void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/) +{ + if (!buffer_) { + LYXERR0("InsetMathRef::updateBuffer: no buffer_!"); + return; + } + // register this inset into the buffer reference cache. + buffer().addReference(getTarget(), this, it); +} + + +string const InsetMathRef::createDialogStr() const { - InsetCommandParams icp(to_ascii(commandname())); + InsetCommandParams icp(REF_CODE, to_ascii(commandname())); icp["reference"] = asString(cell(0)); if (!cell(1).empty()) icp["name"] = asString(cell(1)); - return InsetCommandMailer::params2string(name, icp); + return InsetCommand::params2string(icp); +} + + +docstring const InsetMathRef::getTarget() const +{ + return asString(cell(0)); +} + + +void InsetMathRef::changeTarget(docstring const & target) +{ + InsetCommandParams icp(REF_CODE, to_ascii(commandname())); + icp["reference"] = target; + if (!cell(1).empty()) + icp["name"] = asString(cell(1)); + MathData ar; + Buffer & buf = buffer(); + if (createInsetMath_fromDialogStr( + from_utf8(InsetCommand::params2string(icp)), ar)) { + *this = *ar[0].nucleus()->asRefInset(); + // FIXME audit setBuffer calls + setBuffer(buf); + } } -RefInset::ref_type_info RefInset::types[] = { - { from_ascii("ref"), from_ascii(N_("Standard")), from_ascii(N_("Ref: "))}, +InsetMathRef::ref_type_info InsetMathRef::types[] = { + { from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))}, { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))}, { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))}, { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},