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