]> git.lyx.org Git - features.git/commitdiff
Introduce InitialValue tag for counters. Fixes bug #8707.
authorRichard Heck <rgheck@lyx.org>
Sat, 1 Jun 2013 21:42:08 +0000 (17:42 -0400)
committerRichard Heck <rgheck@lyx.org>
Sat, 1 Jun 2013 21:42:08 +0000 (17:42 -0400)
lib/doc/Customization.lyx
lib/scripts/layout2layout.py
src/Counters.cpp
src/Counters.h
src/TextClass.cpp

index bace2f65acca9b0ffa778caf3d90137859370c96..33b0db01e09f79d25fbe6bae8efba7ceaad8d98e 100644 (file)
@@ -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
index 98cdb94bed5dbed1f6cfda84b0db82c48f7df652..ce8da57275a7e267c776618d87b503f66fd0913e 100644 (file)
@@ -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
index e73e2d89139c6da6a12d0308633980ee72779284..917044a252c22d95a8a2543af838714fe63efb5b 100644 (file)
@@ -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_;
 }
 
 
index 511c4902c84230c26e2dddf52fb1814f9878b691..a195889e313ec0d09986cdf1cdf08792c309f926 100644 (file)
@@ -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
index f6723ec9c2ff3c48fdf33ed91a29f7f2bceba9b2..b77f31b3369c68b7422fe8f5e99ec8b1657d29c1 100644 (file)
@@ -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 {