Embedding: move file validation from InsetExternal to GuiExternal

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23711 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2008-03-13 17:27:20 +00:00
parent 3192307c86
commit 4ce363fcc6
2 changed files with 18 additions and 15 deletions

View File

@ -14,6 +14,7 @@
#include "GuiExternal.h"
#include "Buffer.h"
#include "FuncRequest.h"
#include "support/gettext.h"
#include "Length.h"
@ -27,7 +28,10 @@
#include "graphics/GraphicsCacheItem.h"
#include "graphics/GraphicsImage.h"
#include "frontends/alert.h"
#include "support/convert.h"
#include "support/ExceptionMessage.h"
#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/lstrings.h"
@ -633,7 +637,20 @@ void GuiExternal::updateTemplate()
void GuiExternal::applyView()
{
params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilepath()));
params_.filename.setEmbed(embedCB->checkState() == Qt::Checked);
try {
Buffer & buf = buffer();
EmbeddedFile file(fromqstr(fileED->text()), buf.filePath());
file.setEmbed(embedCB->checkState() == Qt::Checked);
// move file around if needed, an exception may be raised.
file.enable(buf.embedded(), &buf, true);
// if things are OK..., embed params_.filename
params_.filename.setEmbed(file.embedded());
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// failed to embed
params_.filename.setEmbed(false);
}
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);

View File

@ -30,12 +30,9 @@
#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"
@ -63,8 +60,6 @@ string defaultTemplateName;
namespace lyx {
namespace Alert = frontend::Alert;
namespace external {
TempName::TempName()
@ -444,15 +439,6 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetExternalParams p;
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
if (!p.filename.empty()) {
try {
p.filename.enable(buffer().embedded(), &buffer(), true);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// do not set parameter if an error happens
break;
}
}
setParams(p);
break;
}