#include "InsetMathUnknown.h"
#include "MathData.h"
#include "MathFactory.h"
+#include "MathMacro.h"
#include "MathMacroArgument.h"
#include "MathParser.h"
#include "MathStream.h"
cur.recordUndo();
interpretChar(cur, '^');
break;
+
+ case LFUN_MATH_MACRO_FOLD:
+ case LFUN_MATH_MACRO_UNFOLD: {
+ Cursor it = cur;
+ bool fold = cmd.action == LFUN_MATH_MACRO_FOLD;
+ bool found = findMacroToFoldUnfold(it, fold);
+ if (found) {
+ cur.recordUndo();
+ if (fold)
+ it.nextInset()->asInsetMath()->asMacro()->fold(cur);
+ else
+ it.nextInset()->asInsetMath()->asMacro()->unfold(cur);
+ }\v
+ break;
+ }
case LFUN_QUOTE_INSERT:
// interpret this as if a straight " was typed
}
+bool InsetMathNest::findMacroToFoldUnfold(Cursor & it, bool fold) const {
+ // look for macro to open/close, but stay in mathed
+ for (; !it.empty(); it.pop_back()) {
+
+ // go backward through the current cell
+ Inset * inset = it.nextInset();
+ while (inset && inset->asInsetMath()) {
+ MathMacro * macro = inset->asInsetMath()->asMacro();
+ if (macro) {
+ // found the an macro to open/close?
+ if (macro->folded() != fold)
+ return true;
+
+ // wrong folding state -> go up one level
+ break;
+ }
+
+ // go up if this was the left most position
+ if (it.pos() == 0)
+ break;
+
+ // go left
+ it.pos()--;
+ inset = it.nextInset();
+ }
+ }
+
+ return false;
+}
+
+
bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
// Don't do this with multi-cell selections
flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
break;
-
+
+ case LFUN_MATH_MACRO_FOLD:
+ case LFUN_MATH_MACRO_UNFOLD: {
+ Cursor it = cur;
+ bool found = findMacroToFoldUnfold(it, cmd.action == LFUN_MATH_MACRO_FOLD);
+ flag.enabled(found);
+ break;
+ }
+
case LFUN_HYPHENATION_POINT_INSERT:
case LFUN_LIGATURE_BREAK_INSERT:
case LFUN_MENU_SEPARATOR_INSERT:
void lfunMouseRelease(Cursor &, FuncRequest &);
///
void lfunMouseMotion(Cursor &, FuncRequest &);
+ /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
+ /// afterwards if found
+ bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
protected:
/// we store the cells in a vector