]> git.lyx.org Git - features.git/commitdiff
Embedding: move file validation from InsetGraphics to GuiGraphics
authorBo Peng <bpeng@lyx.org>
Thu, 13 Mar 2008 16:49:04 +0000 (16:49 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 13 Mar 2008 16:49:04 +0000 (16:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23709 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiGraphics.cpp
src/insets/InsetGraphics.cpp

index 2f795ae6f8a58650524d5fd2362de5c7a6f557ac..a7398a17b71992dc254acd76f610ae8f80ccf297 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "GuiGraphics.h"
 
+#include "Buffer.h"
 #include "LengthCombo.h"
 #include "Length.h"
 #include "LyXRC.h"
 #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();
index 13de24daabbd79b4705d8bed6f7d9946b76af448..39c5d8ad3af427f7d92e1879ffe2c55dd2740da1 100644 (file)
@@ -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;
        }