/// A cache for the bibfiles (including bibfiles of loaded child
/// documents), needed for appropriate update of natbib labels.
- mutable FileNamePairList bibfiles_cache_;
+ mutable docstring_list bibfiles_cache_;
// FIXME The caching mechanism could be improved. At present, we have a
// cache for each Buffer, that caches all the bibliography info for that
}
-Buffer * Buffer::cloneFromMaster() const
+Buffer * Buffer::cloneWithChildren() const
{
BufferMap bufmap;
cloned_buffers.push_back(new CloneList);
CloneList * clones = cloned_buffers.back();
- masterBuffer()->cloneWithChildren(bufmap, clones);
+ cloneWithChildren(bufmap, clones);
// make sure we got cloned
BufferMap::const_iterator bit = bufmap.find(this);
<< absFileName()
<< ") does not include "
"this document. Ignoring the master assignment.");
+ // If the master has just been created, un-hide it (#11162)
+ if (!master->fileName().exists())
+ lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
+ master->absFileName()));
}
}
}
"file path name."),
inputpath, uncodable_glyphs));
} else {
- string docdir =
- latex_path(original_path);
+ string docdir = os::latex_path(original_path);
if (contains(docdir, '#')) {
docdir = subst(docdir, "#", "\\#");
os << "\\catcode`\\#=11"
os << "\\catcode`\\%=11"
"\\def\\%{%}\\catcode`\\%=14\n";
}
+ bool const detokenize = !isAscii(from_utf8(docdir));
+ bool const quote = contains(docdir, ' ');
os << "\\makeatletter\n"
- << "\\def\\input@path{{"
- << docdir << "}}\n"
+ << "\\def\\input@path{{";
+ if (detokenize)
+ os << "\\detokenize{";
+ if (quote)
+ os << "\"";
+ os << docdir;
+ if (quote)
+ os << "\"";
+ if (detokenize)
+ os << "}";
+ os << "}}\n"
<< "\\makeatother\n";
}
}
}
-FileNamePairList const & Buffer::getBibfiles(UpdateScope scope) const
+docstring_list const & Buffer::getBibfiles(UpdateScope scope) const
{
// FIXME This is probably unnecessary, given where we call this.
// If this is a child document, use the master instead.
}
-void Buffer::registerBibfiles(FileNamePairList const & bf) const {
+void Buffer::registerBibfiles(const docstring_list & bf) const
+{
// We register the bib files in the master buffer,
// if there is one, but also in every single buffer,
// in case a child is compiled alone.
tmp->registerBibfiles(bf);
for (auto const & p : bf) {
- FileNamePairList::const_iterator temp =
+ docstring_list::const_iterator temp =
find(d->bibfiles_cache_.begin(), d->bibfiles_cache_.end(), p);
if (temp == d->bibfiles_cache_.end())
d->bibfiles_cache_.push_back(p);
}
+static map<docstring, FileName> bibfileCache;
+
+FileName Buffer::getBibfilePath(docstring const & bibid) const
+{
+ map<docstring, FileName>::const_iterator it =
+ bibfileCache.find(bibid);
+ if (it != bibfileCache.end()) {
+ // i.e., bibfileCache[bibid]
+ return it->second;
+ }
+
+ LYXERR(Debug::FILES, "Reading file location for " << bibid);
+ string texfile = changeExtension(to_utf8(bibid), "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, filePath()));
+ LYXERR(Debug::FILES, "Found at: " << file);
+
+ bibfileCache[bibid] = file;
+ return bibfileCache[bibid];
+}
+
+
void Buffer::checkIfBibInfoCacheIsValid() const
{
// use the master's cache
return;
// compare the cached timestamps with the actual ones.
- FileNamePairList const & bibfiles_cache = getBibfiles();
- FileNamePairList::const_iterator ei = bibfiles_cache.begin();
- FileNamePairList::const_iterator en = bibfiles_cache.end();
- for (; ei != en; ++ ei) {
- FileName const fn = ei->second;
+ docstring_list const & bibfiles_cache = getBibfiles();
+ for (auto const & bf : bibfiles_cache) {
+ FileName const fn = getBibfilePath(bf);
time_t lastw = fn.lastModified();
time_t prevw = d->bibfile_status_[fn];
if (lastw != prevw) {
}
-void Buffer::reloadBibInfoCache() const
+void Buffer::clearBibFileCache() const
+{
+ bibfileCache.clear();
+}
+
+
+void Buffer::reloadBibInfoCache(bool const force) const
{
// use the master's cache
Buffer const * const tmp = masterBuffer();
if (tmp != this) {
- tmp->reloadBibInfoCache();
+ tmp->reloadBibInfoCache(force);
return;
}
- checkIfBibInfoCacheIsValid();
- if (d->bibinfo_cache_valid_)
- return;
+ if (!force) {
+ checkIfBibInfoCacheIsValid();
+ if (d->bibinfo_cache_valid_)
+ return;
+ }
+ // re-read file locations when this info changes
+ // FIXME Is this sufficient? Or should we also force that
+ // in some other cases? If so, then it is easy enough to
+ // add the following line in some other places.
+ clearBibFileCache();
d->bibinfo_.clear();
FileNameList checkedFiles;
collectBibKeys(checkedFiles);
bi[key] = bin;
if (parent() != 0) {
- BiblioInfo & masterbi = parent()->d->bibinfo_;
+ BiblioInfo & masterbi = masterBuffer()->d->bibinfo_;
masterbi[key] = bin;
}
}
vector<docstring> const Buffer::prepareBibFilePaths(OutputParams const & runparams,
- FileNamePairList const bibfilelist,
+ docstring_list const & bibfilelist,
bool const add_extension) const
{
// If we are processing the LaTeX file in a temp directory then
bool found_space = false;
for (auto const & bit : bibfilelist) {
- string utf8input = to_utf8(bit.first);
+ string utf8input = to_utf8(bit);
string database =
prepareFileNameForLaTeX(utf8input, ".bib", runparams.nice);
FileName try_in_file =
// If the file has not been found, try with the real file name
// (it might come from a child in a sub-directory)
if (!not_from_texmf) {
- try_in_file = bit.second;
+ try_in_file = getBibfilePath(bit);
if (try_in_file.isReadableFile()) {
// Check if the file is in texmf
FileName kpsefile(findtexfile(changeExtension(utf8input, "bib"), "bib", true));
Buffer const * const master = masterBuffer();
DocumentClass const & textclass = master->params().documentClass();
- FileNamePairList old_bibfiles;
+ docstring_list old_bibfiles;
// Do this only if we are the top-level Buffer. We also need to account
// for the case of a previewed child with ignored parent here.
if (master == this && !d->ignore_parent) {
return;
// if the bibfiles changed, the cache of bibinfo is invalid
- FileNamePairList new_bibfiles = d->bibfiles_cache_;
+ docstring_list new_bibfiles = d->bibfiles_cache_;
// this is a trick to determine whether the two vectors have
// the same elements.
sort(new_bibfiles.begin(), new_bibfiles.end());