Bo Peng wrote:
Allow me to answer this critical question first:
Why does it need to happen then? (I understand that this is a high-level
design question.) This seems like something that needs to happen only
when there are certain buffer-level events: Export, saving, etc.
For example, when you insert a file that should be embedded, it should
be immediately copied to temppath(), and further modification to that
file should not change the embedded version. This may not be critical
to normal disk files, but you can imagine pasting from clipboard
(either from lyx or outside), where the source may not exist
afterwards. This is easily the case when you copy an embedded inset to
another buffer, and close the original buffer.
OK. I can see this then, and can adjust for it. That said, however,
speaking as a potential user of this feature, I find this very
counterintuitive. I select a bibliography file, choose "Embed" (let's
say the document is already in embedded status), and now the edits I
make the file have no effect. If my co-author sends me a file, I have to
uncheck Document>Save in Bundled Format (not very intuitive!) to extract
the files, and then remember to recheck it when I save.
This destroys the old EFList and creates a new one from scratch every
time the inset is modified.
I am too lazy to really 'update' the list here, so I just create one.
The false enable call should be used here.
I've implemented that sort of thing. It's painless.
And as far as the true/false issue goes, why don't I have that problem
at line 771? Answer: Because you do the true call in GuiBibtex. But
that's insufficient, because this doesn't have to be called from there.
LFUNs can be called in lots of ways, including from the mini-buffer. So
you really need true here. Or else, what seems a better solution, don't
destroy bibfiles_ and recreate it. Just make the new ones and do the
true call for those. But I can do that as well, right?
Your GuiBlah/InsetBlah argument makes sense and I do not quite
remember why I moved the relevant code to GuiBlah... Anyway, my
implementation can be buggy so let us figure out the overall idea,
then fix the code together. I can see that you understand the
embedding code quite well now. :-)
Check the attached. It's more or less an inverse of what you had before.
In place of updateParams(), we have updateBibFiles(). There are still
some rough edges, though. But this will work, I think, without
undermining the InsetCommand structures.
Richard
Index: src/insets/InsetBibtex.h
===================================================================
--- src/insets/InsetBibtex.h (revision 24016)
+++ src/insets/InsetBibtex.h (working copy)
@@ -12,14 +12,17 @@
#ifndef INSET_BIBTEX_H
#define INSET_BIBTEX_H
-#include <map>
-#include "InsetCommand.h"
#include "BiblioInfo.h"
#include "EmbeddedFiles.h"
+#include "InsetCommand.h"
+#include "support/docstring.h"
+#include "support/FileName.h"
+
+#include <vector>
+
namespace lyx {
-
/** Used to insert BibTeX's information
*/
class InsetBibtex : public InsetCommand {
@@ -27,7 +30,7 @@
///
InsetBibtex(InsetCommandParams const &);
///
- void setBuffer(Buffer & buffer);
+ virtual void setBuffer(Buffer & buffer);
///
docstring screenLabel() const;
///
@@ -40,13 +43,13 @@
int latex(odocstream &, OutputParams const &) const;
///
void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
+ ///
+ EmbeddedFileList const & getBibFiles() const;
///
- EmbeddedFileList embeddedFiles() const;
+ bool addDatabase(docstring const &);
///
- bool addDatabase(std::string const &);
+ bool delDatabase(docstring const &);
///
- bool delDatabase(std::string const &);
- ///
void validate(LaTeXFeatures &) const;
///
static ParamInfo const & findInfo(std::string const &);
@@ -55,25 +58,40 @@
///
static bool isCompatibleCommand(std::string const & s)
{ return s == "bibtex"; }
- /// create bibfiles_ from params bibfiles and embed
- /**
- \param bibfiles comma separated bib files
- \param embed comma separated embed status
- */
- void createBibFiles(docstring const & bibfiles, docstring const & embed) const;
- /// update bibfiles and embed from bibfiles_
- void updateParam();
+ ///
+ static support::FileName
+ getBibTeXPath(docstring const & filename, Buffer const & buf);
private:
+ /// This method updates bibfiles_ from the parameter information and
+ /// MUST be called whenever the parameters may have been changed, in
+ /// particular, whenever a .bib file may have been added or deleted,
+ /// or the embedding information may have changed.
+ void updateBibFiles() const;
///
+ struct Data {
+ docstring bibfile;
+ docstring embfile;
+ Data(docstring const & b, docstring const & e)
+ : bibfile(b), embfile(e) {}
+ };
+ ///
+ typedef std::vector<Data> ParamData;
+ typedef ParamData::const_iterator ParamDataCit;
+ typedef ParamData::iterator ParamDataIt;
+ ///
+ ParamData makeParamStruct() const;
+ ///
+ void writeParamStruct(ParamData const & data);
+ ///
void registerEmbeddedFiles(EmbeddedFileList &) const;
///
void updateEmbeddedFile(EmbeddedFile const & file);
- /// embedded bib files
- mutable EmbeddedFileList bibfiles_;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
Inset * clone() const { return new InsetBibtex(*this); }
+ ///
+ mutable EmbeddedFileList bibfiles_;
};
Index: src/insets/InsetBibtex.cpp
===================================================================
--- src/insets/InsetBibtex.cpp (revision 24016)
+++ src/insets/InsetBibtex.cpp (working copy)
@@ -48,26 +48,27 @@
InsetBibtex::InsetBibtex(InsetCommandParams const & p)
- : InsetCommand(p, "bibtex"), bibfiles_()
+ : InsetCommand(p, "bibtex")
{}
void InsetBibtex::setBuffer(Buffer & buffer)
{
+ // FIXME We ought to have a buffer.
if (buffer_) {
EmbeddedFileList::iterator it = bibfiles_.begin();
- EmbeddedFileList::iterator it_end = bibfiles_.end();
- for (; it != it_end; ++it) {
+ EmbeddedFileList::iterator en = bibfiles_.end();
+ for (; it != en; ++it) {
try {
*it = it->copyTo(&buffer);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// failed to embed
it->setEmbed(false);
- }
+ }
}
}
- Inset::setBuffer(buffer);
+ InsetCommand::setBuffer(buffer);
}
@@ -104,10 +105,9 @@
throw message;
break;
}
- //
- createBibFiles(p["bibfiles"], p["embed"]);
- updateParam();
- setParam("options", p["options"]);
+
+ setParams(p);
+ updateBibFiles();
buffer().updateBibfilesCache();
break;
}
@@ -162,15 +162,21 @@
// use such filenames.)
// Otherwise, store the (maybe absolute) path to the original,
// unmangled database name.
- EmbeddedFileList::const_iterator it = bibfiles_.begin();
- EmbeddedFileList::const_iterator it_end = bibfiles_.end();
+
+ ParamData data = makeParamStruct();
+ ParamDataCit it = data.begin();
+ ParamDataCit en = data.end();
odocstringstream dbs;
- for (; it != it_end; ++it) {
- string utf8input = removeExtension(it->availableFile().absFilename());
+ for (; it != en; ++it) {
+ bool embedded =
+ !runparams.dryrun && buffer().embedded() && !it->embfile.empty();
+ docstring const input =
+ trim(embedded ? it->embfile : it->bibfile);
+ // FIXME UNICODE
+ string utf8input(to_utf8(input));
string database =
normalizeName(buffer(), runparams, utf8input, ".bib");
- FileName const try_in_file =
- makeAbsPath(database + ".bib", buffer().filePath());
+ FileName const try_in_file(makeAbsPath(database + ".bib", buffer().filePath()));
bool const not_from_texmf = try_in_file.isReadableFile();
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
@@ -196,9 +202,11 @@
from_utf8(database));
}
- if (it != bibfiles_.begin())
+ if (it != data.begin())
dbs << ',';
// FIXME UNICODE
+ // FIXME This is wrong for exporting when the file is embedded. But
+ // the solution is not obvious at this point.
dbs << from_utf8(latex_path(database));
}
docstring const db_out = dbs.str();
@@ -305,11 +313,6 @@
}
-EmbeddedFileList InsetBibtex::embeddedFiles() const
-{
- return bibfiles_;
-}
-
namespace {
// methods for parsing bibtex files
@@ -552,30 +555,30 @@
void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist,
InsetIterator const & /*di*/) const
{
- EmbeddedFileList const files = embeddedFiles();
- 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.
- //
- // - it reads the whole bibtex entry and does a syntax check
- // (matching delimiters, missing commas,...
- // - it recovers from errors starting with the next @-character
- // - it reads @string definitions and replaces them in the
- // field values.
- // - it accepts more characters in keys or value names than
- // bibtex does.
- //
- // Officially bibtex does only support ASCII, but in practice
- // you can use the encoding of the main document as long as
- // some elements like keys and names are pure ASCII. Therefore
- // we convert the file from the buffer encoding.
- // We don't restrict keys to ASCII in LyX, since our own
- // InsetBibitem can generate non-ASCII keys, and nonstandard
- // 8bit clean bibtex forks exist.
-
+ // This bibtex parser is a first step to parse bibtex files
+ // more precisely.
+ //
+ // - it reads the whole bibtex entry and does a syntax check
+ // (matching delimiters, missing commas,...
+ // - it recovers from errors starting with the next @-character
+ // - it reads @string definitions and replaces them in the
+ // field values.
+ // - it accepts more characters in keys or value names than
+ // bibtex does.
+ //
+ // Officially bibtex does only support ASCII, but in practice
+ // you can use the encoding of the main document as long as
+ // some elements like keys and names are pure ASCII. Therefore
+ // we convert the file from the buffer encoding.
+ // We don't restrict keys to ASCII in LyX, since our own
+ // InsetBibitem can generate non-ASCII keys, and nonstandard
+ // 8bit clean bibtex forks exist.
+ EmbeddedFileList const files = getBibFiles();
+ EmbeddedFileList::const_iterator it = files.begin();
+ EmbeddedFileList::const_iterator en = files.end();
+ for (; it != en; ++ it) {
idocfstream ifs(it->availableFile().toFilesystemEncoding().c_str(),
- ios_base::in, buffer().params().encoding().iconvName());
+ std::ios_base::in, buffer().params().encoding().iconvName());
char_type ch;
VarMap strings;
@@ -704,38 +707,109 @@
}
+// look up the path to the file using TeX
+FileName InsetBibtex::getBibTeXPath(docstring const & filename, Buffer const & buf)
+{
+ string texfile = changeExtension(to_utf8(filename), "bib");
+ // note that, if the filename can be found directly from the path,
+ // findtexfile will just return a FileName object for that path.
+ FileName file(findtexfile(texfile, "bib"));
+ if (file.empty())
+ file = FileName(makeAbsPath(texfile, buf.filePath()));
+ return file;
+}
-bool InsetBibtex::addDatabase(string const & db)
+
+InsetBibtex::ParamData InsetBibtex::makeParamStruct() const
{
- EmbeddedFile file(changeExtension(db, "bib"), buffer().filePath());
-
- // only compare filename
- EmbeddedFileList::iterator it = bibfiles_.begin();
- EmbeddedFileList::iterator it_end = bibfiles_.end();
- for (; it != it_end; ++it)
- if (it->absFilename() == file.absFilename())
+ docstring bibfiles = getParam("bibfiles");
+ docstring embfiles = getParam("embed");
+ docstring bibfile;
+ docstring embfile;
+
+ ParamData retval;
+ char_type comma(',');
+ bibfiles = split(bibfiles, bibfile, comma);
+ embfiles = split(embfiles, embfile, comma);
+ while (!bibfile.empty()) {
+ retval.push_back(Data(bibfile, embfile));
+ bibfiles = split(bibfiles, bibfile, comma);
+ embfiles = split(embfiles, embfile, comma);
+ }
+ return retval;
+}
+
+
+void InsetBibtex::writeParamStruct(InsetBibtex::ParamData const & data)
+{
+ docstring newbibfiles;
+ docstring newembfiles;
+ bool first = true;
+ char_type comma(',');
+
+ ParamDataCit it = data.begin();
+ ParamDataCit en = data.end();
+ for (; it != en; ++it) {
+ if (!first) {
+ newbibfiles = newbibfiles + comma;
+ newembfiles = newembfiles + comma;
+ } else
+ first = false;
+ newbibfiles = newbibfiles + it->bibfile;
+ newembfiles = newembfiles + it->embfile;
+ }
+ setParam("bibfiles", newbibfiles);
+ setParam("embed", newembfiles);
+}
+
+
+bool InsetBibtex::addDatabase(docstring const & db)
+{
+ // look for the item and update status
+ ParamData data = makeParamStruct();
+
+ ParamDataCit it = data.begin();
+ ParamDataCit en = data.end();
+ for (; it != en; ++it)
+ if (db == it->bibfile)
return false;
-
- bibfiles_.push_back(file);
- updateParam();
+
+ FileName const texPath = getBibTeXPath(db, buffer());
+ string const inzipName =
+ EmbeddedFile::calcInzipName(texPath.absFilename(), buffer().filePath());
+ data.push_back(Data(db, from_utf8(inzipName)));
+
+ writeParamStruct(data);
+ updateBibFiles();
+ buffer().updateBibfilesCache();
return true;
}
-bool InsetBibtex::delDatabase(string const & db)
+bool InsetBibtex::delDatabase(docstring const & db)
{
- EmbeddedFile file(changeExtension(db, "bib"), buffer().filePath());
-
- // only compare filename
- EmbeddedFileList::iterator it = bibfiles_.begin();
- EmbeddedFileList::iterator it_end = bibfiles_.end();
- for (; it != it_end; ++it)
- if (it->absFilename() == file.absFilename()) {
- bibfiles_.erase(it);
- updateParam();
- return true;
+ // look for the item and update status
+ ParamData data = makeParamStruct();
+
+ bool found = false;
+
+ ParamDataIt it = data.begin();
+ ParamDataIt en = data.end();
+ for (; it != en; ++it) {
+ if (db == it->bibfile) {
+ data.erase(it);
+ found = true;
+ break;
}
- return false;
+ }
+
+ if (!found)
+ return false;
+
+ writeParamStruct(data);
+ updateBibFiles();
+ buffer().updateBibfilesCache();
+ return true;
}
@@ -746,69 +820,59 @@
}
-void InsetBibtex::createBibFiles(docstring const & bibParam,
- docstring const & embedParam) const
+EmbeddedFileList const & InsetBibtex::getBibFiles() const
{
- bibfiles_.clear();
-
- string tmp;
- string emb;
-
- string bibfiles = to_utf8(bibParam);
- string embedStatus = to_utf8(embedParam);
-
- LYXERR(Debug::FILES, "Create bib files from parameters "
- << bibfiles << " and " << embedStatus);
-
- bibfiles = split(bibfiles, tmp, ',');
- embedStatus = split(embedStatus, emb, ',');
-
- while (!tmp.empty()) {
- EmbeddedFile file(changeExtension(tmp, "bib"), buffer().filePath());
-
- 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, ',');
- embedStatus = split(embedStatus, emb, ',');
- }
+ return bibfiles_;
}
-void InsetBibtex::updateParam()
+void InsetBibtex::updateBibFiles() const
{
- docstring bibfiles;
- docstring embed;
+ // need to do this to keep old info while also not
+ // copying over any files that have been deleted.
+ EmbeddedFileList oldlist = bibfiles_;
+ bibfiles_.clear();
- bool first = true;
-
- EmbeddedFileList::iterator it = bibfiles_.begin();
- EmbeddedFileList::iterator en = bibfiles_.end();
+ ParamData data = makeParamStruct();
+ ParamDataIt it = data.begin();
+ ParamDataIt en = data.end();
for (; it != en; ++it) {
- if (!first) {
- bibfiles += ',';
- embed += ',';
- } else
- first = false;
- bibfiles += from_utf8(it->outputFilename(buffer().filePath()));
- if (it->embedded())
- embed += from_utf8(it->inzipName());
+ FileName bib = getBibTeXPath(it->bibfile, buffer());
+ EmbeddedFile * efp = oldlist.findFile(bib.absFilename());
+ if (efp) {
+ // already have this one
+ efp->setInzipName(to_utf8(it->embfile));
+ efp->setEmbed(!it->embfile.empty());
+ try {
+ efp->enable(buffer().embedded(), &buffer(), false);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // failed to embed
+ efp->setEmbed(false);
+ }
+ bibfiles_.push_back(*efp);
+ } else {
+ EmbeddedFile file(bib.absFilename(), buffer().filePath());
+ file.setInzipName(to_utf8(it->embfile));
+ file.setEmbed(!it->embfile.empty());
+ try {
+ file.enable(buffer().embedded(), &buffer(), true);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // failed to embed
+ file.setEmbed(false);
+ }
+ bibfiles_.push_back(file);
+ }
}
- setParam("bibfiles", bibfiles);
- setParam("embed", embed);
}
void InsetBibtex::registerEmbeddedFiles(EmbeddedFileList & files) const
{
- if (bibfiles_.empty())
- createBibFiles(params()["bibfiles"], params()["embed"]);
-
EmbeddedFileList::const_iterator it = bibfiles_.begin();
- EmbeddedFileList::const_iterator it_end = bibfiles_.end();
- for (; it != it_end; ++it)
+ EmbeddedFileList::const_iterator en = bibfiles_.end();
+ for (; it != en; ++it)
files.registerFile(*it, this, buffer());
}
@@ -816,12 +880,35 @@
void InsetBibtex::updateEmbeddedFile(EmbeddedFile const & file)
{
// look for the item and update status
- for (EmbeddedFileList::iterator it = bibfiles_.begin();
- it != bibfiles_.end(); ++it)
- if (it->absFilename() == file.absFilename())
- *it = file;
+ string filename = file.absFilename();
+ EmbeddedFile * ef = bibfiles_.findFile(filename);
+ BOOST_ASSERT(ef);
- updateParam();
+ bool first = true;
+ bool found = false;
+ docstring newembfiles;
+ char_type comma(',');
+
+ // now we need to update the relevant parameter
+ ParamData data = makeParamStruct();
+ ParamDataCit it = data.begin();
+ ParamDataCit en = data.end();
+ for (; it != en; ++it) {
+ if (!first)
+ newembfiles = newembfiles + comma;
+ else
+ first = false;
+ string pathToBib(getBibTeXPath(it->bibfile, buffer()).absFilename());
+ if (!found && pathToBib == filename) {
+ //found it, we'll suppose
+ newembfiles = newembfiles + from_utf8(file.inzipName());
+ found = true;
+ } else // just copy the old value
+ newembfiles = newembfiles + it->embfile;
+ }
+
+ BOOST_ASSERT(found); // otherwise there's some nasty inconsistency
+ setParam("embed", newembfiles);
}
Index: src/EmbeddedFiles.h
===================================================================
--- src/EmbeddedFiles.h (revision 24016)
+++ src/EmbeddedFiles.h (working copy)
@@ -94,8 +94,12 @@
class EmbeddedFile : public support::DocFileName
{
public:
+ ///
EmbeddedFile(std::string const & file = std::string(),
std::string const & buffer_path = std::string());
+ ///
+ EmbeddedFile(std::string const & file, std::string const & inzipName,
+ bool embed, Buffer const & buf);
/// set filename and inzipName.
/**
@@ -170,13 +174,14 @@
bool isReadableFile() const;
/// Calculate checksum of availableFile
unsigned long checksum() const;
-
- // calculate inzip_name_ from filename
+ /// move an embedded disk file with an existing inzip_name_ to
+ /// a calculated inzip_name_, if they differ.
+ void syncInzipFile(std::string const & buffer_path);
+ /// calculate inzip_name_ from filename
std::string calcInzipName(std::string const & buffer_path);
- // move an embedded disk file with an existing inzip_name_ to
- // a calculated inzip_name_, if they differ.
- void syncInzipFile(std::string const & buffer_path);
-
+ ///
+ static std::string
+ calcInzipName(std::string const & file, std::string const & path);
private:
/// filename in zip file
std::string inzip_name_;
@@ -209,7 +214,15 @@
*/
void registerFile(EmbeddedFile const & file, Inset const * inset,
Buffer const & buffer);
+ ///
+ void registerFile(std::string const & file, std::string const & inzipName,
+ bool embed, Inset const * inset, Buffer const & buf);
+ /// returns a pointer to the Embedded file representing this object,
+ /// or null if not found. The filename should be absolute.
+ EmbeddedFile const * findFile(std::string const & filename) const;
+ EmbeddedFile * findFile(std::string const & filename);
+
/// validate embedded fies after a file is read.
void validate(Buffer const & buffer);
Index: src/EmbeddedFiles.cpp
===================================================================
--- src/EmbeddedFiles.cpp (revision 24016)
+++ src/EmbeddedFiles.cpp (working copy)
@@ -54,6 +54,22 @@
}
+EmbeddedFile::EmbeddedFile(std::string const & file,
+ std::string const & inzipName, bool embed, Buffer const & buf)
+ : DocFileName("", false), inzip_name_(inzipName), inset_list_()
+{
+ DocFileName::set(file, buf.filePath());
+ setEmbed(embed);
+ try {
+ enable(buf.embedded(), &buf, true);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // failed to embed
+ setEmbed(false);
+ }
+}
+
+
void EmbeddedFile::set(std::string const & filename, std::string const & buffer_path)
{
DocFileName::set(filename, buffer_path);
@@ -368,11 +384,14 @@
const std::string driveName = "LyX.Embed.Drive";
const std::string spaceName = "LyX.Embed.Space";
-std::string EmbeddedFile::calcInzipName(std::string const & buffer_path)
+
+// static
+std::string EmbeddedFile::calcInzipName(
+ std::string const & file, std::string const & buffer_path)
{
- string inzipName = to_utf8(makeRelPath(from_utf8(absFilename()),
+ string inzipName = to_utf8(makeRelPath(from_utf8(file),
from_utf8(buffer_path)));
-
+
if (FileName(inzipName).isAbsolute())
inzipName = absDirName + '/' + inzipName;
@@ -386,10 +405,15 @@
// to avoid name conflict between $docu_path/file and $temp_path/file
// embedded files are in a subdirectory of $temp_path.
inzipName = embDirName + '/' + inzipName;
- return inzipName;
+ return inzipName;
}
+std::string EmbeddedFile::calcInzipName(std::string const & buffer_path)
+{
+ return calcInzipName(absFilename(), buffer_path);
+}
+
void EmbeddedFile::syncInzipFile(std::string const & buffer_path)
{
BOOST_ASSERT(enabled());
@@ -488,35 +512,67 @@
}
+void EmbeddedFileList::registerFile(std::string const & file,
+ std::string const & inzipName, bool embed, Inset const * inset,
+ Buffer const & buf)
+{
+ EmbeddedFile ef(file, inzipName, embed, buf);
+ registerFile(ef, inset, buf);
+}
+
+
void EmbeddedFileList::registerFile(EmbeddedFile const & file,
Inset const * inset, Buffer const & buffer)
{
BOOST_ASSERT(!buffer.embedded() || file.enabled());
- // try to find this file from the list
- std::vector<EmbeddedFile>::iterator it = begin();
- std::vector<EmbeddedFile>::iterator it_end = end();
- for (; it != it_end; ++it)
- if (it->absFilename() == file.absFilename()) {
- if (it->embedded() != file.embedded()) {
+ string newfile = file.absFilename();
+ EmbeddedFile * efp = findFile(newfile);
+ if (efp) {
+ if (efp->embedded() != file.embedded()) {
Alert::error(_("Wrong embedding status."),
bformat(_("File %1$s is included in more than one insets, "
"but with different embedding status. Assuming embedding status."),
- from_utf8(it->outputFilename())));
- it->setEmbed(true);
+ from_utf8(efp->outputFilename())));
+ efp->setEmbed(true);
// update the inset with this embedding status.
- const_cast<Inset*>(inset)->updateEmbeddedFile(*it);
+ const_cast<Inset*>(inset)->updateEmbeddedFile(*efp);
}
- it->addInset(inset);
+ efp->addInset(inset);
return;
}
//
file.clearInsets();
push_back(file);
back().addInset(inset);
+ return;
}
+EmbeddedFile const * EmbeddedFileList::findFile(std::string const & filename) const
+{
+ // try to find this file from the list
+ std::vector<EmbeddedFile>::const_iterator it = begin();
+ std::vector<EmbeddedFile>::const_iterator it_end = end();
+ for (; it != it_end; ++it)
+ if (it->absFilename() == filename)
+ return &*it;
+ return 0;
+}
+
+
+EmbeddedFile * EmbeddedFileList::findFile(std::string const & filename)
+{
+ // try to find this file from the list
+ std::vector<EmbeddedFile>::iterator it = begin();
+ std::vector<EmbeddedFile>::iterator it_end = end();
+ for (; it != it_end; ++it)
+ if (it->absFilename() == filename)
+ return &*it;
+ return 0;
+}
+
+
void EmbeddedFileList::validate(Buffer const & buffer)
{
clear();
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 24016)
+++ src/Buffer.cpp (working copy)
@@ -1405,7 +1405,7 @@
if (it->lyxCode() == BIBTEX_CODE) {
InsetBibtex const & inset =
static_cast<InsetBibtex const &>(*it);
- EmbeddedFileList const bibfiles = inset.embeddedFiles();
+ EmbeddedFileList const & bibfiles = inset.getBibFiles();
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(),
bibfiles.end());
Index: src/frontends/qt4/GuiBibtex.cpp
===================================================================
--- src/frontends/qt4/GuiBibtex.cpp (revision 24016)
+++ src/frontends/qt4/GuiBibtex.cpp (working copy)
@@ -27,6 +27,8 @@
#include "frontends/alert.h"
+#include "insets/InsetBibtex.h"
+
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/FileFilterList.h"
@@ -367,20 +369,14 @@
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
+ QString bibfile = databaseLW->item(i)->text();
+ docstring bibfiled = qstring_to_ucs4(bibfile);
+ dbs += bibfiled;
+ if (databaseLW->item(i)->checkState() == Qt::Checked) {
+ FileName bibfilepath = InsetBibtex::getBibTeXPath(bibfiled, buf);
+ string inzipName =
+ EmbeddedFile::calcInzipName(bibfilepath.absFilename(), buf.filePath());
+ emb += from_utf8(inzipName);
}
}
Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp (revision 24016)
+++ src/BufferView.cpp (working copy)
@@ -1248,7 +1248,7 @@
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
BIBTEX_CODE);
if (inset) {
- if (inset->addDatabase(to_utf8(cmd.argument())))
+ if (inset->addDatabase(cmd.argument()))
buffer_.updateBibfilesCache();
}
break;
@@ -1260,7 +1260,7 @@
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
BIBTEX_CODE);
if (inset) {
- if (inset->delDatabase(to_utf8(cmd.argument())))
+ if (inset->delDatabase(cmd.argument()))
buffer_.updateBibfilesCache();
}
break;
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp (revision 24016)
+++ src/insets/InsetInclude.cpp (working copy)
@@ -227,7 +227,6 @@
// failed to embed
setParam("embed", docstring());
}
-
}
InsetCommand::setBuffer(buffer);
if (label_)
@@ -279,7 +278,6 @@
}
}
setParams(p);
- buffer().updateBibfilesCache();
} else
cur.noUpdate();
break;
@@ -303,6 +301,8 @@
if (type(params()) == INPUT)
add_preview(*preview_, *this, buffer());
+
+ buffer().updateBibfilesCache();
}
@@ -727,7 +727,7 @@
EmbeddedFileList const &
-InsetInclude::getBibfilesCache(Buffer const & buffer) const
+ InsetInclude::getBibfilesCache(Buffer const & buffer) const
{
Buffer * const tmp = getChildBuffer(buffer, params());
if (tmp) {
@@ -946,7 +946,8 @@
void InsetInclude::updateEmbeddedFile(EmbeddedFile const & file)
{
- setParam("filename", from_utf8(file.outputFilename(buffer().filePath())));
+ // FIXME I don't think we either should or need to do this.
+ // setParam("filename", from_utf8(file.outputFilename(buffer().filePath())));
setParam("embed", file.embedded() ? from_utf8(file.inzipName()) : docstring());
}
Index: src/insets/InsetInclude.h
===================================================================
--- src/insets/InsetInclude.h (revision 24016)
+++ src/insets/InsetInclude.h (working copy)
@@ -68,8 +68,7 @@
* Return an empty vector if the child doc is not loaded.
* \param buffer the Buffer containing this inset.
*/
- EmbeddedFileList const &
- getBibfilesCache(Buffer const & buffer) const;
+ EmbeddedFileList const & getBibfilesCache(Buffer const & buffer) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
///