]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / InsetMathNest.cpp
index d7d641515d82c9a128dd0d098effef977ba00be1..4f3656a7364e4b6dee7c582fe3cf3f6ec8187d01 100644 (file)
@@ -25,6 +25,7 @@
 #include "InsetMathSpace.h"
 #include "InsetMathSymbol.h"
 #include "InsetMathUnknown.h"
+#include "MathAutoCorrect.h"
 #include "MathCompletionList.h"
 #include "MathData.h"
 #include "MathFactory.h"
@@ -628,7 +629,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                // Now that we know exactly what we want to do, let's do it!
                cur.selHandle(select);
-               cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
                // try moving forward or backwards as necessary...
@@ -835,7 +835,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        //case LFUN_SERVER_GET_XY:
-       //      sprintf(dispatch_buffer, "%d %d",);
        //      break;
 
        case LFUN_SERVER_SET_XY: {
@@ -981,6 +980,12 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_MATH_FONT_STYLE: {
+               FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, '\\' + cmd.argument());
+               doDispatch(cur, fr);
+               break;
+       }
+
        case LFUN_MATH_SIZE: {
                FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, cmd.argument());
                doDispatch(cur, fr);
@@ -1050,15 +1055,18 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_SPACE_INSERT:
                cur.recordUndoSelection();
-               cur.insert(MathAtom(new InsetMathSpace(from_ascii(","))));
+               cur.insert(MathAtom(new InsetMathSpace));
                break;
 
        case LFUN_MATH_SPACE:
                cur.recordUndoSelection();
                if (cmd.argument().empty())
-                       cur.insert(MathAtom(new InsetMathSpace(from_ascii(","))));
-               else
-                       cur.insert(MathAtom(new InsetMathSpace(cmd.argument())));
+                       cur.insert(MathAtom(new InsetMathSpace));
+               else {
+                       string const name = cmd.getArg(0);
+                       string const len = cmd.getArg(1);
+                       cur.insert(MathAtom(new InsetMathSpace(name, len)));
+               }
                break;
 
        case LFUN_ERT_INSERT:
@@ -1126,6 +1134,9 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                if (name == "ref") {
                        InsetMathRef tmp(name);
                        data = tmp.createDialogStr(to_utf8(name));
+               } else if (name == "mathspace") {
+                       InsetMathSpace tmp;
+                       data = tmp.createDialogStr();
                }
                cur.bv().showDialog(to_utf8(name), data);
                break;
@@ -1248,18 +1259,22 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
                flag.setEnabled(currentMode() != TEXT_MODE);
                break;
 
-       case LFUN_MATH_INSERT: {
+       case LFUN_MATH_FONT_STYLE: {
                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";
+                       arg == "textbf"   || arg == "textsf" ||
+                       arg == "textrm"   || arg == "textmd" ||
+                       arg == "textit"   || arg == "textsc" ||
+                       arg == "textsl"   || arg == "textup" ||
+                       arg == "texttt"   || arg == "textbb" ||
+                       arg == "textnormal";
                flag.setEnabled(currentMode() != TEXT_MODE || textarg);
                break;
        }
 
+       case LFUN_MATH_INSERT:
+               flag.setEnabled(currentMode() != TEXT_MODE);
+               break;
+
        case LFUN_MATH_MATRIX:
                flag.setEnabled(currentMode() == MATH_MODE);
                break;
@@ -1269,7 +1284,7 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
                // getStatus is not called with a valid reference and the
                // dialog would not be applyable.
                string const name = cmd.getArg(0);
-               flag.setEnabled(name == "ref");
+               flag.setEnabled(name == "ref" || name == "mathspace");
                break;
        }
 
@@ -1510,16 +1525,18 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
                return true;
        }
 
-       // This is annoying as one has to press <space> far too often.
-       // Disable it.
 
-#if 0
-               // leave autocorrect mode if necessary
-               if (autocorrect() && c == ' ') {
-                       autocorrect() = false;
-                       return true;
-               }
-#endif
+       // leave autocorrect mode if necessary
+       if (lyxrc.autocorrection_math && c == ' ' && cur.autocorrect()) {
+               cur.autocorrect() = false;
+               cur.message(_("Autocorrect Off ('!' to enter)"));
+               return true;
+       } 
+       if (lyxrc.autocorrection_math && c == '!' && !cur.autocorrect()) {
+               cur.autocorrect() = true;
+               cur.message(_("Autocorrect On (<space> to exit)"));
+               return true;
+       }
 
        // just clear selection on pressing the space bar
        if (cur.selection() && c == ' ') {
@@ -1617,12 +1634,18 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
 
 
        // try auto-correction
-       //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
-       //      return true;
+       if (lyxrc.autocorrection_math && cur.autocorrect() && cur.pos() != 0
+                 && math_autocorrect(cur.prevAtom(), c))
+               return true;
 
        // no special circumstances, so insert the character without any fuss
        cur.insert(c);
-       cur.autocorrect() = true;
+       if (lyxrc.autocorrection_math) {
+               if (!cur.autocorrect())
+                       cur.message(_("Autocorrect Off ('!' to enter)"));
+               else
+                       cur.message(_("Autocorrect On (<space> to exit)"));
+       }
        return true;
 }
 
@@ -1905,6 +1928,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
        globals.push_back(from_ascii("\\color"));
        globals.push_back(from_ascii("\\normalcolor"));
        globals.push_back(from_ascii("\\textcolor"));
+       globals.push_back(from_ascii("\\cfrac"));
        globals.push_back(from_ascii("\\dfrac"));
        globals.push_back(from_ascii("\\tfrac"));
        globals.push_back(from_ascii("\\dbinom"));