]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.C
3bbf20e91badb8b03b0141e152534dcf5f2e1dfa
[lyx.git] / src / insets / insetexternal.C
1 /**
2  * \file insetexternal.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup Nielsen
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "insetexternal.h"
14 #include "insets/ExternalSupport.h"
15 #include "insets/ExternalTemplate.h"
16 #include "insets/render_button.h"
17 #include "insets/render_graphic.h"
18 #include "insets/render_preview.h"
19
20 #include "buffer.h"
21 #include "BufferView.h"
22 #include "cursor.h"
23 #include "debug.h"
24 #include "dispatchresult.h"
25 #include "exporter.h"
26 #include "funcrequest.h"
27 #include "gettext.h"
28 #include "LaTeXFeatures.h"
29 #include "lyx_main.h"
30 #include "lyxlex.h"
31 #include "lyxrc.h"
32 #include "metricsinfo.h"
33 #include "outputparams.h"
34
35 #include "frontends/lyx_gui.h"
36 #include "frontends/LyXView.h"
37
38 #include "graphics/PreviewLoader.h"
39
40 #include "support/FileInfo.h"
41 #include "support/filetools.h"
42 #include "support/lstrings.h"
43 #include "support/lyxlib.h"
44 #include "support/convert.h"
45 #include "support/translator.h"
46
47 #include <boost/bind.hpp>
48
49 #include <sstream>
50
51 namespace support = lyx::support;
52 namespace external = lyx::external;
53 namespace graphics = lyx::graphics;
54
55 using std::endl;
56 using std::string;
57 using std::auto_ptr;
58 using std::istringstream;
59 using std::ostream;
60 using std::ostringstream;
61 using std::vector;
62
63
64 namespace {
65
66 external::DisplayType const defaultDisplayType = external::NoDisplay;
67
68 unsigned int const defaultLyxScale = 100;
69
70 string defaultTemplateName = "RasterImage";
71
72 } // namespace anon
73
74
75 namespace lyx {
76 namespace external {
77
78 TempName::TempName()
79 {
80         tempname_ = support::tempName(string(), "lyxext");
81         // FIXME: This is unsafe
82         support::unlink(tempname_);
83         // must have an extension for the converter code to work correctly.
84         tempname_ += ".tmp";
85 }
86
87
88 TempName::TempName(TempName const &)
89 {
90         tempname_ = TempName()();
91 }
92
93
94 TempName::~TempName()
95 {
96         support::unlink(tempname_);
97 }
98
99
100 TempName &
101 TempName::operator=(TempName const & other)
102 {
103         if (this != &other)
104                 tempname_ = TempName()();
105         return *this;
106 }
107
108
109 namespace {
110
111 /// The translator between the Display enum and corresponding lyx string.
112 Translator<DisplayType, string> const initTranslator()
113 {
114         Translator<DisplayType, string> translator(DefaultDisplay, "default");
115
116         // Fill the display translator
117         translator.addPair(MonochromeDisplay, "monochrome");
118         translator.addPair(GrayscaleDisplay, "grayscale");
119         translator.addPair(ColorDisplay, "color");
120         translator.addPair(PreviewDisplay, "preview");
121         translator.addPair(NoDisplay, "none");
122
123         return translator;
124 }
125
126 } // namespace anon
127
128
129 Translator<DisplayType, string> const & displayTranslator()
130 {
131         static Translator<DisplayType, string> const translator =
132                 initTranslator();
133         return translator;
134 }
135
136 } // namespace external
137 } // namespace lyx
138
139
140 InsetExternalParams::InsetExternalParams()
141         : display(defaultDisplayType),
142           lyxscale(defaultLyxScale),
143           draft(false),
144           templatename_(defaultTemplateName)
145 {}
146
147
148 namespace {
149
150 template <typename T>
151 void clearIfNotFound(T & data, external::TransformID value,
152                      vector<external::TransformID> const & ids)
153 {
154         typedef vector<external::TransformID>::const_iterator
155                 const_iterator;
156
157         const_iterator it  = ids.begin();
158         const_iterator end = ids.end();
159         it = std::find(it, end, value);
160         if (it == end)
161                 data = T();
162 }
163
164 } // namespace anon
165
166
167 void InsetExternalParams::settemplate(string const & name)
168 {
169         templatename_ = name;
170
171         external::TemplateManager const & etm =
172                 external::TemplateManager::get();
173         external::Template const * const et = etm.getTemplateByName(name);
174         if (!et)
175                 // Be safe. Don't lose data.
176                 return;
177
178         // Ascertain which transforms the template supports.
179         // Empty all those that it doesn't.
180         vector<external::TransformID> const & ids = et->transformIds;
181         clearIfNotFound(clipdata,     external::Clip,   ids);
182         clearIfNotFound(extradata,    external::Extra,  ids);
183         clearIfNotFound(resizedata,   external::Resize, ids);
184         clearIfNotFound(rotationdata, external::Rotate, ids);
185 }
186
187
188 void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
189 {
190         os << "External\n"
191            << "\ttemplate " << templatename() << '\n';
192
193         if (!filename.empty())
194                 os << "\tfilename "
195                    << filename.outputFilename(buffer.filePath())
196                    << '\n';
197
198         if (display != defaultDisplayType)
199                 os << "\tdisplay "
200                    << external::displayTranslator().find(display)
201                    << '\n';
202
203         if (lyxscale != defaultLyxScale)
204                 os << "\tlyxscale " << convert<string>(lyxscale) << '\n';
205
206         if (draft)
207                 os << "\tdraft\n";
208
209         if (!clipdata.bbox.empty())
210                 os << "\tboundingBox " << clipdata.bbox << '\n';
211         if (clipdata.clip)
212                 os << "\tclip\n";
213
214         external::ExtraData::const_iterator it  = extradata.begin();
215         external::ExtraData::const_iterator end = extradata.end();
216         for (; it != end; ++it) {
217                 if (!it->second.empty())
218                         os << "\textra " << it->first << " \""
219                            << it->second << "\"\n";
220         }
221
222         if (!rotationdata.no_rotation()) {
223                 os << "\trotateAngle " << rotationdata.adjAngle() << '\n';
224                 if (rotationdata.origin() != external::RotationData::DEFAULT)
225                         os << "\trotateOrigin "
226                            << rotationdata.originString() << '\n';
227         }
228
229         if (!resizedata.no_resize()) {
230                 using support::float_equal;
231                 double scl = support::strToDbl(resizedata.scale);
232                 if (!float_equal(scl, 0.0, 0.05)) {
233                         if (!float_equal(scl, 100.0, 0.05))
234                                 os << "\tscale "
235                                    << resizedata.scale << '\n';
236                 } else {
237                         if (!resizedata.width.zero())
238                                 os << "\twidth "
239                                    << resizedata.width.asString() << '\n';
240                         if (!resizedata.height.zero())
241                                 os << "\theight "
242                                    << resizedata.height.asString() << '\n';
243                 }
244                 if (resizedata.keepAspectRatio)
245                         os << "\tkeepAspectRatio\n";
246         }
247 }
248
249
250 bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
251 {
252         enum ExternalTags {
253                 EX_TEMPLATE = 1,
254                 EX_FILENAME,
255                 EX_DISPLAY,
256                 EX_LYXSCALE,
257                 EX_DRAFT,
258                 EX_BOUNDINGBOX,
259                 EX_CLIP,
260                 EX_EXTRA,
261                 EX_HEIGHT,
262                 EX_KEEPASPECTRATIO,
263                 EX_ROTATEANGLE,
264                 EX_ROTATEORIGIN,
265                 EX_SCALE,
266                 EX_WIDTH,
267                 EX_END
268         };
269
270         keyword_item external_tags[] = {
271                 { "\\end_inset",     EX_END },
272                 { "boundingBox",     EX_BOUNDINGBOX },
273                 { "clip",            EX_CLIP },
274                 { "display",         EX_DISPLAY},
275                 { "draft",           EX_DRAFT},
276                 { "extra",           EX_EXTRA },
277                 { "filename",        EX_FILENAME},
278                 { "height",          EX_HEIGHT },
279                 { "keepAspectRatio", EX_KEEPASPECTRATIO },
280                 { "lyxscale",        EX_LYXSCALE},
281                 { "rotateAngle",     EX_ROTATEANGLE },
282                 { "rotateOrigin",    EX_ROTATEORIGIN },
283                 { "scale",           EX_SCALE },
284                 { "template",        EX_TEMPLATE },
285                 { "width",           EX_WIDTH }
286         };
287
288         pushpophelper pph(lex, external_tags, EX_END);
289
290         bool found_end  = false;
291         bool read_error = false;
292
293         while (lex.isOK()) {
294                 switch (lex.lex()) {
295                 case EX_TEMPLATE:
296                         lex.next();
297                         templatename_ = lex.getString();
298                         break;
299
300                 case EX_FILENAME: {
301                         lex.next();
302                         string const name = lex.getString();
303                         filename.set(name, buffer.filePath());
304                         break;
305                 }
306
307                 case EX_DISPLAY: {
308                         lex.next();
309                         string const name = lex.getString();
310                         display = external::displayTranslator().find(name);
311                         break;
312                 }
313
314                 case EX_LYXSCALE:
315                         lex.next();
316                         lyxscale = lex.getInteger();
317                         break;
318
319                 case EX_DRAFT:
320                         draft = true;
321                         break;
322
323                 case EX_BOUNDINGBOX:
324                         lex.next();
325                         clipdata.bbox.xl = lex.getInteger();
326                         lex.next();
327                         clipdata.bbox.yb = lex.getInteger();
328                         lex.next();
329                         clipdata.bbox.xr = lex.getInteger();
330                         lex.next();
331                         clipdata.bbox.yt = lex.getInteger();
332                         break;
333
334                 case EX_CLIP:
335                         clipdata.clip = true;
336                         break;
337
338                 case EX_EXTRA: {
339                         lex.next();
340                         string const name = lex.getString();
341                         lex.next();
342                         extradata.set(name, lex.getString());
343                         break;
344                 }
345
346                 case EX_HEIGHT:
347                         lex.next();
348                         resizedata.height = LyXLength(lex.getString());
349                         break;
350
351                 case EX_KEEPASPECTRATIO:
352                         resizedata.keepAspectRatio = true;
353                         break;
354
355                 case EX_ROTATEANGLE:
356                         lex.next();
357                         rotationdata.angle = lex.getString();
358                         break;
359
360                 case EX_ROTATEORIGIN:
361                         lex.next();
362                         rotationdata.origin(lex.getString());
363                         break;
364
365                 case EX_SCALE:
366                         lex.next();
367                         resizedata.scale = lex.getString();
368                         break;
369
370                 case EX_WIDTH:
371                         lex.next();
372                         resizedata.width = LyXLength(lex.getString());
373                         break;
374
375                 case EX_END:
376                         found_end = true;
377                         break;
378
379                 default:
380                         lex.printError("ExternalInset::read: "
381                                        "Wrong tag: $$Token");
382                         read_error = true;
383                         break;
384                 }
385
386                 if (found_end || read_error)
387                         break;
388         }
389
390         if (!found_end)
391                 lex.printError("ExternalInsetParams::read: Missing \\end_inset.");
392
393         // This is a trick to make sure that the data are self-consistent.
394         settemplate(templatename_);
395
396         if (lyxerr.debugging(Debug::EXTERNAL)) {
397                 lyxerr  << "InsetExternalParams::read:\n";
398                 write(buffer, lyxerr);
399         }
400
401         return !read_error;
402 }
403
404
405 InsetExternal::InsetExternal()
406         : renderer_(new RenderButton)
407 {}
408
409
410 InsetExternal::InsetExternal(InsetExternal const & other)
411         : InsetOld(other),
412           boost::signals::trackable(),
413           params_(other.params_),
414           renderer_(other.renderer_->clone(this))
415 {}
416
417
418 auto_ptr<InsetBase> InsetExternal::doClone() const
419 {
420         return auto_ptr<InsetBase>(new InsetExternal(*this));
421 }
422
423
424 InsetExternal::~InsetExternal()
425 {
426         InsetExternalMailer(*this).hideDialog();
427 }
428
429
430 void InsetExternal::statusChanged() const
431 {
432         LyX::cref().updateInset(this);
433 }
434
435
436 void InsetExternal::doDispatch(LCursor & cur, FuncRequest & cmd)
437 {
438         switch (cmd.action) {
439
440         case LFUN_EXTERNAL_EDIT: {
441                 Buffer const & buffer = cur.buffer();
442                 InsetExternalParams p;
443                 InsetExternalMailer::string2params(cmd.argument, buffer, p);
444                 external::editExternal(p, buffer);
445                 break;
446         }
447
448         case LFUN_INSET_MODIFY: {
449                 Buffer const & buffer = cur.buffer();
450                 InsetExternalParams p;
451                 InsetExternalMailer::string2params(cmd.argument, buffer, p);
452                 setParams(p, buffer);
453                 break;
454         }
455
456         case LFUN_INSET_DIALOG_UPDATE:
457                 InsetExternalMailer(*this).updateDialog(&cur.bv());
458                 break;
459
460         case LFUN_MOUSE_RELEASE:
461                 InsetExternalMailer(*this).showDialog(&cur.bv());
462                 break;
463
464         default:
465                 InsetBase::doDispatch(cur, cmd);
466         }
467 }
468
469
470 void InsetExternal::edit(LCursor & cur, bool)
471 {
472         InsetExternalMailer(*this).showDialog(&cur.bv());
473 }
474
475
476 void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
477 {
478         renderer_->metrics(mi, dim);
479         dim_ = dim;
480 }
481
482
483 void InsetExternal::draw(PainterInfo & pi, int x, int y) const
484 {
485         setPosCache(pi, x, y);
486         renderer_->draw(pi, x, y);
487 }
488
489
490 namespace {
491
492 enum RenderType {
493         RENDERBUTTON,
494         RENDERGRAPHIC,
495         RENDERPREVIEW
496 };
497
498
499 RenderType getRenderType(InsetExternalParams const & p)
500 {
501         if (!external::getTemplatePtr(p) ||
502             p.filename.empty() ||
503             p.display == external::NoDisplay)
504                 return RENDERBUTTON;
505
506         if (p.display == external::PreviewDisplay) {
507                 if (RenderPreview::status() != LyXRC::PREVIEW_OFF)
508                         return RENDERPREVIEW;
509                 return RENDERBUTTON;
510         }
511
512         if (p.display == external::DefaultDisplay &&
513             lyxrc.display_graphics == graphics::NoDisplay)
514                 return RENDERBUTTON;
515         return RENDERGRAPHIC;
516 }
517
518
519 graphics::Params get_grfx_params(InsetExternalParams const & eparams)
520 {
521         graphics::Params gparams;
522
523         gparams.filename = eparams.filename.absFilename();
524         gparams.scale = eparams.lyxscale;
525         if (eparams.clipdata.clip)
526                 gparams.bb = eparams.clipdata.bbox;
527         gparams.angle = lyx::support::strToDbl(eparams.rotationdata.adjAngle());
528
529         switch (eparams.display) {
530         case external::DefaultDisplay:
531                 gparams.display = graphics::DefaultDisplay;
532                 break;
533         case external::MonochromeDisplay:
534                 gparams.display = graphics::MonochromeDisplay;
535                 break;
536         case external::GrayscaleDisplay:
537                 gparams.display = graphics::GrayscaleDisplay;
538                 break;
539         case external::ColorDisplay:
540                 gparams.display = graphics::ColorDisplay;
541                 break;
542         case external::NoDisplay:
543                 gparams.display = graphics::NoDisplay;
544                 break;
545         default:
546                 BOOST_ASSERT(false);
547         }
548         if (gparams.display == graphics::DefaultDisplay)
549                 gparams.display = lyxrc.display_graphics;
550         // Override the above if we're not using a gui
551         if (!lyx_gui::use_gui)
552                 gparams.display = graphics::NoDisplay;
553
554         return gparams;
555 }
556
557
558 string const getScreenLabel(InsetExternalParams const & params,
559                             Buffer const & buffer)
560 {
561         external::Template const * const ptr =
562                 external::getTemplatePtr(params);
563         if (!ptr)
564                 return support::bformat(_("External template %1$s is not installed"),
565                                         params.templatename());
566         return external::doSubstitution(params, buffer, ptr->guiName);
567 }
568
569 void add_preview_and_start_loading(RenderMonitoredPreview &,
570                                    InsetExternal const &,
571                                    Buffer const &);
572
573 } // namespace anon
574
575
576 InsetExternalParams const & InsetExternal::params() const
577 {
578         return params_;
579 }
580
581
582 void InsetExternal::setParams(InsetExternalParams const & p,
583                               Buffer const & buffer)
584 {
585         params_ = p;
586
587         // Subsequent calls to the InsetExternal::Params default constructor
588         // will use this.
589         defaultTemplateName = params_.templatename();
590
591         switch (getRenderType(params_)) {
592         case RENDERBUTTON: {
593                 RenderButton * button_ptr = renderer_->asButton();
594                 if (!button_ptr) {
595                         renderer_.reset(new RenderButton);
596                         button_ptr = renderer_->asButton();
597                 }
598
599                 button_ptr->update(getScreenLabel(params_, buffer), true);
600                 break;
601
602         } case RENDERGRAPHIC: {
603                 RenderGraphic * graphic_ptr = renderer_->asGraphic();
604                 if (!graphic_ptr) {
605                         renderer_.reset(new RenderGraphic(this));
606                         graphic_ptr = renderer_->asGraphic();
607                 }
608
609                 graphic_ptr->update(get_grfx_params(params_));
610
611                 break;
612
613         } case RENDERPREVIEW: {
614                 RenderMonitoredPreview * preview_ptr =
615                         renderer_->asMonitoredPreview();
616                 if (!preview_ptr) {
617                         renderer_.reset(new RenderMonitoredPreview(this));
618                         preview_ptr = renderer_->asMonitoredPreview();
619                         preview_ptr->fileChanged(
620                                 boost::bind(&InsetExternal::fileChanged, this));
621                 }
622
623                 if (preview_ptr->monitoring())
624                         preview_ptr->stopMonitoring();
625                 add_preview_and_start_loading(*preview_ptr, *this, buffer);
626
627                 break;
628         }
629         }
630 }
631
632
633 void InsetExternal::fileChanged() const
634 {
635         Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
636         if (!buffer_ptr)
637                 return;
638
639         RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
640         BOOST_ASSERT(ptr);
641
642         Buffer const & buffer = *buffer_ptr;
643         ptr->removePreview(buffer);
644         add_preview_and_start_loading(*ptr, *this, buffer);
645 }
646
647
648 void InsetExternal::write(Buffer const & buffer, ostream & os) const
649 {
650         params_.write(buffer, os);
651 }
652
653
654 void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
655 {
656         InsetExternalParams params;
657         if (params.read(buffer, lex))
658                 setParams(params, buffer);
659 }
660
661
662 int InsetExternal::latex(Buffer const & buf, ostream & os,
663                          OutputParams const & runparams) const
664 {
665         if (params_.draft) {
666                 os << "\\fbox{\\ttfamily{}"
667                    << params_.filename.outputFilename(buf.filePath())
668                    << "}\n";
669                 return 1;
670         }
671
672         // "nice" means that the buffer is exported to LaTeX format but not
673         // run through the LaTeX compiler.
674         // If we're running through the LaTeX compiler, we should write the
675         // generated files in the bufer's temporary directory.
676         bool const external_in_tmpdir = !runparams.nice;
677
678         // If the template has specified a PDFLaTeX output, then we try and
679         // use that.
680         if (runparams.flavor == OutputParams::PDFLATEX) {
681                 external::Template const * const et_ptr =
682                         external::getTemplatePtr(params_);
683                 if (!et_ptr)
684                         return 0;
685                 external::Template const & et = *et_ptr;
686
687                 external::Template::Formats::const_iterator cit =
688                         et.formats.find("PDFLaTeX");
689                 if (cit != et.formats.end())
690                         return external::writeExternal(params_, "PDFLaTeX",
691                                                        buf, os,
692                                                        *(runparams.exportdata),
693                                                        external_in_tmpdir);
694         }
695         return external::writeExternal(params_, "LaTeX", buf, os,
696                                        *(runparams.exportdata),
697                                        external_in_tmpdir);
698 }
699
700
701 int InsetExternal::plaintext(Buffer const & buf, ostream & os,
702                          OutputParams const & runparams) const
703 {
704         return external::writeExternal(params_, "Ascii", buf, os,
705                                        *(runparams.exportdata));
706 }
707
708
709 int InsetExternal::linuxdoc(Buffer const & buf, ostream & os,
710                             OutputParams const & runparams) const
711 {
712         return external::writeExternal(params_, "LinuxDoc", buf, os,
713                                        *(runparams.exportdata));
714 }
715
716
717 int InsetExternal::docbook(Buffer const & buf, ostream & os,
718                            OutputParams const & runparams) const
719 {
720         return external::writeExternal(params_, "DocBook", buf, os,
721                                        *(runparams.exportdata));
722 }
723
724
725 void InsetExternal::validate(LaTeXFeatures & features) const
726 {
727         if (params_.draft)
728                 return;
729
730         external::Template const * const et_ptr =
731                 external::getTemplatePtr(params_);
732         if (!et_ptr)
733                 return;
734         external::Template const & et = *et_ptr;
735
736         external::Template::Formats::const_iterator cit =
737                 et.formats.find("LaTeX");
738         if (cit == et.formats.end())
739                 return;
740
741         if (!cit->second.requirement.empty())
742                 features.require(cit->second.requirement);
743
744         external::TemplateManager & etm = external::TemplateManager::get();
745
746         vector<string>::const_iterator it  = cit->second.preambleNames.begin();
747         vector<string>::const_iterator end = cit->second.preambleNames.end();
748         for (; it != end; ++it) {
749                 string const preamble = etm.getPreambleDefByName(*it);
750                 if (!preamble.empty())
751                         features.addExternalPreamble(preamble);
752         }
753 }
754
755
756 //
757 // preview stuff
758 //
759
760 namespace {
761
762 bool preview_wanted(InsetExternalParams const & params)
763 {
764         string const included_file = params.filename.absFilename();
765
766         return params.display == external::PreviewDisplay &&
767                 support::IsFileReadable(included_file);
768 }
769
770
771 string const latex_string(InsetExternal const & inset, Buffer const & buffer)
772 {
773         ostringstream os;
774         OutputParams runparams;
775         runparams.flavor = OutputParams::LATEX;
776         inset.latex(buffer, os, runparams);
777
778         return os.str();
779 }
780
781
782 void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
783                                    InsetExternal const & inset,
784                                    Buffer const & buffer)
785 {
786         InsetExternalParams const & params = inset.params();
787
788         if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
789             preview_wanted(params)) {
790                 renderer.setAbsFile(params.filename.absFilename());
791                 string const snippet = latex_string(inset, buffer);
792                 renderer.addPreview(snippet, buffer);
793                 renderer.startLoading(buffer);
794         }
795 }
796
797 } // namespace anon
798
799
800 void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const
801 {
802         RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
803         if (!ptr)
804                 return;
805
806         if (preview_wanted(params())) {
807                 ptr->setAbsFile(params_.filename.absFilename());
808                 string const snippet = latex_string(*this, ploader.buffer());
809                 ptr->addPreview(snippet, ploader);
810         }
811 }
812
813
814 /// Mailer stuff
815
816 string const InsetExternalMailer::name_("external");
817
818 InsetExternalMailer::InsetExternalMailer(InsetExternal & inset)
819         : inset_(inset)
820 {}
821
822
823 string const InsetExternalMailer::inset2string(Buffer const & buffer) const
824 {
825         return params2string(inset_.params(), buffer);
826 }
827
828
829 void InsetExternalMailer::string2params(string const & in,
830                                         Buffer const & buffer,
831                                         InsetExternalParams & params)
832 {
833         params = InsetExternalParams();
834         if (in.empty())
835                 return;
836
837         istringstream data(in);
838         LyXLex lex(0,0);
839         lex.setStream(data);
840
841         string name;
842         lex >> name;
843         if (!lex || name != name_)
844                 return print_mailer_error("InsetExternalMailer", in, 1, name_);
845
846         // This is part of the inset proper that is usually swallowed
847         // by LyXText::readInset
848         string id;
849         lex >> id;
850         if (!lex || id != "External")
851                 return print_mailer_error("InsetBoxMailer", in, 2, "External");
852
853         params.read(buffer, lex);
854 }
855
856
857 string const
858 InsetExternalMailer::params2string(InsetExternalParams const & params,
859                                    Buffer const & buffer)
860 {
861         ostringstream data;
862         data << name_ << ' ';
863         params.write(buffer, data);
864         data << "\\end_inset\n";
865         return data.str();
866 }