]> git.lyx.org Git - lyx.git/blob - src/factory.C
c0a8cfab93c481e5504ca73a46316c4596a29817
[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/insetcaption.h"
23 #include "insets/insetert.h"
24 #include "insets/insetexternal.h"
25 #include "insets/insetfloat.h"
26 #include "insets/insetfoot.h"
27 #include "insets/insetindex.h"
28 #include "insets/insetmarginal.h"
29 #include "insets/insetminipage.h"
30 #include "insets/insetnote.h"
31 #include "insets/insetoptarg.h"
32 #include "insets/insetparent.h"
33 #include "insets/insetref.h"
34 #include "insets/insettabular.h"
35 #include "insets/insettext.h"
36 #include "insets/insettoc.h"
37 #include "insets/inseturl.h"
38 #include "insets/insetwrap.h"
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
41
42 #include <cstdio>
43
44 using std::endl;
45
46 Inset * createInset(FuncRequest const & cmd)
47 {
48         BufferView * bv = cmd.view();
49         BufferParams const & params = bv->buffer()->params;
50
51         switch (cmd.action) {
52
53                 case LFUN_INSET_MINIPAGE:
54                         return new InsetMinipage(params);
55
56                 case LFUN_INSERT_NOTE:
57                         return new InsetNote(params);
58
59                 case LFUN_INSET_ERT:
60                         return new InsetERT(params);
61
62                 case LFUN_INSET_EXTERNAL:
63                         return new InsetExternal;
64
65                 case LFUN_INSET_FOOTNOTE:
66                         return new InsetFoot(params);
67
68                 case LFUN_INSET_MARGINAL:
69                         return new InsetMarginal(params);
70
71                 case LFUN_INSET_OPTARG:
72                         return new InsetOptArg(params);
73
74                 case LFUN_INSERT_BIBITEM:
75                         return new InsetBibitem(InsetCommandParams("bibitem"));
76
77                 case LFUN_INSET_FLOAT:
78                         // check if the float type exists
79                         if (params.getLyXTextClass().floats().typeExist(cmd.argument))
80                                 return new InsetFloat(params, cmd.argument);
81                         lyxerr << "Non-existent float type: " << cmd.argument << endl;
82                         return 0;
83
84                 case LFUN_INSET_WIDE_FLOAT:
85                         // check if the float type exists
86                         if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
87                                 InsetFloat * p = new InsetFloat(params, cmd.argument);
88                                 p->wide(true, params);
89                         }
90                         lyxerr << "Non-existent float type: " << cmd.argument << endl;
91                         return 0;
92
93                 case LFUN_INSET_WRAP:
94                         if (cmd.argument == "figure")
95                                 return new InsetWrap(params, cmd.argument);
96                         lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
97                         return 0;
98
99                 case LFUN_INDEX_INSERT: {
100                         // Try and generate a valid index entry.
101                         InsetCommandParams icp("index");
102                         string const contents = cmd.argument.empty() ?
103                                 bv->getLyXText()->getStringToIndex(bv) :
104                                 cmd.argument;
105                         icp.setContents(contents);
106
107                         string data = InsetCommandMailer::params2string(icp);
108                         LyXView * lv = bv->owner();
109
110                         if (icp.getContents().empty()) {
111                                 lv->getDialogs().show("index", data, 0);
112                         } else {
113                                 FuncRequest fr(bv, LFUN_INDEX_APPLY, data);
114                                 lv->dispatch(fr);
115                         }
116                         return 0;
117                 }
118
119                 case LFUN_TABULAR_INSERT:
120                         if (!cmd.argument.empty()) {
121                                 int r = 2;
122                                 int c = 2;
123                                 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
124                                 return new InsetTabular(*bv->buffer(), r, c);
125                         }
126                         bv->owner()->getDialogs().showTabularCreate();
127                         return 0;
128
129                 case LFUN_INSET_CAPTION:
130                         if (bv->theLockingInset()) {
131                                 lyxerr << "Locking inset code: "
132                                                          << static_cast<int>(bv->theLockingInset()->lyxCode());
133                                 InsetCaption * inset = new InsetCaption(params);
134                                 inset->setOwner(bv->theLockingInset());
135                                 inset->setAutoBreakRows(true);
136                                 inset->setDrawFrame(0, InsetText::LOCKED);
137                                 inset->setFrameColor(0, LColor::captionframe);
138                                 return inset;
139                         }
140                         return 0;
141
142                 case LFUN_INDEX_PRINT:
143                         return new InsetPrintIndex(InsetCommandParams("printindex"));
144
145                 case LFUN_TOC_INSERT:
146                         return new InsetTOC(InsetCommandParams("tableofcontents"));
147
148                 case LFUN_PARENTINSERT:
149                         return new InsetParent(
150                                 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
151
152                 case LFUN_INSERT_URL:
153                 {
154                         InsetCommandParams p;
155                         p.setFromString(cmd.argument);
156                         return new InsetUrl(p);
157                 }
158
159         #if 0
160                 case LFUN_INSET_LIST:
161                         return new InsetList;
162
163                 case LFUN_INSET_THEOREM:
164                         return new InsetTheorem;
165         #endif
166
167                 default:
168                         break;
169         }
170         return 0;
171 }