]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Revert "Use swap in InsetText::updateBuffer for notes ad friends"
[lyx.git] / src / Layout.cpp
index 4f7f215b707b53839c932889e76499f2b5180b7a..4f3dc1426822a66f5a6b1fe06a9a2c8315761b04 100644 (file)
@@ -40,6 +40,8 @@ enum LayoutTags {
        LT_ALIGN = 1,
        LT_ALIGNPOSSIBLE,
        LT_ARGUMENT,
+       LT_AUTONESTS,
+       LT_AUTONESTEDBY,
        LT_MARGIN,
        LT_BOTTOMSEP,
        LT_CATEGORY,
@@ -72,10 +74,10 @@ enum LayoutTags {
        LT_LATEXTYPE,
        LT_LEFTDELIM,
        LT_LEFTMARGIN,
+       LT_NEED_CPROTECT,
        LT_NEED_PROTECT,
        LT_NEWLINE,
        LT_NEXTNOINDENT,
-       LT_NESTS,
        LT_PAR_GROUP,
        LT_PARINDENT,
        LT_PARSEP,
@@ -119,7 +121,7 @@ enum LayoutTags {
 /////////////////////
 
 Layout::Layout()
-       : add_to_toc_(false), is_toc_caption_(false)
+       : add_to_toc_(false), is_toc_caption_(true)
 {
        unknown_ = false;
        margintype = MARGIN_STATIC;
@@ -129,6 +131,7 @@ Layout::Layout()
        intitle = false;
        inpreamble = false;
        needprotect = false;
+       needcprotect = false;
        keepempty = false;
        font = inherit_font;
        labelfont = inherit_font;
@@ -192,6 +195,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                { "align",          LT_ALIGN },
                { "alignpossible",  LT_ALIGNPOSSIBLE },
                { "argument",       LT_ARGUMENT },
+               { "autonests",      LT_AUTONESTS },
                { "babelpreamble",  LT_BABELPREAMBLE },
                { "bottomsep",      LT_BOTTOMSEP },
                { "category",       LT_CATEGORY },
@@ -218,6 +222,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                { "innertag",       LT_INNERTAG },
                { "inpreamble",     LT_INPREAMBLE },
                { "intitle",        LT_INTITLE },
+               { "isautonestedby", LT_AUTONESTEDBY },
                { "istoccaption",   LT_ISTOCCAPTION },
                { "itemcommand",    LT_ITEMCOMMAND },
                { "itemsep",        LT_ITEMSEP },
@@ -239,8 +244,8 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                { "leftdelim",      LT_LEFTDELIM },
                { "leftmargin",     LT_LEFTMARGIN },
                { "margin",         LT_MARGIN },
+               { "needcprotect",    LT_NEED_CPROTECT },
                { "needprotect",    LT_NEED_PROTECT },
-               { "nests",          LT_NESTS },
                { "newline",        LT_NEWLINE },
                { "nextnoindent",   LT_NEXTNOINDENT },
                { "obsoletedby",    LT_OBSOLETEDBY },
@@ -372,6 +377,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                                latexargs_.clear();
                                itemargs_.clear();
                                postcommandargs_.clear();
+                               listpreamble_.clear();
                        }
                        break;
 
@@ -391,6 +397,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        lex >> needprotect;
                        break;
 
+               case LT_NEED_CPROTECT:
+                       lex >> needcprotect;
+                       break;
+
                case LT_KEEPEMPTY:
                        lex >> keepempty;
                        break;
@@ -594,14 +604,27 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
                }
 
-               case LT_NESTS: {
-                       docstring const nest = subst(subst(subst(lex.getLongString(from_ascii("EndNests")),
-                                                    from_ascii("\n"), docstring()),
-                                                    from_ascii(" "), docstring()),
-                                                    from_ascii("\t"), docstring());
-                       vector<docstring> const nests =
-                               getVectorFromString(nest);
-                       nests_.insert(nests.begin(), nests.end());
+               case LT_AUTONESTS: {
+                       docstring const autonest =
+                               subst(subst(subst(lex.getLongString(from_ascii("EndAutoNests")),
+                                                 from_ascii("\n"), docstring()),
+                                           from_ascii(" "), docstring()),
+                                     from_ascii("\t"), docstring());
+                       vector<docstring> const autonests =
+                               getVectorFromString(autonest);
+                       autonests_.insert(autonests.begin(), autonests.end());
+                       break;
+               }
+
+               case LT_AUTONESTEDBY: {
+                       docstring const autonest =
+                               subst(subst(subst(lex.getLongString(from_ascii("EndIsAutoNestedBy")),
+                                                 from_ascii("\n"), docstring()),
+                                           from_ascii(" "), docstring()),
+                                     from_ascii("\t"), docstring());
+                       vector<docstring> const autonests =
+                               getVectorFromString(autonest);
+                       autonested_by_.insert(autonests.begin(), autonests.end());
                        break;
                }
 
@@ -983,6 +1006,7 @@ void Layout::readArgument(Lexer & lex)
        latexarg arg;
        // writeArgument() makes use of these default values
        arg.mandatory = false;
+       arg.nodelims = false;
        arg.autoinsert = false;
        arg.insertcotext = false;
        bool error = false;
@@ -995,6 +1019,7 @@ void Layout::readArgument(Lexer & lex)
        lex >> id;
        bool const itemarg = prefixIs(id, "item:");
        bool const postcmd = prefixIs(id, "post:");
+       bool const listpreamble = prefixIs(id, "listpreamble:");
 
        while (!finished && lex.isOK() && !error) {
                lex.next();
@@ -1074,7 +1099,11 @@ void Layout::readArgument(Lexer & lex)
                itemargs_[id] = arg;
        else if (postcmd)
                postcommandargs_[id] = arg;
-       else
+       else if (listpreamble) {
+               // list preamble has no delimiters by default
+               arg.nodelims = true;
+               listpreamble_[id] = arg;
+       } else
                latexargs_[id] = arg;
 }
 
@@ -1196,7 +1225,11 @@ void Layout::write(ostream & os) const
        for (LaTeXArgMap::const_iterator it = postcommandargs_.begin();
             it != postcommandargs_.end(); ++it)
                writeArgument(os, it->first, it->second);
+       for (LaTeXArgMap::const_iterator it = listpreamble_.begin();
+            it != listpreamble_.end(); ++it)
+               writeArgument(os, it->first, it->second);
        os << "\tNeedProtect " << needprotect << "\n"
+             "\tNeedCProtect " << needcprotect << "\n"
              "\tKeepEmpty " << keepempty << '\n';
        if (labelfont == font)
                lyxWrite(os, font, "Font", 1);
@@ -1400,15 +1433,25 @@ void Layout::write(ostream & os) const
                }
                os << '\n';
        }
-       if (!nests_.empty()) {
-               os << "\tNests ";
-               for (set<docstring>::const_iterator it = nests_.begin();
-                    it != nests_.end(); ++it) {
-                       if (it != nests_.begin())
+       if (!autonests_.empty()) {
+               os << "\tAutoNests\n\t";
+               for (set<docstring>::const_iterator it = autonests_.begin();
+                    it != autonests_.end(); ++it) {
+                       if (it != autonests_.begin())
                                os << ',';
                        os << to_utf8(*it);
                }
-               os << '\n';
+               os << "\n\tEndAutoNests\n";
+       }
+       if (!autonested_by_.empty()) {
+               os << "\tIsAutoNestedBy\n\t\t";
+               for (set<docstring>::const_iterator it = autonested_by_.begin();
+                    it != autonested_by_.end(); ++it) {
+                       if (it != autonested_by_.begin())
+                               os << ',';
+                       os << to_utf8(*it);
+               }
+               os << "\n\tEndIsAutoNestedBy\n";
        }
        if (refprefix.empty())
                os << "\tRefPrefix OFF\n";
@@ -1446,7 +1489,7 @@ void Layout::write(ostream & os) const
 bool Layout::hasArgs() const
 {
        return !latexargs_.empty() || !postcommandargs_.empty() ||
-               !itemargs_.empty();
+               !itemargs_.empty() || !listpreamble_.empty();
 }
 
 
@@ -1455,6 +1498,8 @@ Layout::LaTeXArgMap Layout::args() const
        LaTeXArgMap args = latexargs_;
        if (!postcommandargs_.empty())
                args.insert(postcommandargs_.begin(), postcommandargs_.end());
+       if (!listpreamble_.empty())
+               args.insert(listpreamble_.begin(), listpreamble_.end());
        if (!itemargs_.empty())
                args.insert(itemargs_.begin(), itemargs_.end());
        return args;