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/insetbibitem.h"
22 #include "insets/insetbibtex.h"
23 #include "insets/insetcaption.h"
24 #include "insets/insetcite.h"
25 #include "insets/insetert.h"
26 #include "insets/insetexternal.h"
27 #include "insets/insetfloat.h"
28 #include "insets/insetfoot.h"
29 #include "insets/insetindex.h"
30 #include "insets/insetlabel.h"
31 #include "insets/insetmarginal.h"
32 #include "insets/insetminipage.h"
33 #include "insets/insetnote.h"
34 #include "insets/insetoptarg.h"
35 #include "insets/insetparent.h"
36 #include "insets/insetref.h"
37 #include "insets/insettabular.h"
38 #include "insets/insettext.h"
39 #include "insets/insettoc.h"
40 #include "insets/inseturl.h"
41 #include "insets/insetwrap.h"
43 #include "frontends/Dialogs.h"
44 #include "frontends/LyXView.h"
50 Inset * createInset(FuncRequest const & cmd)
52 BufferView * bv = cmd.view();
53 BufferParams const & params = bv->buffer()->params;
56 case LFUN_INSET_MINIPAGE:
57 return new InsetMinipage(params);
59 case LFUN_INSERT_NOTE:
60 return new InsetNote(params);
63 return new InsetERT(params);
65 case LFUN_INSET_EXTERNAL:
66 return new InsetExternal;
68 case LFUN_INSET_FOOTNOTE:
69 return new InsetFoot(params);
71 case LFUN_INSET_MARGINAL:
72 return new InsetMarginal(params);
74 case LFUN_INSET_OPTARG:
75 return new InsetOptArg(params);
77 case LFUN_INSERT_BIBITEM:
78 return new InsetBibitem(InsetCommandParams("bibitem"));
80 case LFUN_INSET_FLOAT:
81 // check if the float type exists
82 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
83 return new InsetFloat(params, cmd.argument);
84 lyxerr << "Non-existent float type: " << cmd.argument << endl;
87 case LFUN_INSET_WIDE_FLOAT:
88 // check if the float type exists
89 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
90 InsetFloat * p = new InsetFloat(params, cmd.argument);
91 p->wide(true, params);
93 lyxerr << "Non-existent float type: " << cmd.argument << endl;
97 if (cmd.argument == "figure")
98 return new InsetWrap(params, cmd.argument);
99 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
102 case LFUN_INDEX_INSERT: {
103 // Try and generate a valid index entry.
104 InsetCommandParams icp("index");
105 string const contents = cmd.argument.empty() ?
106 bv->getLyXText()->getStringToIndex(bv) :
108 icp.setContents(contents);
110 string data = InsetCommandMailer::params2string("index", icp);
111 LyXView * lv = bv->owner();
113 if (icp.getContents().empty()) {
114 lv->getDialogs().show("index", data, 0);
116 FuncRequest fr(bv, LFUN_INSET_APPLY, data);
122 case LFUN_TABULAR_INSERT:
123 if (!cmd.argument.empty()) {
126 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
127 return new InsetTabular(*bv->buffer(), r, c);
129 bv->owner()->getDialogs().showTabularCreate();
132 case LFUN_INSET_CAPTION:
133 if (bv->theLockingInset()) {
134 lyxerr << "Locking inset code: "
135 << static_cast<int>(bv->theLockingInset()->lyxCode());
136 InsetCaption * inset = new InsetCaption(params);
137 inset->setOwner(bv->theLockingInset());
138 inset->setAutoBreakRows(true);
139 inset->setDrawFrame(0, InsetText::LOCKED);
140 inset->setFrameColor(0, LColor::captionframe);
145 case LFUN_INDEX_PRINT:
146 return new InsetPrintIndex(InsetCommandParams("printindex"));
148 case LFUN_TOC_INSERT:
149 return new InsetTOC(InsetCommandParams("tableofcontents"));
151 case LFUN_PARENTINSERT:
152 return new InsetParent(
153 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
155 case LFUN_INSERT_URL:
157 InsetCommandParams p;
158 p.setFromString(cmd.argument);
159 return new InsetUrl(p);
163 case LFUN_INSET_LIST:
164 return new InsetList;
166 case LFUN_INSET_THEOREM:
167 return new InsetTheorem;
170 case LFUN_INSET_APPLY: {
171 string const name = cmd.getArg(0);
173 if (name == "bibitem") {
174 InsetCommandParams icp;
175 InsetCommandMailer::string2params(cmd.argument, icp);
176 return new InsetBibitem(icp);
178 } else if (name == "bibtex") {
179 InsetCommandParams icp;
180 InsetCommandMailer::string2params(cmd.argument, icp);
181 return new InsetBibtex(icp);
183 } else if (name == "citation") {
184 InsetCommandParams icp;
185 InsetCommandMailer::string2params(cmd.argument, icp);
186 InsetCitation * inset = new InsetCitation(icp);
187 inset->setLoadingBuffer(bv->buffer(), false);
190 } else if (name == "ert") {
191 InsetERT * inset = new InsetERT(params);
192 InsetERT::ERTStatus s;
193 InsetERTMailer::string2params(cmd.argument, s);
194 inset->status(bv, s);
197 } else if (name == "index") {
198 InsetCommandParams icp;
199 InsetCommandMailer::string2params(cmd.argument, icp);
200 return new InsetIndex(icp);
202 } else if (name == "label") {
203 InsetCommandParams icp;
204 InsetCommandMailer::string2params(cmd.argument, icp);
205 return new InsetLabel(icp);
207 } else if (name == "ref") {
208 InsetCommandParams icp;
209 InsetCommandMailer::string2params(cmd.argument, icp);
210 return new InsetRef(icp, *bv->buffer());
212 } else if (name == "toc") {
213 InsetCommandParams icp;
214 InsetCommandMailer::string2params(cmd.argument, icp);
215 return new InsetTOC(icp);
217 } else if (name == "url") {
218 InsetCommandParams icp;
219 InsetCommandMailer::string2params(cmd.argument, icp);
220 return new InsetUrl(icp);