]> git.lyx.org Git - lyx.git/blobdiff - src/factory.C
Collapse all those LFUN_XYZ_APPLY to a single LFUN_INSET_APPLY.
[lyx.git] / src / factory.C
index 8e032cf51f052b7223ab652af041000967d51b9b..288aa0e15043192bde889bc9e3142ab6ab6855e3 100644 (file)
@@ -19,7 +19,9 @@
 #include "lyxtext.h"
 
 #include "insets/insetbibitem.h"
+#include "insets/insetbibtex.h"
 #include "insets/insetcaption.h"
+#include "insets/insetcite.h"
 #include "insets/insetert.h"
 #include "insets/insetexternal.h"
 #include "insets/insetfloat.h"
@@ -36,6 +38,7 @@
 #include "insets/insettoc.h"
 #include "insets/inseturl.h"
 #include "insets/insetwrap.h"
+
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
 
@@ -49,118 +52,173 @@ Inset * createInset(FuncRequest const & cmd)
        BufferParams const & params = bv->buffer()->params;
 
        switch (cmd.action) {
+       case LFUN_INSET_MINIPAGE:
+               return new InsetMinipage(params);
+
+       case LFUN_INSERT_NOTE:
+               return new InsetNote(params);
+
+       case LFUN_INSET_ERT:
+               return new InsetERT(params);
+
+       case LFUN_INSET_EXTERNAL:
+               return new InsetExternal;
+
+       case LFUN_INSET_FOOTNOTE:
+               return new InsetFoot(params);
+
+       case LFUN_INSET_MARGINAL:
+               return new InsetMarginal(params);
+
+       case LFUN_INSET_OPTARG:
+               return new InsetOptArg(params);
 
-               case LFUN_INSET_MINIPAGE:
-                       return new InsetMinipage(params);
+       case LFUN_INSERT_BIBITEM:
+               return new InsetBibitem(InsetCommandParams("bibitem"));
 
-               case LFUN_INSERT_NOTE:
-                       return new InsetNote(params);
+       case LFUN_INSET_FLOAT:
+               // check if the float type exists
+               if (params.getLyXTextClass().floats().typeExist(cmd.argument))
+                       return new InsetFloat(params, cmd.argument);
+               lyxerr << "Non-existent float type: " << cmd.argument << endl;
+               return 0;
+
+       case LFUN_INSET_WIDE_FLOAT:
+               // check if the float type exists
+               if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
+                       InsetFloat * p = new InsetFloat(params, cmd.argument);
+                       p->wide(true, params);
+               }
+               lyxerr << "Non-existent float type: " << cmd.argument << endl;
+               return 0;
+
+       case LFUN_INSET_WRAP:
+               if (cmd.argument == "figure")
+                       return new InsetWrap(params, cmd.argument);
+               lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
+               return 0;
+
+       case LFUN_INDEX_INSERT: {
+               // Try and generate a valid index entry.
+               InsetCommandParams icp("index");
+               string const contents = cmd.argument.empty() ?
+                       bv->getLyXText()->getStringToIndex(bv) :
+                       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 {
+                       FuncRequest fr(bv, LFUN_INSET_APPLY, data);
+                       lv->dispatch(fr);
+               }
+               return 0;
+       }
+
+       case LFUN_TABULAR_INSERT:
+               if (!cmd.argument.empty()) {
+                       int r = 2;
+                       int c = 2;
+                       ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
+                       return new InsetTabular(*bv->buffer(), r, c);
+               }
+               bv->owner()->getDialogs().showTabularCreate();
+               return 0;
+
+       case LFUN_INSET_CAPTION:
+               if (bv->theLockingInset()) {
+                       lyxerr << "Locking inset code: "
+                              << static_cast<int>(bv->theLockingInset()->lyxCode());
+                       InsetCaption * inset = new InsetCaption(params);
+                       inset->setOwner(bv->theLockingInset());
+                       inset->setAutoBreakRows(true);
+                       inset->setDrawFrame(0, InsetText::LOCKED);
+                       inset->setFrameColor(0, LColor::captionframe);
+                       return inset;
+               }
+               return 0;
 
-               case LFUN_INSET_ERT:
-                       return new InsetERT(params);
+       case LFUN_INDEX_PRINT:
+               return new InsetPrintIndex(InsetCommandParams("printindex"));
 
-               case LFUN_INSET_EXTERNAL:
-                       return new InsetExternal;
+       case LFUN_TOC_INSERT:
+               return new InsetTOC(InsetCommandParams("tableofcontents"));
 
