]> git.lyx.org Git - lyx.git/blob - src/factory.C
Minimal fix needed to give Qt a label dialog again.
[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/insetbibtex.h"
23 #include "insets/insetcaption.h"
24 #include "insets/insetcite.h"
25 #include "insets/insetert.h"
26 #include "insets/insetexternal.h"
27 #include "insets/insetfloat.h"
28 #include "insets/insetfoot.h"
29 #include "insets/insetindex.h"
30 #include "insets/insetlabel.h"
31 #include "insets/insetmarginal.h"
32 #include "insets/insetminipage.h"
33 #include "insets/insetnote.h"
34 #include "insets/insetoptarg.h"
35 #include "insets/insetparent.h"
36 #include "insets/insetref.h"
37 #include "insets/insettabular.h"
38 #include "insets/insettext.h"
39 #include "insets/insettoc.h"
40 #include "insets/inseturl.h"
41 #include "insets/insetwrap.h"
42
43 #include "frontends/Dialogs.h"
44 #include "frontends/LyXView.h"
45
46 #include <cstdio>
47
48 using std::endl;
49
50 Inset * createInset(FuncRequest const & cmd)
51 {
52         BufferView * bv = cmd.view();
53         BufferParams const & params = bv->buffer()->params;
54
55         switch (cmd.action) {
56         case LFUN_INSET_MINIPAGE:
57                 return new InsetMinipage(params);
58
59         case LFUN_INSERT_NOTE:
60                 return new InsetNote(params);
61
62         case LFUN_INSET_ERT:
63                 return new InsetERT(params);
64
65         case LFUN_INSET_EXTERNAL:
66                 return new InsetExternal;
67
68         case LFUN_INSET_FOOTNOTE:
69                 return new InsetFoot(params);
70
71         case LFUN_INSET_MARGINAL:
72                 return new InsetMarginal(params);
73
74         case LFUN_INSET_OPTARG:
75                 return new InsetOptArg(params);
76
77         case LFUN_INSERT_BIBITEM:
78                 return new InsetBibitem(InsetCommandParams("bibitem"));
79
80         case LFUN_INSET_FLOAT:
81                 // check if the float type exists
82                 if (params.getLyXTextClass().floats().typeExist(cmd.argument))
83                         return new InsetFloat(params, cmd.argument);
84                 lyxerr << "Non-existent float type: " << cmd.argument << endl;
85                 return 0;
86
87         case LFUN_INSET_WIDE_FLOAT:
88                 // check if the float type exists
89                 if (params.getLyXTextClass().floats().typeExist(cmd.argument)) {
90                         InsetFloat * p = new InsetFloat(params, cmd.argument);
91                         p->wide(true, params);
92                 }
93                 lyxerr << "Non-existent float type: " << cmd.argument << endl;
94                 return 0;
95
96         case LFUN_INSET_WRAP:
97                 if (cmd.argument == "figure")
98                         return new InsetWrap(params, cmd.argument);
99                 lyxerr << "Non-existent floatflt type: " << cmd.argument << endl;
100                 return 0;
101
102         case LFUN_INDEX_INSERT: {
103                 // Try and generate a valid index entry.
104                 InsetCommandParams icp("index");
105                 string const contents = cmd.argument.empty() ?
106                         bv->getLyXText()->getStringToIndex(bv) :
107                         cmd.argument;
108                 icp.setContents(contents);
109
110                 string data = InsetCommandMailer::params2string("index", icp);
111                 LyXView * lv = bv->owner();
112
113                 if (icp.getContents().empty()) {
114                         lv->getDialogs().show("index", data, 0);
115                 } else {
116                         FuncRequest fr(bv, LFUN_INSET_APPLY, data);
117                         lv->dispatch(fr);
118                 }
119                 return 0;
120         }
121
122         case LFUN_TABULAR_INSERT:
123                 if (!cmd.argument.empty()) {
124                         int r = 2;
125                         int c = 2;
126                         ::sscanf(cmd.argument.c_str(),"%d%d", &r, &c);
127                         return new InsetTabular(*bv->buffer(), r, c);
128                 }
129                 bv->owner()->getDialogs().showTabularCreate();
130                 return 0;
131
132         case LFUN_INSET_CAPTION:
133                 if (bv->theLockingInset()) {
134                         lyxerr << "Locking inset code: "
135                                << static_cast<int>(bv->theLockingInset()->lyxCode());
136                         InsetCaption * inset = new InsetCaption(params);
137                         inset->setOwner(bv->theLockingInset());
138                         inset->setAutoBreakRows(true);
139                         inset->setDrawFrame(0, InsetText::LOCKED);
140                         inset->setFrameColor(0, LColor::captionframe);
141                         return inset;
142                 }
143                 return 0;
144
145         case LFUN_INDEX_PRINT:
146                 return new InsetPrintIndex(InsetCommandParams("printindex"));
147
148         case LFUN_TOC_INSERT:
149                 return new InsetTOC(InsetCommandParams("tableofcontents"));
150
151         case LFUN_PARENTINSERT:
152                 return new InsetParent(
153                         InsetCommandParams("lyxparent", cmd.argument), *bv->buffer());
154
155         case LFUN_INSERT_URL:
156         {
157                 InsetCommandParams p;
158                 p.setFromString(cmd.argument);
159                 return new InsetUrl(p);
160         }
161
162 #if 0
163         case LFUN_INSET_LIST:
164                 return new InsetList;
165
166         case LFUN_INSET_THEOREM:
167                 return new InsetTheorem;
168 #endif
169
170         case LFUN_INSET_APPLY: {
171                 string const name = cmd.getArg(0);
172
173                 if (name == "bibitem") {
174                         InsetCommandParams icp;
175                         InsetCommandMailer::string2params(cmd.argument, icp);
176                         return new InsetBibitem(icp);
177
178                 } else if (name == "bibtex") {
179                         InsetCommandParams icp;
180                         InsetCommandMailer::string2params(cmd.argument, icp);
181                         return new InsetBibtex(icp);
182
183                 } else if (name == "citation") {
184                         InsetCommandParams icp;
185                         InsetCommandMailer::string2params(cmd.argument, icp);
186                         InsetCitation * inset = new InsetCitation(icp);
187                         inset->setLoadingBuffer(bv->buffer(), false);
188                         return inset;
189
190                 } else if (name == "ert") {
191                         InsetERT * inset = new InsetERT(params);
192                         InsetERT::ERTStatus s;
193                         InsetERTMailer::string2params(cmd.argument, s);
194                         inset->status(bv, s);
195                         return inset;
196
197                 } else if (name == "index") {
198                         InsetCommandParams icp;
199                         InsetCommandMailer::string2params(cmd.argument, icp);
200                         return new InsetIndex(icp);
201
202                 } else if (name == "label") {
203                         InsetCommandParams icp;
204                         InsetCommandMailer::string2params(cmd.argument, icp);
205                         return new InsetLabel(icp);
206
207                 } else if (name == "ref") {
208                         InsetCommandParams icp;
209                         InsetCommandMailer::string2params(cmd.argument, icp);
210                         return new InsetRef(icp, *bv->buffer());
211
212                 } else if (name == "toc") {
213                         InsetCommandParams icp;
214                         InsetCommandMailer::string2params(cmd.argument, icp);
215                         return new InsetTOC(icp);
216
217                 } else if (name == "url") {
218                         InsetCommandParams icp;
219                         InsetCommandMailer::string2params(cmd.argument, icp);
220                         return new InsetUrl(icp);
221                 }
222         }
223         break;
224
225         default:
226                 break;
227         }
228
229         return 0;
230 }