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