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