]> git.lyx.org Git - lyx.git/blobdiff - src/factory.C
reduce number of calls to LyXText::getFont
[lyx.git] / src / factory.C
index e42cb3210149d7d482f4d045327014d67d89a69c..9b3258a59351e31c8699750d7f8949ac8ad1a471 100644 (file)
 #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 <boost/assert.hpp>
 
+#include <sstream>
+
 using lyx::support::compare_ascii_no_case;
 
 using std::auto_ptr;
@@ -87,8 +85,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: {
@@ -158,15 +160,8 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
                        cmd.argument;
                icp.setContents(contents);
 
-               string data = InsetCommandMailer::params2string("index", icp);
-               LyXView * lv = bv->owner();
+               return new InsetIndex(icp);
 
-               if (icp.getContents().empty()) {
-                       lv->getDialogs().show("index", data, 0);
-               } else {
-                       lv->dispatch(FuncRequest(LFUN_INSET_APPLY, data));
-               }
-               return 0;
        }
 
        case LFUN_TABULAR_INSERT:
@@ -178,7 +173,6 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
                        if (c <= 0) c = 2;
                        return new InsetTabular(*bv->buffer(), r, c);
                }
-               bv->owner()->getDialogs().show("tabularcreate");
                return 0;
 
        case LFUN_INSET_CAPTION: {
@@ -186,7 +180,7 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
                if (!up) {
                        auto_ptr<InsetCaption> inset(new InsetCaption(params));
                        inset->setAutoBreakRows(true);
-                       inset->setDrawFrame(InsetText::LOCKED);
+                       inset->setDrawFrame(true);
                        inset->setFrameColor(LColor::captionframe);
                        return inset.release();
                }
@@ -416,7 +410,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()));
@@ -469,6 +468,17 @@ 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<MathMacroTemplate*>(inset.get());
+                       MacroTable::globalMacros().insert
+                               (tmpl->name(), tmpl->asMacroData());
+                       lyxerr << "creating local macro " << tmpl->name() << endl;
+               }
        }
 
        return inset.release();