]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacroTemplate.cpp
tex2lyx: support for \item with opt arg in itemize environment
[lyx.git] / src / mathed / MathMacroTemplate.cpp
index 3687bd185a8fa3ed5cb757457d68e06524637a9e..ce3494c61ad1c5b7456e760a4098ddb4fb54fd38 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;
 }
 
 
@@ -737,14 +735,14 @@ public:
        ///
        AddRemoveMacroInstanceFix(int n, bool insert) : n_(n), insert_(insert) {}
        ///
-       bool operator()(MathMacro * macro) {
+       void operator()(MathMacro * macro)
+       {
                if (macro->folded()) {
                        if (insert_)
                                macro->insertArgument(n_);
                        else
                                macro->removeArgument(n_);
                }
-               return true;
        }
 
 private:
@@ -762,9 +760,9 @@ public:
        ///
        OptionalsMacroInstanceFix(int optionals) : optionals_(optionals) {}
        ///
-       bool operator()(MathMacro * macro) {
+       void operator()(MathMacro * macro)
+       {
                macro->setOptionals(optionals_);
-               return true;
        }
 
 private:
@@ -778,7 +776,7 @@ class NullMacroInstanceFix
 {
 public:
        ///
-       bool operator()(MathMacro * ) { return false; }
+       void operator()(MathMacro * ) {}
 };
 
 
@@ -833,7 +831,8 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
 
                MathMacro * macro = insetMath->asMacro();
                if (macro && macro->name() == name && macro->folded()) {
-                       if (fix(macro) && RenderPreview::status() == LyXRC::PREVIEW_ON)
+                       fix(macro);
+                       if (RenderPreview::previewMath())
                                preview_reload_needed = true;
                }
        }
@@ -845,7 +844,7 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
                for (; sit != end; ++sit) {
                        InsetMathHull * inset_hull =
                                sit->nextInset()->asInsetMath()->asHullInset();
-                       LASSERT(inset_hull, /**/);
+                       LBUFERR(inset_hull);
                        inset_hull->reloadPreview(*sit);
                }
                cur.screenUpdateFlags(Update::Force);
@@ -993,7 +992,7 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
                        commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
                        size_t pos = numargs_;
-                       if (arg.size() != 0)
+                       if (!arg.empty())
                                pos = (size_t)convert<int>(arg) - 1; // it is checked for >=0 in getStatus
                        insertParameter(cur, cur, pos);
                }
@@ -1005,7 +1004,7 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
                        commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
                        size_t pos = numargs_ - 1;
-                       if (arg.size() != 0)
+                       if (!arg.empty())
                                pos = (size_t)convert<int>(arg) - 1; // it is checked for >=0 in getStatus
                        removeParameter(cur, cur, pos);
                }
@@ -1079,7 +1078,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
        switch (cmd.action()) {
                case LFUN_MATH_MACRO_ADD_PARAM: {
                        int num = numargs_ + 1;
-                       if (arg.size() != 0)
+                       if (!arg.empty())
                                num = convert<int>(arg);
                        bool on = (num >= optionals_
                                   && numargs_ < 9 && num <= numargs_ + 1);
@@ -1094,7 +1093,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
                case LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM:
                case LFUN_MATH_MACRO_REMOVE_PARAM: {
                        int num = numargs_;
-                       if (arg.size() != 0)
+                       if (!arg.empty())
                                num = convert<int>(arg);
                        flag.setEnabled(num >= 1 && num <= numargs_);
                        break;
@@ -1251,8 +1250,8 @@ docstring MathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
        return docstring();
 }
 
-int MathMacroTemplate::plaintext(odocstream & os,
-                                OutputParams const &) const
+int MathMacroTemplate::plaintext(odocstringstream & os,
+                                OutputParams const &, size_t) const
 {
        static docstring const str = '[' + buffer().B_("math macro") + ']';
 
@@ -1265,8 +1264,7 @@ bool MathMacroTemplate::validName() const
 {
        docstring n = name();
 
-       // empty name?
-       if (n.size() == 0)
+       if (n.empty())
                return false;
 
        // converting back and force doesn't swallow anything?
@@ -1315,7 +1313,7 @@ bool MathMacroTemplate::fixNameAndCheckIfValid()
        }
 
        // now it should be valid if anything in the name survived
-       return data.size() > 0;
+       return !data.empty();
 }
 
        
@@ -1366,9 +1364,9 @@ void MathMacroTemplate::infoize(odocstream & os) const
 }
 
 
-docstring MathMacroTemplate::contextMenuName() const
+string MathMacroTemplate::contextMenuName() const
 {
-       return from_ascii("context-math-macro-definition");
+       return "context-math-macro-definition";
 }
 
 } // namespace lyx