]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetexternal.C
* In the process of fixing the math background color bug, this commit transfer backgr...
[lyx.git] / src / insets / insetexternal.C
index 6726d9859e69bbedae220d330ddf67d5ac4d6d6c..588dabc39969747a563997b3ae28e1ad6b4a506a 100644 (file)
@@ -70,11 +70,11 @@ namespace external {
 
 TempName::TempName()
 {
-       string const tempname = support::tempName(string(), "lyxext");
+       support::FileName const tempname(support::tempName(support::FileName(), "lyxext"));
        // FIXME: This is unsafe
-       support::unlink(support::FileName(tempname));
+       support::unlink(tempname);
        // must have an extension for the converter code to work correctly.
-       tempname_ = support::FileName(tempname + ".tmp");
+       tempname_ = support::FileName(tempname.absFilename() + ".tmp");
 }
 
 
@@ -290,7 +290,7 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
                        break;
 
                case EX_FILENAME: {
-                       lex.next();
+                       lex.eatLine();
                        string const name = lex.getString();
                        filename.set(name, buffer.filePath());
                        break;
@@ -482,10 +482,12 @@ void InsetExternal::edit(LCursor & cur, bool)
 }
 
 
-void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        renderer_->metrics(mi, dim);
+       bool const changed = dim_ != dim;
        dim_ = dim;
+       return changed;
 }
 
 
@@ -672,7 +674,7 @@ void InsetExternal::read(Buffer const & buffer, LyXLex & lex)
 
 
 int InsetExternal::latex(Buffer const & buf, odocstream & os,
-                        OutputParams const & runparams) const
+                         OutputParams const & runparams) const
 {
        if (params_.draft) {
                // FIXME UNICODE
@@ -685,8 +687,9 @@ int InsetExternal::latex(Buffer const & buf, odocstream & os,
        // "nice" means that the buffer is exported to LaTeX format but not
        // run through the LaTeX compiler.
        // If we're running through the LaTeX compiler, we should write the
-       // generated files in the bufer's temporary directory.
-       bool const external_in_tmpdir = !runparams.nice && !runparams.dryrun;
+       // generated files in the buffer's temporary directory.
+       bool const external_in_tmpdir = !runparams.nice;
+       bool const dryrun = runparams.dryrun || runparams.inComment;
 
        // If the template has specified a PDFLaTeX output, then we try and
        // use that.
@@ -705,33 +708,34 @@ int InsetExternal::latex(Buffer const & buf, odocstream & os,
                                                        buf, os,
                                                        *(runparams.exportdata),
                                                        external_in_tmpdir,
-                                                       runparams.inComment);
+                                                       dryrun);
                 }
-                
        }
-        
+
        return external::writeExternal(params_, "LaTeX", buf, os,
                                        *(runparams.exportdata),
                                        external_in_tmpdir,
-                                       runparams.inComment);
+                                       dryrun);
 }
 
 
 int InsetExternal::plaintext(Buffer const & buf, odocstream & os,
-                        OutputParams const & runparams) const
+                             OutputParams const & runparams) const
 {
-       return external::writeExternal(params_, "Ascii", buf, os,
-                                      *(runparams.exportdata), false,
-                                      runparams.inComment);
+       os << '\n'; // output external material on a new line
+       external::writeExternal(params_, "Ascii", buf, os,
+                               *(runparams.exportdata), false,
+                               runparams.dryrun || runparams.inComment);
+       return PLAINTEXT_NEWLINE;
 }
 
 
 int InsetExternal::docbook(Buffer const & buf, odocstream & os,
-                          OutputParams const & runparams) const
+                           OutputParams const & runparams) const
 {
        return external::writeExternal(params_, "DocBook", buf, os,
                                       *(runparams.exportdata), false,
-                                      runparams.inComment);
+                                      runparams.dryrun || runparams.inComment);
 }
 
 
@@ -778,7 +782,7 @@ void InsetExternal::validate(LaTeXFeatures & features) const
        for (; it != end; ++it) {
                string const preamble = etm.getPreambleDefByName(*it);
                if (!preamble.empty())
-                       features.addExternalPreamble(preamble);
+                       features.addPreambleSnippet(preamble);
        }
 }
 
@@ -799,7 +803,9 @@ bool preview_wanted(InsetExternalParams const & params)
 docstring const latex_string(InsetExternal const & inset, Buffer const & buffer)
 {
        odocstringstream os;
-       OutputParams runparams;
+       // We don't need to set runparams.encoding since it is not used by
+       // latex().
+       OutputParams runparams(0);
        runparams.flavor = OutputParams::LATEX;
        inset.latex(buffer, os, runparams);
        return os.str();