Add a Buffer::fully_loaded member function, returning true only when

the file has been loaded fully. Used to prevent the premature generation
of previews and by the citation inset to prevent computation of
the natbib-style label.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7953 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-10-22 13:15:18 +00:00
parent cf536b5db7
commit 78046794cc
9 changed files with 66 additions and 56 deletions

View File

@ -1,3 +1,12 @@
2003-10-22 Angus Leeming <leeming@lyx.org>
* buffer.[Ch] (fully_loaded): new member function, returning true
only when the file has been loaded fully.
Used to prevent the premature generation of previews and by the
citation inset to prevent computation of the natbib-style label.
* factory.C (createInset): remove call to InsetCitation::setLoadingBuffer.
2003-10-22 Martin Vermeer <martin.vermeer@hut.fi>
* text.C: fixed an "oops" in the "is a bit silly"

View File

@ -186,13 +186,19 @@ struct Buffer::Impl
string filepath;
boost::scoped_ptr<Messages> messages;
/** set to true only when the file is fully loaded.
* Used to prevent the premature generation of previews
* and by the citation inset.
*/
bool file_fully_loaded;
};
Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
: nicefile(true),
lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
filename(file), filepath(OnlyPath(file))
filename(file), filepath(OnlyPath(file)), file_fully_loaded(false)
{
lyxvc.buffer(&parent);
if (readonly_ || lyxrc.use_tempdir)
@ -606,6 +612,12 @@ bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
}
bool Buffer::fully_loaded() const
{
return pimpl_->file_fully_loaded;
}
bool Buffer::readFile(LyXLex & lex, string const & filename,
ParagraphList::iterator pit)
{
@ -697,6 +709,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
" that it is probably corrupted."),
filename));
}
pimpl_->file_fully_loaded = true;
return true;
}

View File

@ -367,6 +367,12 @@ public:
///
InsetOld * getInsetFromID(int id_arg) const;
/** \returns true only when the file is fully loaded.
* Used to prevent the premature generation of previews
* and by the citation inset.
*/
bool fully_loaded() const;
private:
/** Inserts a file into a document
\param par if != 0 insert the file.

View File

@ -212,9 +212,7 @@ InsetOld * createInset(FuncRequest const & cmd)
} else if (name == "citation") {
InsetCommandParams icp;
InsetCommandMailer::string2params(cmd.argument, icp);
InsetCitation * inset = new InsetCitation(icp);
inset->setLoadingBuffer(*bv->buffer(), false);
return inset;
return new InsetCitation(icp);
} else if (name == "ert") {
InsetERT * inset = new InsetERT(params);

View File

@ -1,3 +1,8 @@
2003-10-22 Angus Leeming <leeming@lyx.org>
* PreviewLoader.C (startLoading): do nothing if the buffer is not yet
loaded.
2003-10-13 Angus Leeming <leeming@lyx.org>
* GraphicsTypes.[Ch] (setDisplayTranslator): removed.

View File

@ -450,12 +450,15 @@ void PreviewLoader::Impl::startLoading()
if (pending_.empty() || !pconverter_)
return;
// Only start the process off after the buffer is loaded from file.
if (!buffer_.fully_loaded())
return;
lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl;
// As used by the LaTeX file and by the resulting image files
string directory = buffer_.temppath();
if (directory.empty())
directory = buffer_.filePath();
string const directory = buffer_.temppath().empty() ?
buffer_.filePath() : buffer_.temppath();
string const filename_base(unique_filename(directory));

View File

@ -1,3 +1,11 @@
2003-10-22 Angus Leeming <leeming@lyx.org>
* insetcite.[Ch] (setLoadingBuffer): removed.
(getNatbibLabel): use the new Buffer::fully_loaded member function to
ascertain whether to proceed with the (expensive) task of computing
the natbib-style label. Remove the home-grown hack providing
similar functionality.
2003-10-22 Angus Leeming <leeming@lyx.org>
* render_graphic.[Ch] (statusMessage, readyToDisplay): move out of the

View File

@ -38,51 +38,34 @@ using std::map;
namespace {
// An optimisation. We assume that until the first InsetCitation::edit is
// called, we're loading the buffer and that, therefore, we don't need to
// reload the bibkey list
std::map<Buffer const *, bool> loading_buffer;
string const getNatbibLabel(Buffer const & buffer,
string const & citeType, string const & keyList,
string const & before, string const & after,
bool numerical)
{
// Only start the process off after the buffer is loaded from file.
if (!buffer.fully_loaded())
return string();
typedef std::map<Buffer const *, biblio::InfoMap> CachedMap;
static CachedMap cached_keys;
// Only load the bibkeys once if we're loading up the buffer,
// else load them afresh each time.
map<Buffer const *, bool>::iterator lit = loading_buffer.find(&buffer);
if (lit == loading_buffer.end())
loading_buffer[&buffer] = true;
// build the keylist
typedef vector<std::pair<string, string> > InfoType;
InfoType bibkeys;
buffer.fillWithBibKeys(bibkeys);
bool loadkeys = !loading_buffer[&buffer];
if (!loadkeys) {
CachedMap::iterator kit = cached_keys.find(&buffer);
loadkeys = kit == cached_keys.end();
InfoType::const_iterator bit = bibkeys.begin();
InfoType::const_iterator bend = bibkeys.end();
biblio::InfoMap infomap;
for (; bit != bend; ++bit) {
infomap[bit->first] = bit->second;
}
if (infomap.empty())
return string();
if (loadkeys) {
// build the keylist
typedef vector<std::pair<string, string> > InfoType;
InfoType bibkeys;
buffer.fillWithBibKeys(bibkeys);
InfoType::const_iterator bit = bibkeys.begin();
InfoType::const_iterator bend = bibkeys.end();
biblio::InfoMap infomap;
for (; bit != bend; ++bit) {
infomap[bit->first] = bit->second;
}
if (infomap.empty())
return string();
cached_keys[&buffer] = infomap;
}
biblio::InfoMap infomap = cached_keys[&buffer];
cached_keys[&buffer] = infomap;
// the natbib citation-styles
// CITET: author (year)
@ -325,22 +308,12 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const
}
void InsetCitation::setLoadingBuffer(Buffer const & buffer, bool state) const
{
// Doesn't matter if there is no bv->buffer() entry in the map.
loading_buffer[&buffer] = state;
}
dispatch_result
InsetCitation::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
// A call to edit indicates that we're no longer loading the
// buffer but doing some real work.
setLoadingBuffer(*cmd.view()->buffer(), false);
InsetCommandMailer("citation", *this).showDialog(cmd.view());
return DISPATCHED;

View File

@ -43,11 +43,6 @@ public:
dispatch_result localDispatch(FuncRequest const & cmd);
///
void validate(LaTeXFeatures &) const;
/** Invoked by BufferView::Pimpl::dispatch when a new citation key
is inserted. Tells us that the buffer is no longer being loaded
and that the cache of BibTeX keys should be reloaded in the future.
*/
void setLoadingBuffer(Buffer const & buffer, bool state) const;
protected:
///
virtual