From 905324dd1646b8ead3cd83a6cd9bf4aa570fe2cf Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Tue, 11 Sep 2007 16:00:16 +0000 Subject: [PATCH] Embedding: for safety, update before changing embedding status git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20213 a592a061-630c-0410-9148-cb99ea01b6c8 --- .../controllers/ControlEmbeddedFiles.cpp | 13 +++++++------ src/frontends/controllers/ControlEmbeddedFiles.h | 2 +- src/frontends/qt4/GuiEmbeddedFiles.cpp | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/frontends/controllers/ControlEmbeddedFiles.cpp b/src/frontends/controllers/ControlEmbeddedFiles.cpp index d1a718d16b..41fb786302 100644 --- a/src/frontends/controllers/ControlEmbeddedFiles.cpp +++ b/src/frontends/controllers/ControlEmbeddedFiles.cpp @@ -81,14 +81,15 @@ void ControlEmbeddedFiles::view(EmbeddedFile const & item) } -void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed) +void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update) { - // FIXME: updateFromExternalFile() or extract() may fail... - if (embed) - item.updateFromExternalFile(&buffer()); - else - item.extract(&buffer()); item.setEmbed(embed); + if (update) { + if (embed) + item.updateFromExternalFile(&buffer()); + else + item.extract(&buffer()); + } } diff --git a/src/frontends/controllers/ControlEmbeddedFiles.h b/src/frontends/controllers/ControlEmbeddedFiles.h index 79d0885a3b..ef824e7695 100644 --- a/src/frontends/controllers/ControlEmbeddedFiles.h +++ b/src/frontends/controllers/ControlEmbeddedFiles.h @@ -48,7 +48,7 @@ public: /// void view(EmbeddedFile const & item); /// - void setEmbed(EmbeddedFile & item, bool embed); + void setEmbed(EmbeddedFile & item, bool embed, bool update); /// docstring const browseFile(); /// diff --git a/src/frontends/qt4/GuiEmbeddedFiles.cpp b/src/frontends/qt4/GuiEmbeddedFiles.cpp index fbe1b1eab5..be720a7023 100644 --- a/src/frontends/qt4/GuiEmbeddedFiles.cpp +++ b/src/frontends/qt4/GuiEmbeddedFiles.cpp @@ -37,12 +37,16 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemChanged(QListWidgetItem* item) if (item->checkState() == Qt::Checked) { if (files[filesLW->row(item)].embedded()) return; - controller_.setEmbed(files[filesLW->row(item)], true); + // this should not be needed after EmbeddedFiles are updated correctly. + files.update(); + controller_.setEmbed(files[filesLW->row(item)], true, files.enabled()); controller_.dispatchMessage("Embed file " + fromqstr(item->text())); } else { if (!files[filesLW->row(item)].embedded()) return; - controller_.setEmbed(files[filesLW->row(item)], false); + // this should not be needed after EmbeddedFiles are updated correctly. + files.update(); + controller_.setEmbed(files[filesLW->row(item)], false, files.enabled()); controller_.dispatchMessage("Stop embedding file " + fromqstr(item->text())); } } @@ -138,11 +142,13 @@ void GuiEmbeddedFilesDialog::updateView() void GuiEmbeddedFilesDialog::on_selectPB_clicked() { EmbeddedFiles & files = controller_.embeddedFiles(); + // this should not be needed after EmbeddedFiles are updated correctly. + files.update(); QList selection = filesLW->selectedItems(); for (QList::iterator it = selection.begin(); it != selection.end(); ++it) { (*it)->setCheckState(Qt::Checked); - controller_.setEmbed(files[filesLW->row(*it)], true); + controller_.setEmbed(files[filesLW->row(*it)], true, files.enabled()); } controller_.dispatchMessage("Embedding files"); } @@ -151,11 +157,13 @@ void GuiEmbeddedFilesDialog::on_selectPB_clicked() void GuiEmbeddedFilesDialog::on_unselectPB_clicked() { EmbeddedFiles & files = controller_.embeddedFiles(); + // this should not be needed after EmbeddedFiles are updated correctly. + files.update(); QList selection = filesLW->selectedItems(); for (QList::iterator it = selection.begin(); it != selection.end(); ++it) { (*it)->setCheckState(Qt::Checked); - controller_.setEmbed(files[filesLW->row(*it)], false); + controller_.setEmbed(files[filesLW->row(*it)], false, files.enabled()); } controller_.dispatchMessage("Stop embedding files"); }