Slightly improved version of same. Makes it nearly impossible to mess up
:-)

- Martin

Index: src/mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.153
diff -u -p -r1.153 math_nestinset.C
--- src/mathed/math_nestinset.C 25 Apr 2005 14:10:08 -0000      1.153
+++ src/mathed/math_nestinset.C 29 Apr 2005 16:31:06 -0000
@@ -865,6 +865,7 @@ bool MathNestInset::getStatus(LCursor & 
        // the font related toggles
        //string tc = "mathnormal";
        bool ret = true;
+       string const arg = cmd.argument;
        switch (cmd.action) {
        case LFUN_TABULAR_FEATURE:
                flag.enabled(false);
@@ -924,7 +925,25 @@ bool MathNestInset::getStatus(LCursor & 
        case LFUN_MATH_EXTERN:
                flag.enabled(true);
                break;
-
+       case LFUN_INSERT_MATH: {
+               bool const textarg = 
+                       arg == "\\textbf"   || arg == "\\textsf" ||
+                       arg == "\\textrm"   || arg == "\\textmd" ||
+                       arg == "\\textit"   || arg == "\\textsc" ||
+                       arg == "\\textsl"   || arg == "\\textup" ||
+                       arg == "\\texttt"   || arg == "\\textbb" ||
+                       arg == "\\textnormal";
+               flag.enabled(currentMode() == MATH_MODE && !textarg
+                       ||   currentMode() == TEXT_MODE && textarg);
+               break;
+       }
+       case LFUN_INSERT_MATRIX:
+               flag.enabled(currentMode() == MATH_MODE);
+               break;
+       case LFUN_MATH_MODE:
+               // i.e., "math-mode on" gets through in text mode
+               flag.enabled(currentMode() == MATH_MODE || !arg.empty());
+               break;
        default:
                ret = false;
                break;
@@ -1139,14 +1158,21 @@ bool MathNestInset::interpret(LCursor & 
                return cur.pos() != cur.lastpos();
        }
 
-       if (c == '_') {
-               script(cur, false);
-               return true;
-       }
+       // These shouldn't work in text mode:
+       if (currentMode() != MathInset::TEXT_MODE) {
+               if (c == '_') {
+                       script(cur, false);
+                       return true;
+               }
 
-       if (c == '^') {
-               script(cur, true);
-               return true;
+               if (c == '^') {
+                       script(cur, true);
+                       return true;
+               }
+               if (c == '~') {
+                       cur.niceInsert(createMathInset("sim"));
+                       return true;
+               }
        }
 
        if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == 
'%') {
@@ -1154,10 +1180,6 @@ bool MathNestInset::interpret(LCursor & 
                return true;
        }
 
-       if (c == '~') {
-               cur.niceInsert(createMathInset("sim"));
-               return true;
-       }
 
        // try auto-correction
        //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
Index: lib/ui/stdmenus.ui
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/stdmenus.ui,v
retrieving revision 1.45
diff -u -p -r1.45 stdmenus.ui
--- lib/ui/stdmenus.ui  25 Apr 2005 14:10:10 -0000      1.45
+++ lib/ui/stdmenus.ui  29 Apr 2005 16:31:06 -0000
@@ -320,7 +320,9 @@ Menuset
                Item "Text Small Caps Shape" "math-insert \textsc"
                Item "Text Slanted Shape" "math-insert \textsl"
                Item "Text Upright Shape" "math-insert \textup"
-                       End
+               Separator
+               Item "Text box" "math-mode"
+       End
 
        Menu "insert_float"
                FloatInsert

Attachment: pgpgara7qiU3i.pgp
Description: PGP signature

Reply via email to