From dc177e2546ca97bed229fc58af1df5fe9a647398 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Thu, 13 Mar 2008 16:49:04 +0000 Subject: [PATCH] Embedding: move file validation from InsetGraphics to GuiGraphics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23709 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiGraphics.cpp | 18 +++++++++++++++++- src/insets/InsetGraphics.cpp | 11 ++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 2f795ae6f8..a7398a17b7 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -16,6 +16,7 @@ #include "GuiGraphics.h" +#include "Buffer.h" #include "LengthCombo.h" #include "Length.h" #include "LyXRC.h" @@ -28,10 +29,13 @@ #include "graphics/GraphicsCacheItem.h" #include "graphics/GraphicsImage.h" +#include "frontends/alert.h" + #include "insets/InsetGraphicsParams.h" #include "support/convert.h" #include "support/debug.h" +#include "support/ExceptionMessage.h" #include "support/FileFilterList.h" #include "support/filetools.h" #include "support/gettext.h" @@ -579,7 +583,19 @@ void GuiGraphics::applyView() InsetGraphicsParams & igp = params_; igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath())); - igp.filename.setEmbed(embedCB->checkState() == Qt::Checked); + try { + Buffer & buf = buffer(); + EmbeddedFile file(fromqstr(filename->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 igp.filename + igp.filename.setEmbed(file.embedded()); + } catch (ExceptionMessage const & message) { + Alert::error(message.title_, message.details_); + // failed to embed + igp.filename.setEmbed(false); + } // the bb section igp.bb.erase(); diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 13de24daab..39c5d8ad3a 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -167,16 +167,9 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: { InsetGraphicsParams p; InsetGraphicsMailer::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; - } + if (!p.filename.empty()) setParams(p); - } else + else cur.noUpdate(); break; } -- 2.39.2