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