Martin Vermeer <[EMAIL PROTECTED]> writes:

| On Wed, Sep 04, 2002 at 04:56:13PM +0200, Lars Gullik Bjønnes wrote:
|  
| > Ok, but for Algorithm, this problem must have been there earlier as
| > well?
| 
| Undoubtedly... but I had no algorithm listings in my test files :-)

I have a counters patch for you, it is the first patch in the series
to push the counters out into the layout files. Please test it and
check that it works as expected with your test files. Other comments
are of course welcome as well.

Index: src/counters.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.h,v
retrieving revision 1.10
diff -u -p -r1.10 counters.h
--- src/counters.h	11 Aug 2002 20:34:20 -0000	1.10
+++ src/counters.h	4 Sep 2002 16:19:27 -0000
@@ -20,7 +20,7 @@
 
 #include "LString.h"
 #include <map>
-#include <vector>
+
 
 /// This represents a single counter.
 class Counter {
@@ -96,10 +96,6 @@ public:
 			string const & labeltype,
 			string const & langtype = "latin",
 			int head = 0);
-	/// Maps numbers to enumeration of sectioning counter name strings.
-	std::vector<string> enums;
-	std::vector<string> sects;
-
 private:
 	/// Maps counter (layout) names to actual counters.
 	typedef std::map<string, Counter> CounterList;
Index: src/counters.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.C,v
retrieving revision 1.12
diff -u -p -r1.12 counters.C
--- src/counters.C	12 Aug 2002 20:24:07 -0000	1.12
+++ src/counters.C	4 Sep 2002 16:19:27 -0000
@@ -83,24 +83,28 @@ Counters::Counters()
 	newCounter("paragraph", "subsubsection");
 	newCounter("subparagraph", "paragraph");
 
+#if 0
 	sects.push_back("chapter");
 	sects.push_back("section");
 	sects.push_back("subsection");
 	sects.push_back("subsubsection");
 	sects.push_back("paragraph");
 	sects.push_back("subparagraph");
-
+#endif
+	
 	// Enumeration counters:
 	newCounter("enumi");
 	newCounter("enumii", "enumi");
 	newCounter("enumiii", "enumii");
 	newCounter("enumiv", "enumiii");
 
+#if 0
 	enums.push_back("enumi");
 	enums.push_back("enumii");
 	enums.push_back("enumiii");
 	enums.push_back("enumiv");
-
+#endif
+	
 	// Biblio:
 	newCounter("bibitem");
 
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.258
diff -u -p -r1.258 text2.C
--- src/text2.C	29 Aug 2002 12:00:50 -0000	1.258
+++ src/text2.C	4 Sep 2002 16:19:28 -0000
@@ -1266,13 +1266,17 @@ void LyXText::setCounter(Buffer const * 
 	if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
 
 		int i = layout->labeltype - LABEL_COUNTER_CHAPTER;
-		string numbertype, langtype;
+		string numbertype;
+		string langtype;
 		ostringstream s;
 
 		if (i >= 0 && i <= buf->params.secnumdepth) {
 
+#if 0
 			buf->counters().step(buf->counters().sects[i]);
-
+#else
+			buf->counters().step(layout->latexname());
+#endif
 			// Is there a label? Useful for Chapter layout
 			if (!par->params().appendix()) {
 				if (!layout->labelstring().empty())
@@ -1298,8 +1302,14 @@ void LyXText::setCounter(Buffer const * 
 					langtype = "latin";
 			}
 
+#if 0
 			s << buf->counters().numberLabel(buf->counters().sects[i],
 				numbertype, langtype, head);
+#else
+			s << buf->counters()
+				.numberLabel(layout->latexname(),
+					     numbertype, langtype, head);
+#endif
 
 			par->params().labelString(par->params().labelString() + s.str().c_str());
 			// We really want to remove the c_str as soon as
@@ -1310,18 +1320,39 @@ void LyXText::setCounter(Buffer const * 
 		} else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
 			buf->counters().reset("enum");
 		} else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
-			buf->counters().step(buf->counters().enums[par->enumdepth]);
+			// FIXME
+			// Yes I know this is a really, really! bad solution
+			// (Lgb)
+			string enumcounter("enum");
+
+			switch (par->enumdepth) {
+			case 2:
+				enumcounter += 'i';
+			case 1:
+				enumcounter += 'i';
+			case 0:
+				enumcounter += 'i';
+				break;
+			case 3:
+				enumcounter += "iv";
+				break;
+			default:
+				// not a valid enumdepth...
+				break;
+			}
 
-			s << buf->counters().numberLabel(buf->counters().enums[par->enumdepth],
-				"enumeration", langtype);
-			par->params().labelString(s.str().c_str());
+			buf->counters().step(enumcounter);
 
+			s << buf->counters()
+				.numberLabel(enumcounter,
+					     "enumeration", langtype);
+			par->params().labelString(s.str().c_str());
 		}
 	} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
 		buf->counters().step("bibitem");
 		int number = buf->counters().value("bibitem");
 		if (!par->bibkey) {
-			InsetCommandParams p("bibitem" );
+			InsetCommandParams p("bibitem");
 			par->bibkey = new InsetBibKey(p);
 		}
 		par->bibkey->setCounter(number);
@@ -1351,7 +1382,7 @@ void LyXText::setCounter(Buffer const * 
 				Floating const & fl
 					= textclass.floats().getType(static_cast<InsetFloat*>(in)->type());
 
-				buf->counters().step(fl.name());
+				buf->counters().step(fl.type());
 
 				// Doesn't work... yet.
 				ostringstream o;
@@ -1369,9 +1400,7 @@ void LyXText::setCounter(Buffer const * 
 
 		// reset the enumeration counter. They are always resetted
 		// when there is any other layout between
-		for (int i = par->enumdepth; i < 4; ++i) {
-			buf->counters().set(buf->counters().enums[i], 0);
-		}
+		buf->counters().reset("enum");
 	}
 }
 

-- 
        Lgb

Reply via email to