-               case LFUN_INSET_FOOTNOTE:
-                       return new InsetFoot(params);
+       case LFUN_PARENTINSERT:
+               return new InsetParent(
+                       InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
 
-               case LFUN_INSET_MARGINAL:
-                       return new InsetMarginal(params);
+       case LFUN_INSERT_URL:
+       {
+               InsetCommandParams p;
+               p.setFromString(cmd.argument);
+               return new InsetUrl(p);
+       }
 
-               case LFUN_INSET_OPTARG:
-                       return new InsetOptArg(params);
+#if 0
+       case LFUN_INSET_LIST:
+               return new InsetList;
 
-               case LFUN_INSERT_BIBITEM:
-                       return new InsetBibitem(InsetCommandParams("bibitem"));
+       case LFUN_INSET_THEOREM:
+               return new InsetTheorem;
+#endif
 
-               case LFUN_INSET_FLOAT:
-                       // check if the float type exists
-                       if (params.getLyXTextClass().floats().typeExist(cmd.argument))
-                               return new InsetFloat(params, cmd.argument);
-                       lyxerr << "Non-existent float type: " << cmd.argument << endl;
-                       return 0;
+       case LFUN_INSET_APPLY: {
+               string const name = cmd.getArg(0);
 
-               case LFUN_INSET_WIDE_FLOAT:
-                       // check if the float type exists
-                       if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
-                               InsetFloat * p = new InsetFloat(params, cmd.argument);
-                               p->wide(true, params);
-                       }
-                       lyxerr << "Non-existent float type: " << cmd.argument << endl;
-                       return 0;
+               if (name == "bibitem") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetBibitem(icp);
 
-               case LFUN_INSET_WRAP:
-                       if (cmd.argument == "figure")
-                               return new InsetWrap(params, cmd.argument);
-                       lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
-                       return 0;
+               } else if (name == "bibtex") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetBibtex(icp);
 
-               case LFUN_INDEX_INSERT: {
-                       string const entry = cmd.argument.empty() ?
-                               "index" : cmd.argument;
+               } else if (name == "citation") {
                        InsetCommandParams icp;
-                       icp.setFromString(entry);
-
-                       if (icp.getContents().empty())
-                               icp.setContents(bv->getLyXText()->getStringToIndex(bv));
-                       if (!icp.getContents().empty())
-                               return new InsetIndex(icp);
-                       
-                       bv->owner()->getDialogs().createIndex();
-                       return 0;
-               }
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       InsetCitation * inset = new InsetCitation(icp);
+                       inset->setLoadingBuffer(bv->buffer(), false);
+                       return inset;
+
+               } else if (name == "ert") {
+                       InsetERT * inset = new InsetERT(params);
+                       InsetERT::ERTStatus s;
+                       InsetERTMailer::string2params(cmd.argument, s);
+                       inset->status(bv, s);
+                       return inset;
+
+               } else if (name == "index") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetIndex(icp);
 
-               case LFUN_TABULAR_INSERT:
-                       if (!cmd.argument.empty()) {
-                               int r = 2;
-                               int c = 2;
-                               ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
-                               return new InsetTabular(*bv->buffer(), r, c);
-                       }
-                       bv->owner()->getDialogs().showTabularCreate();
-                       return 0;
-
-               case LFUN_INSET_CAPTION:
-                       if (bv->theLockingInset()) {
-                               lyxerr << "Locking inset code: "
-                                                        << static_cast<int>(bv->theLockingInset()->lyxCode());
-                               InsetCaption * inset = new InsetCaption(params);
-                               inset->setOwner(bv->theLockingInset());
-                               inset->setAutoBreakRows(true);
-                               inset->setDrawFrame(0, InsetText::LOCKED);
-                               inset->setFrameColor(0, LColor::captionframe);
-                               return inset;
-                       }
-                       return 0;
-
-               case LFUN_INDEX_PRINT:
-                       return new InsetPrintIndex(InsetCommandParams("printindex"));
-
-               case LFUN_TOC_INSERT:
-                       return new InsetTOC(InsetCommandParams("tableofcontents"));
-
-               case LFUN_PARENTINSERT:
-                       return new InsetParent(
-                               InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
-
-               case LFUN_INSERT_URL:
-               {
-                       InsetCommandParams p;
-                       p.setFromString(cmd.argument);
-                       return new InsetUrl(p);
-               }
+               } else if (name == "ref") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetRef(icp, *bv->buffer());
 
-       #if 0
-               case LFUN_INSET_LIST:
-                       return new InsetList;
+               } else if (name == "toc") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetTOC(icp);
 
-               case LFUN_INSET_THEOREM:
-                       return new InsetTheorem;
-       #endif
+               } else if (name == "url") {
+                       InsetCommandParams icp;
+                       InsetCommandMailer::string2params(cmd.argument, icp);
+                       return new InsetUrl(icp);
+               }
+       }
+       break;
 
-               default:
-                       break;
+       default:
+               break;
        }
+
        return 0;
 }