diff --git a/development/FORMAT b/development/FORMAT index eced9bc155..7935c207e4 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2008-03-09 Bo Peng + * Format incremented to 318: add \extra_embedded_files to buffer params + 2008-03-02 Uwe Stöhr * Format incremented to 317: support floating placements for wrap floats diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 1a2f0c7ea6..1e4ca51909 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 2)), - ("1_6", range(277,318), minor_versions("1.6" , 0))] # Uwe: wrap placement + ("1_6", range(277,319), minor_versions("1.6" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 7c67513330..708747bbb9 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -1380,6 +1380,14 @@ def revert_wrapplacement(document): i = i + 1 +def remove_extra_embedded_files(document): + "Remove \extra_embedded_files from buffer params" + i = find_token(document.header, '\\extra_embedded_files', 0) + if i == -1: + document.warning("Malformed lyx document: Missing '\\extra_embedded_files'.") + return + document.header.pop(i) + ## # Conversion hub # @@ -1425,10 +1433,12 @@ convert = [[277, [fix_wrong_tables]], [314, []], [315, []], [316, [convert_subfig]], - [317, []] + [317, []], + [318, []], ] -revert = [[316, [revert_wrapplacement]], +revert = [[317, [remove_extra_embedded_files]], + [316, [revert_wrapplacement]], [315, [revert_subfig]], [314, [revert_colsep]], [313, []], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 22f5d97c46..b3d1091aff 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -117,7 +117,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 317; // Uwe Stöhr: float placement support for wrap floats +int const LYX_FORMAT = 318; typedef map DepClean; typedef map > RefCache; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 9ed248fcea..22da6812ee 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -275,6 +275,7 @@ public: AuthorList authorlist; BranchList branchlist; + vector extraEmbeddedFiles; Bullet temp_bullets[4]; Bullet user_defined_bullets[4]; Spacing spacing; @@ -379,6 +380,18 @@ AuthorList const & BufferParams::authors() const } +vector & BufferParams::extraEmbeddedFiles() +{ + return pimpl_->extraEmbeddedFiles; +} + + +vector const & BufferParams::extraEmbeddedFiles() const +{ + return pimpl_->extraEmbeddedFiles; +} + + BranchList & BufferParams::branchlist() { return pimpl_->branchlist; @@ -658,6 +671,16 @@ string const BufferParams::readToken(Lexer & lex, string const & token, toktmp << endl; return toktmp; } + } else if (token == "\\extra_embedded_files") { + extraEmbeddedFiles().clear(); + string par; + lex >> par; + string tmp; + par = split(par, tmp, ','); + while (!tmp.empty()) { + extraEmbeddedFiles().push_back(tmp); + par = split(par, tmp, ','); + } } else { lyxerr << "BufferParams::readToken(): Unknown token: " << token << endl; @@ -811,6 +834,19 @@ void BufferParams::writeFile(ostream & os) const else os << "\\author " << Author() << "\n"; } + + vector::const_iterator e_it = extraEmbeddedFiles().begin(); + vector::const_iterator e_end = extraEmbeddedFiles().end(); + os << "\\extra_embedded_files \""; + bool first = true; + for (; e_it != e_end; ++e_it) { + if (!first) + os << ","; + else + first = false; + os << *e_it; + } + os << "\"\n"; } diff --git a/src/BufferParams.h b/src/BufferParams.h index 9e858275ae..39d515eec0 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -270,6 +270,9 @@ public: bool compressed; /// bool embedded; + /// + std::vector & extraEmbeddedFiles(); + std::vector const & extraEmbeddedFiles() const; /// the author list for the document AuthorList & authors(); diff --git a/src/EmbeddedFiles.cpp b/src/EmbeddedFiles.cpp index f87494c821..3eb5476cdc 100644 --- a/src/EmbeddedFiles.cpp +++ b/src/EmbeddedFiles.cpp @@ -59,7 +59,8 @@ void EmbeddedFile::set(std::string const & filename, std::string const & buffer_ if (filename.empty()) return; - inzip_name_ = calcInzipName(buffer_path); + if (!buffer_path.empty()) + inzip_name_ = calcInzipName(buffer_path); } @@ -386,8 +387,8 @@ void EmbeddedFileList::enable(bool flag, Buffer & buffer, bool updateFile) int count_embedded = 0; int count_external = 0; - std::vector::iterator it = begin(); - std::vector::iterator it_end = end(); + iterator it = begin(); + iterator it_end = end(); // an exception may be thrown for (; it != it_end; ++it) { it->enable(flag, &buffer, updateFile); @@ -443,6 +444,7 @@ void EmbeddedFileList::registerFile(EmbeddedFile const & file, return; } // + file.clearInsets(); push_back(file); back().addInset(inset); } @@ -454,6 +456,17 @@ void EmbeddedFileList::update(Buffer const & buffer) for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it) it->registerEmbeddedFiles(*this); + + // add extra embedded files + vector extra = buffer.params().extraEmbeddedFiles(); + vector::iterator it = extra.begin(); + vector::iterator it_end = extra.end(); + for (; it != it_end; ++it) { + EmbeddedFile file = EmbeddedFile(*it, buffer.filePath()); + file.setEmbed(true); + file.enable(buffer.embedded(), &buffer, true); + insert(end(), file); + } } @@ -468,8 +481,9 @@ bool EmbeddedFileList::writeFile(DocFileName const & filename, Buffer const & bu filenames.push_back(make_pair(content, "content.lyx")); // prepare list of embedded file update(buffer); - std::vector::iterator it = begin(); - std::vector::iterator it_end = end(); + // + iterator it = begin(); + iterator it_end = end(); for (; it != it_end; ++it) { if (it->embedded()) { string file = it->embeddedFile(); diff --git a/src/EmbeddedFiles.h b/src/EmbeddedFiles.h index 42b02f39c7..3981d1687e 100644 --- a/src/EmbeddedFiles.h +++ b/src/EmbeddedFiles.h @@ -137,7 +137,7 @@ public: /// add an inset that refers to this file void addInset(Inset const * inset); - int refCount() const { return inset_list_.size(); } + void clearInsets() const { inset_list_.clear(); } /// embedding status of this file bool embedded() const { return embedded_; } @@ -180,7 +180,7 @@ private: bool embedded_; /// Insets that contains this file item. Because a /// file item can be referred by several Insets, a vector is used. - std::vector inset_list_; + mutable std::vector inset_list_; /// Embedded file needs to know whether enbedding is enabled, /// and where is the lyx temporary directory. Such information can /// be retrived from a buffer, but a buffer is not always available when diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 90884b8c9b..1dd083077e 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -20,7 +20,6 @@ #include "BufferParams.h" #include "BufferView.h" #include "Color.h" -#include "EmbeddedFiles.h" #include "Encoding.h" #include "FloatPlacement.h" #include "FuncRequest.h" @@ -44,6 +43,7 @@ #include "support/debug.h" #include "support/FileName.h" +#include "support/FileFilterList.h" #include "support/filetools.h" #include "support/lstrings.h" @@ -919,12 +919,10 @@ GuiDocument::GuiDocument(GuiView & lv) // embedded files embeddedFilesModule = new UiWidget; - connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)), - this, SLOT(change_adaptor())); connect(embeddedFilesModule->addPB, SIGNAL(clicked()), - this, SLOT(change_adaptor())); + this, SLOT(addExtraEmbeddedFile())); connect(embeddedFilesModule->removePB, SIGNAL(clicked()), - this, SLOT(change_adaptor())); + this, SLOT(removeExtraEmbeddedFile())); // PDF support pdfSupportModule = new UiWidget; @@ -1359,28 +1357,32 @@ void GuiDocument::updateModuleInfo() } -void GuiDocument::updateEmbeddedFileList() +void GuiDocument::setExtraEmbeddedFileList() { - embeddedFilesModule->filesLW->clear(); + embeddedFilesModule->extraLW->clear(); // add current embedded files - EmbeddedFileList & files = buffer().embeddedFiles(); - files.update(buffer()); - EmbeddedFileList::iterator fit = files.begin(); - EmbeddedFileList::iterator fit_end = files.end(); - for (; fit != fit_end; ++fit) { - QString label = toqstr(fit->relFilename(buffer().filePath())); - if (fit->refCount() > 1) - label += " (" + QString::number(fit->refCount()) + ")"; - QListWidgetItem * item = new QListWidgetItem(label); - item->setFlags(item->flags() | Qt::ItemIsSelectable - | Qt::ItemIsUserCheckable); - if(fit->embedded()) - item->setCheckState(Qt::Checked); - else - item->setCheckState(Qt::Unchecked); - // index of the currently used ParConstIterator - embeddedFilesModule->filesLW->addItem(item); - } + vector const & files = buffer().params().extraEmbeddedFiles(); + vector::const_iterator fit = files.begin(); + vector::const_iterator fit_end = files.end(); + for (; fit != fit_end; ++fit) + embeddedFilesModule->extraLW->addItem(toqstr(*fit)); +} + + +void GuiDocument::addExtraEmbeddedFile() +{ + QString file = browseRelFile(QString(), bufferFilepath(), + qt_("Extra embedded file"), FileFilterList(), true); + + if (embeddedFilesModule->extraLW->findItems(file, Qt::MatchExactly).empty()) + embeddedFilesModule->extraLW->addItem(file); +} + + +void GuiDocument::removeExtraEmbeddedFile() +{ + int index = embeddedFilesModule->extraLW->currentRow(); + delete embeddedFilesModule->extraLW->takeItem(index); } @@ -1688,7 +1690,12 @@ void GuiDocument::apply(BufferParams & params) fromqstr(pdfSupportModule->optionsLE->text())); // Embedded files - // FIXME + vector & files = params.extraEmbeddedFiles(); + files.clear(); + for (size_t i = 0; i < embeddedFilesModule->extraLW->count(); ++i) { + QListWidgetItem * item = embeddedFilesModule->extraLW->item(i); + files.push_back(fromqstr(item->text())); + } } @@ -1993,9 +2000,8 @@ void GuiDocument::updateParams(BufferParams const & params) pdfSupportModule->optionsLE->setText( toqstr(pdf.quoted_options)); - - // embedded files - updateEmbeddedFileList(); + + setExtraEmbeddedFileList(); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 7ebeae461f..489cc1efd4 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -137,7 +137,9 @@ private Q_SLOTS: void portraitChanged(); void classChanged(); void updateModuleInfo(); - void updateEmbeddedFileList(); + void setExtraEmbeddedFileList(); + void addExtraEmbeddedFile(); + void removeExtraEmbeddedFile(); private: UiWidget *textLayoutModule; diff --git a/src/frontends/qt4/ui/EmbeddedFilesUi.ui b/src/frontends/qt4/ui/EmbeddedFilesUi.ui index afbf0cfc04..4bed46ac65 100644 --- a/src/frontends/qt4/ui/EmbeddedFilesUi.ui +++ b/src/frontends/qt4/ui/EmbeddedFilesUi.ui @@ -19,7 +19,31 @@ 6 - + + + + Extra embedded files: + + + + + + + + + + Add + + + + + + + Remove + + + + Qt::Vertical @@ -32,47 +56,6 @@ - - - - Remove - - - - - - - Add - - - - - - - - - - Extra embedded files: - - - - - - - - - - Save this document in bundled format - - - - - - - Embedded files: - - -