]> git.lyx.org Git - features.git/commitdiff
getStatus() for environment depth lfuns
authorJohn Levon <levon@movementarian.org>
Thu, 3 Apr 2003 01:26:02 +0000 (01:26 +0000)
committerJohn Levon <levon@movementarian.org>
Thu, 3 Apr 2003 01:26:02 +0000 (01:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6696 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/bufferview_funcs.C
src/bufferview_funcs.h
src/lyxfunc.C
src/lyxtext.h
src/text2.C

index a2347b2e68292727885d1691e4bd5c675a62200b..19ccd095c99de197aaa62525de96943c8ed8d144 100644 (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:
index 0064047ecd29baa693b6b36227d4c0c55fb4a0ed..798ff2870a556862a363ff3fb2e7845285b0b238 100644 (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;
 }
 
 
index b847825df38b2625ae7cb5c825ec582917b99581..c0bade96251b9b9b6ae2a7a553f0b9fe90b63234 100644 (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 *);
index b2bc4533efc0839a5834ec574298794a99dfeeac..94e51a6f2db7100962b6745285c6f93634d54030 100644 (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:
index dbaa3e3c2493ee0088e153506048166c4c256f19..9471864766604c7a5b14ec1e2a0a7d5d06f8b56b 100644 (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;
index 0e599ce305163a62a6e10222500547f65d80f22c..5eefb7731e57cd7c2b3bb8a62ec93bed69b735d7 100644 (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;
 }