string s = cmd.getArg(0);
InsetLayout il =
cur.buffer().params().documentClass().insetLayout(from_utf8(s));
- if (il.lyxtype() != "charstyle" &&
- il.lyxtype() != "custom" &&
- il.lyxtype() != "element" &&
- il.lyxtype ()!= "standard")
+ if (il.lyxtype() != InsetLayout::CHARSTYLE &&
+ il.lyxtype() != InsetLayout::CUSTOM &&
+ il.lyxtype() != InsetLayout::ELEMENT &&
+ il.lyxtype ()!= InsetLayout::STANDARD)
enable = false;
break;
}
case LFUN_INSET_DISSOLVE:
if (!cmd.argument().empty()) {
- InsetLayout il = cur.inset().getLayout(cur.buffer().params());
+ InsetLayout const & il = cur.inset().getLayout(cur.buffer().params());
+ InsetLayout::InsetLyXType const type =
+ translateLyXType(to_utf8(cmd.argument()));
enable = cur.inset().lyxCode() == FLEX_CODE
- && il.lyxtype() == to_utf8(cmd.argument());
+ && il.lyxtype() == type;
} else {
enable = !isMainText(cur.bv().buffer())
&& cur.inset().nargs() == 1;
void expandFormats(MenuItem::Kind kind, Buffer const * buf);
void expandFloatListInsert(Buffer const * buf);
void expandFloatInsert(Buffer const * buf);
- void expandFlexInsert(Buffer const * buf, std::string s);
+ void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type);
void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth);
void expandToc(Buffer const * buf);
void expandPasteRecent(Buffer const * buf);
}
-void MenuDefinition::expandFlexInsert(Buffer const * buf, string s)
+void MenuDefinition::expandFlexInsert(
+ Buffer const * buf, InsetLayout::InsetLyXType type)
{
if (!buf) {
add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
TextClass::InsetLayouts::const_iterator end = insetLayouts.end();
for (; cit != end; ++cit) {
docstring const label = cit->first;
- if (cit->second.lyxtype() == s)
+ if (cit->second.lyxtype() == type)
addWithStatusCheck(MenuItem(MenuItem::Command,
toqstr(translateIfPossible(label)),
FuncRequest(LFUN_FLEX_INSERT, label)));
}
// FIXME This is a little clunky.
- if (items_.empty() && s == "custom")
+ if (items_.empty() && type == InsetLayout::CUSTOM)
add(MenuItem(MenuItem::Command,
qt_("No custom insets defined!"),
FuncRequest(LFUN_NOACTION)));
break;
case MenuItem::CharStyles:
- tomenu.expandFlexInsert(buf, "charstyle");
+ tomenu.expandFlexInsert(buf, InsetLayout::CHARSTYLE);
break;
case MenuItem::Custom:
- tomenu.expandFlexInsert(buf, "custom");
+ tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
break;
case MenuItem::Elements:
- tomenu.expandFlexInsert(buf, "element");
+ tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
break;
case MenuItem::FloatListInsert:
namespace lyx {
InsetLayout::InsetLayout() :
- name_(from_ascii("undefined")), labelstring_(from_ascii("UNDEFINED")),
- decoration_(InsetLayout::Default),
+ name_(from_ascii("undefined")), lyxtype_(STANDARD),
+ labelstring_(from_ascii("UNDEFINED")), decoration_(InsetLayout::Default),
font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error),
multipar_(false), custompars_(false), forceplain_(true),
passthru_(false), needprotect_(false), freespacing_(false),
break;
}
switch (le) {
- case IL_LYXTYPE:
- lex >> lyxtype_;
+ case IL_LYXTYPE: {
+ string lt;
+ lex >> lt;
+ lyxtype_ = translateLyXType(lt);
+ if (lyxtype_ == NOLYXTYPE)
+ LYXERR0("Unknown LyXType `" << lt << "'.");
break;
+ }
case IL_LATEXTYPE:
lex >> latextype_;
break;
return true;
}
+
+InsetLayout::InsetLyXType translateLyXType(std::string const & str)
+{
+
+ if (support::compare_ascii_no_case(str, "charstyle") == 0)
+ return InsetLayout::CHARSTYLE;
+ if (support::compare_ascii_no_case(str, "custom") == 0)
+ return InsetLayout::CUSTOM;
+ if (support::compare_ascii_no_case(str, "element") == 0)
+ return InsetLayout::ELEMENT;
+ if (support::compare_ascii_no_case(str, "end") == 0)
+ return InsetLayout::END;
+ if (support::compare_ascii_no_case(str, "standard") == 0)
+ return InsetLayout::STANDARD;
+ return InsetLayout::NOLYXTYPE;
+}
+
} //namespace lyx
Conglomerate,
Default
};
+ enum InsetLyXType {
+ NOLYXTYPE,
+ CHARSTYLE,
+ CUSTOM,
+ ELEMENT,
+ END,
+ STANDARD
+ };
///
bool read(Lexer & lexrc, TextClass & tclass);
///
docstring name() const { return name_; };
///
- std::string lyxtype() const { return lyxtype_; };
+ InsetLyXType lyxtype() const { return lyxtype_; };
///
docstring labelstring() const { return labelstring_; };
///
* Values are 'charstyle', 'custom' (things that by default look like a
* footnote), 'element' (docbook), 'standard'.
*/
- std::string lyxtype_;
+ InsetLyXType lyxtype_;
///
docstring labelstring_;
///
bool forceltr_;
};
+///
+InsetLayout::InsetLyXType translateLyXType(std::string const & str);
+
} // namespace lyx
#endif