]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
This patch from Richard was correct.
[lyx.git] / src / TextClass.cpp
index 0a349e85720d3935faa1593a9d928c9a589bb722..c73857f6e3214ecbf82f34d95bc168197ee9494d 100644 (file)
 #include <fstream>
 #include <sstream>
 
+#ifdef ERROR
+#undef ERROR
+#endif
+
 using namespace std;
 using namespace lyx::support;
 
@@ -62,7 +66,7 @@ private:
 };
 
 // Keep the changes documented in the Customization manual. 
-int const FORMAT = 16;
+int const FORMAT = 20;
 
 
 bool layout2layout(FileName const & filename, FileName const & tempfile)
@@ -164,6 +168,7 @@ enum TextClassTags {
        TC_OUTPUTFORMAT,
        TC_INPUT,
        TC_STYLE,
+       TC_IFSTYLE,
        TC_DEFAULTSTYLE,
        TC_INSETLAYOUT,
        TC_NOSTYLE,
@@ -182,6 +187,7 @@ enum TextClassTags {
        TC_RIGHTMARGIN,
        TC_FLOAT,
        TC_COUNTER,
+       TC_IFCOUNTER,
        TC_NOFLOAT,
        TC_TITLELATEXNAME,
        TC_TITLELATEXTYPE,
@@ -209,6 +215,8 @@ namespace {
                { "float",             TC_FLOAT },
                { "format",            TC_FORMAT },
                { "htmlpreamble",      TC_HTMLPREAMBLE },
+               { "ifcounter",         TC_IFCOUNTER },
+               { "ifstyle",           TC_IFSTYLE },
                { "input",             TC_INPUT },
                { "insetlayout",       TC_INSETLAYOUT },
                { "leftmargin",        TC_LEFTMARGIN },
@@ -352,6 +360,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        break;
                }
 
+               // used below to track whether we are in an IfStyle or IfCounter tag.
+               bool ifstyle    = false;
+               bool ifcounter  = false;
+
                switch (static_cast<TextClassTags>(le)) {
 
                case TC_FORMAT:
@@ -404,6 +416,9 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        }
                        break;
 
+               case TC_IFSTYLE:
+                       ifstyle = true;
+                       // fall through
                case TC_STYLE: {
                        if (!lexrc.next()) {
                                lexrc.printError("No name given for style: `$$Token'.");
@@ -423,7 +438,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        } else if (hasLayout(name)) {
                                Layout & lay = operator[](name);
                                error = !readStyle(lexrc, lay);
-                       } else {
+                       } else if (!ifstyle) {
                                Layout layout;
                                layout.setName(name);
                                error = !readStyle(lexrc, layout);
@@ -436,6 +451,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                        defaultlayout_ = name;
                                }
                        }
+                       else {
+                               // scan the rest and discard it
+                               Layout lay;
+                               readStyle(lexrc, lay);
+                               error = false;
+                       }
+
+                       // reset flag
+                       ifstyle = false;
                        break;
                }
 
@@ -605,6 +629,8 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        readFloat(lexrc);
                        break;
 
+               case TC_IFCOUNTER:
+                       ifcounter = true;
                case TC_COUNTER:
                        if (lexrc.next()) {
                                docstring const name = lexrc.getDocString();
@@ -617,12 +643,14 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                        // and discard it.
                                        c.read(lexrc);
                                } else
-                                       error = !counters_.read(lexrc, name);
+                                       error = !counters_.read(lexrc, name, !ifcounter);
                        }
                        else {
                                lexrc.printError("No name given for style: `$$Token'.");
                                error = true;
                        }
+                       // reset flag
+                       ifcounter = false;
                        break;
 
                case TC_TITLELATEXTYPE:
@@ -824,8 +852,8 @@ void TextClass::readFloat(Lexer & lexrc)
                FT_LISTNAME,
                FT_BUILTIN,
                FT_HTMLSTYLE,
-               FT_HTMLCLASS,
-               FT_HTMLTYPE,
+               FT_HTMLATTR,
+               FT_HTMLTAG,
                FT_END
        };
 
@@ -833,9 +861,9 @@ void TextClass::readFloat(Lexer & lexrc)
                { "end", FT_END },
                { "extension", FT_EXT },
                { "guiname", FT_NAME },
-               { "htmlclass", FT_HTMLCLASS },
+               { "htmlattr", FT_HTMLATTR },
                { "htmlstyle", FT_HTMLSTYLE },
-               { "htmltype", FT_HTMLTYPE },
+               { "htmltag", FT_HTMLTAG },
                { "latexbuiltin", FT_BUILTIN },
                { "listname", FT_LISTNAME },
                { "numberwithin", FT_WITHIN },
@@ -847,9 +875,9 @@ void TextClass::readFloat(Lexer & lexrc)
        lexrc.pushTable(floatTags);
 
        string ext;
-       string htmlclass;
+       string htmlattr;
        string htmlstyle;
-       string htmltype;
+       string htmltag;
        string listName;
        string name;
        string placement;
@@ -912,17 +940,17 @@ void TextClass::readFloat(Lexer & lexrc)
                        lexrc.next();
                        builtin = lexrc.getBool();
                        break;
-               case FT_HTMLCLASS:
+               case FT_HTMLATTR:
                        lexrc.next();
-                       htmlclass = lexrc.getString();
+                       htmlattr = lexrc.getString();
                        break;
                case FT_HTMLSTYLE:
                        lexrc.next();
                        htmlstyle = lexrc.getLongString("EndHTMLStyle");
                        break;
-               case FT_HTMLTYPE:
+               case FT_HTMLTAG:
                        lexrc.next();
-                       htmltype = lexrc.getString();
+                       htmltag = lexrc.getString();
                        break;
                case FT_END:
                        getout = true;
@@ -933,7 +961,7 @@ void TextClass::readFloat(Lexer & lexrc)
        // Here if have a full float if getout == true
        if (getout) {
                Floating fl(type, placement, ext, within, style, name, 
-                               listName, htmltype, htmlclass, htmlstyle, builtin);
+                               listName, htmltag, htmlattr, htmlstyle, builtin);
                floatlist_.newFloat(fl);
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
@@ -1174,7 +1202,7 @@ DocumentClass & DocumentClassBundle::makeDocumentClass(
        LayoutModuleList::const_iterator en = modlist.end();
        for (; it != en; it++) {
                string const modName = *it;
-               LyXModule * lm = moduleList[modName];
+               LyXModule * lm = theModuleList[modName];
                if (!lm) {
                        docstring const msg =
                                                bformat(_("The module %1$s has been requested by\n"