>>>>> "Jean-Marc" == Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:

Jean-Marc> Could you try the following quick and dirty patch? It
Jean-Marc> should do the right thing it you set the number of optargs
Jean-Marc> in memoir layouts to more than one.

Here is a better patch to try, with proper changelog entries and the
two bugs I mentionned fixed. You will have to modify memoir.layout to
make it work, of course.

Does it work as you intend?

JMarc

Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2036
diff -u -p -r1.2036 ChangeLog
--- src/ChangeLog	16 Nov 2004 10:46:19 -0000	1.2036
+++ src/ChangeLog	16 Nov 2004 11:38:12 -0000
@@ -1,3 +1,13 @@
+2004-11-16  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* text3.C (getStatus): disable LFUN_INSET_OPTARG when the max
+	number of InsetOptArgs has already been inserted.
+
+	* output_latex.C (latexOptArgInsets): new method. This outputs all
+	the optarg insets, up to the limit defined in the layout file.
+	(optArgInset): removed
+	(TeXOnePar): call latexOptArgInsets; correctly update texrow
+
 2004-11-15  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* lyxfunc.C (getStatus): when the origin of the request is menu or
Index: src/output_latex.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/output_latex.C,v
retrieving revision 1.16
diff -u -p -r1.16 output_latex.C
--- src/output_latex.C	15 Nov 2004 13:39:06 -0000	1.16
+++ src/output_latex.C	16 Nov 2004 11:38:12 -0000
@@ -195,18 +195,22 @@ TeXEnvironment(Buffer const & buf,
 }
 
 
-InsetOptArg * optArgInset(Paragraph const & par)
+int latexOptArgInsets(Buffer const & buf, Paragraph const & par, 
+		      ostream & os, OutputParams const & runparams, int number)
 {
-	// Find the entry.
+	int lines = 0;
+	
 	InsetList::const_iterator it = par.insetlist.begin();
 	InsetList::const_iterator end = par.insetlist.end();
-	for (; it != end; ++it) {
-		InsetBase * ins = it->inset;
-		if (ins->lyxCode() == InsetBase::OPTARG_CODE) {
-			return static_cast<InsetOptArg *>(ins);
+	for (; it != end && number > 0 ; ++it) {
+		if (it->inset->lyxCode() == InsetBase::OPTARG_CODE) {
+			InsetOptArg * ins = 
+				static_cast<InsetOptArg *>(it->inset);
+			lines += ins->latexOptional(buf, os, runparams);
+			--number;
 		}
 	}
-	return 0;
+	return lines;
 }
 
 
@@ -308,10 +312,13 @@ TeXOnePar(Buffer const & buf,
 		os << '\\' << style->latexname();
 
 		// Separate handling of optional argument inset.
-		if (style->optionalargs == 1) {
-			InsetOptArg * it = optArgInset(*pit);
-			if (it)
-				it->latexOptional(buf, os, runparams);
+		if (style->optionalargs > 0) {
+			int ret = latexOptArgInsets(buf, *pit, os, runparams, 
+						    style->optionalargs);
+			while (ret > 0) {
+				texrow.newline();
+				--ret;
+			}
 		}
 		else
 			os << style->latexparam();
Index: src/paragraph_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v
retrieving revision 1.108
diff -u -p -r1.108 paragraph_funcs.C
--- src/paragraph_funcs.C	7 Nov 2004 13:30:53 -0000	1.108
+++ src/paragraph_funcs.C	16 Nov 2004 11:38:12 -0000
@@ -353,3 +353,20 @@ void getParsInRange(ParagraphList & pars
 	for (end = beg ; end != endpar && pars[end].y <= yend; ++end)
 		;
 }
+
+
+/// return the number of InsetOptArg in a paragraph
+int numberOfOptArgs(Paragraph const & par)
+{
+	int num = 0;
+	
+	InsetList::const_iterator it = par.insetlist.begin();
+	InsetList::const_iterator end = par.insetlist.end();
+	for (; it != end ; ++it) {
+		if (it->inset->lyxCode() == InsetBase::OPTARG_CODE) 
+			++num;
+	}
+	return num;
+}
+
+
Index: src/paragraph_funcs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.h,v
retrieving revision 1.43
diff -u -p -r1.43 paragraph_funcs.h
--- src/paragraph_funcs.h	16 Aug 2004 00:32:00 -0000	1.43
+++ src/paragraph_funcs.h	16 Nov 2004 11:38:12 -0000
@@ -67,4 +67,8 @@ void getParsInRange(ParagraphList & plis
 				lyx::par_type & beg,
 				lyx::par_type & end);
 
+/// return the number of InsetOptArg in a paragraph
+int numberOfOptArgs(Paragraph const & par);
+
+
 #endif // PARAGRAPH_FUNCS_H
Index: src/text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.268
diff -u -p -r1.268 text3.C
--- src/text3.C	2 Nov 2004 14:25:14 -0000	1.268
+++ src/text3.C	16 Nov 2004 11:38:12 -0000
@@ -1594,7 +1594,8 @@ bool LyXText::getStatus(LCursor & cur, F
 		break;
 
 	case LFUN_INSET_OPTARG:
-		enable = cur.paragraph().layout()->optionalargs;
+		enable = numberOfOptArgs(cur.paragraph()) 
+			< cur.paragraph().layout()->optionalargs;
 		break;
 
 	case LFUN_APPENDIX:
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1075
diff -u -p -r1.1075 ChangeLog
--- src/insets/ChangeLog	15 Nov 2004 13:35:49 -0000	1.1075
+++ src/insets/ChangeLog	16 Nov 2004 11:38:12 -0000
@@ -1,3 +1,8 @@
+2004-11-16  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* insetoptarg.C (latexOptional): return number of lines instead of
+	number of characters
+
 2004-11-10  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* insetlatexaccent.h (isLetter): implement, so that word selection
Index: src/insets/insetoptarg.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetoptarg.C,v
retrieving revision 1.25
diff -u -p -r1.25 insetoptarg.C
--- src/insets/insetoptarg.C	5 Oct 2004 10:11:41 -0000	1.25
+++ src/insets/insetoptarg.C	16 Nov 2004 11:38:12 -0000
@@ -75,10 +75,10 @@ int InsetOptArg::latexOptional(Buffer co
 			       OutputParams const & runparams) const
 {
 	ostringstream ss;
-	InsetText::latex(buf, ss, runparams);
+	int ret = InsetText::latex(buf, ss, runparams);
 	string str = ss.str();
 	if (str.find(']') != string::npos)
 		str = '{' + str + '}';
 	os << '[' << str << ']';
-	return str.length() + 2;
+	return ret;
 }

Reply via email to