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/insetinclude.h"
30 #include "insets/insetindex.h"
31 #include "insets/insetlabel.h"
32 #include "insets/insetmarginal.h"
33 #include "insets/insetminipage.h"
34 #include "insets/insetnote.h"
35 #include "insets/insetoptarg.h"
36 #include "insets/insetparent.h"
37 #include "insets/insetref.h"
38 #include "insets/insettabular.h"
39 #include "insets/insettext.h"
40 #include "insets/insettoc.h"
41 #include "insets/inseturl.h"
42 #include "insets/insetwrap.h"
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.h"
51 Inset * createInset(FuncRequest const & cmd)
53 BufferView * bv = cmd.view();
54 BufferParams const & params = bv->buffer()->params;
57 case LFUN_INSET_MINIPAGE:
58 return new InsetMinipage(params);
60 case LFUN_INSERT_NOTE:
61 return new InsetNote(params);
64 return new InsetERT(params);
66 case LFUN_INSET_FOOTNOTE:
67 return new InsetFoot(params);
69 case LFUN_INSET_MARGINAL:
70 return new InsetMarginal(params);
72 case LFUN_INSET_OPTARG:
73 return new InsetOptArg(params);
75 case LFUN_INSERT_BIBITEM:
76 return new InsetBibitem(InsetCommandParams("bibitem"));
78 case LFUN_INSET_FLOAT:
79 // check if the float type exists
80 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
81 return new InsetFloat(params, cmd.argument);
82 lyxerr << "Non-existent float type: " << cmd.argument << endl;
85 case LFUN_INSET_WIDE_FLOAT:
86 // check if the float type exists
87 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
88 InsetFloat * p = new InsetFloat(params, cmd.argument);
89 p->wide(true, params);
91 lyxerr << "Non-existent float type: " << cmd.argument << endl;
95 if (cmd.argument == "figure")
96 return new InsetWrap(params, cmd.argument);
97 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
100 case LFUN_INDEX_INSERT: {
101 // Try and generate a valid index entry.
102 InsetCommandParams icp("index");
103 string const contents = cmd.argument.empty() ?
104 bv->getLyXText()->getStringToIndex(bv) :
106 icp.setContents(contents);
108 string data = InsetCommandMailer::params2string("index", icp);
109 LyXView * lv = bv->owner();
111 if (icp.getContents().empty()) {
112 lv->getDialogs().show("index", data, 0);
114 FuncRequest fr(bv, LFUN_INSET_APPLY, data);
120 case LFUN_TABULAR_INSERT:
121 if (!cmd.argument.empty()) {
124 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
125 return new InsetTabular(*bv->buffer(), r, c);
127 bv->owner()->getDialogs().showTabularCreate();
130 case LFUN_INSET_CAPTION:
131 if (bv->theLockingInset()) {
132 lyxerr << "Locking inset code: "
133 << static_cast<int>(bv->theLockingInset()->lyxCode());
134 InsetCaption * inset = new InsetCaption(params);
135 inset->setOwner(bv->theLockingInset());
136 inset->setAutoBreakRows(true);
137 inset->setDrawFrame(0, InsetText::LOCKED);
138 inset->setFrameColor(0, LColor::captionframe);
143 case LFUN_INDEX_PRINT:
144 return new InsetPrintIndex(InsetCommandParams("printindex"));
146 case LFUN_TOC_INSERT:
147 return new InsetTOC(InsetCommandParams("tableofcontents"));
149 case LFUN_PARENTINSERT:
150 return new InsetParent(
151 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
154 case LFUN_INSET_LIST:
155 return new InsetList;
157 case LFUN_INSET_THEOREM:
158 return new InsetTheorem;
161 case LFUN_INSET_APPLY: {
162 string const name = cmd.getArg(0);
164 if (name == "bibitem") {
165 InsetCommandParams icp;
166 InsetCommandMailer::string2params(cmd.argument, icp);
167 return new InsetBibitem(icp);
169 } else if (name == "bibtex") {
170 InsetCommandParams icp;
171 InsetCommandMailer::string2params(cmd.argument, icp);
172 return new InsetBibtex(icp);
174 } else if (name == "citation") {
175 InsetCommandParams icp;
176 InsetCommandMailer::string2params(cmd.argument, icp);
177 InsetCitation * inset = new InsetCitation(icp);
178 inset->setLoadingBuffer(bv->buffer(), false);
181 } else if (name == "ert") {
182 InsetERT * inset = new InsetERT(params);
183 InsetERT::ERTStatus s;
184 InsetERTMailer::string2params(cmd.argument, s);
185 inset->status(bv, s);
188 } else if (name == "external") {
189 InsetExternal::Params iep;
190 InsetExternalMailer::string2params(cmd.argument, iep);
191 InsetExternal * inset = new InsetExternal;
192 inset->setFromParams(iep);
195 } else if (name == "include") {
196 InsetInclude::Params iip;
197 InsetIncludeMailer::string2params(cmd.argument, iip);
198 return new InsetInclude(iip);
200 } else if (name == "index") {
201 InsetCommandParams icp;
202 InsetCommandMailer::string2params(cmd.argument, icp);
203 return new InsetIndex(icp);
205 } else if (name == "label") {
206 InsetCommandParams icp;
207 InsetCommandMailer::string2params(cmd.argument, icp);
208 return new InsetLabel(icp);
210 } else if (name == "ref") {
211 InsetCommandParams icp;
212 InsetCommandMailer::string2params(cmd.argument, icp);
213 return new InsetRef(icp, *bv->buffer());
215 } else if (name == "toc") {
216 InsetCommandParams icp;
217 InsetCommandMailer::string2params(cmd.argument, icp);
218 return new InsetTOC(icp);
220 } else if (name == "url") {
221 InsetCommandParams icp;
222 InsetCommandMailer::string2params(cmd.argument, icp);
223 return new InsetUrl(icp);