Currently, if you repeat an InsetLayout declaration, it completely over-writes the original, rather than updating it, as ordinary Style declarations do. The attached patch, for trunk, aims to fix that problem. Comments welcome.
Richard
Index: src/insets/InsetLayout.cpp =================================================================== --- src/insets/InsetLayout.cpp (revision 27894) +++ src/insets/InsetLayout.cpp (working copy) @@ -72,12 +72,6 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) { - name_ = support::subst(lex.getDocString(), '_', ' '); - // FIXME We need to check for name_.empty() here, and - // take the same sort of action as in TextClass::read() - // if it is empty. Or, better, we could read name_ there, - // take action there, etc. - enum { IL_BGCOLOR, IL_COPYSTYLE, Index: src/insets/InsetLayout.h =================================================================== --- src/insets/InsetLayout.h (revision 27894) +++ src/insets/InsetLayout.h (working copy) @@ -57,6 +57,8 @@ /// docstring name() const { return name_; }; /// + void setName(docstring const & n) { name_ = n; } + /// InsetLyXType lyxtype() const { return lyxtype_; }; /// docstring labelstring() const { return labelstring_; }; Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (revision 27894) +++ src/TextClass.cpp (working copy) @@ -60,7 +60,6 @@ docstring name_; }; - int const FORMAT = 11; @@ -532,14 +531,34 @@ rightmargin_ = lexrc.getDocString(); break; - case TC_INSETLAYOUT: + case TC_INSETLAYOUT: { if (lexrc.next()) { - InsetLayout il; - if (il.read(lexrc, *this)) - insetlayoutlist_[il.name()] = il; - // else there was an error, so forget it + docstring const name = subst(lexrc.getDocString(), '_', ' '); + if (name.empty()) { + string s = "Could not read name for InsetLayout: `$$Token' " + + lexrc.getString() + " is probably not valid UTF-8!"; + lexrc.printError(s.c_str()); + InsetLayout il; + // Since we couldn't read the name, we just scan the rest + // of the style and discard it. + il.read(lexrc, *this); + error = true; + } else if (hasInsetLayout(name)) { + InsetLayout & il = insetlayoutlist_[name]; + error = !il.read(lexrc, *this); + } else { + InsetLayout il; + il.setName(name); + error = !il.read(lexrc, *this); + if (!error) + insetlayoutlist_[name] = il; + } + } else { + lexrc.printError("No name given for InsetLayout: `$$Token'."); + error = true; } break; + } case TC_FLOAT: readFloat(lexrc); @@ -877,6 +896,19 @@ } +bool TextClass::hasInsetLayout(docstring const & n) const +{ + if (n.empty()) + return false; + InsetLayouts::const_iterator it = insetlayoutlist_.begin(); + InsetLayouts::const_iterator en = insetlayoutlist_.end(); + for (; it != en; ++it) + if (n == it->first) + return true; + return false; +} + + Layout const & TextClass::operator[](docstring const & name) const { LASSERT(!name.empty(), /**/); Index: src/TextClass.h =================================================================== --- src/TextClass.h (revision 27894) +++ src/TextClass.h (working copy) @@ -101,7 +101,7 @@ typedef std::map<docstring, InsetLayout> InsetLayouts; /// typedef LayoutList::const_iterator const_iterator; - + /////////////////////////////////////////////////////////////////// // Iterators /////////////////////////////////////////////////////////////////// @@ -134,6 +134,8 @@ /// bool hasLayout(docstring const & name) const; /// + bool hasInsetLayout(docstring const & name) const; + /// Layout const & operator[](docstring const & vname) const; /// Inset layouts of this doc class InsetLayouts const & insetLayouts() const { return insetlayoutlist_; };