]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetExternal.cpp
Some things did not need to be mutable after all
[lyx.git] / src / insets / InsetExternal.cpp
index 8b0f00c5def651cb63c8faeadacd5fa322ee5679..1a1974804122a265b2f812c8d9ddb47ca67c437f 100644 (file)
@@ -30,6 +30,7 @@
 #include "MetricsInfo.h"
 #include "OutputParams.h"
 #include "output_latex.h"
+#include "texstream.h"
 #include "TocBackend.h"
 
 #include "frontends/alert.h"
@@ -69,13 +70,20 @@ namespace Alert = frontend::Alert;
 
 namespace external {
 
-TempName::TempName() : tempfile_(new support::TempFile("lyxextXXXXXX.tmp"))
+TempName::TempName()
 {
        // must have an extension for the converter code to work correctly.
+       support::TempFile f("lyxextXXXXXX.tmp");
+       // Let f go out of scope here and delete the file ourselves in
+       // ~TempName(), since otherwise external processes would not be able
+       // to use the file on windows (bug 9925). This is not as safe as
+       // keeping a support::TempFile member would be, but the best we can do.
+       f.setAutoRemove(false);
+       tempname_ = f.name();
 }
 
 
-TempName::TempName(TempName const & that) : tempfile_(0)
+TempName::TempName(TempName const & that)
 {
        *this = that;
 }
@@ -83,15 +91,17 @@ TempName::TempName(TempName const & that) : tempfile_(0)
 
 TempName::~TempName()
 {
-       delete tempfile_;
+       tempname_.removeFile();
 }
 
 
 TempName & TempName::operator=(TempName const & other)
 {
        if (this != &other) {
-               delete tempfile_;
-               tempfile_ = new support::TempFile("lyxextXXXXXX.tmp");
+               tempname_.removeFile();
+               support::TempFile f("lyxextXXXXXX.tmp");
+               f.setAutoRemove(false);
+               tempname_ = f.name(); 
        }
        return *this;
 }
@@ -99,7 +109,7 @@ TempName & TempName::operator=(TempName const & other)
 
 support::FileName TempName::operator()() const
 {
-       return tempfile_->name();
+       return tempname_;
 }
 
 } // namespace external
@@ -107,6 +117,7 @@ support::FileName TempName::operator()() const
 
 InsetExternalParams::InsetExternalParams()
        : display(true),
+         preview_mode(PREVIEW_OFF),
          lyxscale(defaultLyxScale),
          draft(false)
 {
@@ -366,6 +377,8 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
 
        if (lyxerr.debugging(Debug::EXTERNAL)) {
                lyxerr  << "InsetExternalParams::read:\n";
+               // false positive
+               // coverity[NEGATIVE_RETURNS]
                write(buffer, lyxerr);
        }
 
@@ -409,7 +422,7 @@ InsetExternal::InsetExternal(Buffer * buf)
 // Mouse hover is not copied and remains empty
 InsetExternal::InsetExternal(InsetExternal const & other)
        : Inset(other),
-         boost::signals::trackable(),
+         boost::signals2::trackable(),
          params_(other.params_),
          renderer_(other.renderer_->clone(this))
 {}
@@ -548,9 +561,8 @@ static bool isPreviewWanted(InsetExternalParams const & params)
 
 static docstring latexString(InsetExternal const & inset)
 {
-       TexRow texrow;
        odocstringstream ods;
-       otexstream os(ods, texrow);
+       otexstream os(ods, false);
        // We don't need to set runparams.encoding since it is not used by
        // latex().
        OutputParams runparams(0);
@@ -718,8 +730,7 @@ int InsetExternal::plaintext(odocstringstream & os,
        if (runparams.for_tooltip)
                return 0;
 
-       TexRow texrow;
-       otexstream ots(os, texrow);
+       otexstream ots(os, false);
        ots << '\n'; // output external material on a new line
        external::writeExternal(params_, "Ascii", buffer(), ots,
                                *(runparams.exportdata), false,
@@ -731,9 +742,8 @@ int InsetExternal::plaintext(odocstringstream & os,
 int InsetExternal::docbook(odocstream & os,
                           OutputParams const & runparams) const
 {
-       TexRow texrow;
        odocstringstream ods;
-       otexstream ots(ods, texrow);
+       otexstream ots(ods, false);
        external::writeExternal(params_, "DocBook", buffer(), ots,
                                *(runparams.exportdata), false,
                                runparams.dryrun || runparams.inComment);