getStatus() for environment depth lfuns

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6696 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-04-03 01:26:02 +00:00
parent d533ee3995
commit ebe7e44590
6 changed files with 51 additions and 13 deletions

View File

@ -1,3 +1,11 @@
2003-04-03 John Levon <levon@movementarian.org>
* bufferview_funcs.h:
* bufferview_funcs.C:
* lyxfunc.C:
* lyxtext.h:
* text2.C: make getStatus work for the env depth lfuns
2003-04-03 John Levon <levon@movementarian.org>
* bufferview_funcs.h:

View File

@ -217,17 +217,21 @@ void lang(BufferView * bv, string const & l)
}
void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type)
bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_only)
{
if (!bv->available() || !text)
return;
return false;
if (test_only)
return text->changeDepth(type, true);
bv->hideCursor();
bv->update(BufferView::SELECT);
text->changeDepth(type);
bool const changed = text->changeDepth(type, false);
if (text->inset_owner)
bv->updateInset((Inset *)text->inset_owner);
bv->update(BufferView::SELECT);
return changed;
}

View File

@ -48,8 +48,12 @@ enum DEPTH_CHANGE {
DEC_DEPTH
};
/// change the nesting depth of the selection
extern void changeDepth(BufferView *, LyXText *, DEPTH_CHANGE);
/**
* Increase or decrease the nesting depth of the selected paragraph(s)
* if test_only, don't change any depths. Returns whether something
* (would have) changed
*/
extern bool changeDepth(BufferView *, LyXText *, DEPTH_CHANGE, bool test_only);
///
extern void emph(BufferView *);

View File

@ -365,6 +365,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
&& !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
break;
case LFUN_DEPTH_MIN:
disable = !changeDepth(view(), TEXT(false), DEC_DEPTH, true);
break;
case LFUN_DEPTH_PLUS:
disable = !changeDepth(view(), TEXT(false), INC_DEPTH, true);
break;
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH: {
Inset * inset = TEXT(false)->cursor.par()->inInset();
@ -1110,11 +1118,11 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
break;
case LFUN_DEPTH_MIN:
changeDepth(view(), TEXT(false), bv_funcs::DEC_DEPTH);
changeDepth(view(), TEXT(false), DEC_DEPTH, false);
break;
case LFUN_DEPTH_PLUS:
changeDepth(view(), TEXT(false), bv_funcs::INC_DEPTH);
changeDepth(view(), TEXT(false), INC_DEPTH, false);
break;
case LFUN_FREEFONT_APPLY:

View File

@ -129,8 +129,12 @@ public:
///
void setLayout(string const & layout);
/// increase or decrease the nesting depth of the selected paragraph(s)
void changeDepth(bv_funcs::DEPTH_CHANGE type);
/**
* Increase or decrease the nesting depth of the selected paragraph(s)
* if test_only, don't change any depths. Returns whether something
* (would have) changed
*/
bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
/// get the depth at current cursor position
int getDepth() const;

View File

@ -457,7 +457,7 @@ void LyXText::setLayout(string const & layout)
}
void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
{
ParagraphList::iterator pit(cursor.par());
ParagraphList::iterator end(cursor.par());
@ -473,6 +473,8 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
++pastend;
setUndo(bv(), Undo::EDIT, &(*start), &(*pastend));
bool changed = false;
int prev_after_depth = 0;
#warning parlist ... could be nicer ?
if (start != ownerParagraphs().begin())
@ -483,10 +485,13 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
if (type == bv_funcs::INC_DEPTH) {
if (depth < prev_after_depth
&& pit->layout()->labeltype != LABEL_BIBLIO) {
pit->params().depth(depth + 1);
changed = true;
if (!test_only)
pit->params().depth(depth + 1);
}
} else {
if (depth)
} else if (depth) {
changed = true;
if (!test_only)
pit->params().depth(depth - 1);
}
@ -498,6 +503,9 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
++pit;
}
if (test_only)
return changed;
// Wow, redoParagraphs is stupid.
LyXCursor tmpcursor;
setCursor(tmpcursor, &(*start), 0);
@ -518,6 +526,8 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
updateCounters();
setSelection();
setCursor(tmpcursor.par(), tmpcursor.pos());
return changed;
}