X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathMacro.cpp;h=f4150f30f84250533ff313105aa5ebfda07605cb;hb=ff85a4902ec4fff1b3bf0dbc9c9c53b3e87563cf;hp=fe6e9188b0bd8b188c5fe96f7f23d7da54fc12bf;hpb=d79225ae987164c59d92621f5f7de203d3179c4c;p=lyx.git diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index fe6e9188b0..f4150f30f8 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -36,11 +36,13 @@ #include "support/debug.h" #include "support/gettext.h" #include "support/lassert.h" +#include "support/lstrings.h" #include "support/textutils.h" #include #include +using namespace lyx::support; using namespace std; namespace lyx { @@ -126,7 +128,8 @@ private: MathMacro::MathMacro(Buffer * buf, docstring const & name) : InsetMathNest(buf, 0), name_(name), displayMode_(DISPLAY_INIT), expanded_(buf), attachedArgsNum_(0), optionals_(0), nextFoldMode_(true), - macroBackup_(buf), macro_(0), needsUpdate_(false), appetite_(9) + macroBackup_(buf), macro_(0), needsUpdate_(false), + isUpdating_(false), appetite_(9) {} @@ -312,9 +315,27 @@ void MathMacro::updateMacro(MacroContext const & mc) } +class MathMacro::UpdateLocker +{ +public: + explicit UpdateLocker(MathMacro & mm) : mac(mm) + { + mac.isUpdating_ = true; + } + ~UpdateLocker() { mac.isUpdating_ = false; } +private: + MathMacro & mac; +}; + + void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc, UpdateType utype) { + if (isUpdating_) + return; + + UpdateLocker locker(*this); + // known macro? if (macro_ == 0) return; @@ -707,8 +728,8 @@ void MathMacro::write(WriteStream & os) const // we should be ok to continue even if this fails. LATTEST(macro_); - // optional arguments make macros fragile - if (optionals_ > 0 && os.fragile()) + // Always protect macros in a fragile environment + if (os.fragile()) os << "\\protect"; os << "\\" << name(); @@ -787,14 +808,13 @@ void MathMacro::octave(OctaveStream & os) const void MathMacro::infoize(odocstream & os) const { - os << "Macro: " << name(); + os << bformat(_("Macro: %1$s"), name()); } void MathMacro::infoize2(odocstream & os) const { - os << "Macro: " << name(); - + os << bformat(_("Macro: %1$s"), name()); }