]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetGraphics.cpp
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[lyx.git] / src / insets / InsetGraphics.cpp
index cbfd9ddd56e2ff213fb03711adcdfd5e4a42d7d4..cff5a843ea8d01f74c538c81db49a62397b06286 100644 (file)
@@ -71,6 +71,7 @@ TODO
 #include "Mover.h"
 #include "OutputParams.h"
 #include "sgml.h"
+#include "EmbeddedFiles.h"
 
 #include "frontends/alert.h"
 
@@ -230,24 +231,40 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+void InsetGraphics::registerEmbeddedFiles(Buffer const &, 
+       EmbeddedFiles & files) const
+{
+       files.registerFile(params().filename.absFilename(), 
+               false, this);
+}
+
+
+void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
+       EmbeddedFile const & file)
+{
+       BOOST_ASSERT(buf.embeddedFiles().enabled());
+       params_.filename = file;
+       LYXERR(Debug::FILES) << "Update InsetGraphic with File " 
+               << params_.filename.toFilesystemEncoding() 
+               << ", embedding status: "
+               << params_.filename.embedded() << std::endl;
+}
+
+
 void InsetGraphics::edit(Cursor & cur, bool)
 {
        InsetGraphicsMailer(*this).showDialog(&cur.bv());
 }
 
 
-bool InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        graphic_->metrics(mi, dim);
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
 }
 
 
 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
-       setPosCache(pi, x, y);
        graphic_->draw(pi, x, y);
 }
 
@@ -261,7 +278,7 @@ Inset::EDITABLE InsetGraphics::editable() const
 void InsetGraphics::write(Buffer const & buf, ostream & os) const
 {
        os << "Graphics\n";
-       params().Write(os, buf.filePath());
+       params().Write(os, buf);
 }
 
 
@@ -274,6 +291,16 @@ void InsetGraphics::read(Buffer const & buf, Lexer & lex)
        else
                LYXERR(Debug::GRAPHICS) << "Not a Graphics inset!" << endl;
 
+       // InsetGraphics is read, with filename in params_. We do not know if this file actually
+       // exists or is embedded so we need to get the 'availableFile' from buf.embeddedFiles()
+       if (buf.embeddedFiles().enabled()) {
+               EmbeddedFiles::EmbeddedFileList::const_iterator it = 
+                       buf.embeddedFiles().find(params_.filename.toFilesystemEncoding());
+               if (it != buf.embeddedFiles().end())
+                       // using available file, embedded or external, depending on file availability and
+                       // embedding status.
+                       params_.filename = *it;
+       }
        graphic_->update(params().as_grfxParams());
 }
 
@@ -600,13 +627,12 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
        if (status == FAILURE)
                return orig_file;
 
-       // a relative filename should be relative to the master
-       // buffer.
+       // a relative filename should be relative to the master buffer.
        // "nice" means that the buffer is exported to LaTeX format but not
-       //        run through the LaTeX compiler.
-       string output_file = support::os::external_path(runparams.nice ?
+       // run through the LaTeX compiler.
+       string output_file = runparams.nice ?
                params().filename.outputFilename(m_buffer->filePath()) :
-               onlyFilename(temp_file.absFilename()));
+               onlyFilename(temp_file.absFilename());
 
        if (runparams.nice && !isValidLaTeXFilename(output_file)) {
                frontend::Alert::warning(_("Invalid filename"),
@@ -1007,7 +1033,7 @@ InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
 {
        ostringstream data;
        data << name_ << ' ';
-       params.Write(data, buffer.filePath());
+       params.Write(data, buffer);
        data << "\\end_inset\n";
        return data.str();
 }