* 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
This commit is contained in:
Stefan Schimanski 2007-11-01 11:14:14 +00:00
parent 1231489798
commit dbbf47ab14
2 changed files with 59 additions and 1 deletions

View File

@ -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:

View File

@ -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