}
-void EmbeddedFile::enable(bool flag, Buffer const * buf)
+void EmbeddedFile::enable(bool flag, Buffer const * buf, bool updateFile)
{
- if (enabled() == flag)
- return;
+ // This function will be called when
+ // 1. through EmbeddedFiles::enable() when a file is read. Files
+ // should be in place so no updateFromExternalFile or extract()
+ // should be called. (updateFile should be false in this case).
+ // 2. through menu item enable/disable. updateFile should be true.
+ // 3. A single embedded file is added or modified. updateFile
+ // can be true or false.
+ LYXERR(Debug::FILES, (flag ? "Enable" : "Disable")
+ << " " << absFilename()
+ << (updateFile ? " (update file)." : " (no update)."));
if (flag) {
temp_path_ = buf->temppath();
if (embedded()) {
if (inzip_name_ != calcInzipName(buf->filePath()))
syncInzipFile(buf->filePath());
- updateFromExternalFile();
- } else
- extract();
+ if (updateFile)
+ updateFromExternalFile();
+ }
} else {
- extract();
+ if (embedded() && updateFile)
+ extract();
temp_path_ = "";
}
}
}
-void EmbeddedFile::updateInsets(Buffer const * buf) const
+void EmbeddedFile::updateInsets() const
{
vector<Inset const *>::const_iterator it = inset_list_.begin();
vector<Inset const *>::const_iterator it_end = inset_list_.end();
for (; it != it_end; ++it)
- const_cast<Inset *>(*it)->updateEmbeddedFile(*buf, *this);
+ const_cast<Inset *>(*it)->updateEmbeddedFile(*this);
}
}
-void EmbeddedFileList::enable(bool flag, Buffer & buffer)
+void EmbeddedFileList::enable(bool flag, Buffer & buffer, bool updateFile)
{
- if (buffer.embedded() == flag)
- return;
-
// update embedded file list
update(buffer);
std::vector<EmbeddedFile>::iterator it_end = end();
// an exception may be thrown
for (; it != it_end; ++it) {
- it->enable(flag, &buffer);
+ it->enable(flag, &buffer, updateFile);
if (it->embedded())
- count_embedded ++;
+ ++count_embedded;
else
- count_external ++;
+ ++count_external;
}
// if operation is successful (no exception is thrown)
buffer.markDirty();
// if the operation is successful, update insets
for (it = begin(); it != it_end; ++it)
- it->updateInsets(&buffer);
-
+ it->updateInsets();
+
+ if (!updateFile)
+ return;
+
// show result
if (flag) {
docstring const msg = bformat(_("%1$d external files are ignored.\n"
void EmbeddedFileList::registerFile(EmbeddedFile const & file,
Inset const * inset, Buffer const & buffer)
{
- BOOST_ASSERT(!buffer.embedded() || file.availableFile().exists());
BOOST_ASSERT(!buffer.embedded() || file.enabled());
// try to find this file from the list
from_utf8(it->outputFilename())));
it->setEmbed(true);
// update the inset with this embedding status.
- const_cast<Inset*>(inset)->updateEmbeddedFile(buffer, *it);
+ const_cast<Inset*>(inset)->updateEmbeddedFile(*it);
}
it->addInset(inset);
return;
clear();
for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it)
- it->registerEmbeddedFiles(buffer, *this);
+ it->registerEmbeddedFiles(*this);
}
return true;
}
-}
+} // namespace lyx