From 2fdc6062482c2667d018fbf2ad4d7bb36b2abb9d Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 22 Nov 2005 13:52:25 +0000 Subject: [PATCH] fix bug 2126 (references in math) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10616 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 14 ++++++++++++++ src/mathed/command_inset.C | 7 +++++++ src/mathed/command_inset.h | 2 ++ src/mathed/math_hullinset.C | 17 +++++++++++++++++ src/mathed/math_nestinset.C | 22 +--------------------- src/mathed/ref_inset.C | 28 ++++++++++++++++++++++++++++ src/mathed/ref_inset.h | 3 +++ 7 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 804e5bcc2e..205ca8a5e2 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,17 @@ +2005-11-15 Georg Baum + + * command_inset.[Ch] (editXY): implement, since MathNestInset::editXY + loops through the cells and that is not possible here because they are + not visible + * math_hullinset.C (getStatus): allow reference and label in + LFUN_INSET_INSERT + * math_hullinset.C (doDispatch): create ref inset in LFUN_INSET_INSERT + * math_nestinset.C (doDispatch): allow references + * math_nestinset.C (doDispatch): remove never reached code for + LFUN_INSET_APPLY + * ref_inset.[Ch] (getStatus): implement, otherwise we'll trigger an + assertion in LyXFunc::getStatus + 2005-11-08 Georg Baum * math_parser.C (delEmptyLastRow): Don't delete the dummy row, but diff --git a/src/mathed/command_inset.C b/src/mathed/command_inset.C index 3e4c7f4055..40c38acc44 100644 --- a/src/mathed/command_inset.C +++ b/src/mathed/command_inset.C @@ -47,6 +47,13 @@ void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const } +InsetBase * CommandInset::editXY(LCursor & cur, int x, int y) +{ + edit(cur, true); + return this; +} + + void CommandInset::draw(PainterInfo & pi, int x, int y) const { button_.draw(pi, x, y); diff --git a/src/mathed/command_inset.h b/src/mathed/command_inset.h index b0de073df5..8872cfec91 100644 --- a/src/mathed/command_inset.h +++ b/src/mathed/command_inset.h @@ -28,6 +28,8 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// + InsetBase * editXY(LCursor &, int, int); + /// void write(WriteStream & os) const; // // void infoize(std::ostream & os) const; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index b264756962..12417efb4c 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -14,6 +14,7 @@ #include "math_colorinset.h" #include "math_data.h" #include "math_extern.h" +#include "math_factory.h" #include "math_hullinset.h" #include "math_mathmlstream.h" #include "math_streamstr.h" @@ -1075,7 +1076,14 @@ void MathHullInset::doDispatch(LCursor & cur, FuncRequest & cmd) cur.bv().buffer()->changeRefsIfUnique(old, str); label(r, str); } + break; } + MathArray ar; + if (createMathInset_fromDialogStr(cmd.argument, ar)) { + recordUndo(cur); + cur.insert(ar); + } else + cur.undispatched(); break; } @@ -1138,6 +1146,15 @@ bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_INSERT_LABEL: status.enabled(type_ != "simple"); return true; + case LFUN_INSET_INSERT: { + // Don't test createMathInset_fromDialogStr(), since + // getStatus is not called with a valid reference and the + // dialog would not be applyable. + string const name = cmd.getArg(0); + status.enabled(name == "ref" || + (name == "label" && type_ != "simple")); + break; + } case LFUN_TABULAR_FEATURE: { istringstream is(cmd.argument); string s; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index ec23d10bdc..c6ef7f2d51 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -30,6 +30,7 @@ #include "math_symbolinset.h" #include "math_support.h" #include "math_unknowninset.h" +#include "ref_inset.h" #include "BufferView.h" #include "CutAndPaste.h" @@ -56,7 +57,6 @@ using lyx::cap::copySelection; using lyx::cap::grabAndEraseSelection; using lyx::cap::cutSelection; -using lyx::cap::pasteSelection; using lyx::cap::replaceSelection; using lyx::cap::selClearOrDel; @@ -885,34 +885,14 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_DIALOG_SHOW_NEW_INSET: { string const & name = cmd.argument; string data; -#if 0 if (name == "ref") { RefInset tmp(name); data = tmp.createDialogStr(name); } -#endif cur.bv().owner()->getDialogs().show(name, data, 0); break; } - case LFUN_INSET_APPLY: { - string const name = cmd.getArg(0); - InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name); - - if (base) { - FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument); - base->dispatch(cur, fr); - break; - } - MathArray ar; - if (createMathInset_fromDialogStr(cmd.argument, ar)) { - cur.insert(ar); - break; - } - cur.undispatched(); - break; - } - default: MathDimInset::doDispatch(cur, cmd); break; diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C index 47734214da..3d33e81529 100644 --- a/src/mathed/ref_inset.C +++ b/src/mathed/ref_inset.C @@ -18,6 +18,7 @@ #include "cursor.h" #include "debug.h" #include "funcrequest.h" +#include "FuncStatus.h" #include "gettext.h" #include "math_data.h" #include "math_factory.h" @@ -70,6 +71,14 @@ void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd) cur.undispatched(); break; + case LFUN_INSET_DIALOG_UPDATE: { + string const data = createDialogStr("ref"); + if (cur.bv().owner()->getDialogs().visible("ref")) + cur.bv().owner()->getDialogs().update("ref", data); + break; + } + + case LFUN_INSET_DIALOG_SHOW: case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3) { lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl; @@ -97,6 +106,25 @@ void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd) } +bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & status) const +{ + switch (cmd.action) { + // we handle these + case LFUN_INSET_MODIFY: + case LFUN_INSET_DIALOG_UPDATE: + case LFUN_INSET_DIALOG_SHOW: + case LFUN_MOUSE_RELEASE: + case LFUN_MOUSE_PRESS: + case LFUN_MOUSE_MOTION: + status.enabled(true); + return true; + default: + return CommandInset::getStatus(cur, cmd, status); + } +} + + string const RefInset::screenLabel() const { string str; diff --git a/src/mathed/ref_inset.h b/src/mathed/ref_inset.h index 7e3c58ce2d..cf5298ef1a 100644 --- a/src/mathed/ref_inset.h +++ b/src/mathed/ref_inset.h @@ -55,7 +55,10 @@ public: /// static std::string const & getName(int type); protected: + /// virtual void doDispatch(LCursor & cur, FuncRequest & cmd); + /// + bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const; private: /// virtual std::auto_ptr doClone() const; -- 2.39.2