]> git.lyx.org Git - features.git/blobdiff - src/insets/insetinclude.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / insets / insetinclude.C
index 675f80e7955e48341682a65fb2f61989dfe0a434..a8bd6600b9343cc0c3bc6fe5054c36937b753a7f 100644 (file)
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "exporter.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "lyx_main.h"
+#include "lyxrc.h"
 #include "lyxlex.h"
 #include "metricsinfo.h"
 #include "outputparams.h"
@@ -32,6 +34,7 @@
 #include "frontends/LyXView.h"
 #include "frontends/Painter.h"
 
+#include "graphics/PreviewImage.h"
 #include "graphics/PreviewLoader.h"
 
 #include "insets/render_preview.h"
@@ -46,7 +49,8 @@
 #include <boost/bind.hpp>
 
 #include "support/std_ostream.h"
-#include "support/std_sstream.h"
+
+#include <sstream>
 
 using lyx::support::AddName;
 using lyx::support::AbsolutePath;
@@ -91,10 +95,9 @@ string const uniqueID()
 
 InsetInclude::InsetInclude(InsetCommandParams const & p)
        : params_(p), include_label(uniqueID()),
-         preview_(new RenderMonitoredPreview),
+         preview_(new RenderMonitoredPreview(this)),
          set_label_(false)
 {
-       preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
        preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
 }
 
@@ -103,10 +106,9 @@ InsetInclude::InsetInclude(InsetInclude const & other)
        : InsetOld(other),
          params_(other.params_),
          include_label(other.include_label),
-         preview_(new RenderMonitoredPreview),
+         preview_(new RenderMonitoredPreview(this)),
          set_label_(other.set_label_)
 {
-       preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
        preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
 }
 
@@ -332,13 +334,15 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
        }
 
        // write it to a file (so far the complete file)
-       string writefile = ChangeExtension(included_file, ".tex");
+       string const exportfile = ChangeExtension(incfile, ".tex");
+       string const mangled = FileName(ChangeExtension(included_file,
+                                                       ".tex")).mangledFilename();
+       string const writefile = MakeAbsPath(mangled, m_buffer->temppath());
 
-       if (!runparams.nice) {
-               incfile = FileName(writefile).mangledFilename();
-               writefile = MakeAbsPath(incfile, m_buffer->temppath());
-       }
+       if (!runparams.nice)
+               incfile = mangled;
        lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+       lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
        lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
        if (loadIfNeeded(buffer, params_)) {
@@ -366,7 +370,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
                tmp->makeLaTeXFile(writefile,
                                   OnlyPath(masterFilename(buffer)),
                                   runparams, false);
-       } else if (!runparams.nice) {
+       } else {
                // Copy the file to the temp dir, so that .aux files etc.
                // are not created in the original dir. Files included by
                // this file will be found via input@path, see ../buffer.C.
@@ -388,6 +392,9 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
        if (isVerbatim(params_)) {
                os << '\\' << params_.getCmdName() << '{' << incfile << '}';
        } else if (type(params_) == INPUT) {
+               runparams.exportdata->addExternalFile("latex", writefile,
+                                                     exportfile);
+
                // \input wants file with extension (default is .tex)
                if (!IsLyXFilename(included_file)) {
                        os << '\\' << params_.getCmdName() << '{' << incfile << '}';
@@ -397,6 +404,9 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
                           <<  '}';
                }
        } else {
+               runparams.exportdata->addExternalFile("latex", writefile,
+                                                     exportfile);
+
                // \include don't want extension and demands that the
                // file really have .tex
                os << '\\' << params_.getCmdName() << '{'
@@ -428,31 +438,34 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os,
 
        string const included_file = includedFilename(buffer, params_);
 
+       // write it to a file (so far the complete file)
+       string const exportfile = ChangeExtension(incfile, ".sgml");
+       string writefile = ChangeExtension(included_file, ".sgml");
+
        if (loadIfNeeded(buffer, params_)) {
                Buffer * tmp = bufferlist.getBuffer(included_file);
 
-               // write it to a file (so far the complete file)
-               string writefile = ChangeExtension(included_file, ".sgml");
-
-               if (!runparams.nice) {
-                       incfile = FileName(writefile).mangledFilename();
-                       writefile = MakeAbsPath(incfile,
-                                               buffer.getMasterBuffer()->temppath());
-               }
+               writefile = MakeAbsPath(FileName(writefile).mangledFilename(),
+                                       buffer.getMasterBuffer()->temppath());
+               if (!runparams.nice)
+                       incfile = writefile;
 
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+               lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-               OutputParams runp = runparams;
-               tmp->makeLinuxDocFile(writefile, runp, true);
+               tmp->makeLinuxDocFile(writefile, runparams, true);
        }
 
        if (isVerbatim(params_)) {
                os << "<![CDATA["
                   << GetFileContents(included_file)
                   << "]]>";
-       } else
+       } else {
+               runparams.exportdata->addExternalFile("linuxdoc", writefile,
+                                                     exportfile);
                os << '&' << include_label << ';';
+       }
 
        return 0;
 }
