]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetExternal.cpp
* InsetCollapsable:
[lyx.git] / src / insets / InsetExternal.cpp
index 2ac08de09f534b756ea8459107756efa805689ab..2ca4511163fb54e422e1e7ff463dd77074c3a877 100644 (file)
 
 #include <sstream>
 
-using std::endl;
 using std::string;
-using std::auto_ptr;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
 using std::vector;
 
+using lyx::support::DocFileName;
 
 namespace {
 
@@ -188,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 "
@@ -299,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;
                }
 
@@ -413,9 +423,9 @@ InsetExternal::InsetExternal(InsetExternal const & other)
 {}
 
 
-auto_ptr<Inset> InsetExternal::doClone() const
+Inset * InsetExternal::clone() const
 {
-       return auto_ptr<Inset>(new InsetExternal(*this));
+       return new InsetExternal(*this);
 }
 
 
@@ -483,24 +493,27 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+void InsetExternal::registerEmbeddedFiles(Buffer const &,
+       EmbeddedFiles & files) const
+{
+       files.registerFile(params_.filename.absFilename(), false, this);
+}
+
+
 void InsetExternal::edit(Cursor & cur, bool)
 {
        InsetExternalMailer(*this).showDialog(&cur.bv());
 }
 
 
-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);
 }
 
@@ -564,7 +577,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
                BOOST_ASSERT(false);
        }
        if (gparams.display == graphics::DefaultDisplay)
-               gparams.display = lyxrc.display_graphics;
+               gparams.display = graphics::DisplayType(lyxrc.display_graphics);
        // Override the above if we're not using a gui
        if (!use_gui)
                gparams.display = graphics::NoDisplay;
@@ -804,7 +817,7 @@ namespace {
 bool preview_wanted(InsetExternalParams const & params)
 {
        return params.display == external::PreviewDisplay &&
-               support::isFileReadable(params.filename);
+               params.filename.isFileReadable();
 }