#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Lexer.h"
-#include "LyXRC.h"
#include "frontends/Painter.h"
}
-void MathMacroTemplate::updateToContext(MacroContext const & mc) const
+void MathMacroTemplate::updateToContext(MacroContext const & mc)
{
redefinition_ = mc.get(name()) != 0;
}
// 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_) {
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;
}
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;
}
}
for (; sit != end; ++sit) {
InsetMathHull * inset_hull =
sit->nextInset()->asInsetMath()->asHullInset();
- LBUFERR(inset_hull, _("Error loading macro previews."));
+ LBUFERR(inset_hull);
inset_hull->reloadPreview(*sit);
}
cur.screenUpdateFlags(Update::Force);
{
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);
{
if (pos <= numargs_ && pos >= optionals_ && numargs_ < 9) {
++numargs_;
-
+
// append example #n
if (addarg) {
shiftArguments(pos, 1);
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
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
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;
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);
}
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);
}
}
-bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
+bool MathMacroTemplate::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
bool ret = true;
break;
default:
- ret = false;
+ ret = InsetMathNest::getStatus(cur, cmd, flag);
break;
}
return ret;
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();
void MathMacroTemplate::infoize(odocstream & os) const
{
- os << "Math Macro: \\" << name();
+ os << bformat(_("Math Macro: \\%1$s"), name());
}