Martin Vermeer <[EMAIL PROTECTED]> writes:

| On Thu, Sep 05, 2002 at 12:11:39PM +0300, Martin Vermeer wrote:
| 
| > I suspect that your statement 
| > 
| >  buf->counters().reset("enum");
| > 
| > may be too simple. Remember the non-standard pre-increment :-)
| 
| Do it like this:
| 
|         // reset the enumeration counter. They are always resetted
|         // when there is any other layout between
|         switch (par->enumdepth) {
|                 case 0:
|                 buf->counters().reset("enumi");
|                 case 1:
|                 buf->counters().reset("enumii");
|                 case 2:
|                 buf->counters().reset("enumiii");
|                 case 3:
|                 buf->counters().reset("enumiv");
|         }
| 
| Verified to work.

Ok, thanks.

How do this patch look to you then?

My way forward is to let the Style(s) in layoutfiles actually do
the counter creation. I am not quite sure how this will look yet, but
there might be a notion of Counter-Types.

Especially the enumeration counters give me a git of a head ache... it
can perhaps be a "enum" type of counter that changes behaviour
depending on depth.
 
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	5 Sep 2002 11:45:38 -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	5 Sep 2002 11:45:38 -0000
@@ -83,30 +83,18 @@ Counters::Counters()
 	newCounter("paragraph", "subsubsection");
 	newCounter("subparagraph", "paragraph");
 
-	sects.push_back("chapter");
-	sects.push_back("section");
-	sects.push_back("subsection");
-	sects.push_back("subsubsection");
-	sects.push_back("paragraph");
-	sects.push_back("subparagraph");
-
 	// Enumeration counters:
 	newCounter("enumi");
 	newCounter("enumii", "enumi");
 	newCounter("enumiii", "enumii");
 	newCounter("enumiv", "enumiii");
 
-	enums.push_back("enumi");
-	enums.push_back("enumii");
-	enums.push_back("enumiii");
-	enums.push_back("enumiv");
-
 	// Biblio:
 	newCounter("bibitem");
 
 	// Float counters:
-	newCounter("Figure");
-	newCounter("Table");
+	newCounter("figure");
+	newCounter("table");
 }
 
 
@@ -295,13 +283,15 @@ string Counters::labelItem(string const 
 			   string const & langtype,
 			   bool first)
 {
-	ostringstream s, o;
+	ostringstream s;
+	ostringstream o;
+
 	CounterList::iterator it = counterList.find(ctr);
 	if (it == counterList.end()) {
 		lyxerr << "Counter does not exist." << endl;
 		return "";
 	}
-	string mstr = it->second.master();
+
 	if (!first) {
 		s << "." << value(ctr);
 	} else {
@@ -344,7 +334,7 @@ string Counters::numberLabel(string cons
 		} else if (ctr == "subparagraph" && head <= 5) {
 			s << numberLabel("paragraph", numbertype, langtype, head)
 			  << labelItem("subparagraph", numbertype, langtype, head == 5);
-		} else if (ctr == "Figure" || ctr == "Table") {
+		} else if (ctr == "figure" || ctr == "table") {
 			// figure, table, ...
 			lyxerr << "Counter:" << ctr << endl;
 			s << numberLabel("chapter", numbertype, langtype, head)
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	5 Sep 2002 11:45:40 -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,8 +1400,15 @@ 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);
+		switch (par->enumdepth) {
+		case 0:
+			buf->counters().reset("enumi");
+		case 1:
+			buf->counters().reset("enumii");
+		case 2:
+			buf->counters().reset("enumiii");
+		case 3:
+			buf->counters().reset("enumiv");
 		}
 	}
 }

-- 
        Lgb

Reply via email to