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