mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 11:08:41 +00:00
* 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:
parent
1231489798
commit
dbbf47ab14
@ -28,6 +28,7 @@
|
|||||||
#include "InsetMathUnknown.h"
|
#include "InsetMathUnknown.h"
|
||||||
#include "MathData.h"
|
#include "MathData.h"
|
||||||
#include "MathFactory.h"
|
#include "MathFactory.h"
|
||||||
|
#include "MathMacro.h"
|
||||||
#include "MathMacroArgument.h"
|
#include "MathMacroArgument.h"
|
||||||
#include "MathParser.h"
|
#include "MathParser.h"
|
||||||
#include "MathStream.h"
|
#include "MathStream.h"
|
||||||
@ -988,6 +989,21 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
interpretChar(cur, '^');
|
interpretChar(cur, '^');
|
||||||
break;
|
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:
|
case LFUN_QUOTE_INSERT:
|
||||||
// interpret this as if a straight " was typed
|
// interpret this as if a straight " was typed
|
||||||
cur.recordUndo();
|
cur.recordUndo();
|
||||||
@ -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,
|
bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||||
FuncStatus & flag) const
|
FuncStatus & flag) const
|
||||||
{
|
{
|
||||||
@ -1132,6 +1179,14 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
|
flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
|
||||||
break;
|
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_HYPHENATION_POINT_INSERT:
|
||||||
case LFUN_LIGATURE_BREAK_INSERT:
|
case LFUN_LIGATURE_BREAK_INSERT:
|
||||||
case LFUN_MENU_SEPARATOR_INSERT:
|
case LFUN_MENU_SEPARATOR_INSERT:
|
||||||
|
@ -149,6 +149,9 @@ private:
|
|||||||
void lfunMouseRelease(Cursor &, FuncRequest &);
|
void lfunMouseRelease(Cursor &, FuncRequest &);
|
||||||
///
|
///
|
||||||
void lfunMouseMotion(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:
|
protected:
|
||||||
/// we store the cells in a vector
|
/// we store the cells in a vector
|
||||||
|
Loading…
Reference in New Issue
Block a user