From c247f0ffe06b2354c8345b81b714e9e8f569f46a Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Mon, 3 Sep 2007 04:03:43 +0000 Subject: [PATCH] Embedding: fix a few embedding bugs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20017 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/EmbeddedFiles.cpp | 5 ++- .../controllers/ControlEmbeddedFiles.cpp | 10 ++++- .../controllers/ControlEmbeddedFiles.h | 5 +-- src/frontends/qt4/GuiEmbeddedFiles.cpp | 41 ++++++++----------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index f1e388bc99..9218384542 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -297,8 +297,9 @@ string const EmbeddedFiles::getInzipName(string const & abs_filename) from_utf8(buffer_->fileName()))); // if inzip_name is an absolute path, use filename only to avoid // leaking of filesystem information in inzip_name - if (absolutePath(inzip_name) || prefixIs(inzip_name, "..")) - inzip_name = onlyFilename(inzip_name); + // The second case covers cases '../path/file' and '.' + if (absolutePath(inzip_name) || prefixIs(inzip_name, ".")) + inzip_name = onlyFilename(abs_filename); // if this name has been used... // use _1_name, _2_name etc string tmp = inzip_name; diff --git a/src/frontends/controllers/ControlEmbeddedFiles.cpp b/src/frontends/controllers/ControlEmbeddedFiles.cpp index 1d654ef4e2..674568020b 100644 --- a/src/frontends/controllers/ControlEmbeddedFiles.cpp +++ b/src/frontends/controllers/ControlEmbeddedFiles.cpp @@ -35,10 +35,16 @@ using support::FileFilterList; namespace frontend { ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent) - : Dialog::Controller(parent), embedded_files(NULL) + : Dialog::Controller(parent) {} +EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles() +{ + return kernel().buffer().embeddedFiles(); +} + + bool ControlEmbeddedFiles::initialiseParams(string const &) { return true; @@ -49,7 +55,7 @@ void ControlEmbeddedFiles::updateEmbeddedFiles() { // copy buffer embeddedFiles to a local copy kernel().buffer().embeddedFiles().update(); - embedded_files = &kernel().buffer().embeddedFiles(); + kernel().buffer().embeddingChanged(); } diff --git a/src/frontends/controllers/ControlEmbeddedFiles.h b/src/frontends/controllers/ControlEmbeddedFiles.h index 77ce15a833..e50c98d007 100644 --- a/src/frontends/controllers/ControlEmbeddedFiles.h +++ b/src/frontends/controllers/ControlEmbeddedFiles.h @@ -26,8 +26,7 @@ public: /// virtual ~ControlEmbeddedFiles() {} /// - EmbeddedFiles const & embeddedFiles() const { return *embedded_files; } - EmbeddedFiles & embeddedFiles() { return *embedded_files; } + EmbeddedFiles & embeddedFiles(); /// virtual bool initialiseParams(std::string const &); /// obtain embedded files from buffer @@ -54,8 +53,6 @@ public: bool extract(EmbeddedFile const & item); protected: - // directly handle buffer embedded files - EmbeddedFiles * embedded_files; // std::string message_; }; diff --git a/src/frontends/qt4/GuiEmbeddedFiles.cpp b/src/frontends/qt4/GuiEmbeddedFiles.cpp index c9afffdea2..dc1b57105a 100644 --- a/src/frontends/qt4/GuiEmbeddedFiles.cpp +++ b/src/frontends/qt4/GuiEmbeddedFiles.cpp @@ -34,26 +34,6 @@ GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog(GuiEmbeddedFiles * form) : form_(form) { setupUi(this); - - form_->updateEmbeddedFiles(); - - EmbeddedFiles const & files = form_->embeddedFiles(); - enableCB->setChecked(files.enabled()); - EmbeddedFiles::EmbeddedFileList::const_iterator it = files.begin(); - EmbeddedFiles::EmbeddedFileList::const_iterator it_end = files.end(); - for (; it != it_end; ++it) { - QListWidgetItem * item = new QListWidgetItem(toqstr(it->inzipName())); - if (!it->valid()) - item->setTextColor(INVALID_COLOR); - else if(it->status() == EmbeddedFile::AUTO) - item->setTextColor(AUTO_COLOR); - else if(it->status() == EmbeddedFile::EMBEDDED) - item->setTextColor(EMBEDDED_COLOR); - else - item->setTextColor(EXTERNAL_COLOR); - filesLW->addItem(item); - } - filesLW->setCurrentRow(0); // update(); } @@ -107,12 +87,28 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked() void GuiEmbeddedFilesDialog::update() { + filesLW->clear(); + + // EmbeddedFiles const & files = form_->embeddedFiles(); - + EmbeddedFiles::EmbeddedFileList::const_iterator it = files.begin(); + EmbeddedFiles::EmbeddedFileList::const_iterator it_end = files.end(); + for (; it != it_end; ++it) { + QListWidgetItem * item = new QListWidgetItem(toqstr(it->inzipName())); + if (!it->valid()) + item->setTextColor(INVALID_COLOR); + else if(it->status() == EmbeddedFile::AUTO) + item->setTextColor(AUTO_COLOR); + else if(it->status() == EmbeddedFile::EMBEDDED) + item->setTextColor(EMBEDDED_COLOR); + else + item->setTextColor(EXTERNAL_COLOR); + filesLW->addItem(item); + } + // bool enabled = files.enabled(); enableCB->setChecked(enabled); statusGB->setEnabled(enabled); - filesLW->setEnabled(enabled); fullpathLE->setEnabled(enabled); } @@ -145,7 +141,6 @@ void GuiEmbeddedFilesDialog::on_enableCB_toggled(bool enable) // embedded files. Otherwise, embedded files will be lost!!! // form_->embeddedFiles().enable(enable); - update(); // immediately post the change to buffer (and bufferView) if (enable) form_->setMessage("Enable file embedding");