John Levon <[EMAIL PROTECTED]> writes:

| On Tue, Oct 07, 2003 at 11:42:22PM +0200, Lars Gullik Bj?nnes wrote:
>
>> [EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:
>> 
>> | Have a look.
>> 
>> This seems to fix the problem:
>> (please verify)
>
| I think we have least two counter bugs worth testing against on bugzilla

Ok, I have a patch... not the nicest one, but it seems to work, and I
need others to thest it.

Please throw all itemize and enumerate stuff you can think of at this
one. If you can find a situation where we do something different than
LaTeX please produce a small test file and add it to bugzilla case
1025 (and notify me of course).

? counter.diff
? deptherror.diff
? deptherror.lyx
? kystskipper-a-1.lyx
? morectrs.lyx
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.470
diff -u -p -r1.470 text2.C
--- src/text2.C	6 Oct 2003 15:42:40 -0000	1.470
+++ src/text2.C	8 Oct 2003 09:48:02 -0000
@@ -868,49 +868,79 @@ void LyXText::setCounter(Buffer const & 
 	LyXTextClass const & textclass = bufparams.getLyXTextClass();
 	LyXLayout_ptr const & layout = pit->layout();
 
-	if (pit != ownerParagraphs().begin()) {
+	// Always reset
+	pit->enumdepth = 0;
+	pit->itemdepth = 0;
+
+	if (pit == ownerParagraphs().begin()) {
+		pit->params().appendix(pit->params().startOfAppendix());
+	} else {
 		pit->params().appendix(boost::prior(pit)->params().appendix());
 		if (!pit->params().appendix() &&
 		    pit->params().startOfAppendix()) {
 			pit->params().appendix(true);
 			textclass.counters().reset();
 		}
-		pit->enumdepth = boost::prior(pit)->enumdepth;
-		pit->itemdepth = boost::prior(pit)->itemdepth;
-	} else {
-		pit->params().appendix(pit->params().startOfAppendix());
-		pit->enumdepth = 0;
-		pit->itemdepth = 0;
-	}
 
 	// Maybe we have to increment the enumeration depth.
-	// Bibliographies can't have their depth changed ie. they
-	//	are always of depth 0
-	if (pit != ownerParagraphs().begin()
-	    && boost::prior(pit)->getDepth() < pit->getDepth()
-	    && boost::prior(pit)->layout()->labeltype == LABEL_ENUMERATE
-	    && pit->enumdepth < 3
-	    && layout->labeltype != LABEL_BIBLIO) {
-		pit->enumdepth++;
-	}
+	{
+		int const cur_depth = pit->getDepth();
+		ParagraphList::iterator prev_pit = boost::prior(pit);
+		while (true) {
+			int const prev_depth = prev_pit->getDepth();
+			int const prev_labeltype = prev_pit->layout()->labeltype;
+			if (prev_depth == 0 && cur_depth > 0) {
+				if (prev_labeltype == LABEL_ENUMERATE) {
+					pit->enumdepth = prev_pit->enumdepth + 1;
+				}
+				break;
+			} else if (prev_depth < cur_depth) {
+				if (prev_labeltype == LABEL_ENUMERATE) {
+					pit->enumdepth = prev_pit->enumdepth + 1;
+					break;
+				}
+			} else if (prev_depth == cur_depth) {
+				if (prev_labeltype == LABEL_ENUMERATE) {
+					pit->enumdepth = prev_pit->enumdepth;
+					break;
+				}
+			}
+			if (prev_pit == ownerParagraphs().begin())
+				break;
 
-	// Maybe we have to increment the enumeration depth.
-	// Bibliographies can't have their depth changed ie. they
-	//	are always of depth 0
-	if (pit != ownerParagraphs().begin()
-	    && boost::prior(pit)->getDepth() < pit->getDepth()
-	    && boost::prior(pit)->layout()->labeltype == LABEL_ITEMIZE
-	    && pit->itemdepth < 3
-	    && layout->labeltype != LABEL_BIBLIO) {
-		pit->itemdepth++;
+			--prev_pit;
+		}
 	}
 
-	// Maybe we have to decrement the enumeration depth, see note above
-	if (pit != ownerParagraphs().begin()
-	    && boost::prior(pit)->getDepth() > pit->getDepth()
-	    && layout->labeltype != LABEL_BIBLIO) {
-		pit->enumdepth = depthHook(pit, ownerParagraphs(),
-							 pit->getDepth())->enumdepth;
+	// Maybe we have to increment the itemization depth.
+	{
+		int const cur_depth = pit->getDepth();
+		ParagraphList::iterator prev_pit = boost::prior(pit);
+		while (true) {
+			int const prev_depth = prev_pit->getDepth();
+			int const prev_labeltype = prev_pit->layout()->labeltype;
+
+			if (prev_depth == 0 && cur_depth > 0) {
+				if (prev_labeltype == LABEL_ITEMIZE) {
+					pit->itemdepth = prev_pit->itemdepth + 1;
+				}
+				break;
+			} else if (prev_depth < cur_depth) {
+				if (prev_labeltype == LABEL_ITEMIZE) {
+					pit->itemdepth = prev_pit->itemdepth + 1;
+					break;
+				}
+			} else if (prev_depth == cur_depth) {
+				if (prev_labeltype == LABEL_ITEMIZE) {
+					pit->itemdepth = prev_pit->itemdepth;
+					break;
+				}
+			}
+			if (prev_pit == ownerParagraphs().begin())
+				break;
+			--prev_pit;
+		}
+	}
 	}
 
 	// erase what was there before
@@ -930,16 +960,65 @@ void LyXText::setCounter(Buffer const & 
 		textclass.counters().step(layout->counter);
 		string label = expandLabel(textclass, layout, pit->params().appendix());
 		pit->params().labelString(label);
-		textclass.counters().reset("enum");
 	} else if (layout->labeltype == LABEL_ITEMIZE) {
 		// At some point of time we should do something more clever here,
 		// like:
 		//   pit->params().labelString(
 		//     bufparams.user_defined_bullet(pit->itemdepth).getText());
 		// for now, use a static label
-		pit->params().labelString("*");
-		textclass.counters().reset("enum");
+		string itemlabel;
+		switch (pit->itemdepth) {
+		case 0:
+			itemlabel = "*";
+			break;
+		case 1:
+			itemlabel = "-";
+			break;
+		case 2:
+			itemlabel = "@";
+			break;
+		case 3:
+			itemlabel = "·";
+			break;
+		}
+
+		pit->params().labelString(itemlabel);
 	} else if (layout->labeltype == LABEL_ENUMERATE) {
+	// Maybe we have to reset the enumeration counter.
+	if (pit != ownerParagraphs().begin())
+	{
+		int const cur_depth = pit->getDepth();
+		ParagraphList::iterator prev_pit = boost::prior(pit);
+		while (true) {
+			int const prev_depth = prev_pit->getDepth();
+			int const prev_labeltype = prev_pit->layout()->labeltype;
+			if (prev_depth <= cur_depth) {
+				if (prev_labeltype != LABEL_ENUMERATE) {
+					// reset the enumeration counter. They are always reset
+					// when there is any other layout between
+					// Just fall-through between the cases so that all
+					// enum counters deeper than enumdepth is also reset.
+					switch (pit->enumdepth) {
+					case 0:
+						textclass.counters().reset("enumi");
+					case 1:
+						textclass.counters().reset("enumii");
+					case 2:
+						textclass.counters().reset("enumiii");
+					case 3:
+						textclass.counters().reset("enumiv");
+					}
+				}
+				break;
+			}
+
+			if (prev_pit == ownerParagraphs().begin())
+				break;
+
+			--prev_pit;
+		}
+	}
+
 		// FIXME
 		// Yes I know this is a really, really! bad solution
 		// (Lgb)
@@ -1022,20 +1101,6 @@ void LyXText::setCounter(Buffer const & 
 		}
 		pit->params().labelString(s);
 
-		// reset the enumeration counter. They are always reset
-		// when there is any other layout between
-		// Just fall-through between the cases so that all
-		// enum counters deeper than enumdepth is also reset.
-		switch (pit->enumdepth) {
-		case 0:
-			textclass.counters().reset("enumi");
-		case 1:
-			textclass.counters().reset("enumii");
-		case 2:
-			textclass.counters().reset("enumiii");
-		case 3:
-			textclass.counters().reset("enumiv");
-		}
 	}
 }
 
-- 
        Lgb

Reply via email to