diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 934da30745..77621b3abc 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -785,7 +785,7 @@ int InsetCollapsable::latex(odocstream & os, // collapsable insets should not redefine this, non-standard ones may // call this. if (!layout_->latexname().empty()) { - if (layout_->latextype() == "command") { + if (layout_->latextype() == InsetLayout::COMMAND) { // FIXME UNICODE if (runparams.moving_arg) os << "\\protect"; @@ -793,7 +793,7 @@ int InsetCollapsable::latex(odocstream & os, if (!layout_->latexparam().empty()) os << from_utf8(layout_->latexparam()); os << '{'; - } else if (layout_->latextype() == "environment") { + } else if (layout_->latextype() == InsetLayout::ENVIRONMENT) { os << "%\n\\begin{" << from_utf8(layout_->latexname()) << "}\n"; if (!layout_->latexparam().empty()) os << from_utf8(layout_->latexparam()); @@ -806,9 +806,9 @@ int InsetCollapsable::latex(odocstream & os, rp.moving_arg = true; int i = InsetText::latex(os, rp); if (!layout_->latexname().empty()) { - if (layout_->latextype() == "command") { + if (layout_->latextype() == InsetLayout::COMMAND) { os << "}"; - } else if (layout_->latextype() == "environment") { + } else if (layout_->latextype() == InsetLayout::ENVIRONMENT) { os << "\n\\end{" << from_utf8(layout_->latexname()) << "}\n"; i += 4; } diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 40873cb49e..9a321c2046 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -32,8 +32,9 @@ namespace lyx { InsetLayout::InsetLayout() : name_(from_ascii("undefined")), lyxtype_(STANDARD), - labelstring_(from_ascii("UNDEFINED")), decoration_(InsetLayout::DEFAULT), - font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error), + labelstring_(from_ascii("UNDEFINED")), decoration_(DEFAULT), + latextype_(NOLATEXTYPE), font_(sane_font), + labelfont_(sane_font), bgcolor_(Color_error), multipar_(false), custompars_(false), forceplain_(true), passthru_(false), needprotect_(false), freespacing_(false), keepempty_(false), forceltr_(false) @@ -55,6 +56,17 @@ InsetLayout::InsetDecoration translateDecoration(std::string const & str) return InsetLayout::DEFAULT; } +InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str) +{ + if (support::compare_ascii_no_case(str, "command") == 0) + return InsetLayout::COMMAND; + if (support::compare_ascii_no_case(str, "environment") == 0) + return InsetLayout::ENVIRONMENT; + if (support::compare_ascii_no_case(str, "none") == 0) + return InsetLayout::NOLATEXTYPE; + return InsetLayout::ILT_ERROR; +} + } @@ -144,9 +156,14 @@ bool InsetLayout::read(Lexer & lex, TextClass & tclass) LYXERR0("Unknown LyXType `" << lt << "'."); break; } - case IL_LATEXTYPE: - lex >> latextype_; + case IL_LATEXTYPE: { + string lt; + lex >> lt; + latextype_ = translateLaTeXType(lt); + if (latextype_ == ILT_ERROR) + LYXERR0("Unknown LaTeXType `" << lt << "'."); break; + } case IL_LABELSTRING: lex >> labelstring_; break; diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 84ede0adc8..9b5865c907 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -46,6 +46,12 @@ public: END, STANDARD }; + enum InsetLaTeXType { + NOLATEXTYPE, + COMMAND, + ENVIRONMENT, + ILT_ERROR + }; /// bool read(Lexer & lexrc, TextClass & tclass); /// @@ -57,7 +63,7 @@ public: /// InsetDecoration decoration() const { return decoration_; }; /// - std::string latextype() const { return latextype_; }; + InsetLaTeXType latextype() const { return latextype_; }; /// std::string latexname() const { return latexname_; }; /// @@ -102,7 +108,7 @@ private: /// InsetDecoration decoration_; /// - std::string latextype_; + InsetLaTeXType latextype_; /// std::string latexname_; ///