]> git.lyx.org Git - features.git/commitdiff
Embedding: fix the add file feature (update dialog, mark buffer dirty, copy embedded...
authorBo Peng <bpeng@lyx.org>
Thu, 13 Sep 2007 05:30:44 +0000 (05:30 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 13 Sep 2007 05:30:44 +0000 (05:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20256 a592a061-630c-0410-9148-cb99ea01b6c8

src/EmbeddedFiles.cpp
src/EmbeddedFiles.h
src/frontends/controllers/ControlEmbeddedFiles.cpp
src/frontends/controllers/ControlEmbeddedFiles.h
src/frontends/qt4/GuiEmbeddedFiles.cpp

index 73db1e4bda2a021775e1e7bec76672af360d052b..a28864b4b221d2c2e230283e10303414a41f9a63 100644 (file)
@@ -256,7 +256,7 @@ void EmbeddedFiles::enable(bool flag)
 }
 
 
-void EmbeddedFiles::registerFile(string const & filename,
+EmbeddedFile & EmbeddedFiles::registerFile(string const & filename,
        bool embed, Inset const * inset, string const & inzipName)
 {
        // filename can be relative or absolute, translate to absolute filename
@@ -271,11 +271,12 @@ void EmbeddedFiles::registerFile(string const & filename,
        if (it != file_list_.end()) {
                it->addInset(inset);
                it->validate();
-               return;
+               return *it;
        }
        // try to be more careful
        file_list_.push_back(EmbeddedFile(abs_filename, 
                getInzipName(abs_filename, inzipName), embed, inset));
+       return file_list_.back();
 }
 
 
index ccd6a9a118aab60915f230ec44d3bacd779eeac1..0191c3b3661065dcb6325d57a34cf99c39cb8257 100644 (file)
@@ -197,7 +197,7 @@ public:
         * \param inset Inset pointer
         * \param inzipName suggested inzipname
         */
-       void registerFile(std::string const & filename, bool embed = false,
+       EmbeddedFile & registerFile(std::string const & filename, bool embed = false,
                Inset const * inset = 0,
                std::string const & inzipName = std::string());
 
index 4b5f3aa3c8794993a9dd5d09b2e860b763771d17..4cc77c62cc23fd43e11e8bef50c31c6664ca2794 100644 (file)
@@ -114,14 +114,23 @@ void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update
 }
 
 
-docstring const ControlEmbeddedFiles::browseFile()
+bool ControlEmbeddedFiles::browseAndAddFile()
 {
        std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
                                  from_utf8(lyxrc.document_path));
        FileFilterList const filter(_("All file (*.*)"));
-       return browseRelFile(docstring(), from_utf8(bufferFilepath()),
+       docstring const file = browseRelFile(docstring(), from_utf8(bufferFilepath()),
                             _("Select a file to embed"),
                             filter, false, dir1);
+       if (!file.empty()) {
+               EmbeddedFile & ef = embeddedFiles().registerFile(to_utf8(file), true);
+               if (embeddedFiles().enabled())
+                       ef.updateFromExternalFile(&buffer());
+               buffer().markDirty();
+               dispatchMessage("Add an embedded file" + to_utf8(file));
+               return true;
+       }
+       return false;
 }
 
 
index ca0f979430595b9a05bdd6b7b63475471923b1ce..d60867a223fcd5228d8c13f15d6b478b7e924cf3 100644 (file)
@@ -52,7 +52,7 @@ public:
        ///
        void setEmbed(EmbeddedFile & item, bool embed, bool update);
        ///
-       docstring const browseFile();
+       bool browseAndAddFile();
        ///
        bool extract(EmbeddedFile const & item);
        ///
index 0a4530e3a2050e3e06c66308f8aaaac9cd099cbb..28ff324780c1523d7b7cd2ef007e7b4276c51731 100644 (file)
@@ -93,7 +93,7 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemClicked(QListWidgetItem* item)
                QString label = toqstr(files[idx].inzipName())
                        + QString(" (%1/%2)").arg(k + 1).arg(files[idx].refCount());
                item->setText(label);
-       } else
+       } else if (files[idx].refCount() == 1)
                controller_.goTo(files[idx], 0);
 }
 
@@ -164,12 +164,8 @@ void GuiEmbeddedFilesDialog::on_unselectPB_clicked()
 
 void GuiEmbeddedFilesDialog::on_addPB_clicked()
 {
-       docstring const file = controller_.browseFile();
-       if (!file.empty()) {
-               EmbeddedFiles & files = controller_.embeddedFiles();
-               files.registerFile(to_utf8(file), true);
-       }
-       controller_.dispatchMessage("Add an embedded file");
+       if (controller_.browseAndAddFile())
+               updateView();
 }