From ca281eaa0c6bff9655c19905cce502cdb0e5b984 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Wed, 12 Sep 2007 14:27:47 +0000 Subject: [PATCH] Embedding: update related insets when the embedding status of a fileitem is changed git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20240 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/EmbeddedFiles.cpp | 21 +++++++++++++++++++ src/EmbeddedFiles.h | 8 +++++++ .../controllers/ControlEmbeddedFiles.cpp | 1 + src/insets/Inset.h | 3 +++ src/insets/InsetGraphics.cpp | 14 +++++++++++++ src/insets/InsetGraphics.h | 2 ++ 6 files changed, 49 insertions(+) diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index e6a02c4aac..73db1e4bda 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -225,6 +225,15 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const } +void EmbeddedFile::updateInsets(Buffer const * buf) const +{ + vector::const_iterator it = inset_list_.begin(); + vector::const_iterator it_end = inset_list_.end(); + for (; it != it_end; ++it) + const_cast(*it)->updateEmbeddedFile(*buf, *this); +} + + bool EmbeddedFiles::enabled() const { return buffer_->params().embedded; @@ -241,6 +250,8 @@ void EmbeddedFiles::enable(bool flag) // if operation is successful buffer_->markDirty(); buffer_->params().embedded = flag; + if (flag) + updateInsets(); } } @@ -468,4 +479,14 @@ void EmbeddedFiles::writeManifest(ostream & os) const } +void EmbeddedFiles::updateInsets() const +{ + EmbeddedFiles::EmbeddedFileList::const_iterator it = begin(); + EmbeddedFiles::EmbeddedFileList::const_iterator it_end = end(); + for (; it != it_end; ++it) + if (it->valid() && it->refCount() > 0) + it->updateInsets(buffer_); +} + + } diff --git a/src/EmbeddedFiles.h b/src/EmbeddedFiles.h index 115a8e5b6c..ccd6a9a118 100644 --- a/src/EmbeddedFiles.h +++ b/src/EmbeddedFiles.h @@ -155,6 +155,12 @@ public: bool extract(Buffer const * buf) const; /// update embedded file from external file, does not change embedding status bool updateFromExternalFile(Buffer const * buf) const; + /// + /// After the embedding status is changed, update all insets related + /// to this file item. + /// Because inset pointers may not be up to date, EmbeddedFiles::update() + /// would better be called before this function is called. + void updateInsets(Buffer const * buf) const; private: /// filename in zip file @@ -220,6 +226,8 @@ public: /// bool readManifest(Lexer & lex, ErrorList & errorList); void writeManifest(std::ostream & os) const; + /// update all insets to use embedded files when embedding status is changed + void updateInsets() const; private: /// get a unique inzip name, a suggestion can be given. std::string const getInzipName(std::string const & name, std::string const & inzipName); diff --git a/src/frontends/controllers/ControlEmbeddedFiles.cpp b/src/frontends/controllers/ControlEmbeddedFiles.cpp index 41fb786302..ebba9163d8 100644 --- a/src/frontends/controllers/ControlEmbeddedFiles.cpp +++ b/src/frontends/controllers/ControlEmbeddedFiles.cpp @@ -89,6 +89,7 @@ void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update item.updateFromExternalFile(&buffer()); else item.extract(&buffer()); + item.updateInsets(&buffer()); } } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 6782a59622..e451c7718b 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -49,6 +49,7 @@ class ParConstIterator; class ParIterator; class Text; class TocList; +class EmbeddedFile; class EmbeddedFiles; @@ -441,6 +442,8 @@ public: virtual void addToToc(TocList &, Buffer const &, ParConstIterator const &) const {} /// report files that can be embedded with the lyx file virtual void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const {}; + /// use embedded or external file after the embedding status of a file is changed + virtual void updateEmbeddedFile(Buffer const &, EmbeddedFile const &) {} /// Fill keys with BibTeX information virtual void fillWithBibKeys(Buffer const &, BiblioInfo &, InsetIterator const &) const { return; } diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 70cfe9767d..e979e24e2f 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -239,6 +239,20 @@ void InsetGraphics::registerEmbeddedFiles(Buffer const &, } +void InsetGraphics::updateEmbeddedFile(Buffer const & buf, + EmbeddedFile const & file) +{ + BOOST_ASSERT(buf.embeddedFiles().enabled()); + LYXERR(Debug::FILES) << "Update InsetGraphics file from " + << params_.filename.toFilesystemEncoding() << std::endl; + params_.filename.set(file.availableFile(&buf), buf.filePath()); + LYXERR(Debug::FILES) << " to " + << params_.filename.toFilesystemEncoding() << std::endl; + // FIXME: graphics dialog is not updated even if the underlying + // filename is updated. What should I do? +} + + void InsetGraphics::edit(Cursor & cur, bool) { InsetGraphicsMailer(*this).showDialog(&cur.bv()); diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index 98e44a5db2..d8b25cc8a5 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -80,6 +80,8 @@ public: bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; /// all graphics can be embedded void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const; + /// + void updateEmbeddedFile(Buffer const &, EmbeddedFile const &); protected: InsetGraphics(InsetGraphics const &); /// -- 2.39.5