]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.cpp
make Pavel happy
[lyx.git] / src / mathed / InsetMathNest.cpp
index ffde2ad45fba967544306d14f501f5548c13237b..837b6234e1364d191fe4170469639a02786b64d1 100644 (file)
@@ -3,13 +3,15 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
+//#define AUTOCORRECT
+
 #include "InsetMathNest.h"
 
 #include "InsetMathArray.h"
@@ -25,6 +27,9 @@
 #include "InsetMathSpace.h"
 #include "InsetMathSymbol.h"
 #include "InsetMathUnknown.h"
+#ifdef AUTOCORRECT
+#include "MathAutoCorrect.h"
+#endif
 #include "MathCompletionList.h"
 #include "MathData.h"
 #include "MathFactory.h"
@@ -835,7 +840,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: {
@@ -964,6 +968,23 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_REGEXP_MODE: {
+               InsetMathHull * i = dynamic_cast<InsetMathHull *>(cur.inset().asInsetMath());
+               if (i && i->getType() == hullRegexp) {
+                       cur.message(_("Already in regexp mode"));
+                       break;
+               }
+               cur.macroModeClose();
+               docstring const save_selection = grabAndEraseSelection(cur);
+               selClearOrDel(cur);
+               cur.plainInsert(MathAtom(new InsetMathHull(hullRegexp)));
+               cur.posBackward();
+               cur.pushBackward(*cur.nextInset());
+               cur.niceInsert(save_selection);
+               cur.message(_("Regexp editor mode"));
+               break;
+       }
+
        case LFUN_MATH_SIZE: {
                FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, cmd.argument());
                doDispatch(cur, fr);
@@ -1033,15 +1054,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:
@@ -1109,6 +1133,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;
@@ -1252,7 +1279,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;
        }
 
@@ -1394,7 +1421,7 @@ void InsetMathNest::lfunMouseRelease(Cursor & cur, FuncRequest & cmd)
 }
 
 
-bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
+bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
 {
        //lyxerr << "interpret 2: '" << c << "'" << endl;
        docstring save_selection;
@@ -1420,7 +1447,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
                MathWordList const & mwl = mathedWordList();
                bool star_macro = c == '*'
                        && (mwl.find(name.substr(1) + "*") != mwl.end()
-                           || cur.buffer().getMacro(name.substr(1) + "*", cur, true));
+                           || cur.buffer()->getMacro(name.substr(1) + "*", cur, true));
                if (isAlphaASCII(c) || star_macro) {
                        cur.activeMacro()->setName(name + docstring(1, c));
                        return true;
@@ -1496,10 +1523,10 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
        // This is annoying as one has to press <space> far too often.
        // Disable it.
 
-#if 0
+#ifdef AUTOCORRECT
                // leave autocorrect mode if necessary
-               if (autocorrect() && c == ' ') {
-                       autocorrect() = false;
+               if (cur.autocorrect() && c == ' ') {
+                       cur.autocorrect() = false;
                        return true;
                }
 #endif
@@ -1599,9 +1626,11 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
        }
 
 
+#ifdef AUTOCORRECT
        // try auto-correction
-       //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
-       //      return true;
+       if (cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c))
+               return true;
+#endif
 
        // no special circumstances, so insert the character without any fuss
        cur.insert(c);
@@ -1827,10 +1856,10 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
 {
        // fill it with macros from the buffer
        MacroNameSet macros;
-       cur.buffer().listMacroNames(macros);
+       cur.buffer()->listMacroNames(macros);
        MacroNameSet::const_iterator it;
        for (it = macros.begin(); it != macros.end(); ++it) {
-               if (cur.buffer().getMacro(*it, cur, false))
+               if (cur.buffer()->getMacro(*it, cur, false))
                        locals.push_back("\\" + *it);
        }
        sort(locals.begin(), locals.end());