]> git.lyx.org Git - lyx.git/blob - src/factory.C
601f72684cffd60f90b9aa7eaad54360137e3fe9
[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/insetbib.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_BIBKEY:
75                         return new InsetBibKey(InsetCommandParams("bibkey"));
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                         string const entry = cmd.argument.empty() ?
101                                 "index" : cmd.argument;
102                         InsetCommandParams icp;
103                         icp.setFromString(entry);
104
105                         if (icp.getContents().empty())
106                                 icp.setContents(bv->getLyXText()->getStringToIndex(bv));
107                         if (!icp.getContents().empty())
108                                 return new InsetIndex(icp);
109                         
110                         bv->owner()->getDialogs().createIndex();
111                         return 0;
112                 }
113
114                 case LFUN_TABULAR_INSERT:
115                         if (!cmd.argument.empty()) {
116                                 int r = 2;
117                                 int c = 2;
118                                 ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
119                                 return new InsetTabular(*bv->buffer(), r, c);
120                         }
121                         bv->owner()->getDialogs().showTabularCreate();
122                         return 0;
123
124                 case LFUN_INSET_CAPTION:
125                         if (bv->theLockingInset()) {
126                                 lyxerr << "Locking inset code: "
127                                                          << static_cast<int>(bv->theLockingInset()->lyxCode());
128                                 InsetCaption * inset = new InsetCaption(params);
129                                 inset->setOwner(bv->theLockingInset());
130                                 inset->setAutoBreakRows(true);
131                                 inset->setDrawFrame(0, InsetText::LOCKED);
132                                 inset->setFrameColor(0, LColor::captionframe);
133                                 return inset;
134                         }
135                         return 0;
136
137                 case LFUN_INDEX_PRINT:
138                         return new InsetPrintIndex(InsetCommandParams("printindex"));
139
140                 case LFUN_TOC_INSERT:
141                         return new InsetTOC(InsetCommandParams("tableofcontents"));
142
143                 case LFUN_PARENTINSERT:
144                         return new InsetParent(
145                                 InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
146
147                 case LFUN_INSERT_URL:
148                 {
149                         InsetCommandParams p;
150                         p.setFromString(cmd.argument);
151                         return new InsetUrl(p);
152                 }
153
154         #if 0
155                 case LFUN_INSET_LIST:
156                         return new InsetList;
157
158                 case LFUN_INSET_THEOREM:
159                         return new InsetTheorem;
160         #endif
161
162                 default:
163                         break;
164         }
165         return 0;
166 }