-
- if (name == "bibitem") {
- InsetCommandParams icp(name);
- InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
- icp);
- return new InsetBibitem(icp);
-
- } else if (name == "bibtex") {
- InsetCommandParams icp(name);
- InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
- icp);
- return new InsetBibtex(icp);
-
- } else if (name == "citation") {
- InsetCommandParams icp("citation");
- InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
- icp);
- return new InsetCitation(icp);
-
- } else if (name == "ert") {
- InsetCollapsable::CollapseStatus st;
- InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
- return new InsetERT(params, st);
-
- } else if (name == "listings") {
- InsetListingsParams par;
- InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
- return new InsetListings(params, par);
-
- } else if (name == "external") {
- Buffer const & buffer = bv->buffer();
- InsetExternalParams iep;
- InsetExternalMailer::string2params(to_utf8(cmd.argument()),
- buffer, iep);
- auto_ptr<InsetExternal> inset(new InsetExternal);
- inset->setParams(iep, buffer);
- return inset.release();
-
- } else if (name == "graphics") {
- Buffer const & buffer = bv->buffer();
- InsetGraphicsParams igp;
- InsetGraphicsMailer::string2params(to_utf8(cmd.argument()),
- buffer, igp);
- auto_ptr<InsetGraphics> inset(new InsetGraphics);
- inset->setParams(igp);
- return inset.release();
-
- } else if (name == "href") {
- InsetCommandParams icp(name);
- InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
- icp);
- return new InsetHyperlink(icp);
-
- } else if (name == "include") {
- InsetCommandParams iip(name);
- InsetIncludeMailer::string2params(to_utf8(cmd.argument()), iip);
- return new InsetInclude(iip);
-
- } else if (name == "index") {
+ InsetCode code = insetCode(name);
+ switch (code) {
+ case NO_CODE:
+ lyxerr << "No such inset '" << name << "'.";
+ return 0;
+
+ case BIBITEM_CODE: {
+ InsetCommandParams icp(name);
+ InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+ return new InsetBibitem(icp);
+ }
+
+ case BIBTEX_CODE: {
+ InsetCommandParams icp(name);
+ InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+ return new InsetBibtex(icp);
+ }
+
+ case CITE_CODE: {
+ InsetCommandParams icp("citation");
+ InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+ return new InsetCitation(icp);
+ }
+
+ case ERT_CODE: {
+ InsetCollapsable::CollapseStatus st;
+ InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
+ return new InsetERT(params, st);
+ }
+
+ case LISTINGS_CODE: {
+ InsetListingsParams par;
+ InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
+ return new InsetListings(params, par);
+ }
+
+ case EXTERNAL_CODE: {
+ Buffer const & buffer = bv->buffer();
+ InsetExternalParams iep;
+ InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, iep);
+ auto_ptr<InsetExternal> inset(new InsetExternal);
+ inset->setParams(iep, buffer);
+ return inset.release();
+ }
+
+ case GRAPHICS_CODE: {
+ Buffer const & buffer = bv->buffer();
+ InsetGraphicsParams igp;
+ InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, igp);
+ auto_ptr<InsetGraphics> inset(new InsetGraphics);
+ inset->setParams(igp);
+ return inset.release();
+ }
+
+ case HYPERLINK_CODE: {
+ InsetCommandParams icp(name);
+ InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+ return new InsetHyperlink(icp);
+ }
+
+ case INCLUDE_CODE: {
+ InsetCommandParams iip(name);
+ InsetIncludeMailer::string2params(to_utf8(cmd.argument()), iip);
+ return new InsetInclude(iip);
+ }
+
+ case INDEX_CODE: