]> git.lyx.org Git - features.git/commitdiff
Substack should not be allowed to change columns
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 21 Nov 2022 09:43:08 +0000 (10:43 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 21 Nov 2022 11:08:17 +0000 (12:08 +0100)
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.

src/mathed/InsetMathCases.cpp
src/mathed/InsetMathSubstack.cpp
src/mathed/InsetMathSubstack.h

index f9415dbeaccdf71810bc9e46aa573af605bbb449..082e956f1326912aeccee915942b19c4f4e6b45b 100644 (file)
@@ -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;
index 11678b559d91226093474bbe052d1477fed7ad90..5db39c2e5a1b3c15faa41123350659c20a5f9e90 100644 (file)
@@ -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;
        }
 
index 4f0a9e79dbac090eca76bf601d905ac295b36228..784e3f3d54a39a10d735703b74ba8fffb65f353d 100644 (file)
@@ -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;