3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "funcrequest.h"
14 #include "bufferparams.h"
16 #include "FloatList.h"
18 #include "BufferView.h"
21 #include "insets/insetcaption.h"
22 #include "insets/insetert.h"
23 #include "insets/insetexternal.h"
24 #include "insets/insetfloat.h"
25 #include "insets/insetfoot.h"
26 #include "insets/insetindex.h"
27 #include "insets/insetmarginal.h"
28 #include "insets/insetminipage.h"
29 #include "insets/insetnote.h"
30 #include "insets/insetoptarg.h"
31 #include "insets/insetparent.h"
32 #include "insets/insetref.h"
33 #include "insets/insettabular.h"
34 #include "insets/insettext.h"
35 #include "insets/insettoc.h"
36 #include "insets/inseturl.h"
37 #include "insets/insetwrap.h"
38 #include "frontends/Dialogs.h"
39 #include "frontends/LyXView.h"
45 Inset * createInset(FuncRequest const & cmd)
47 BufferView * bv = cmd.view();
48 BufferParams const & params = bv->buffer()->params;
52 case LFUN_INSET_MINIPAGE:
53 return new InsetMinipage(params);
55 case LFUN_INSERT_NOTE:
56 return new InsetNote(params);
59 return new InsetERT(params);
61 case LFUN_INSET_EXTERNAL:
62 return new InsetExternal;
64 case LFUN_INSET_FOOTNOTE:
65 return new InsetFoot(params);
67 case LFUN_INSET_MARGINAL:
68 return new InsetMarginal(params);
70 case LFUN_INSET_OPTARG:
71 return new InsetOptArg(params);
73 case LFUN_INSET_FLOAT:
74 // check if the float type exists
75 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
76 return new InsetFloat(params, cmd.argument);
77 lyxerr << "Non-existent float type: " << cmd.argument << endl;
80 case LFUN_INSET_WIDE_FLOAT:
81 // check if the float type exists
82 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
83 InsetFloat * p = new InsetFloat(params, cmd.argument);
84 p->wide(true, params);
86 lyxerr << "Non-existent float type: " << cmd.argument << endl;
90 if (cmd.argument == "figure")
91 return new InsetWrap(params, cmd.argument);
92 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
95 case LFUN_INDEX_INSERT: {
96 string const entry = cmd.argument.empty() ?
97 "index" : cmd.argument;
98 InsetCommandParams icp;
99 icp.setFromString(entry);
101 if (icp.getContents().empty())
102 icp.setContents(bv->getLyXText()->getStringToIndex(bv));
103 if (!icp.getContents().empty())
104 return new InsetIndex(icp);
106 bv->owner()->getDialogs().createIndex();
110 case LFUN_TABULAR_INSERT:
111 if (!cmd.argument.empty()) {
114 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
115 return new InsetTabular(*bv->buffer(), r, c);
117 bv->owner()->getDialogs().showTabularCreate();
120 case LFUN_INSET_CAPTION:
121 if (bv->theLockingInset()) {
122 lyxerr << "Locking inset code: "
123 << static_cast<int>(bv->theLockingInset()->lyxCode());
124 InsetCaption * inset = new InsetCaption(params);
125 inset->setOwner(bv->theLockingInset());
126 inset->setAutoBreakRows(true);
127 inset->setDrawFrame(0, InsetText::LOCKED);
128 inset->setFrameColor(0, LColor::captionframe);
133 case LFUN_INDEX_PRINT:
134 return new InsetPrintIndex(InsetCommandParams("printindex"));
136 case LFUN_TOC_INSERT:
137 return new InsetTOC(InsetCommandParams("tableofcontents"));
139 case LFUN_PARENTINSERT:
140 return new InsetParent(
141 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
143 case LFUN_INSERT_URL:
145 InsetCommandParams p;
146 p.setFromString(cmd.argument);
147 return new InsetUrl(p);
151 case LFUN_INSET_LIST:
152 return new InsetList;
154 case LFUN_INSET_THEOREM:
155 return new InsetTheorem;