]> git.lyx.org Git - lyx.git/blob - src/factory.cpp
Warn in GUI when mixing Title and InTitle layouts
[lyx.git] / src / factory.cpp
1 /**
2  * \file factory.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "factory.h"
14
15 #include "Buffer.h"
16 #include "BufferParams.h"
17 #include "FloatList.h"
18 #include "FuncRequest.h"
19 #include "Lexer.h"
20 #include "LyX.h"
21 #include "TextClass.h"
22
23 #include "insets/InsetBibitem.h"
24 #include "insets/InsetBibtex.h"
25 #include "insets/InsetBox.h"
26 #include "insets/InsetBranch.h"
27 #include "insets/InsetCaption.h"
28 #include "insets/InsetCitation.h"
29 #include "insets/InsetFlex.h"
30 #include "insets/InsetERT.h"
31 #include "insets/InsetListings.h"
32 #include "insets/InsetExternal.h"
33 #include "insets/InsetFloat.h"
34 #include "insets/InsetFloatList.h"
35 #include "insets/InsetFoot.h"
36 #include "insets/InsetGraphics.h"
37 #include "insets/InsetHyperlink.h"
38 #include "insets/InsetInclude.h"
39 #include "insets/InsetIndex.h"
40 #include "insets/InsetInfo.h"
41 #include "insets/InsetIPA.h"
42 #include "insets/InsetIPAMacro.h"
43 #include "insets/InsetLabel.h"
44 #include "insets/InsetLine.h"
45 #include "insets/InsetMarginal.h"
46 #include "insets/InsetNewline.h"
47 #include "insets/InsetNewpage.h"
48 #include "insets/InsetNomencl.h"
49 #include "insets/InsetNote.h"
50 #include "insets/InsetArgument.h"
51 #include "insets/InsetPhantom.h"
52 #include "insets/InsetPreview.h"
53 #include "insets/InsetRef.h"
54 #include "insets/InsetScript.h"
55 #include "insets/InsetSeparator.h"
56 #include "insets/InsetSpace.h"
57 #include "insets/InsetTabular.h"
58 #include "insets/InsetTOC.h"
59 #include "insets/InsetVSpace.h"
60 #include "insets/InsetWrap.h"
61
62 #include "mathed/MathMacroTemplate.h"
63 #include "mathed/InsetMathHull.h"
64
65 #include "frontends/alert.h"
66
67 #include "support/debug.h"
68 #include "support/lstrings.h"
69 #include "support/ExceptionMessage.h"
70
71 #include "support/lassert.h"
72
73 #include <sstream>
74
75 using namespace std;
76 using namespace lyx::support;
77
78 namespace lyx {
79
80 namespace Alert = frontend::Alert;
81
82
83 Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
84 {
85         try {
86
87                 switch (cmd.action()) {
88
89                 case LFUN_NEWPAGE_INSERT: {
90                         string const name = cmd.getArg(0);
91                         InsetNewpageParams inp;
92                         if (name.empty() || name == "newpage")
93                                 inp.kind = InsetNewpageParams::NEWPAGE;
94                         else if (name == "pagebreak")
95                                 inp.kind = InsetNewpageParams::PAGEBREAK;
96                         else if (name == "clearpage")
97                                 inp.kind = InsetNewpageParams::CLEARPAGE;
98                         else if (name == "cleardoublepage")
99                                 inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
100                         return new InsetNewpage(inp);
101                 }
102
103                 case LFUN_SEPARATOR_INSERT: {
104                         string const name = cmd.getArg(0);
105                         InsetSeparatorParams inp;
106                         if (name.empty() || name == "plain")
107                                 inp.kind = InsetSeparatorParams::PLAIN;
108                         else if (name == "parbreak")
109                                 inp.kind = InsetSeparatorParams::PARBREAK;
110                         else if (name == "latexpar")
111                                 inp.kind = InsetSeparatorParams::LATEXPAR;
112                         else {
113                                 lyxerr << "Wrong argument for LyX function 'separator-insert'." << endl;
114                                 break;
115                         }
116                         return new InsetSeparator(inp);
117                 }
118
119                 case LFUN_FLEX_INSERT: {
120                         string s = cmd.getArg(0);
121                         return new InsetFlex(buf, s);
122                 }
123
124                 case LFUN_NOTE_INSERT: {
125                         string arg = cmd.getArg(0);
126                         if (arg.empty())
127                                 arg = "Note";
128                         return new InsetNote(buf, arg);
129                 }
130
131                 case LFUN_BOX_INSERT: {
132                         string arg = cmd.getArg(0);
133                         if (arg.empty())
134                                 arg = "Boxed";
135                         return new InsetBox(buf, arg);
136                 }
137
138                 case LFUN_BRANCH_INSERT: {
139                         docstring arg = cmd.argument();
140                         if (arg.empty())
141                                 arg = from_ascii("none");
142                         return new InsetBranch(buf, InsetBranchParams(arg));
143                 }
144
145                 case LFUN_PHANTOM_INSERT: {
146                         string arg = cmd.getArg(0);
147                         if (arg.empty())
148                                 arg = "Phantom";
149                         return new InsetPhantom(buf, arg);
150                 }
151
152                 case LFUN_IPAMACRO_INSERT: {
153                         string const arg1 = cmd.getArg(0);
154                         string const arg2 = cmd.getArg(1);
155                         if (arg1 != "deco") {
156                                 LYXERR0("LFUN_IPAMACRO_INSERT: wrong argument");
157                                 return 0;
158                         }
159                         return new InsetIPADeco(buf, arg2);
160                 }
161
162                 case LFUN_ERT_INSERT:
163                         return new InsetERT(buf);
164
165                 case LFUN_LISTING_INSERT:
166                         return new InsetListings(buf);
167
168                 case LFUN_FOOTNOTE_INSERT:
169                         return new InsetFoot(buf);
170
171                 case LFUN_MARGINALNOTE_INSERT:
172                         return new InsetMarginal(buf);
173
174                 case LFUN_ARGUMENT_INSERT: {
175                         string arg = cmd.getArg(0);
176                         if (arg.empty()) {
177                                 LYXERR0("argument-insert needs an argument!");
178                                 return 0;
179                         }
180                         return new InsetArgument(buf, arg);
181                 }
182
183                 case LFUN_FLOAT_INSERT: {
184                         string argument = to_utf8(cmd.argument());
185                         if (!argument.empty()) {
186                                 if (!contains(argument, "sideways")) {
187                                         if (!contains(argument, "wide"))
188                                                 argument += "\nwide false";
189                                         argument += "\nsideways false";
190                                 }
191                         }
192                         return new InsetFloat(buf, argument);
193                 }
194
195                 case LFUN_FLOAT_WIDE_INSERT: {
196                         string argument = to_utf8(cmd.argument());
197                         if (!argument.empty()) {
198                                 if (!contains(argument, "sideways")) {
199                                         if (!contains(argument, "wide"))
200                                                 argument += "\nwide true";
201                                         argument += "\nsideways false";
202                                 }
203                         }
204                         InsetFloat * fl = new InsetFloat(buf, argument);
205                         fl->setWide(true);
206                         return fl;
207                 }
208
209                 case LFUN_WRAP_INSERT: {
210                         string const argument = to_utf8(cmd.argument());
211                         if (argument == "figure" || argument == "table")
212                                 return new InsetWrap(buf, argument);
213                         lyxerr << "Non-existent wrapfig type: " << argument << endl;
214                         return 0;
215                 }
216
217                 case LFUN_INDEX_INSERT: {
218                         docstring arg = cmd.argument();
219                         return new InsetIndex(buf, InsetIndexParams(arg));
220                 }
221
222                 case LFUN_IPA_INSERT:
223                         return new InsetIPA(buf);
224
225                 case LFUN_NOMENCL_INSERT: {
226                         InsetCommandParams icp(NOMENCL_CODE);
227                         icp["symbol"] = cmd.argument();
228                         return new InsetNomencl(buf, icp);
229                 }
230
231                 case LFUN_TABULAR_INSERT: {
232                         if (cmd.argument().empty())
233                                 return 0;
234                         istringstream ss(to_utf8(cmd.argument()));
235                         int r = 0, c = 0;
236                         ss >> r >> c;
237                         if (r <= 0)
238                                 r = 2;
239                         if (c <= 0)
240                                 c = 2;
241                         return new InsetTabular(buf, r, c);
242                 }
243
244                 case LFUN_CAPTION_INSERT: {
245                         string arg = cmd.getArg(0);
246                         if (arg.empty())
247                                 arg = "Standard";
248                         return new InsetCaption(buf, arg);
249                 }
250
251                 case LFUN_INDEX_PRINT:  {
252                         InsetCommandParams icp(INDEX_PRINT_CODE);
253                         icp["type"] = cmd.argument();
254                         return new InsetPrintIndex(buf, icp);
255                 }
256
257                 case LFUN_NOMENCL_PRINT: {
258                         InsetCommandParams icp(NOMENCL_PRINT_CODE);
259                         icp["set_width"] = from_ascii("auto");
260                         return new InsetPrintNomencl(buf, icp);
261                 }
262
263                 case LFUN_INFO_INSERT: {
264                         InsetInfo * inset = new InsetInfo(buf, to_utf8(cmd.argument()));
265                         inset->updateInfo();
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_ptr<InsetExternal> inset(new 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_ptr<InsetGraphics> inset(new 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         auto_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 MathMacroTemplate(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 tmptok = lex.getString();
656                         inset.reset(new InsetWrap(buf, tmptok));
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                 // (InsetCollapsable 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