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/insetgraphics.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetindex.h"
32 #include "insets/insetlabel.h"
33 #include "insets/insetmarginal.h"
34 #include "insets/insetminipage.h"
35 #include "insets/insetnote.h"
36 #include "insets/insetoptarg.h"
37 #include "insets/insetparent.h"
38 #include "insets/insetref.h"
39 #include "insets/insettabular.h"
40 #include "insets/insettext.h"
41 #include "insets/insettoc.h"
42 #include "insets/inseturl.h"
43 #include "insets/insetwrap.h"
45 #include "frontends/Dialogs.h"
46 #include "frontends/LyXView.h"
52 Inset * createInset(FuncRequest const & cmd)
54 BufferView * bv = cmd.view();
55 BufferParams const & params = bv->buffer()->params;
58 case LFUN_INSET_MINIPAGE:
59 return new InsetMinipage(params);
61 case LFUN_INSERT_NOTE:
62 return new InsetNote(params);
65 return new InsetERT(params);
67 case LFUN_INSET_FOOTNOTE:
68 return new InsetFoot(params);
70 case LFUN_INSET_MARGINAL:
71 return new InsetMarginal(params);
73 case LFUN_INSET_OPTARG:
74 return new InsetOptArg(params);
76 case LFUN_INSERT_BIBITEM:
77 return new InsetBibitem(InsetCommandParams("bibitem"));
79 case LFUN_INSET_FLOAT:
80 // check if the float type exists
81 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
82 return new InsetFloat(params, cmd.argument);
83 lyxerr << "Non-existent float type: " << cmd.argument << endl;
86 case LFUN_INSET_WIDE_FLOAT:
87 // check if the float type exists
88 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
89 InsetFloat * p = new InsetFloat(params, cmd.argument);
90 p->wide(true, params);
92 lyxerr << "Non-existent float type: " << cmd.argument << endl;
96 if (cmd.argument == "figure")
97 return new InsetWrap(params, cmd.argument);
98 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
101 case LFUN_INDEX_INSERT: {
102 // Try and generate a valid index entry.
103 InsetCommandParams icp("index");
104 string const contents = cmd.argument.empty() ?
105 bv->getLyXText()->getStringToIndex(bv) :
107 icp.setContents(contents);
109 string data = InsetCommandMailer::params2string("index", icp);
110 LyXView * lv = bv->owner();
112 if (icp.getContents().empty()) {
113 lv->getDialogs().show("index", data, 0);
115 FuncRequest fr(bv, LFUN_INSET_APPLY, data);
121 case LFUN_TABULAR_INSERT:
122 if (!cmd.argument.empty()) {
125 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
126 return new InsetTabular(*bv->buffer(), r, c);
128 bv->owner()->getDialogs().show("tabularcreate", string(), 0);
131 case LFUN_INSET_CAPTION:
132 if (bv->theLockingInset()) {
133 lyxerr << "Locking inset code: "
134 << static_cast<int>(bv->theLockingInset()->lyxCode());
135 InsetCaption * inset = new InsetCaption(params);
136 inset->setOwner(bv->theLockingInset());
137 inset->setAutoBreakRows(true);
138 inset->setDrawFrame(0, InsetText::LOCKED);
139 inset->setFrameColor(0, LColor::captionframe);
144 case LFUN_INDEX_PRINT:
145 return new InsetPrintIndex(InsetCommandParams("printindex"));
147 case LFUN_TOC_INSERT:
148 return new InsetTOC(InsetCommandParams("tableofcontents"));
150 case LFUN_PARENTINSERT:
151 return new InsetParent(
152 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
155 case LFUN_INSET_LIST:
156 return new InsetList;
158 case LFUN_INSET_THEOREM:
159 return new InsetTheorem;
162 case LFUN_INSET_APPLY: {
163 string const name = cmd.getArg(0);
165 if (name == "bibitem") {
166 InsetCommandParams icp;
167 InsetCommandMailer::string2params(cmd.argument, icp);
168 return new InsetBibitem(icp);
170 } else if (name == "bibtex") {
171 InsetCommandParams icp;
172 InsetCommandMailer::string2params(cmd.argument, icp);
173 return new InsetBibtex(icp);
175 } else if (name == "citation") {
176 InsetCommandParams icp;
177 InsetCommandMailer::string2params(cmd.argument, icp);
178 InsetCitation * inset = new InsetCitation(icp);
179 inset->setLoadingBuffer(bv->buffer(), false);
182 } else if (name == "ert") {
183 InsetERT * inset = new InsetERT(params);
184 InsetERT::ERTStatus s;
185 InsetERTMailer::string2params(cmd.argument, s);
186 inset->status(bv, s);
189 } else if (name == "external") {
190 InsetExternal::Params iep;
191 InsetExternalMailer::string2params(cmd.argument, iep);
192 InsetExternal * inset = new InsetExternal;
193 inset->setFromParams(iep);
196 } else if (name == "graphics") {
197 InsetGraphicsParams igp;
198 InsetGraphicsMailer::string2params(cmd.argument, igp);
199 InsetGraphics * inset = new InsetGraphics;
200 string const fpath = cmd.view()->buffer()->filePath();
201 inset->setParams(igp, fpath);
204 } else if (name == "include") {
205 InsetInclude::Params iip;
206 InsetIncludeMailer::string2params(cmd.argument, iip);
207 return new InsetInclude(iip);
209 } else if (name == "index") {
210 InsetCommandParams icp;
211 InsetCommandMailer::string2params(cmd.argument, icp);
212 return new InsetIndex(icp);
214 } else if (name == "label") {
215 InsetCommandParams icp;
216 InsetCommandMailer::string2params(cmd.argument, icp);
217 return new InsetLabel(icp);
219 } else if (name == "ref") {
220 InsetCommandParams icp;
221 InsetCommandMailer::string2params(cmd.argument, icp);
222 return new InsetRef(icp, *bv->buffer());
224 } else if (name == "toc") {
225 InsetCommandParams icp;
226 InsetCommandMailer::string2params(cmd.argument, icp);
227 return new InsetTOC(icp);
229 } else if (name == "url") {
230 InsetCommandParams icp;
231 InsetCommandMailer::string2params(cmd.argument, icp);
232 return new InsetUrl(icp);