From 3192307c861ab66122f47e3327f1f91892b3889d Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Thu, 13 Mar 2008 17:19:36 +0000 Subject: [PATCH] Embedding: move file validation from InsetBibtex to GuiBibtex git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23710 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiBibtex.cpp | 36 +++++++++++++++++++++++++-------- src/insets/InsetBibtex.cpp | 30 ++++++++------------------- src/insets/InsetBibtex.h | 6 +----- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/frontends/qt4/GuiBibtex.cpp b/src/frontends/qt4/GuiBibtex.cpp index 946490c59d..1a1dfb6ca9 100644 --- a/src/frontends/qt4/GuiBibtex.cpp +++ b/src/frontends/qt4/GuiBibtex.cpp @@ -17,6 +17,7 @@ #include "Buffer.h" #include "BufferParams.h" +#include "EmbeddedFiles.h" #include "ui_BibtexAddUi.h" #include "qt_helpers.h" #include "Validator.h" @@ -24,7 +25,10 @@ #include "ButtonPolicy.h" +#include "frontends/alert.h" + #include "support/debug.h" +#include "support/ExceptionMessage.h" #include "support/FileFilterList.h" #include "support/filetools.h" // changeExtension #include "support/gettext.h" @@ -353,18 +357,34 @@ void GuiBibtex::updateContents() void GuiBibtex::applyView() { - QString dbs = databaseLW->item(0)->text(); - docstring emb = databaseLW->item(0)->checkState() == Qt::Checked ? _("true") : _("false"); + docstring dbs; + docstring emb; unsigned int maxCount = databaseLW->count(); - for (unsigned int i = 1; i < maxCount; i++) { - dbs += ','; - dbs += databaseLW->item(i)->text(); - emb += ','; - emb += databaseLW->item(i)->checkState() == Qt::Checked ? _("true") : _("false"); + Buffer & buf = buffer(); + for (unsigned int i = 0; i < maxCount; i++) { + if (i != 0) { + dbs += ','; + emb += ','; + } + QString filename = databaseLW->item(i)->text(); + dbs += qstring_to_ucs4(filename); + try { + EmbeddedFile file(fromqstr(changeExtension(filename, "bib")), + buf.filePath()); + file.setEmbed(databaseLW->item(i)->checkState() == Qt::Checked); + // move file around if needed, an exception may be raised. + file.enable(buf.embedded(), &buf, true); + // if things are OK..., + if (file.embedded()) + emb += from_utf8(file.inzipName()); + } catch (ExceptionMessage const & message) { + Alert::error(message.title_, message.details_); + // failed to embed + } } - params_["bibfiles"] = qstring_to_ucs4(dbs); + params_["bibfiles"] = dbs; params_["embed"] = emb; docstring const bibstyle = qstring_to_ucs4(styleCB->currentText()); diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 5313b1d477..2b12c9f03b 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -27,8 +27,8 @@ #include "frontends/alert.h" #include "support/debug.h" -#include "support/ExceptionMessage.h" #include "support/docstream.h" +#include "support/ExceptionMessage.h" #include "support/filetools.h" #include "support/gettext.h" #include "support/lstrings.h" @@ -86,17 +86,8 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd) break; } // - InsetCommandParams orig = params(); - try { - // returned "embed" is composed of "true" or "false", which needs to be adjusted - createBibFiles(p["bibfiles"], p["embed"], true, true); - updateParam(); - } catch (ExceptionMessage const & message) { - Alert::error(message.title_, message.details_); - // do not set parameter if an error happens - setParams(orig); - break; - } + createBibFiles(p["bibfiles"], p["embed"]); + updateParam(); buffer().updateBibfilesCache(); break; } @@ -736,7 +727,7 @@ void InsetBibtex::validate(LaTeXFeatures & features) const void InsetBibtex::createBibFiles(docstring const & bibParam, - docstring const & embedParam, bool boolStatus, bool updateFile) const + docstring const & embedParam) const { bibfiles_.clear(); @@ -755,14 +746,9 @@ void InsetBibtex::createBibFiles(docstring const & bibParam, while (!tmp.empty()) { EmbeddedFile file(changeExtension(tmp, "bib"), buffer().filePath()); - if (boolStatus) { - BOOST_ASSERT(emb == "true" || emb == "false"); - file.setEmbed(emb == "true"); - } else { - file.setInzipName(emb); - file.setEmbed(emb != ""); - } - file.enable(buffer().embedded(), &buffer(), updateFile); + file.setInzipName(emb); + file.setEmbed(!emb.empty()); + file.enable(buffer().embedded(), &buffer(), false); bibfiles_.push_back(file); // Get next file name bibfiles = split(bibfiles, tmp, ','); @@ -796,7 +782,7 @@ void InsetBibtex::updateParam() void InsetBibtex::registerEmbeddedFiles(EmbeddedFileList & files) const { if (bibfiles_.empty()) - createBibFiles(params()["bibfiles"], params()["embed"], false, false); + createBibFiles(params()["bibfiles"], params()["embed"]); EmbeddedFileList::const_iterator it = bibfiles_.begin(); EmbeddedFileList::const_iterator it_end = bibfiles_.end(); diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index ca15e131ec..ff511d2479 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -57,12 +57,8 @@ public: /** \param bibfiles comma separated bib files \param embed comma separated embed status - \param boolStatus if true, embed has values true/false, which - needs to be converted to inzip names. - \param updateFile whether or not try to update file. */ - void createBibFiles(docstring const & bibfiles, docstring const & embed, - bool boolStatus, bool updateFile) const; + void createBibFiles(docstring const & bibfiles, docstring const & embed) const; /// update bibfiles and embed from bibfiles_ void updateParam(); private: -- 2.39.5