[LyX/master] Substack should not be allowed to change columns
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Mon Nov 21 10:38:14 UTC 2022
commit 593bfe248a15be99bfce7e12cde6c59c92951f5f
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Mon Nov 21 10:43:08 2022 +0100
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 <lorenzobertini97 at gmail.com>
Part of bug #12590.
---
src/mathed/InsetMathCases.cpp | 12 ++++--------
src/mathed/InsetMathSubstack.cpp | 27 +++++++++++++++++++++++++++
src/mathed/InsetMathSubstack.h | 2 ++
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/mathed/InsetMathCases.cpp b/src/mathed/InsetMathCases.cpp
index f9415db..082e956 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 11678b5..5db39c2 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 4f0a9e7..784e3f3 100644
--- a/src/mathed/InsetMathSubstack.h
+++ b/src/mathed/InsetMathSubstack.h
@@ -32,6 +32,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;
///
More information about the lyx-cvs
mailing list