]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.cpp
make Pavel happy
[lyx.git] / src / mathed / InsetMathNest.cpp
index f2d8d2ac7641a51e65873b2c55c17aafeb772f29..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"
@@ -513,9 +518,16 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "InsetMathNest: request: " << cmd << endl;
 
+       Parse::flags parseflg = Parse::QUIET;
+
        switch (cmd.action) {
 
+       case LFUN_CLIPBOARD_PASTE:
+               parseflg |= Parse::VERBATIM;
+               // fall through
        case LFUN_PASTE: {
+               if (cur.currentMode() == TEXT_MODE)
+                       parseflg |= Parse::TEXTMODE;
                cur.recordUndoSelection();
                cur.message(_("Paste"));
                replaceSelection(cur);
@@ -528,7 +540,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                        is >> n;
                        topaste = cap::selection(n);
                }
-               cur.niceInsert(topaste);
+               cur.niceInsert(topaste, parseflg);
                cur.clearSelection(); // bug 393
                cur.finishUndo();
                break;
@@ -828,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: {
@@ -957,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);
@@ -1026,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:
@@ -1102,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;
@@ -1245,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;
        }
 
@@ -1387,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;
@@ -1413,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;
@@ -1428,6 +1462,9 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
                                        cur.niceInsert(createInsetMath("textbackslash"));
                                else
                                        cur.niceInsert(createInsetMath("backslash"));
+                       } else if (c == '^' && currentMode() == InsetMath::MATH_MODE) {
+                               cur.backspace();
+                               cur.niceInsert(createInsetMath("mathcircumflex"));
                        } else if (c == '{') {
                                cur.backspace();
                                cur.niceInsert(MathAtom(new InsetMathBrace));
@@ -1486,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
@@ -1557,7 +1594,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
                return cur.pos() != cur.lastpos();
        }
 
-       // These shouldn't work in text mode:
+       // These should be treated differently when not in text mode:
        if (currentMode() != InsetMath::TEXT_MODE) {
                if (c == '_') {
                        script(cur, false, save_selection);
@@ -1571,18 +1608,29 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
                        cur.niceInsert(createInsetMath("sim"));
                        return true;
                }
+       } else {
+               if (c == '^') {
+                       cur.niceInsert(createInsetMath("textasciicircum"));
+                       return true;
+               }
+               if (c == '~') {
+                       cur.niceInsert(createInsetMath("textasciitilde"));
+                       return true;
+               }
        }
 
        if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
-           c == '%' || c == '_' || c == '^') {
+           c == '%' || c == '_') {
                cur.niceInsert(createInsetMath(docstring(1, c)));
                return true;
        }
 
 
+#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);
@@ -1808,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());