X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffactory.C;h=f642f4bd83d9d99a70904cde355b3676540710fe;hb=414a11684e77aee713135ae65ec7438cfc4b162f;hp=b0f443fdab9ed8ea3a06f3662e6510cce9fe6d71;hpb=1eaa3eb913b16f4e6f5991b9c53b0b9ab3f84948;p=lyx.git diff --git a/src/factory.C b/src/factory.C index b0f443fdab..f642f4bd83 100644 --- a/src/factory.C +++ b/src/factory.C @@ -53,16 +53,15 @@ #include "insets/insetvspace.h" #include "insets/insetwrap.h" -#include "mathed/formulamacro.h" +#include "mathed/math_macrotemplate.h" #include "mathed/math_hullinset.h" -#include "frontends/Dialogs.h" -#include "frontends/LyXView.h" - #include "support/lstrings.h" -#include "support/std_sstream.h" #include +#include + +#include using lyx::support::compare_ascii_no_case; @@ -87,8 +86,12 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd) case LFUN_INSERT_CHARSTYLE: { string s = cmd.getArg(0); - CharStyles::iterator found_cs = params.getLyXTextClass().charstyle(s); - return new InsetCharStyle(params, found_cs); + LyXTextClass tclass = params.getLyXTextClass(); + CharStyles::iterator found_cs = tclass.charstyle(s); + if (found_cs != tclass.charstyles().end()) + return new InsetCharStyle(params, found_cs); + else + return new InsetCharStyle(params, s); } case LFUN_INSERT_NOTE: { @@ -154,45 +157,31 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd) // Try and generate a valid index entry. InsetCommandParams icp("index"); string const contents = cmd.argument.empty() ? - bv->getLyXText()->getStringToIndex() : + bv->getLyXText()->getStringToIndex(bv->cursor()) : cmd.argument; icp.setContents(contents); - - string data = InsetCommandMailer::params2string("index", icp); - LyXView * lv = bv->owner(); - - if (icp.getContents().empty()) { - lv->getDialogs().show("index", data, 0); - } else { - lv->dispatch(FuncRequest(LFUN_INSET_APPLY, data)); - } - return 0; + return new InsetIndex(icp); } - case LFUN_TABULAR_INSERT: - if (!cmd.argument.empty()) { - std::istringstream ss(cmd.argument); - int r = 0, c = 0; - ss >> r >> c; - if (r <= 0) r = 2; - if (c <= 0) c = 2; - return new InsetTabular(*bv->buffer(), r, c); - } - bv->owner()->getDialogs().show("tabularcreate"); - return 0; + case LFUN_TABULAR_INSERT: { + if (cmd.argument.empty()) + return 0; + std::istringstream ss(cmd.argument); + int r = 0, c = 0; + ss >> r >> c; + if (r <= 0) + r = 2; + if (c <= 0) + c = 2; + return new InsetTabular(*bv->buffer(), r, c); + } case LFUN_INSET_CAPTION: { - UpdatableInset * up = bv->cursor().inset() - ? bv->cursor().inset()->asUpdatableInset() : 0; - if (!up) { - auto_ptr inset(new InsetCaption(params)); - inset->setOwner(up); - inset->setAutoBreakRows(true); - inset->setDrawFrame(InsetText::LOCKED); - inset->setFrameColor(LColor::captionframe); - return inset.release(); - } - return 0; + auto_ptr inset(new InsetCaption(params)); + inset->setAutoBreakRows(true); + inset->setDrawFrame(true); + inset->setFrameColor(LColor::captionframe); + return inset.release(); } case LFUN_INDEX_PRINT: @@ -343,7 +332,7 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf) auto_ptr inset; LyXTextClass tclass = buf.params().getLyXTextClass(); - + lex.next(); string tmptok = lex.getString(); @@ -405,7 +394,7 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf) } else if (tmptok == "External") { inset.reset(new InsetExternal); } else if (tmptok == "FormulaMacro") { - inset.reset(new InsetFormulaMacro); + inset.reset(new MathMacroTemplate); } else if (tmptok == "Formula") { inset.reset(new MathHullInset); } else if (tmptok == "Graphics") { @@ -418,7 +407,12 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf) lex.next(); string s = lex.getString(); CharStyles::iterator found_cs = tclass.charstyle(s); - inset.reset(new InsetCharStyle(buf.params(), found_cs)); + if (found_cs != tclass.charstyles().end()) + inset.reset(new InsetCharStyle(buf.params(), found_cs)); + else { + // "Undefined" inset + inset.reset(new InsetCharStyle(buf.params(), s)); + } } else if (tmptok == "Branch") { inset.reset(new InsetBranch(buf.params(), InsetBranchParams())); @@ -471,6 +465,20 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf) } inset->read(buf, lex); + +#ifdef WITH_WARNINGS +#warning hack.. +#endif + if (inset->lyxCode() == InsetBase::MATHMACRO_CODE) { + MathMacroTemplate const * tmpl = + static_cast(inset.get()); + MacroTable::globalMacros().insert + (tmpl->name(), tmpl->asMacroData()); + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION + << ": creating local macro " << tmpl->name() + << endl; + } } return inset.release();