]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacroTemplate.cpp
Fix build with GNU libstdc++ C++11 ABI
[lyx.git] / src / mathed / MathMacroTemplate.cpp
index e82de015bfddc0957ba69cd375a50565301acdda..485a060244bf65cd61613f8560e96c41e1da3d7b 100644 (file)
@@ -34,7 +34,6 @@
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "Lexer.h"
-#include "LyXRC.h" 
 
 #include "frontends/Painter.h"
 
@@ -465,7 +464,7 @@ docstring MathMacroTemplate::name() const
 }
 
 
-void MathMacroTemplate::updateToContext(MacroContext const & mc) const
+void MathMacroTemplate::updateToContext(MacroContext const & mc)
 {
        redefinition_ = mc.get(name()) != 0;
 }
@@ -551,13 +550,9 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
 
        // valid macro?
        MacroData const * macro = 0;
-       if (validName()) {
+       if (validName())
                macro = mi.macrocontext.get(name());
 
-               // updateToContext() - avoids another lookup
-               redefinition_ = macro != 0;
-       }
-
        // update look?
        int argsInDef = maxArgumentInDefinition();
        if (lookOutdated_ || argsInDef != argsInLook_) {
@@ -624,10 +619,13 @@ void MathMacroTemplate::edit(Cursor & cur, bool front, EntryDirection entry_from
 
 bool MathMacroTemplate::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
+       unsigned int const nargs_before = nargs();
        commitEditChanges(cur, old);
        updateLook();
        cur.screenUpdateFlags(Update::Force);
-       return InsetMathNest::notifyCursorLeaves(old, cur);
+       // If we have removed a cell, we might have invalidated the cursor
+       return InsetMathNest::notifyCursorLeaves(old, cur)
+               || nargs() < nargs_before;
 }
 
 
@@ -834,7 +832,7 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
                MathMacro * macro = insetMath->asMacro();
                if (macro && macro->name() == name && macro->folded()) {
                        fix(macro);
-                       if (RenderPreview::status() == LyXRC::PREVIEW_ON)
+                       if (RenderPreview::previewMath())
                                preview_reload_needed = true;
                }
        }
@@ -859,7 +857,9 @@ void MathMacroTemplate::commitEditChanges(Cursor & cur,
 {
        int args_in_def = maxArgumentInDefinition();
        if (args_in_def != numargs_) {
-               cur.recordUndoFullDocument();
+               // FIXME: implement precise undo handling (only a few places
+               //   need undo)
+               cur.recordUndoFullBuffer();
                changeArity(cur, inset_pos, args_in_def);
        }
        insertMissingArguments(args_in_def);
@@ -875,7 +875,7 @@ void MathMacroTemplate::insertParameter(Cursor & cur,
 {
        if (pos <= numargs_ && pos >= optionals_ && numargs_ < 9) {
                ++numargs_;
-               
+
                // append example #n
                if (addarg) {
                        shiftArguments(pos, 1);
@@ -992,7 +992,9 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MACRO_ADD_PARAM:
                if (numargs_ < 9) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        size_t pos = numargs_;
                        if (!arg.empty())
                                pos = (size_t)convert<int>(arg) - 1; // it is checked for >=0 in getStatus
@@ -1004,7 +1006,9 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MACRO_REMOVE_PARAM:
                if (numargs_ > 0) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        size_t pos = numargs_ - 1;
                        if (!arg.empty())
                                pos = (size_t)convert<int>(arg) - 1; // it is checked for >=0 in getStatus
@@ -1015,7 +1019,9 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MACRO_APPEND_GREEDY_PARAM:
                if (numargs_ < 9) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        insertParameter(cur, cur, numargs_, true);
                }
                break;
@@ -1023,27 +1029,35 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM:
                if (numargs_ > 0) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        removeParameter(cur, cur, numargs_ - 1, true);
                }
                break;
 
        case LFUN_MATH_MACRO_MAKE_OPTIONAL:
                commitEditChanges(cur, cur);
-               cur.recordUndoFullDocument();
+               // FIXME: implement precise undo handling (only a few places
+               //   need undo)
+               cur.recordUndoFullBuffer();
                makeOptional(cur, cur);
                break;
 
        case LFUN_MATH_MACRO_MAKE_NONOPTIONAL:
                commitEditChanges(cur, cur);
-               cur.recordUndoFullDocument();
+               // FIXME: implement precise undo handling (only a few places
+               //   need undo)
+               cur.recordUndoFullBuffer();
                makeNonOptional(cur, cur);
                break;
 
        case LFUN_MATH_MACRO_ADD_OPTIONAL_PARAM:
                if (numargs_ < 9) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        insertParameter(cur, cur, optionals_);
                        makeOptional(cur, cur);
                }
@@ -1052,14 +1066,18 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MACRO_REMOVE_OPTIONAL_PARAM:
                if (optionals_ > 0) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        removeParameter(cur, cur, optionals_ - 1);
                } break;
 
        case LFUN_MATH_MACRO_ADD_GREEDY_OPTIONAL_PARAM:
                if (numargs_ == optionals_) {
                        commitEditChanges(cur, cur);
-                       cur.recordUndoFullDocument();
+                       // FIXME: implement precise undo handling (only a few places
+                       //   need undo)
+                       cur.recordUndoFullBuffer();
                        insertParameter(cur, cur, 0, true);
                        makeOptional(cur, cur);
                }
@@ -1072,7 +1090,7 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
 }
 
 
-bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
+bool MathMacroTemplate::getStatus(Cursor & cur, FuncRequest const & cmd,
        FuncStatus & flag) const
 {
        bool ret = true;
@@ -1130,7 +1148,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
                        break;
 
                default:
-                       ret = false;
+                       ret = InsetMathNest::getStatus(cur, cmd, flag);
                        break;
        }
        return ret;
@@ -1255,7 +1273,7 @@ docstring MathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
 int MathMacroTemplate::plaintext(odocstringstream & os,
                                 OutputParams const &, size_t) const
 {
-       static docstring const str = '[' + buffer().B_("math macro") + ']';
+       docstring const str = '[' + buffer().B_("math macro") + ']';
 
        os << str;
        return str.size();
@@ -1362,7 +1380,7 @@ size_t MathMacroTemplate::numOptionals() const
 
 void MathMacroTemplate::infoize(odocstream & os) const
 {
-       os << "Math Macro: \\" << name();
+       os << bformat(_("Math Macro: \\%1$s"), name());
 }