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