]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetLayout.cpp
Move isMultiCell() to Cursor, and use it.
[lyx.git] / src / insets / InsetLayout.cpp
index f50d1c8ce0ae8c1dbbd7901f03121152dc636b3d..5a317e01736b5b43cf5ebb2229c361a19f206cc4 100644 (file)
@@ -17,6 +17,9 @@
 #include "Color.h"
 #include "Font.h"
 #include "Lexer.h"
+#include "TextClass.h"
+
+#include "support/debug.h"
 #include "support/lstrings.h"
 
 #include <vector>
@@ -54,16 +57,17 @@ InsetLayout::InsetDecoration translateDecoration(std::string const & str)
 }
 
 
-bool InsetLayout::read(Lexer & lex)
+bool InsetLayout::read(Lexer & lex, TextClass & tclass)
 {
        name_ = support::subst(lex.getDocString(), '_', ' ');
 
        enum {
-               IL_FONT,
                IL_BGCOLOR,
+               IL_COPYSTYLE,
                IL_DECORATION,
-               IL_FREESPACING,
+               IL_FONT,
                IL_FORCELTR,
+               IL_FREESPACING,
                IL_LABELFONT,
                IL_LABELSTRING,
                IL_LATEXNAME,
@@ -82,6 +86,7 @@ bool InsetLayout::read(Lexer & lex)
 
        LexerKeyword elementTags[] = {
                { "bgcolor", IL_BGCOLOR },
+               { "copystyle", IL_COPYSTYLE}, 
                { "decoration", IL_DECORATION },
                { "end", IL_END },
                { "font", IL_FONT },
@@ -160,6 +165,33 @@ bool InsetLayout::read(Lexer & lex)
                case IL_NEEDPROTECT:
                        lex >> needprotect_;
                        break;
+               case IL_COPYSTYLE: {     // initialize with a known style
+                       docstring style;
+                       lex >> style;
+                       style = support::subst(style, '_', ' ');
+
+                       // We don't want to apply the algorithm in DocumentClass::insetLayout()
+                       // here. So we do it the long way.
+                       TextClass::InsetLayouts::const_iterator it = 
+                                       tclass.insetLayouts().find(style);
+                       if (it != tclass.insetLayouts().end()) {
+                               docstring const tmpname = name_;
+                               this->operator=(it->second);
+                               name_ = tmpname;
+                       } else {
+                               LYXERR0("Cannot copy unknown InsetLayout `"
+                                       << style << "'\n"
+                                       << "All InsetLayouts so far:");
+                               TextClass::InsetLayouts::const_iterator lit = 
+                                               tclass.insetLayouts().begin();
+                               TextClass::InsetLayouts::const_iterator len = 
+                                               tclass.insetLayouts().end();
+                               for (; lit != len; ++lit)
+                                       lyxerr << lit->second.name() << "\n";
+                       }
+                       break;
+               }
+
                case IL_FONT: {
                        font_ = lyxRead(lex, inherit_font);
                        // If you want to define labelfont, you need to do so after