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@gmail.com>

Part of bug #12590.
This commit is contained in:
Jean-Marc Lasgouttes 2022-11-21 10:43:08 +01:00
parent 1482e174df
commit 593bfe248a
3 changed files with 33 additions and 8 deletions

View File

@ -61,19 +61,15 @@ void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd) void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
{ {
//lyxerr << "*** InsetMathCases: request: " << cmd << endl;
switch (cmd.action()) { switch (cmd.action()) {
case LFUN_TABULAR_FEATURE: { case LFUN_TABULAR_FEATURE: {
string s = cmd.getArg(0); string s = cmd.getArg(0);
// vertical lines and adding/deleting columns is not allowed for \cases // 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" if (s == "append-column" || s == "delete-column"
|| s == "add-vline-left" || s == "add-vline-right") { || s == "add-vline-left" || s == "add-vline-right") {
cur.undispatched(); cur.undispatched();
break; return;
} }
cur.recordUndo();
} }
default: default:
break; break;
@ -91,15 +87,15 @@ bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
if (s == "add-vline-left" || s == "add-vline-right") { if (s == "add-vline-left" || s == "add-vline-right") {
flag.setEnabled(false); flag.setEnabled(false);
flag.message(bformat( flag.message(bformat(
from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")), from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
from_utf8(s))); from_utf8("cases")));
return true; return true;
} }
if (s == "append-column" || s == "delete-column") { if (s == "append-column" || s == "delete-column") {
flag.setEnabled(false); flag.setEnabled(false);
flag.message(bformat( flag.message(bformat(
from_utf8(N_("Changing number of columns not allowed in " from_utf8(N_("Changing number of columns not allowed in "
"'cases': feature %1$s")), from_utf8(s))); "'%1$s'")), from_utf8("cases")));
return true; return true;
} }
break; break;

View File

@ -15,6 +15,7 @@
#include "MathData.h" #include "MathData.h"
#include "MathStream.h" #include "MathStream.h"
#include "Cursor.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "FuncStatus.h" #include "FuncStatus.h"
#include "LaTeXFeatures.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, bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const FuncStatus & flag) const
{ {
@ -81,6 +100,14 @@ bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(false); flag.setEnabled(false);
return true; 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; break;
} }

View File

@ -31,6 +31,8 @@ public:
/// ///
InsetMathSubstack const * asSubstackInset() const override { return this; } InsetMathSubstack const * asSubstackInset() const override { return this; }
///
void doDispatch(Cursor & cur, FuncRequest & cmd) override;
/// ///
bool getStatus(Cursor & cur, FuncRequest const & cmd, bool getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const override; FuncStatus & flag) const override;