]> git.lyx.org Git - lyx.git/blob - src/factory.C
Move the include dialog to the new scheme
[lyx.git] / src / factory.C
1 /**
2  * \file factory.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "funcrequest.h"
14 #include "bufferparams.h"
15 #include "buffer.h"
16 #include "FloatList.h"
17 #include "debug.h"
18 #include "BufferView.h"
19 #include "lyxtext.h"
20
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"
43
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.h"
46
47 #include <cstdio>
48
49 using std::endl;
50
51 Inset * createInset(FuncRequest const & cmd)
52 {
53         BufferView * bv = cmd.view();
54         BufferParams const & params = bv->buffer()->params;
55
56         switch (cmd.action) {
57         case LFUN_INSET_MINIPAGE:
58                 return new InsetMinipage(params);
59
60         case LFUN_INSERT_NOTE:
61                 return new InsetNote(params);
62
63         case LFUN_INSET_ERT:
64                 return new InsetERT(params);
65
66         case LFUN_INSET_FOOTNOTE:
67                 return new InsetFoot(params);
68
69         case LFUN_INSET_MARGINAL:
70                 return new InsetMarginal(params);
71
72         case LFUN_INSET_OPTARG:
73                 return new InsetOptArg(params);
74
75         case LFUN_INSERT_BIBITEM:
76                 return new InsetBibitem(InsetCommandParams("bibitem"));
77
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;
83                 return 0;
84
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);
90                 }
91                 lyxerr << "Non-existent float type: " << cmd.argument << endl;
92                 return 0;
93
94         case LFUN_INSET_WRAP:
95                 if (cmd.argument == "figure")
96                         return new InsetWrap(params, cmd.argument);
97                 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
98                 return 0;
99
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) :
105                         cmd.argument;
106                 icp.setContents(contents);
107
108                 string data = InsetCommandMailer::params2string("index", icp);
109                 LyXView * lv = bv->owner();
110
111                 if (icp.getContents().empty()) {
112                         lv->getDialogs().show("index", data, 0);
113                 } else {
114                         FuncRequest fr(bv, LFUN_INSET_APPLY, data);
115                         lv->dispatch(fr);
116                 }
117                 return 0;
118         }
119
120         case LFUN_TABULAR_INSERT:
121                 if (!cmd.argument.empty()) {
122                         int r = 2;
123                         int c = 2;
124                         ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
125                         return new InsetTabular(*bv->buffer(), r, c);
126                 }
127                 bv->owner()->getDialogs().showTabularCreate();
128                 return 0;
129
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);
139                         return inset;
140                 }
141                 return 0;
142
143         case LFUN_INDEX_PRINT:
144                 return new InsetPrintIndex(InsetCommandParams("printindex"));
145
146         case LFUN_TOC_INSERT:
147                 return new InsetTOC(InsetCommandParams("tableofcontents"));
148
149         case LFUN_PARENTINSERT:
150                 return new InsetParent(
151                         InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
152
153 #if 0
154         case LFUN_INSET_LIST:
155                 return new InsetList;
156
157         case LFUN_INSET_THEOREM:
158                 return new InsetTheorem;
159 #endif
160
161         case LFUN_INSET_APPLY: {
162                 string const name = cmd.getArg(0);
163
164                 if (name == "bibitem") {
165                         InsetCommandParams icp;
166                         InsetCommandMailer::string2params(cmd.argument, icp);
167                         return new InsetBibitem(icp);
168
169                 } else if (name == "bibtex") {
170                         InsetCommandParams icp;
171                         InsetCommandMailer::string2params(cmd.argument, icp);
172                         return new InsetBibtex(icp);
173
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);
179                         return inset;
180
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);
186                         return inset;
187
188                 } else if (name == "external") {
189                         InsetExternal::Params iep;                      
190                         InsetExternalMailer::string2params(cmd.argument, iep);
191                         InsetExternal * inset = new InsetExternal;
192                         inset->setFromParams(iep);
193                         return inset;
194
195                 } else if (name == "include") {
196                         InsetInclude::Params iip;
197                         InsetIncludeMailer::string2params(cmd.argument, iip);
198                         return new InsetInclude(iip);
199
200                 } else if (name == "index") {
201                         InsetCommandParams icp;
202                         InsetCommandMailer::string2params(cmd.argument, icp);
203                         return new InsetIndex(icp);
204
205                 } else if (name == "label") {
206                         InsetCommandParams icp;
207                         InsetCommandMailer::string2params(cmd.argument, icp);
208                         return new InsetLabel(icp);
209
210                 } else if (name == "ref") {
211                         InsetCommandParams icp;
212                         InsetCommandMailer::string2params(cmd.argument, icp);
213                         return new InsetRef(icp, *bv->buffer());
214
215                 } else if (name == "toc") {
216                         InsetCommandParams icp;
217                         InsetCommandMailer::string2params(cmd.argument, icp);
218                         return new InsetTOC(icp);
219
220                 } else if (name == "url") {
221                         InsetCommandParams icp;
222                         InsetCommandMailer::string2params(cmd.argument, icp);
223                         return new InsetUrl(icp);
224                 }
225         }
226         break;
227
228         default:
229                 break;
230         }
231
232         return 0;
233 }