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/insethfill.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetindex.h"
33 #include "insets/insetlabel.h"
34 #include "insets/insetmarginal.h"
35 #include "insets/insetminipage.h"
36 #include "insets/insetnote.h"
37 #include "insets/insetoptarg.h"
38 #include "insets/insetparent.h"
39 #include "insets/insetref.h"
40 #include "insets/insettabular.h"
41 #include "insets/insettext.h"
42 #include "insets/insettoc.h"
43 #include "insets/inseturl.h"
44 #include "insets/insetwrap.h"
46 #include "frontends/Dialogs.h"
47 #include "frontends/LyXView.h"
53 Inset * createInset(FuncRequest const & cmd)
55 BufferView * bv = cmd.view();
56 BufferParams const & params = bv->buffer()->params;
60 return new InsetHFill();
62 case LFUN_INSET_MINIPAGE:
63 return new InsetMinipage(params);
65 case LFUN_INSERT_NOTE:
66 return new InsetNote(params);
69 return new InsetERT(params);
71 case LFUN_INSET_FOOTNOTE:
72 return new InsetFoot(params);
74 case LFUN_INSET_MARGINAL:
75 return new InsetMarginal(params);
77 case LFUN_INSET_OPTARG:
78 return new InsetOptArg(params);
80 case LFUN_INSERT_BIBITEM:
81 return new InsetBibitem(InsetCommandParams("bibitem"));
83 case LFUN_INSET_FLOAT:
84 // check if the float type exists
85 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
86 return new InsetFloat(params, cmd.argument);
87 lyxerr << "Non-existent float type: " << cmd.argument << endl;
90 case LFUN_INSET_WIDE_FLOAT:
91 // check if the float type exists
92 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
93 InsetFloat * p = new InsetFloat(params, cmd.argument);
94 p->wide(true, params);
96 lyxerr << "Non-existent float type: " << cmd.argument << endl;
100 if (cmd.argument == "figure")
101 return new InsetWrap(params, cmd.argument);
102 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
105 case LFUN_INDEX_INSERT: {
106 // Try and generate a valid index entry.
107 InsetCommandParams icp("index");
108 string const contents = cmd.argument.empty() ?
109 bv->getLyXText()->getStringToIndex(bv) :
111 icp.setContents(contents);
113 string data = InsetCommandMailer::params2string("index", icp);
114 LyXView * lv = bv->owner();
116 if (icp.getContents().empty()) {
117 lv->getDialogs().show("index", data, 0);
119 FuncRequest fr(bv, LFUN_INSET_APPLY, data);
125 case LFUN_TABULAR_INSERT:
126 if (!cmd.argument.empty()) {
129 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
130 return new InsetTabular(*bv->buffer(), r, c);
132 bv->owner()->getDialogs().show("tabularcreate");
135 case LFUN_INSET_CAPTION:
136 if (bv->theLockingInset()) {
137 lyxerr << "Locking inset code: "
138 << static_cast<int>(bv->theLockingInset()->lyxCode());
139 InsetCaption * inset = new InsetCaption(params);
140 inset->setOwner(bv->theLockingInset());
141 inset->setAutoBreakRows(true);
142 inset->setDrawFrame(0, InsetText::LOCKED);
143 inset->setFrameColor(0, LColor::captionframe);
148 case LFUN_INDEX_PRINT:
149 return new InsetPrintIndex(InsetCommandParams("printindex"));
151 case LFUN_TOC_INSERT:
152 return new InsetTOC(InsetCommandParams("tableofcontents"));
154 case LFUN_PARENTINSERT:
155 return new InsetParent(
156 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
159 case LFUN_INSET_LIST:
160 return new InsetList;
162 case LFUN_INSET_THEOREM:
163 return new InsetTheorem;
166 case LFUN_INSET_APPLY: {
167 string const name = cmd.getArg(0);
169 if (name == "bibitem") {
170 InsetCommandParams icp;
171 InsetCommandMailer::string2params(cmd.argument, icp);
172 return new InsetBibitem(icp);
174 } else if (name == "bibtex") {
175 InsetCommandParams icp;
176 InsetCommandMailer::string2params(cmd.argument, icp);
177 return new InsetBibtex(icp);
179 } else if (name == "citation") {
180 InsetCommandParams icp;
181 InsetCommandMailer::string2params(cmd.argument, icp);
182 InsetCitation * inset = new InsetCitation(icp);
183 inset->setLoadingBuffer(bv->buffer(), false);
186 } else if (name == "ert") {
187 InsetERT * inset = new InsetERT(params);
188 InsetERT::ERTStatus s;
189 InsetERTMailer::string2params(cmd.argument, s);
190 inset->status(bv, s);
193 } else if (name == "external") {
194 InsetExternal::Params iep;
195 InsetExternalMailer::string2params(cmd.argument, iep);
196 InsetExternal * inset = new InsetExternal;
197 inset->setFromParams(iep);
200 } else if (name == "graphics") {
201 InsetGraphicsParams igp;
202 InsetGraphicsMailer::string2params(cmd.argument, igp);
203 InsetGraphics * inset = new InsetGraphics;
204 string const fpath = cmd.view()->buffer()->filePath();
205 inset->setParams(igp, fpath);
208 } else if (name == "include") {
209 InsetInclude::Params iip;
210 InsetIncludeMailer::string2params(cmd.argument, iip);
211 return new InsetInclude(iip);
213 } else if (name == "index") {
214 InsetCommandParams icp;
215 InsetCommandMailer::string2params(cmd.argument, icp);
216 return new InsetIndex(icp);
218 } else if (name == "label") {
219 InsetCommandParams icp;
220 InsetCommandMailer::string2params(cmd.argument, icp);
221 return new InsetLabel(icp);
223 } else if (name == "ref") {
224 InsetCommandParams icp;
225 InsetCommandMailer::string2params(cmd.argument, icp);
226 return new InsetRef(icp, *bv->buffer());
228 } else if (name == "toc") {
229 InsetCommandParams icp;
230 InsetCommandMailer::string2params(cmd.argument, icp);
231 return new InsetTOC(icp);
233 } else if (name == "url") {
234 InsetCommandParams icp;
235 InsetCommandMailer::string2params(cmd.argument, icp);
236 return new InsetUrl(icp);