From ded962802e5198405dc267542873fb76d4726820 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Thu, 13 Mar 2008 14:16:47 +0000 Subject: [PATCH] Embedding: prepare params()[embed] in GuiInclude rather than InsetInclude git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23708 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/EmbeddedFiles.cpp | 4 +++- src/frontends/qt4/GuiInclude.cpp | 18 +++++++++++++++++- src/insets/InsetInclude.cpp | 19 ------------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index b9f3c2a111..e3bbeb90c4 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -131,7 +131,9 @@ void EmbeddedFile::enable(bool flag, Buffer const * buf, bool updateFile) if (embedded() && updateFile) updateFromExternalFile(); } else { - if (embedded() && updateFile) + // when a new embeddeed file is created, it is not enabled, and + // there is no need to extract. + if (enabled() && embedded() && updateFile) extract(); temp_path_ = ""; } diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index b728efcafe..eedc1536b0 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -15,6 +15,7 @@ #include "GuiInclude.h" #include "Buffer.h" +#include "EmbeddedFiles.h" #include "Format.h" #include "FuncRequest.h" #include "support/gettext.h" @@ -23,8 +24,11 @@ #include "qt_helpers.h" #include "LyXRC.h" +#include "frontends/alert.h" + #include "support/os.h" #include "support/lstrings.h" +#include "support/ExceptionMessage.h" #include "support/FileFilterList.h" #include "support/filetools.h" @@ -240,7 +244,19 @@ void GuiInclude::updateContents() void GuiInclude::applyView() { params_["filename"] = from_utf8(internal_path(fromqstr(filenameED->text()))); - params_["embed"] = embedCB->checkState() == Qt::Checked ? _("true") : _("false"); + params_["embed"].clear(); + try { + Buffer & buf = buffer(); + EmbeddedFile file(to_utf8(params_["filename"]), 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..., set params_["embed"] + params_["embed"] = file.embedded() ? from_utf8(file.inzipName()) : docstring(); + } catch (ExceptionMessage const & message) { + Alert::error(message.title_, message.details_); + // params_["embed"] will be empty if a file is failed to embed + } params_.preview(previewCB->isChecked()); int const item = typeCO->currentIndex(); diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 140fe76cc2..f50241795e 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -47,7 +47,6 @@ #include "support/debug.h" #include "support/docstream.h" -#include "support/ExceptionMessage.h" #include "support/FileNameList.h" #include "support/filetools.h" #include "support/gettext.h" @@ -267,24 +266,6 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) label_->initView(); } } - try { - // the embed parameter passed back from the dialog - // is "true" or "false", we need to change it. - EmbeddedFile file = EmbeddedFile(to_utf8(p["filename"]), - onlyPath(parentFilename(buf))); - file.setEmbed(p["embed"] == _("true")); - // move file around if needed, an exception may be raised. - file.enable(buf.embedded(), &buf, true); - // if things are OK..., set p["embed"] - if (file.embedded()) - p["embed"] = from_utf8(file.inzipName()); - else - p["embed"].clear(); - } catch (ExceptionMessage const & message) { - Alert::error(message.title_, message.details_); - // do not set parameter if an error happens - break; - } setParams(p); buffer().updateBibfilesCache(); } else