Embedding: paste an inset with an embedded file may fail, if the source buffer has been closed and the embedded file has been removed. This patch fixes this.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23771 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2008-03-16 05:10:41 +00:00
parent c4cd2f2daf
commit ccb09162e5
4 changed files with 48 additions and 10 deletions

View File

@ -57,8 +57,15 @@ void InsetBibtex::setBuffer(Buffer & buffer)
if (buffer_) {
EmbeddedFileList::iterator it = bibfiles_.begin();
EmbeddedFileList::iterator it_end = bibfiles_.end();
for (; it != it_end; ++it)
*it = it->copyTo(&buffer);
for (; it != it_end; ++it) {
try {
*it = it->copyTo(&buffer);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// failed to embed
it->setEmbed(false);
}
}
}
Inset::setBuffer(buffer);
}

View File

@ -30,9 +30,12 @@
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "frontends/alert.h"
#include "graphics/PreviewLoader.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
@ -60,6 +63,8 @@ string defaultTemplateName;
namespace lyx {
namespace Alert = frontend::Alert;
namespace external {
TempName::TempName()
@ -421,8 +426,17 @@ InsetExternal::~InsetExternal()
void InsetExternal::setBuffer(Buffer & buffer)
{
if (buffer_)
params_.filename = params_.filename.copyTo(&buffer);
if (buffer_) {
try {
// a file may not be copied successfully when, e.g. buffer_
// has already been closed.
params_.filename = params_.filename.copyTo(&buffer);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// failed to embed
params_.filename.setEmbed(false);
}
}
Inset::setBuffer(buffer);
}

View File

@ -156,8 +156,17 @@ InsetGraphics::~InsetGraphics()
void InsetGraphics::setBuffer(Buffer & buffer)
{
if (buffer_)
params_.filename = params_.filename.copyTo(&buffer);
if (buffer_) {
try {
// a file may not be copied successfully when, e.g. buffer_
// has already been closed.
params_.filename = params_.filename.copyTo(&buffer);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// failed to embed
params_.filename.setEmbed(false);
}
}
Inset::setBuffer(buffer);
}

View File

@ -47,6 +47,7 @@
#include "support/debug.h"
#include "support/docstream.h"
#include "support/ExceptionMessage.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
#include "support/gettext.h"
@ -216,10 +217,17 @@ InsetInclude::~InsetInclude()
void InsetInclude::setBuffer(Buffer & buffer)
{
if (buffer_) {
EmbeddedFile file_from = includedFilename(*buffer_, params());
EmbeddedFile file_to = file_from.copyTo(&buffer);
if (file_to.embedded())
setParam("embed", from_utf8(file_to.inzipName()));
try {
EmbeddedFile file_from = includedFilename(*buffer_, params());
EmbeddedFile file_to = file_from.copyTo(&buffer);
if (file_to.embedded())
setParam("embed", from_utf8(file_to.inzipName()));
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// failed to embed
setParam("embed", docstring());
}
}
buffer_ = &buffer;
if (label_)