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
This commit is contained in:
Bo Peng 2008-03-13 14:16:47 +00:00
parent 72c26ac6d1
commit ded962802e
3 changed files with 20 additions and 21 deletions

View File

@ -131,7 +131,9 @@ void EmbeddedFile::enable(bool flag, Buffer const * buf, bool updateFile)
if (embedded() && updateFile) if (embedded() && updateFile)
updateFromExternalFile(); updateFromExternalFile();
} else { } 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(); extract();
temp_path_ = ""; temp_path_ = "";
} }

View File

@ -15,6 +15,7 @@
#include "GuiInclude.h" #include "GuiInclude.h"
#include "Buffer.h" #include "Buffer.h"
#include "EmbeddedFiles.h"
#include "Format.h" #include "Format.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "support/gettext.h" #include "support/gettext.h"
@ -23,8 +24,11 @@
#include "qt_helpers.h" #include "qt_helpers.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "frontends/alert.h"
#include "support/os.h" #include "support/os.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/ExceptionMessage.h"
#include "support/FileFilterList.h" #include "support/FileFilterList.h"
#include "support/filetools.h" #include "support/filetools.h"
@ -240,7 +244,19 @@ void GuiInclude::updateContents()
void GuiInclude::applyView() void GuiInclude::applyView()
{ {
params_["filename"] = from_utf8(internal_path(fromqstr(filenameED->text()))); 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()); params_.preview(previewCB->isChecked());
int const item = typeCO->currentIndex(); int const item = typeCO->currentIndex();

View File

@ -47,7 +47,6 @@
#include "support/debug.h" #include "support/debug.h"
#include "support/docstream.h" #include "support/docstream.h"
#include "support/ExceptionMessage.h"
#include "support/FileNameList.h" #include "support/FileNameList.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/gettext.h" #include "support/gettext.h"
@ -267,24 +266,6 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
label_->initView(); 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); setParams(p);
buffer().updateBibfilesCache(); buffer().updateBibfilesCache();
} else } else