From ebe7e44590a977b16cbc3f1a2a0ad0bb1476180d Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 3 Apr 2003 01:26:02 +0000 Subject: [PATCH] getStatus() for environment depth lfuns git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6696 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 8 ++++++++ src/bufferview_funcs.C | 10 +++++++--- src/bufferview_funcs.h | 8 ++++++-- src/lyxfunc.C | 12 ++++++++++-- src/lyxtext.h | 8 ++++++-- src/text2.C | 18 ++++++++++++++---- 6 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a2347b2e68..19ccd095c9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-04-03 John Levon + + * 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 * bufferview_funcs.h: diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 0064047ecd..798ff2870a 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -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; } diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index b847825df3..c0bade9625 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -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 *); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b2bc4533ef..94e51a6f2d 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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: diff --git a/src/lyxtext.h b/src/lyxtext.h index dbaa3e3c24..9471864766 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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; diff --git a/src/text2.C b/src/text2.C index 0e599ce305..5eefb7731e 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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; } -- 2.39.2