mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
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
This commit is contained in:
parent
dc177e2546
commit
3192307c86
@ -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());
|
||||
|
@ -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();
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user