#include "Color.h"
#include "Font.h"
#include "Lexer.h"
+#include "TextClass.h"
+
+#include "support/debug.h"
#include "support/lstrings.h"
#include <vector>
}
-bool InsetLayout::read(Lexer & lexrc)
+bool InsetLayout::read(Lexer & lex, TextClass & tclass)
{
- name_ = support::subst(lexrc.getDocString(), '_', ' ');
+ 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,
LexerKeyword elementTags[] = {
{ "bgcolor", IL_BGCOLOR },
+ { "copystyle", IL_COPYSTYLE},
{ "decoration", IL_DECORATION },
{ "end", IL_END },
{ "font", IL_FONT },
{ "requires", IL_REQUIRES }
};
- lexrc.pushTable(elementTags);
+ lex.pushTable(elementTags);
FontInfo font = inherit_font;
labelfont_ = inherit_font;
bgcolor_ = Color_background;
bool getout = false;
-
- while (!getout && lexrc.isOK()) {
- int le = lexrc.lex();
+
+ string tmp;
+ while (!getout && lex.isOK()) {
+ int le = lex.lex();
switch (le) {
case Lexer::LEX_UNDEF:
- lexrc.printError("Unknown InsetLayout tag `$$Token'");
+ lex.printError("Unknown InsetLayout tag");
continue;
- default: break;
+ default:
+ break;
}
switch (le) {
case IL_LYXTYPE:
- lexrc.next();
- lyxtype_ = lexrc.getString();
+ lex >> lyxtype_;
break;
case IL_LATEXTYPE:
- lexrc.next();
- latextype_ = lexrc.getString();
+ lex >> latextype_;
break;
case IL_LABELSTRING:
- lexrc.next();
- labelstring_ = lexrc.getDocString();
+ lex >> labelstring_;
break;
case IL_DECORATION:
- lexrc.next();
- decoration_ = translateDecoration(lexrc.getString());
+ lex >> tmp;
+ decoration_ = translateDecoration(tmp);
break;
case IL_LATEXNAME:
- lexrc.next();
- latexname_ = lexrc.getString();
+ lex >> latexname_;
break;
case IL_LATEXPARAM:
- lexrc.next();
- latexparam_ = support::subst(lexrc.getString(), """, "\"");
+ lex >> tmp;
+ latexparam_ = support::subst(tmp, """, "\"");
break;
case IL_LABELFONT:
- labelfont_ = lyxRead(lexrc, inherit_font);
+ labelfont_ = lyxRead(lex, inherit_font);
break;
case IL_FORCELTR:
- lexrc.next();
- forceltr_ = lexrc.getBool();
+ lex >> forceltr_;
break;
case IL_MULTIPAR:
- lexrc.next();
- multipar_ = lexrc.getBool();
+ lex >> multipar_;
break;
case IL_PASSTHRU:
- lexrc.next();
- passthru_ = lexrc.getBool();
+ lex >> passthru_;
break;
case IL_KEEPEMPTY:
- lexrc.next();
- keepempty_ = lexrc.getBool();
+ lex >> keepempty_;
break;
case IL_FREESPACING:
- lexrc.next();
- freespacing_ = lexrc.getBool();
+ lex >> freespacing_;
break;
case IL_NEEDPROTECT:
- lexrc.next();
- needprotect_ = lexrc.getBool();
+ 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(lexrc, inherit_font);
+ font_ = lyxRead(lex, inherit_font);
// If you want to define labelfont, you need to do so after
// font is defined.
labelfont_ = font_;
break;
}
- case IL_BGCOLOR: {
- lexrc.next();
- string const token = lexrc.getString();
- bgcolor_ = lcolor.getFromLyXName(token);
+ case IL_BGCOLOR:
+ lex >> tmp;
+ bgcolor_ = lcolor.getFromLyXName(tmp);
break;
- }
case IL_PREAMBLE:
- preamble_ = lexrc.getLongString("EndPreamble");
+ preamble_ = lex.getLongString("EndPreamble");
break;
case IL_REQUIRES: {
- lexrc.eatLine();
+ lex.eatLine();
vector<string> const req
- = support::getVectorFromString(lexrc.getString());
+ = support::getVectorFromString(lex.getString());
requires_.insert(req.begin(), req.end());
break;
}
// any realization against a given context.
labelfont_.realize(sane_font);
- lexrc.popTable();
+ lex.popTable();
return true;
}