From: Jean-Marc Lasgouttes Date: Mon, 21 Nov 2022 09:43:08 +0000 (+0100) Subject: Substack should not be allowed to change columns X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=593bfe248a15be99bfce7e12cde6c59c92951f5f;p=features.git Substack should not be allowed to change columns Disable the arguments append-column and delete-column of tabular-features. The code is taken from InsetMathCases, with some changes * no need to record undo here * in dispatch, return is prefered to break, since we do not want to invoke InsetMathGrid::doDispatch. Propagate these changes to InsetMathCases. Cleanup of the InsetMathCases error messages to fit with other parts of the code. The handling of tabular-features in mathed needs to be unified somehow. Based on a commit from lynx Part of bug #12590. --- diff --git a/src/mathed/InsetMathCases.cpp b/src/mathed/InsetMathCases.cpp index f9415dbeac..082e956f13 100644 --- a/src/mathed/InsetMathCases.cpp +++ b/src/mathed/InsetMathCases.cpp @@ -61,19 +61,15 @@ void InsetMathCases::draw(PainterInfo & pi, int x, int y) const void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd) { - //lyxerr << "*** InsetMathCases: request: " << cmd << endl; switch (cmd.action()) { case LFUN_TABULAR_FEATURE: { string s = cmd.getArg(0); // vertical lines and adding/deleting columns is not allowed for \cases - // FIXME: "I suspect that the break after cur.undispatched() should be a - // return; the recordUndo seems bogus too." (lasgouttes) if (s == "append-column" || s == "delete-column" || s == "add-vline-left" || s == "add-vline-right") { cur.undispatched(); - break; + return; } - cur.recordUndo(); } default: break; @@ -91,15 +87,15 @@ bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd, if (s == "add-vline-left" || s == "add-vline-right") { flag.setEnabled(false); flag.message(bformat( - from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")), - from_utf8(s))); + from_utf8(N_("Can't add vertical grid lines in '%1$s'")), + from_utf8("cases"))); return true; } if (s == "append-column" || s == "delete-column") { flag.setEnabled(false); flag.message(bformat( from_utf8(N_("Changing number of columns not allowed in " - "'cases': feature %1$s")), from_utf8(s))); + "'%1$s'")), from_utf8("cases"))); return true; } break; diff --git a/src/mathed/InsetMathSubstack.cpp b/src/mathed/InsetMathSubstack.cpp index 11678b559d..5db39c2e5a 100644 --- a/src/mathed/InsetMathSubstack.cpp +++ b/src/mathed/InsetMathSubstack.cpp @@ -15,6 +15,7 @@ #include "MathData.h" #include "MathStream.h" +#include "Cursor.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LaTeXFeatures.h" @@ -59,6 +60,24 @@ void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const } +void InsetMathSubstack::doDispatch(Cursor & cur, FuncRequest & cmd) +{ + switch (cmd.action()) { + case LFUN_TABULAR_FEATURE: { + string s = cmd.getArg(0); + if (s == "append-column" || s == "delete-column" + || s == "add-vline-left" || s == "add-vline-right") { + cur.undispatched(); + return; + } + } + default: + break; + } + InsetMathGrid::doDispatch(cur, cmd); +} + + bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { @@ -81,6 +100,14 @@ bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(false); return true; } + // disallow changing number of columns + if (s == "append-column" || s == "delete-column") { + flag.setEnabled(false); + flag.message(bformat( + from_utf8(N_("Changing number of columns not allowed in " + "'%1$s'")), from_utf8("substack"))); + return true; + } break; } diff --git a/src/mathed/InsetMathSubstack.h b/src/mathed/InsetMathSubstack.h index 4f0a9e79db..784e3f3d54 100644 --- a/src/mathed/InsetMathSubstack.h +++ b/src/mathed/InsetMathSubstack.h @@ -31,6 +31,8 @@ public: /// InsetMathSubstack const * asSubstackInset() const override { return this; } + /// + void doDispatch(Cursor & cur, FuncRequest & cmd) override; /// bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const override;