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