+
+
+InsetBase * readInset(LyXLex & lex, Buffer const & buf)
+{
+ // consistency check
+ if (lex.getString() != "\\begin_inset") {
+ lyxerr << "Buffer::readInset: Consistency check failed."
+ << endl;
+ }
+
+ auto_ptr<InsetBase> inset;
+
+ LyXTextClass tclass = buf.params().getLyXTextClass();
+
+ lex.next();
+ string tmptok = lex.getString();
+
+ // test the different insets
+ if (tmptok == "LatexCommand") {
+ InsetCommandParams inscmd;
+ inscmd.read(lex);
+
+ string const cmdName = inscmd.getCmdName();
+
+ // This strange command allows LyX to recognize "natbib" style
+ // citations: citet, citep, Citet etc.
+ if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
+ inset.reset(new InsetCitation(inscmd));
+ } else if (cmdName == "bibitem") {
+ lex.printError("Wrong place for bibitem");
+ inset.reset(new InsetBibitem(inscmd));
+ } else if (cmdName == "bibtex") {
+ inset.reset(new InsetBibtex(inscmd));
+ } else if (cmdName == "index") {
+ inset.reset(new InsetIndex(inscmd));
+ } else if (cmdName == "include") {
+ inset.reset(new InsetInclude(inscmd));
+ } else if (cmdName == "label") {
+ inset.reset(new InsetLabel(inscmd));
+ } else if (cmdName == "url"
+ || cmdName == "htmlurl") {
+ inset.reset(new InsetUrl(inscmd));
+ } else if (cmdName == "ref"
+ || cmdName == "eqref"
+ || cmdName == "pageref"
+ || cmdName == "vref"
+ || cmdName == "vpageref"
+ || cmdName == "prettyref") {
+ if (!inscmd.getOptions().empty()
+ || !inscmd.getContents().empty()) {
+ inset.reset(new InsetRef(inscmd, buf));
+ }
+ } else if (cmdName == "tableofcontents") {
+ inset.reset(new InsetTOC(inscmd));
+ } else if (cmdName == "listofalgorithms") {
+ inset.reset(new InsetFloatList("algorithm"));
+ } else if (cmdName == "listoffigures") {
+ inset.reset(new InsetFloatList("figure"));
+ } else if (cmdName == "listoftables") {
+ inset.reset(new InsetFloatList("table"));
+ } else if (cmdName == "printindex") {
+ inset.reset(new InsetPrintIndex(inscmd));
+ } else {
+ lyxerr << "unknown CommandInset '" << cmdName
+ << "'" << std::endl;
+ while (lex.isOK() && lex.getString() != "\\end_inset")
+ lex.next();
+ return 0;
+ }
+ } else {
+ if (tmptok == "Quotes") {
+ inset.reset(new InsetQuotes);
+ } else if (tmptok == "External") {
+ inset.reset(new InsetExternal);
+ } else if (tmptok == "FormulaMacro") {
+ inset.reset(new MathMacroTemplate);
+ } else if (tmptok == "Formula") {
+ inset.reset(new MathHullInset);
+ } else if (tmptok == "Graphics") {
+ inset.reset(new InsetGraphics);
+ } else if (tmptok == "Note") {
+ inset.reset(new InsetNote(buf.params(), tmptok));
+ } else if (tmptok == "Box") {
+ inset.reset(new InsetBox(buf.params(), tmptok));
+ } else if (tmptok == "CharStyle") {
+ lex.next();
+ string s = lex.getString();
+ CharStyles::iterator found_cs = tclass.charstyle(s);
+ inset.reset(new InsetCharStyle(buf.params(), found_cs));
+ } else if (tmptok == "Branch") {
+ inset.reset(new InsetBranch(buf.params(),
+ InsetBranchParams()));
+ } else if (tmptok == "Include") {
+ InsetCommandParams p("Include");
+ inset.reset(new InsetInclude(p));
+ } else if (tmptok == "Environment") {
+ lex.next();
+ inset.reset(new InsetEnvironment(buf.params(), lex.getString()));
+ } else if (tmptok == "ERT") {
+ inset.reset(new InsetERT(buf.params()));
+ } else if (tmptok == "InsetSpace") {
+ inset.reset(new InsetSpace);
+ } else if (tmptok == "Tabular") {
+ inset.reset(new InsetTabular(buf));
+ } else if (tmptok == "Text") {
+ inset.reset(new InsetText(buf.params()));
+ } else if (tmptok == "VSpace") {
+ inset.reset(new InsetVSpace);
+ } else if (tmptok == "Foot") {
+ inset.reset(new InsetFoot(buf.params()));
+ } else if (tmptok == "Marginal") {
+ inset.reset(new InsetMarginal(buf.params()));
+ } else if (tmptok == "OptArg") {
+ inset.reset(new InsetOptArg(buf.params()));
+ } else if (tmptok == "Float") {
+ lex.next();
+ string tmptok = lex.getString();
+ inset.reset(new InsetFloat(buf.params(), tmptok));
+ } else if (tmptok == "Wrap") {
+ lex.next();
+ string tmptok = lex.getString();
+ inset.reset(new InsetWrap(buf.params(), tmptok));
+#if 0
+ } else if (tmptok == "List") {
+ inset.reset(new InsetList);
+ } else if (tmptok == "Theorem") {
+ inset.reset(new InsetList);
+#endif
+ } else if (tmptok == "Caption") {
+ inset.reset(new InsetCaption(buf.params()));
+ } else if (tmptok == "FloatList") {
+ inset.reset(new InsetFloatList);
+ } else {
+ lyxerr << "unknown Inset type '" << tmptok
+ << "'" << std::endl;
+ while (lex.isOK() && lex.getString() != "\\end_inset")
+ lex.next();
+ return 0;
+ }
+
+ inset->read(buf, lex);
+
+#ifdef WITH_WARNINGS
+#warning hack..
+#endif
+ if (inset->lyxCode() == InsetBase::MATHMACRO_CODE) {
+ MathMacroTemplate const * tmpl =
+ static_cast<MathMacroTemplate*>(inset.get());
+ MacroTable::globalMacros().insert
+ (tmpl->name(), tmpl->asMacroData());
+ lyxerr << "creating local macro " << tmpl->name() << endl;
+ }
+ }
+
+ return inset.release();
+}