]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetExternal.cpp
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[lyx.git] / src / insets / InsetExternal.cpp
index 31115a4a85b1d4b1e675ea66ea2f3996a8a5c5a6..ef49384ce646d1ac1dc64d084b7c6bdc018f0f2a 100644 (file)
@@ -50,6 +50,7 @@ using std::ostream;
 using std::ostringstream;
 using std::vector;
 
+using lyx::support::DocFileName;
 
 namespace {
 
@@ -186,10 +187,15 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
        os << "External\n"
           << "\ttemplate " << templatename() << '\n';
 
-       if (!filename.empty())
-               os << "\tfilename "
-                  << filename.outputFilename(buffer.filePath())
-                  << '\n';
+       if (!filename.empty()) {
+               // when we save, we still use the original filename
+               EmbeddedFiles::EmbeddedFileList::const_iterator it = 
+                       buffer.embeddedFiles().find(filename.toFilesystemEncoding());
+               if (it != buffer.embeddedFiles().end())
+                       os << "\tfilename " << DocFileName(it->absFilename()).outputFilename(buffer.filePath()) << '\n';
+               else
+                       os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
+       }
 
        if (display != defaultDisplayType)
                os << "\tdisplay "
@@ -297,6 +303,12 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
                        lex.eatLine();
                        string const name = lex.getString();
                        filename.set(name, buffer.filePath());
+                       // maybe this file is embedded
+                       EmbeddedFiles::EmbeddedFileList::const_iterator it = buffer.embeddedFiles().find(filename.toFilesystemEncoding());
+                       if (it != buffer.embeddedFiles().end())
+                               // using available file, embedded or external, depending on file availability and
+                               // embedding status.
+                               filename = DocFileName(it->availableFile(&buffer));
                        break;
                }
 
@@ -482,9 +494,9 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 
 void InsetExternal::registerEmbeddedFiles(Buffer const &,
-       EmbeddedFiles & files, ParConstIterator const & pit) const
+       EmbeddedFiles & files) const
 {
-       files.registerFile(params_.filename.absFilename(), EmbeddedFile::AUTO, pit);
+       files.registerFile(params_.filename.absFilename(), false, this);
 }
 
 
@@ -494,18 +506,14 @@ void InsetExternal::edit(Cursor & cur, bool)
 }
 
 
-bool InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        renderer_->metrics(mi, dim);
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
 }
 
 
 void InsetExternal::draw(PainterInfo & pi, int x, int y) const
 {
-       setPosCache(pi, x, y);
        renderer_->draw(pi, x, y);
 }