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