From: Stefan Schimanski Date: Thu, 1 Nov 2007 11:14:14 +0000 (+0000) Subject: * LFUN handler for folding/unfolding of math macros X-Git-Tag: 1.6.10~7563 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=dbbf47ab14e5eaa2a504acbbfb4bd55e86191805;p=lyx.git * LFUN handler for folding/unfolding of math macros git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21329 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index a6f9e7165a..d8c8365279 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -28,6 +28,7 @@ #include "InsetMathUnknown.h" #include "MathData.h" #include "MathFactory.h" +#include "MathMacro.h" #include "MathMacroArgument.h" #include "MathParser.h" #include "MathStream.h" @@ -987,6 +988,21 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) 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); + } + break; + } case LFUN_QUOTE_INSERT: // interpret this as if a straight " was typed @@ -1040,6 +1056,37 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) } +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 { @@ -1131,7 +1178,15 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd, // 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: diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 3e8e1a7087..db4cfa7414 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -149,6 +149,9 @@ private: 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