]> git.lyx.org Git - lyx.git/blob - src/factory.cpp
Update it.po
[lyx.git] / src / factory.cpp
1 /**
2  * \file factory.cpp
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 "factory.h"
14
15 #include "Buffer.h"
16 #include "BufferParams.h"
17 #include "FloatList.h"
18 #include "FuncRequest.h"
19 #include "Lexer.h"
20 #include "LyX.h"
21 #include "TextClass.h"
22
23 #include "insets/InsetBibitem.h"
24 #include "insets/InsetBibtex.h"
25 #include "insets/InsetBox.h"
26 #include "insets/InsetBranch.h"
27 #include "insets/InsetCaption.h"
28 #include "insets/InsetCitation.h"
29 #include "insets/InsetFlex.h"
30 #include "insets/InsetERT.h"
31 #include "insets/InsetListings.h"
32 #include "insets/InsetExternal.h"
33 #include "insets/InsetFloat.h"
34 #include "insets/InsetFloatList.h"
35 #include "insets/InsetFoot.h"
36 #include "insets/InsetGraphics.h"
37 #include "insets/InsetHyperlink.h"
38 #include "insets/InsetInclude.h"
39 #include "insets/InsetIndex.h"
40 #include "insets/InsetInfo.h"
41 #include "insets/InsetIPA.h"
42 #include "insets/InsetIPAMacro.h"
43 #include "insets/InsetLabel.h"
44 #include "insets/InsetLine.h"
45 #include "insets/InsetMarginal.h"
46 #include "insets/InsetNewline.h"
47 #include "insets/InsetNewpage.h"
48 #include "insets/InsetNomencl.h"
49 #include "insets/InsetNote.h"
50 #include "insets/InsetArgument.h"
51 #include "insets/InsetPhantom.h"
52 #include "insets/InsetPreview.h"
53 #include "insets/InsetRef.h"
54 #include "insets/InsetScript.h"
55 #include "insets/InsetSeparator.h"
56 #include "insets/InsetSpace.h"
57 #include "insets/InsetTabular.h"
58 #include "insets/InsetTOC.h"
59 #include "insets/InsetVSpace.h"
60 #include "insets/InsetWrap.h"
61
62 #include "mathed/InsetMathMacroTemplate.h"
63 #include "mathed/InsetMathHull.h"
64
65 #include "frontends/alert.h"
66
67 #include "support/debug.h"
68 #include "support/ExceptionMessage.h"
69 #include "support/lassert.h"
70 #include "support/lstrings.h"
71 #include "support/unique_ptr.h"
72
73 #include <sstream>
74
75
76 using namespace std;
77 using namespace lyx::support;
78
79 namespace lyx {
80
81 namespace Alert = frontend::Alert;
82
83
84 Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
85 {
86         try {
87
88                 switch (cmd.action()) {
89
90                 case LFUN_NEWPAGE_INSERT: {
91                         string const name = cmd.getArg(0);
92                         InsetNewpageParams inp;
93                         if (name.empty() || name == "newpage")
94                                 inp.kind = InsetNewpageParams::NEWPAGE;
95                         else if (name == "pagebreak")
96                                 inp.kind = InsetNewpageParams::PAGEBREAK;
97                         else if (name == "clearpage")
98                                 inp.kind = InsetNewpageParams::CLEARPAGE;
99                         else if (name == "cleardoublepage")
100                                 inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
101                         return new InsetNewpage(inp);
102                 }
103
104                 case LFUN_SEPARATOR_INSERT: {
105                         string const name = cmd.getArg(0);
106                         InsetSeparatorParams inp;
107                         if (name.empty() || name == "plain")
108                                 inp.kind = InsetSeparatorParams::PLAIN;
109                         else if (name == "parbreak")
110                                 inp.kind = InsetSeparatorParams::PARBREAK;
111                         else if (name == "latexpar")
112                                 inp.kind = InsetSeparatorParams::LATEXPAR;
113                         else {
114                                 lyxerr << "Wrong argument for LyX function 'separator-insert'." << endl;
115                                 break;
116                         }
117                         return new InsetSeparator(inp);
118                 }
119
120                 case LFUN_FLEX_INSERT: {
121                         string s = cmd.getArg(0);
122                         return new InsetFlex(buf, s);
123                 }
124
125                 case LFUN_NOTE_INSERT: {
126                         string arg = cmd.getArg(0);
127                         if (arg.empty())
128                                 arg = "Note";
129                         return new InsetNote(buf, arg);
130                 }
131
132                 case LFUN_BOX_INSERT: {
133                         string arg = cmd.getArg(0);
134                         if (arg.empty())
135                                 arg = "Boxed";
136                         return new InsetBox(buf, arg);
137                 }
138
139                 case LFUN_BRANCH_INSERT: {
140                         docstring arg = cmd.argument();
141                         if (arg.empty())
142                                 arg = from_ascii("none");
143                         return new InsetBranch(buf, InsetBranchParams(arg));
144                 }
145
146                 case LFUN_PHANTOM_INSERT: {
147                         string arg = cmd.getArg(0);
148                         if (arg.empty())
149                                 arg = "Phantom";
150                         return new InsetPhantom(buf, arg);
151                 }
152
153                 case LFUN_IPAMACRO_INSERT: {
154                         string const arg1 = cmd.getArg(0);
155                         string const arg2 = cmd.getArg(1);
156                         if (arg1 != "deco") {
157                                 LYXERR0("LFUN_IPAMACRO_INSERT: wrong argument");
158                                 return 0;
159                         }
160                         return new InsetIPADeco(buf, arg2);
161                 }
162
163                 case LFUN_ERT_INSERT:
164                         return new InsetERT(buf);
165
166                 case LFUN_LISTING_INSERT:
167                         return new InsetListings(buf);
168
169                 case LFUN_FOOTNOTE_INSERT:
170                         return new InsetFoot(buf);
171
172                 case LFUN_MARGINALNOTE_INSERT:
173                         return new InsetMarginal(buf);
174
175                 case LFUN_ARGUMENT_INSERT: {
176                         string arg = cmd.getArg(0);
177                         if (arg.empty()) {
178                                 LYXERR0("argument-insert needs an argument!");
179                                 return 0;
180                         }
181                         return new InsetArgument(buf, arg);
182                 }
183
184                 case LFUN_FLOAT_INSERT: {
185                         string argument = to_utf8(cmd.argument());
186                         if (!argument.empty()) {
187                                 if (!contains(argument, "sideways")) {
188                                         if (!contains(argument, "wide"))
189                                                 argument += "\nwide false";
190                                         argument += "\nsideways false";
191                                 }
192                         }
193                         return new InsetFloat(buf, argument);
194                 }
195
196                 case LFUN_FLOAT_WIDE_INSERT: {
197                         string argument = to_utf8(cmd.argument());
198                         if (!argument.empty()) {
199                                 if (!contains(argument, "sideways")) {
200                                         if (!contains(argument, "wide"))
201                                                 argument += "\nwide true";
202                                         argument += "\nsideways false";
203                                 }
204                         }
205                         InsetFloat * fl = new InsetFloat(buf, argument);
206                         fl->setWide(true);
207                         return fl;
208                 }
209
210                 case LFUN_WRAP_INSERT: {
211                         string const argument = to_utf8(cmd.argument());
212                         if (argument == "figure" || argument == "table")
213                                 return new InsetWrap(buf, argument);
214                         lyxerr << "Non-existent wrapfig type: " << argument << endl;
215                         return 0;
216                 }
217
218                 case LFUN_INDEX_INSERT: {
219                         docstring arg = cmd.argument();
220                         return new InsetIndex(buf, InsetIndexParams(arg));
221                 }
222
223                 case LFUN_IPA_INSERT:
224                         return new InsetIPA(buf);
225
226                 case LFUN_NOMENCL_INSERT: {
227                         InsetCommandParams icp(NOMENCL_CODE);
228                         icp["symbol"] = cmd.argument();
229                         return new InsetNomencl(buf, icp);
230                 }
231
232                 case LFUN_TABULAR_INSERT: {
233                         if (cmd.argument().empty())
234                                 return 0;
235                         istringstream ss(to_utf8(cmd.argument()));
236                         int r = 0, c = 0;
237                         ss >> r >> c;
238                         if (r <= 0)
239                                 r = 2;
240                         if (c <= 0)
241                                 c = 2;
242                         return new InsetTabular(buf, r, c);
243                 }
244
245                 case LFUN_CAPTION_INSERT: {
246                         string arg = cmd.getArg(0);
247                         if (arg.empty())
248                                 arg = "Standard";
249                         return new InsetCaption(buf, arg);
250                 }
251
252                 case LFUN_INDEX_PRINT:  {
253                         InsetCommandParams icp(INDEX_PRINT_CODE);
254                         icp["type"] = cmd.argument();
255                         return new InsetPrintIndex(buf, icp);
256                 }
257
258                 case LFUN_NOMENCL_PRINT: {
259                         InsetCommandParams icp(NOMENCL_PRINT_CODE);
260                         icp["set_width"] = from_ascii("auto");
261                         return new InsetPrintNomencl(buf, icp);
262                 }
263
264                 case LFUN_INFO_INSERT: {
265                         InsetInfo * inset = new InsetInfo(buf, to_utf8(cmd.argument()));
266                         inset->updateInfo();
267                         return inset;
268                 }
269
270                 case LFUN_PREVIEW_INSERT:
271                         return new InsetPreview(buf);
272
273                 case LFUN_SCRIPT_INSERT: {
274                         InsetScriptParams isp;
275                         InsetScript::string2params("script script " + to_utf8(cmd.argument()), isp);
276                         return new InsetScript(buf, isp);
277                 }
278
279                 case LFUN_INSET_INSERT: {
280                         string const name = cmd.getArg(0);
281                         InsetCode code = insetCode(name);
282                         switch (code) {
283                         case NO_CODE:
284                                 lyxerr << "No such inset '" << name << "'.";
285                                 return 0;
286
287                         case BIBITEM_CODE: {
288                                 InsetCommandParams icp(code);
289                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
290                                 return new InsetBibitem(buf, icp);
291                         }
292
293                         case BIBTEX_CODE: {
294                                 InsetCommandParams icp(code);
295                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
296                                 return new InsetBibtex(buf, icp);
297                         }
298
299                         case CITE_CODE: {
300                                 InsetCommandParams icp(code);
301                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
302                                 return new InsetCitation(buf, icp);
303                         }
304
305                         case ERT_CODE: {
306                                 return new InsetERT(buf,
307                                         InsetERT::string2params(to_utf8(cmd.argument())));
308                         }
309
310                         case EXTERNAL_CODE: {
311                                 InsetExternalParams iep;
312                                 InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
313                                 auto inset = make_unique<InsetExternal>(buf);
314                                 inset->setBuffer(*buf);
315                                 inset->setParams(iep);
316                                 return inset.release();
317                         }
318
319                         case GRAPHICS_CODE: {
320                                 InsetGraphicsParams igp;
321                                 InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
322                                 auto inset = make_unique<InsetGraphics>(buf);
323                                 inset->setParams(igp);
324                                 return inset.release();
325                         }
326
327                         case HYPERLINK_CODE: {
328                                 InsetCommandParams icp(code);
329                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
330                                 return new InsetHyperlink(buf, icp);
331                         }
332
333                         case INCLUDE_CODE: {
334                                 InsetCommandParams icp(code);
335                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
336                                 return new InsetInclude(buf, icp);
337                         }
338
339                         case INDEX_CODE: {
340                                 docstring arg = cmd.argument();
341                                 return new InsetIndex(buf, InsetIndexParams(arg));
342                         }
343
344                         case INDEX_PRINT_CODE:  {
345                                 InsetCommandParams icp(code);
346                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
347                                 return new InsetPrintIndex(buf, icp);
348                         }
349
350                         case LABEL_CODE: {
351                                 InsetCommandParams icp(code);
352                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
353                                 return new InsetLabel(buf, icp);
354                         }
355
356                         case LINE_CODE: {
357                                 InsetCommandParams icp(code);
358                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
359                                 return new InsetLine(buf, icp);
360                         }
361
362                         case LISTINGS_CODE: {
363                                 InsetListingsParams par;
364                                 InsetListings::string2params(to_utf8(cmd.argument()), par);
365                                 return new InsetListings(buf, par);
366                         }
367
368                         case NOMENCL_CODE: {
369                                 InsetCommandParams icp(code);
370                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
371                                 return new InsetNomencl(buf, icp);
372                         }
373
374                         case REF_CODE: {
375                                 InsetCommandParams icp(code);
376                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
377                                 return new InsetRef(buf, icp);
378                         }
379
380                         case SCRIPT_CODE: {
381                                 InsetScriptParams isp;
382                                 InsetScript::string2params(to_utf8(cmd.argument()), isp);
383                                 return new InsetScript(buf, isp);
384                         }
385
386                         case SPACE_CODE: {
387                                 InsetSpaceParams isp;
388                                 InsetSpace::string2params(to_utf8(cmd.argument()), isp);
389                                 return new InsetSpace(isp);
390                         }
391
392                         case TOC_CODE: {
393                                 InsetCommandParams icp(code);
394                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
395                                 return new InsetTOC(buf, icp);
396                         }
397
398                         case VSPACE_CODE: {
399                                 VSpace vspace;
400                                 InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
401                                 return new InsetVSpace(vspace);
402                         }
403
404                         case PREVIEW_CODE:
405                                 return new InsetPreview(buf);
406
407                         default:
408                                 lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
409                                                 << endl;
410                                 return 0;
411
412                         }
413                 } //end LFUN_INSET_INSERT
414
415                 case LFUN_SPACE_INSERT: {
416                         string const name = cmd.getArg(0);
417                         string const len = cmd.getArg(1);
418                         if (name.empty()) {
419                                 lyxerr << "LyX function 'space-insert' needs an argument." << endl;
420                                 break;
421                         }
422                         InsetSpaceParams isp;
423                         // The tests for isp.math might be disabled after a file format change
424                         if (name == "normal")
425                                 isp.kind = InsetSpaceParams::NORMAL;
426                         else if (name == "protected")
427                                 isp.kind = InsetSpaceParams::PROTECTED;
428                         else if (name == "visible")
429                                 isp.kind = InsetSpaceParams::VISIBLE;
430                         else if (name == "thin")
431                                 isp.kind = InsetSpaceParams::THIN;
432                         else if (isp.math && name == "med")
433                                 isp.kind = InsetSpaceParams::MEDIUM;
434                         else if (isp.math && name == "thick")
435                                 isp.kind = InsetSpaceParams::THICK;
436                         else if (name == "quad")
437                                 isp.kind = InsetSpaceParams::QUAD;
438                         else if (name == "qquad")
439                                 isp.kind = InsetSpaceParams::QQUAD;
440                         else if (name == "enspace")
441                                 isp.kind = InsetSpaceParams::ENSPACE;
442                         else if (name == "enskip")
443                                 isp.kind = InsetSpaceParams::ENSKIP;
444                         else if (name == "negthinspace")
445                                 isp.kind = InsetSpaceParams::NEGTHIN;
446                         else if (name == "negmedspace")
447                                 isp.kind = InsetSpaceParams::NEGMEDIUM;
448                         else if (name == "negthickspace")
449                                 isp.kind = InsetSpaceParams::NEGTHICK;
450                         else if (name == "hfill")
451                                 isp.kind = InsetSpaceParams::HFILL;
452                         else if (name == "hfill*")
453                                 isp.kind = InsetSpaceParams::HFILL_PROTECTED;
454                         else if (name == "dotfill")
455                                 isp.kind = InsetSpaceParams::DOTFILL;
456                         else if (name == "hrulefill")
457                                 isp.kind = InsetSpaceParams::HRULEFILL;
458                         else if (name == "hspace") {
459                                 if (len.empty() || !isValidGlueLength(len)) {
460                                         lyxerr << "LyX function 'space-insert hspace' "
461                                                << "needs a valid length argument." << endl;
462                                         break;
463                                 }
464                                 isp.kind = InsetSpaceParams::CUSTOM;
465                                 isp.length = GlueLength(len);
466                         }
467                         else if (name == "hspace*") {
468                                 if (len.empty() || !isValidGlueLength(len)) {
469                                         lyxerr << "LyX function 'space-insert hspace*' "
470                                                << "needs a valid length argument." << endl;
471                                         break;
472                                 }
473                                 isp.kind = InsetSpaceParams::CUSTOM_PROTECTED;
474                                 isp.length = GlueLength(len);
475                         }
476                         else {
477                                 lyxerr << "Wrong argument for LyX function 'space-insert'." << endl;
478                                 break;
479                         }
480                         return new InsetSpace(isp);
481                 }
482                 break;
483
484                 default:
485                         break;
486                 }
487
488         } catch (ExceptionMessage const & message) {
489                 if (message.type_ == ErrorException) {
490                         // This should never happen!
491                         Alert::error(message.title_, message.details_);
492                         lyx_exit(1);
493                 } else if (message.type_ == WarningException) {
494                         Alert::warning(message.title_, message.details_);
495                         return 0;
496                 }
497         }
498
499         return 0;
500 }
501
502
503 Inset * createInset(Buffer * buf, FuncRequest const & cmd)
504 {
505         Inset * inset = createInsetHelper(buf, cmd);
506         if (inset)
507                 inset->setBuffer(*buf);
508         return inset;
509 }
510
511
512 Inset * readInset(Lexer & lex, Buffer * buf)
513 {
514         // consistency check
515         if (lex.getString() != "\\begin_inset")
516                 LYXERR0("Buffer::readInset: Consistency check failed.");
517
518         unique_ptr<Inset> inset;
519
520         string tmptok;
521         lex >> tmptok;
522
523         // test the different insets
524
525         // FIXME It would be better if we did not have this branch and could
526         // just do one massive switch for all insets. But at present, it's
527         // easier to do it this way, and we can't do the massive switch until
528         // the conversion mentioned below.  Note that if we do want to do a
529         // single switch, we need to remove this "CommandInset" line---or
530         // replace it with a single "InsetType" line that would be used in all
531         // insets.
532         if (tmptok == "CommandInset") {
533                 lex.next();
534                 string const insetType = lex.getString();
535                 lex.pushToken(insetType);
536
537                 InsetCode const code = insetCode(insetType);
538
539                 //FIXME If we do the one massive switch, we cannot do this here, since
540                 //we do not know in advance that we're dealing with a command inset.
541                 //Worst case, we could put it in each case below. Better, we could
542                 //pass the lexer to the constructor and let the params be built there.
543                 InsetCommandParams inscmd(code);
544                 inscmd.Read(lex, buf);
545
546                 switch (code) {
547                         case BIBITEM_CODE:
548                                 inset.reset(new InsetBibitem(buf, inscmd));
549                                 break;
550                         case BIBTEX_CODE:
551                                 inset.reset(new InsetBibtex(buf, inscmd));
552                                 break;
553                         case CITE_CODE:
554                                 inset.reset(new InsetCitation(buf, inscmd));
555                                 break;
556                         case HYPERLINK_CODE:
557                                 inset.reset(new InsetHyperlink(buf, inscmd));
558                                 break;
559                         case INCLUDE_CODE:
560                                 inset.reset(new InsetInclude(buf, inscmd));
561                                 break;
562                         case INDEX_PRINT_CODE:
563                                 inset.reset(new InsetPrintIndex(buf, inscmd));
564                                 break;
565                         case LABEL_CODE:
566                                 inset.reset(new InsetLabel(buf, inscmd));
567                                 break;
568                         case LINE_CODE:
569                                 inset.reset(new InsetLine(buf, inscmd));
570                                 break;
571                         case NOMENCL_CODE:
572                                 inset.reset(new InsetNomencl(buf, inscmd));
573                                 break;
574                         case NOMENCL_PRINT_CODE:
575                                 inset.reset(new InsetPrintNomencl(buf, inscmd));
576                                 break;
577                         case REF_CODE:
578                                 if (inscmd["name"].empty() && inscmd["reference"].empty())
579                                         return 0;
580                                 inset.reset(new InsetRef(buf, inscmd));
581                                 break;
582                         case TOC_CODE:
583                                 inset.reset(new InsetTOC(buf, inscmd));
584                                 break;
585                         case NO_CODE:
586                         default:
587                                 lyxerr << "unknown CommandInset '" << insetType
588                                                         << "'" << endl;
589                                 while (lex.isOK() && lex.getString() != "\\end_inset")
590                                         lex.next();
591                                 return 0;
592                 }
593                 inset->setBuffer(*buf);
594         } else {
595                 // FIXME This branch should be made to use inset codes
596                 // as the preceding branch does. Unfortunately, that
597                 // will take some doing. It requires converting the
598                 // representation of the insets in LyX files so that
599                 // they use the inset names listed in Inset.cpp. Then,
600                 // as above, the inset names can be translated to
601                 // inset codes using insetCode(). And the insets'
602                 // write() routines should use insetName() rather than
603                 // hardcoding it.
604                 if (tmptok == "Quotes") {
605                         inset.reset(new InsetQuotes(buf));
606                 } else if (tmptok == "External") {
607                         inset.reset(new InsetExternal(buf));
608                 } else if (tmptok == "FormulaMacro") {
609                         inset.reset(new InsetMathMacroTemplate(buf));
610                 } else if (tmptok == "Formula") {
611                         inset.reset(new InsetMathHull(buf));
612                 } else if (tmptok == "Graphics") {
613                         inset.reset(new InsetGraphics(buf));
614                 } else if (tmptok == "Note") {
615                         inset.reset(new InsetNote(buf, tmptok));
616                 } else if (tmptok == "Box") {
617                         inset.reset(new InsetBox(buf, tmptok));
618                 } else if (tmptok == "Flex") {
619                         lex.eatLine();
620                         string s = lex.getString();
621                         inset.reset(new InsetFlex(buf, s));
622                 } else if (tmptok == "Branch") {
623                         inset.reset(new InsetBranch(buf, InsetBranchParams()));
624                 } else if (tmptok == "Phantom") {
625                         inset.reset(new InsetPhantom(buf, tmptok));
626                 } else if (tmptok == "ERT") {
627                         inset.reset(new InsetERT(buf));
628                 } else if (tmptok == "listings") {
629                         inset.reset(new InsetListings(buf));
630                 } else if (tmptok == "script") {
631                         inset.reset(new InsetScript(buf));
632                 } else if (tmptok == "space") {
633                         inset.reset(new InsetSpace);
634                 } else if (tmptok == "Tabular") {
635                         inset.reset(new InsetTabular(buf));
636                 } else if (tmptok == "Text") {
637                         inset.reset(new InsetText(buf));
638                 } else if (tmptok == "VSpace") {
639                         inset.reset(new InsetVSpace);
640                 } else if (tmptok == "Foot") {
641                         inset.reset(new InsetFoot(buf));
642                 } else if (tmptok == "Marginal") {
643                         inset.reset(new InsetMarginal(buf));
644                 } else if (tmptok == "Newpage") {
645                         inset.reset(new InsetNewpage);
646                 } else if (tmptok == "Newline") {
647                         inset.reset(new InsetNewline);
648                 } else if (tmptok == "Separator") {
649                         inset.reset(new InsetSeparator);
650                 } else if (tmptok == "Argument") {
651                         inset.reset(new InsetArgument(buf, tmptok));
652                 } else if (tmptok == "Float") {
653                         inset.reset(new InsetFloat(buf, string()));
654                 } else if (tmptok == "Wrap") {
655                         lex.next();
656                         string tmptok = lex.getString();
657                         inset.reset(new InsetWrap(buf, tmptok));
658                 } else if (tmptok == "Caption") {
659                         lex.eatLine();
660                         string s = lex.getString();
661                         inset.reset(new InsetCaption(buf, s));
662                 } else if (tmptok == "Index") {
663                         inset.reset(new InsetIndex(buf, InsetIndexParams()));
664                 } else if (tmptok == "FloatList") {
665                         inset.reset(new InsetFloatList(buf));
666                 } else if (tmptok == "Info") {
667                         inset.reset(new InsetInfo(buf));
668                 } else if (tmptok == "IPA") {
669                         inset.reset(new InsetIPA(buf));
670                 } else if (tmptok == "IPADeco") {
671                         inset.reset(new InsetIPADeco(buf, tmptok));
672                 } else if (tmptok == "Preview") {
673                         inset.reset(new InsetPreview(buf));
674                 } else {
675                         lyxerr << "unknown Inset type '" << tmptok
676                                << "'" << endl;
677                         while (lex.isOK() && lex.getString() != "\\end_inset")
678                                 lex.next();
679                         return 0;
680                 }
681
682                 // Set the buffer reference for proper parsing of some insets
683                 // (InsetCollapsible for example)
684                 inset->setBuffer(*buf);
685                 inset->read(lex);
686                 // Set again the buffer for insets that are created inside this inset
687                 // (InsetMathHull for example).
688                 inset->setBuffer(*buf);
689         }
690         return inset.release();
691 }
692
693
694 } // namespace lyx