/// A cache for the bibfiles (including bibfiles of loaded child
/// documents), needed for appropriate update of natbib labels.
- mutable FileNameList bibfilesCache_;
+ mutable EmbeddedFileList bibfilesCache_;
};
/// Creates the per buffer temporary directory
if (it->lyxCode() == BIBTEX_CODE) {
InsetBibtex const & inset =
static_cast<InsetBibtex const &>(*it);
- FileNameList const bibfiles = inset.getFiles(*this);
+ EmbeddedFileList const bibfiles = inset.getFiles(*this);
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(),
bibfiles.end());
InsetInclude & inset =
static_cast<InsetInclude &>(*it);
inset.updateBibfilesCache(*this);
- FileNameList const & bibfiles =
+ EmbeddedFileList const & bibfiles =
inset.getBibfilesCache(*this);
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(),
}
-FileNameList const & Buffer::getBibfilesCache() const
+EmbeddedFileList const & Buffer::getBibfilesCache() const
{
// if this is a child document and the parent is already loaded
// use the parent's cache instead
namespace support {
class FileName;
-class FileNameList;
+class EmbeddedFileList;
}
/** The buffer object.
void updateBibfilesCache() const;
/// Return the cache with all bibfiles in use (including bibfiles
/// of loaded child documents).
- support::FileNameList const & getBibfilesCache() const;
+ support::EmbeddedFileList const & getBibfilesCache() const;
///
void getLabelList(std::vector<docstring> &) const;
add_->bibLW->setItemSelected(item, false);
QList<QListWidgetItem *> matches =
databaseLW->findItems(item->text(), Qt::MatchExactly);
- if (matches.empty())
- databaseLW->addItem(item->text());
+ if (matches.empty()) {
+ QString label = item->text();
+ QListWidgetItem * db = new QListWidgetItem(label);
+ db->setFlags(db->flags() | Qt::ItemIsSelectable
+ | Qt::ItemIsUserCheckable);
+ db->setCheckState(Qt::Checked);
+ databaseLW->addItem(db);
+ }
}
}
QString const f = toqstr(from_utf8(changeExtension(to_utf8(file), "")));
QList<QListWidgetItem *> matches =
databaseLW->findItems(f, Qt::MatchExactly);
- if (matches.empty())
+ if (matches.empty()) {
+ QListWidgetItem * db = new QListWidgetItem(f);
+ db->setFlags(db->flags() | Qt::ItemIsSelectable
+ | Qt::ItemIsUserCheckable);
+ db->setCheckState(Qt::Checked);
databaseLW->addItem(f);
+ }
}
changed();
databaseLW->clear();
docstring bibs = params_["bibfiles"];
+ docstring embs = params_["embed"];
docstring bib;
+ docstring emb;
while (!bibs.empty()) {
bibs = split(bibs, bib, ',');
+ embs = split(embs, emb, ',');
bib = trim(bib);
- if (!bib.empty())
- databaseLW->addItem(toqstr(bib));
+ if (!bib.empty()) {
+ QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
+ db->setFlags(db->flags() | Qt::ItemIsSelectable
+ | Qt::ItemIsUserCheckable);
+ db->setCheckState(emb == _("true") ? Qt::Checked : Qt::Unchecked);
+ databaseLW->addItem(db);
+ }
}
add_->bibLW->clear();
for (vector<string>::const_iterator it = bib_str.begin();
it != bib_str.end(); ++it) {
string bibItem(changeExtension(*it, ""));
- add_->bibLW->addItem(toqstr(bibItem));
+ QListWidgetItem * db = new QListWidgetItem(toqstr(bibItem));
+ db->setFlags(db->flags() & ~Qt::ItemIsSelectable
+ | Qt::ItemIsUserCheckable);
+ db->setCheckState(Qt::Unchecked);
+ add_->bibLW->addItem(db);
}
string bibstyle = getStylefile();
void GuiBibtex::applyView()
{
docstring dbs = qstring_to_ucs4(databaseLW->item(0)->text());
+ docstring emb = databaseLW->item(0)->checkState() == Qt::Checked ? _("true") : _("false");
unsigned int maxCount = databaseLW->count();
for (unsigned int i = 1; i < maxCount; i++) {
dbs += ',';
dbs += qstring_to_ucs4(databaseLW->item(i)->text());
+ emb += ',';
+ emb += databaseLW->item(i)->checkState() == Qt::Checked ? _("true") : _("false");
}
params_["bibfiles"] = dbs;
+ params_["embed"] = emb;
docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
bool const bibtotoc = bibtocCB->isChecked();
<string>BibTeX database to use</string>
</property>
<property name="text" >
- <string>Databa&ses</string>
+ <string>Databa&ses (select to embed when saved in bundled format)</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
CommandInfo const * InsetBibtex::findInfo(string const & /* cmdName */)
{
static const char * const paramnames[] =
- {"options", "btprint", "bibfiles", ""};
- static const bool isoptional[] = {true, true, false};
- static const CommandInfo info = {3, paramnames, isoptional};
+ {"options", "btprint", "bibfiles", "embed", ""};
+ static const bool isoptional[] = {true, true, false, false};
+ static const CommandInfo info = {4, paramnames, isoptional};
return &info;
}
throw message;
break;
}
+ //
+ InsetCommandParams orig = params();
setParams(p);
+ // test parameter and copy files
+ try {
+ // enable() in getFiles will try to copy files
+ getFiles(cur.buffer());
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // do not set parameter if an error happens
+ setParams(orig);
+ break;
+ }
cur.buffer().updateBibfilesCache();
break;
}
}
-FileNameList const InsetBibtex::getFiles(Buffer const & buffer) const
+EmbeddedFileList const InsetBibtex::getFiles(Buffer const & buffer) const
{
FileName path(buffer.filePath());
PathChanger p(path);
- FileNameList vec;
+ EmbeddedFileList vec;
string tmp;
+ string emb;
// FIXME UNICODE
string bibfiles = to_utf8(getParam("bibfiles"));
+ string embedStatus = to_utf8(getParam("embed"));
bibfiles = split(bibfiles, tmp, ',');
+ embedStatus = split(embedStatus, emb, ',');
while (!tmp.empty()) {
- FileName const file = findtexfile(changeExtension(tmp, "bib"), "bib");
- LYXERR(Debug::LATEX, "Bibfile: " << file);
-
- // If we didn't find a matching file name just fail silently
- if (!file.empty())
+ if (emb == "true") {
+ EmbeddedFile file(changeExtension(tmp, "bib"), buffer.filePath());
+ // If the file structure is correct, this should not fail.
+ file.setEmbed(true);
+ file.enable(buffer.embeddedFiles().enabled(), &buffer);
vec.push_back(file);
+ } else {
+ // this includes the cases when the embed parameter is empty
+ FileName const file = findtexfile(changeExtension(tmp, "bib"), "bib");
+
+ // If we didn't find a matching file name just fail silently
+ if (!file.empty()) {
+ EmbeddedFile efile = EmbeddedFile(file.absFilename(), buffer.filePath());
+ efile.setEmbed(false);
+ efile.enable(buffer.embeddedFiles().enabled(), &buffer);
+ vec.push_back(efile);
+ }
+ }
// Get next file name
bibfiles = split(bibfiles, tmp, ',');
+ embedStatus = split(embedStatus, emb, ',');
}
return vec;
void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
BiblioInfo & keylist, InsetIterator const & /*di*/) const
{
- FileNameList const files = getFiles(buffer);
- for (vector<FileName>::const_iterator it = files.begin();
+ EmbeddedFileList const files = getFiles(buffer);
+ for (vector<EmbeddedFile>::const_iterator it = files.begin();
it != files.end(); ++ it) {
// This bibtex parser is a first step to parse bibtex files
// more precisely.
// InsetBibitem can generate non-ASCII keys, and nonstandard
// 8bit clean bibtex forks exist.
- idocfstream ifs(it->toFilesystemEncoding().c_str(),
+ idocfstream ifs(it->availableFile().toFilesystemEncoding().c_str(),
ios_base::in,
buffer.params().encoding().iconvName());
}
+void InsetBibtex::registerEmbeddedFiles(Buffer const & buffer, EmbeddedFiles & files) const
+{
+ EmbeddedFileList const dbs = getFiles(buffer);
+ for (vector<EmbeddedFile>::const_iterator it = dbs.begin();
+ it != dbs.end(); ++ it)
+ files.registerFile(*it, this);
+}
+
+
+void InsetBibtex::updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file)
+{
+ // look for the item and update status
+ docstring bibfiles;
+ docstring embed;
+
+ bool first = true;
+ EmbeddedFileList dbs = getFiles(buf);
+ for (vector<EmbeddedFile>::iterator it = dbs.begin();
+ it != dbs.end(); ++ it) {
+ // update from file
+ if (it->absFilename() == file.absFilename())
+ it->setEmbed(file.embedded());
+ // write parameter string
+ if (!first) {
+ bibfiles += ',';
+ embed += ',';
+ first = false;
+ }
+ bibfiles += from_utf8(it->outputFilename(buf.filePath()));
+ embed += it->embedded() ? _("true") : _("false");
+ }
+ setParam("bibfiles", bibfiles);
+ setParam("embed", embed);
+}
+
+
} // namespace lyx
namespace lyx {
namespace support {
-class FileNameList;
+class EmbeddedFileList;
}
virtual void fillWithBibKeys(Buffer const &,
BiblioInfo &, InsetIterator const &) const;
///
- support::FileNameList const getFiles(Buffer const &) const;
+ support::EmbeddedFileList const getFiles(Buffer const &) const;
///
bool addDatabase(std::string const &);
///
///
static bool isCompatibleCommand(std::string const & s)
{ return s == "bibtex"; }
+ ///
+ void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
+ ///
+ void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file);
+
protected:
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
private:
BiblioInfo biblist;
- FileNameList const & bibfilesCache = buffer.getBibfilesCache();
+ support::EmbeddedFileList const & bibfilesCache = buffer.getBibfilesCache();
// compare the cached timestamps with the actual ones.
bool changed = false;
- for (FileNameList::const_iterator it = bibfilesCache.begin();
+ for (support::EmbeddedFileList::const_iterator it = bibfilesCache.begin();
it != bibfilesCache.end(); ++ it) {
FileName const f = *it;
time_t lastw = f.lastModified();
}
-FileNameList const &
+EmbeddedFileList const &
InsetInclude::getBibfilesCache(Buffer const & buffer) const
{
Buffer * const tmp = getChildBuffer(buffer, params());
if (tmp) {
tmp->setParent(0);
- FileNameList const & cache = tmp->getBibfilesCache();
+ EmbeddedFileList const & cache = tmp->getBibfilesCache();
tmp->setParent(&buffer);
return cache;
}
- static FileNameList const empty;
+ static EmbeddedFileList const empty;
return empty;
}
class RenderMonitoredPreview;
namespace support {
-class FileNameList;
+class EmbeddedFileList;
}
/// for including tex/lyx files
* Return an empty vector if the child doc is not loaded.
* \param buffer the Buffer containing this inset.
*/
- support::FileNameList const &
+ support::EmbeddedFileList const &
getBibfilesCache(Buffer const & buffer) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
#define FILENAMELIST_H
#include "support/FileName.h"
+#include "EmbeddedFiles.h"
#include <vector>
{
};
+class EmbeddedFileList: public std::vector<EmbeddedFile>
+{
+};
+
} // namespace support
} // namespace lyx