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