@@ -469,25 +482,31 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os,
 
        string const included_file = includedFilename(buffer, params_);
 
+       // write it to a file (so far the complete file)
+       string const exportfile = ChangeExtension(incfile, ".sgml");
+       string writefile = ChangeExtension(included_file, ".sgml");
+
        if (loadIfNeeded(buffer, params_)) {
                Buffer * tmp = bufferlist.getBuffer(included_file);
 
-               // write it to a file (so far the complete file)
-               string writefile = ChangeExtension(included_file, ".sgml");
-
-               if (!runparams.nice) {
-                       incfile = FileName(writefile).mangledFilename();
-                       writefile = MakeAbsPath(incfile,
-                                               buffer.getMasterBuffer()->temppath());
-               }
+               string const mangled = FileName(writefile).mangledFilename();
+               writefile = MakeAbsPath(mangled,
+                                       buffer.getMasterBuffer()->temppath());
+               if (!runparams.nice)
+                       incfile = mangled;
 
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+               lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-               OutputParams runp = runparams;
-               tmp->makeDocBookFile(writefile, runp, true);
+               tmp->makeDocBookFile(writefile, runparams, true);
        }
 
+       runparams.exportdata->addExternalFile("docbook", writefile,
+                                             exportfile);
+       runparams.exportdata->addExternalFile("docbook-xml", writefile,
+                                             exportfile);
+
        if (isVerbatim(params_)) {
                os << "<inlinegraphic fileref=\""
                   << '&' << include_label << ';'
@@ -570,7 +589,16 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
 
 void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       if (RenderPreview::activated() && preview_->previewReady()) {
+       BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
+
+       bool use_preview = false;
+       if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
+               lyx::graphics::PreviewImage const * pimage =
+                       preview_->getPreviewImage(*mi.base.bv->buffer());
+               use_preview = pimage && pimage->image();
+       }
+
+       if (use_preview) {
                preview_->metrics(mi, dim);
        } else {
                if (!set_label_) {
@@ -594,12 +622,19 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
        setPosCache(pi, x, y);
 
-       if (!RenderPreview::activated() || !preview_->previewReady()) {
-               button_.draw(pi, x + button_.box().x1, y);
-               return;
+       BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
+
+       bool use_preview = false;
+       if (RenderPreview::status() == LyXRC::PREVIEW_OFF) {
+               lyx::graphics::PreviewImage const * pimage =
+                       preview_->getPreviewImage(*pi.base.bv->buffer());
+               use_preview = pimage && pimage->image();
        }
 
-       preview_->draw(pi, x + button_.box().x1, y);
+       if (use_preview)
+               preview_->draw(pi, x + button_.box().x1, y);
+       else
+               button_.draw(pi, x + button_.box().x1, y);
 }
 
 
@@ -607,12 +642,6 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 // preview stuff
 //
 
-void InsetInclude::statusChanged() const
-{
-       LyX::cref().updateInset(this);
-}
-
-
 void InsetInclude::fileChanged() const
 {
        Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
@@ -652,7 +681,8 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
                 Buffer const & buffer)
 {
        InsetCommandParams const & params = inset.params();
-       if (RenderPreview::activated() && preview_wanted(params, buffer)) {
+       if (RenderPreview::status() == LyXRC::PREVIEW_OFF &&
+           preview_wanted(params, buffer)) {
                renderer.setAbsFile(includedFilename(buffer, params));
                string const snippet = latex_string(inset, buffer);
                renderer.addPreview(snippet, buffer);