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/insetmarginal.h"
31 #include "insets/insetminipage.h"
32 #include "insets/insetnote.h"
33 #include "insets/insetoptarg.h"
34 #include "insets/insetparent.h"
35 #include "insets/insetref.h"
36 #include "insets/insettabular.h"
37 #include "insets/insettext.h"
38 #include "insets/insettoc.h"
39 #include "insets/inseturl.h"
40 #include "insets/insetwrap.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
49 Inset * createInset(FuncRequest const & cmd)
51 BufferView * bv = cmd.view();
52 BufferParams const & params = bv->buffer()->params;
55 case LFUN_INSET_MINIPAGE:
56 return new InsetMinipage(params);
58 case LFUN_INSERT_NOTE:
59 return new InsetNote(params);
62 return new InsetERT(params);
64 case LFUN_INSET_EXTERNAL:
65 return new InsetExternal;
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().showTabularCreate();
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());
154 case LFUN_INSERT_URL:
156 InsetCommandParams p;
157 p.setFromString(cmd.argument);
158 return new InsetUrl(p);
162 case LFUN_INSET_LIST:
163 return new InsetList;
165 case LFUN_INSET_THEOREM:
166 return new InsetTheorem;
169 case LFUN_INSET_APPLY: {
170 string const name = cmd.getArg(0);
172 if (name == "bibitem") {
173 InsetCommandParams icp;
174 InsetCommandMailer::string2params(cmd.argument, icp);
175 return new InsetBibitem(icp);
177 } else if (name == "bibtex") {
178 InsetCommandParams icp;
179 InsetCommandMailer::string2params(cmd.argument, icp);
180 return new InsetBibtex(icp);
182 } else if (name == "citation") {
183 InsetCommandParams icp;
184 InsetCommandMailer::string2params(cmd.argument, icp);
185 InsetCitation * inset = new InsetCitation(icp);
186 inset->setLoadingBuffer(bv->buffer(), false);
189 } else if (name == "ert") {
190 InsetERT * inset = new InsetERT(params);
191 InsetERT::ERTStatus s;
192 InsetERTMailer::string2params(cmd.argument, s);
193 inset->status(bv, s);
196 } else if (name == "index") {
197 InsetCommandParams icp;
198 InsetCommandMailer::string2params(cmd.argument, icp);
199 return new InsetIndex(icp);
201 } else if (name == "ref") {
202 InsetCommandParams icp;
203 InsetCommandMailer::string2params(cmd.argument, icp);
204 return new InsetRef(icp, *bv->buffer());
206 } else if (name == "toc") {
207 InsetCommandParams icp;
208 InsetCommandMailer::string2params(cmd.argument, icp);
209 return new InsetTOC(icp);
211 } else if (name == "url") {
212 InsetCommandParams icp;
213 InsetCommandMailer::string2params(cmd.argument, icp);
214 return new InsetUrl(icp);