diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index bace2f65ac..33b0db01e0 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -19388,6 +19388,37 @@ End The following parameters can also be used: \end_layout +\begin_layout Description + +\change_inserted 1414654397 1370012684 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 1414654397 1370012589 +InitialValue +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 1414654397 1370012639 +number +\end_layout + +\end_inset + +=1] Sets the initial value for the counter, to which it will be reset whenever + that happens. + Normally, one will want the default, 1. +\end_layout + \begin_layout Description \begin_inset Flex Code status collapsed diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 98cdb94bed..ce8da57275 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -160,6 +160,9 @@ import os, re, string, sys # Incremented to format 47, 23 May 2013 by rgh # Add PackageOptions tag +# Incremented to format 48, 31 May 2013 by rgh +# Add InitialValue tag for counters + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -167,7 +170,7 @@ import os, re, string, sys # development/tools/updatelayouts.sh script to update all # layout files to the new format. -currentFormat = 47 +currentFormat = 48 def usage(prog_name): @@ -384,7 +387,7 @@ def convert(lines): i += 1 continue - if format >= 44 and format <= 46: + if format >= 44 and format <= 47: # nothing to do. i += 1 continue diff --git a/src/Counters.cpp b/src/Counters.cpp index e73e2d8913..917044a252 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -40,7 +40,7 @@ Counter::Counter() Counter::Counter(docstring const & mc, docstring const & ls, docstring const & lsa) - : master_(mc), labelstring_(ls), labelstringappendix_(lsa) + : initial_value_(0), master_(mc), labelstring_(ls), labelstringappendix_(lsa) { reset(); } @@ -53,11 +53,13 @@ bool Counter::read(Lexer & lex) CT_LABELSTRING, CT_LABELSTRING_APPENDIX, CT_PRETTYFORMAT, + CT_INITIALVALUE, CT_END }; LexerKeyword counterTags[] = { { "end", CT_END }, + { "initialvalue", CT_INITIALVALUE}, { "labelstring", CT_LABELSTRING }, { "labelstringappendix", CT_LABELSTRING_APPENDIX }, { "prettyformat", CT_PRETTYFORMAT }, @@ -83,6 +85,18 @@ bool Counter::read(Lexer & lex) if (master_ == "none") master_.erase(); break; + case CT_INITIALVALUE: + lex.next(); + initial_value_ = lex.getInteger(); + // getInteger() returns -1 on error, and larger + // negative values do not make much sense. + // In the other case, we subtract one, since the + // counter will be incremented before its first use. + if (initial_value_ <= -1) + initial_value_ = 0; + else + initial_value_ -= 1; + break; case CT_PRETTYFORMAT: lex.next(); prettyformat_ = lex.getDocString(); @@ -136,7 +150,7 @@ void Counter::step() void Counter::reset() { - value_ = 0; + value_ = initial_value_; } diff --git a/src/Counters.h b/src/Counters.h index 511c4902c8..a195889e31 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -76,6 +76,9 @@ public: private: /// int value_; + /// This is actually one less than the initial value, since the + /// counter is always stepped before being used. + int initial_value_; /// contains master counter name. /** The master counter is the counter that, if stepped * (incremented) zeroes this counter. E.g. "subsection"'s diff --git a/src/TextClass.cpp b/src/TextClass.cpp index f6723ec9c2..b77f31b336 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -61,7 +61,7 @@ namespace lyx { // development/tools/updatelayouts.sh script, to update the format of // all of our layout files. // -int const LAYOUT_FORMAT = 47; //rgh: package options +int const LAYOUT_FORMAT = 48; //rgh: initial values for counter namespace {