mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
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:
parent
cf536b5db7
commit
78046794cc
@ -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>
|
2003-10-22 Martin Vermeer <martin.vermeer@hut.fi>
|
||||||
|
|
||||||
* text.C: fixed an "oops" in the "is a bit silly"
|
* text.C: fixed an "oops" in the "is a bit silly"
|
||||||
|
15
src/buffer.C
15
src/buffer.C
@ -186,13 +186,19 @@ struct Buffer::Impl
|
|||||||
string filepath;
|
string filepath;
|
||||||
|
|
||||||
boost::scoped_ptr<Messages> messages;
|
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_)
|
Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
|
||||||
: nicefile(true),
|
: nicefile(true),
|
||||||
lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
|
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);
|
lyxvc.buffer(&parent);
|
||||||
if (readonly_ || lyxrc.use_tempdir)
|
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,
|
bool Buffer::readFile(LyXLex & lex, string const & filename,
|
||||||
ParagraphList::iterator pit)
|
ParagraphList::iterator pit)
|
||||||
{
|
{
|
||||||
@ -697,6 +709,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
|
|||||||
" that it is probably corrupted."),
|
" that it is probably corrupted."),
|
||||||
filename));
|
filename));
|
||||||
}
|
}
|
||||||
|
pimpl_->file_fully_loaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +367,12 @@ public:
|
|||||||
///
|
///
|
||||||
InsetOld * getInsetFromID(int id_arg) const;
|
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:
|
private:
|
||||||
/** Inserts a file into a document
|
/** Inserts a file into a document
|
||||||
\param par if != 0 insert the file.
|
\param par if != 0 insert the file.
|
||||||
|
@ -212,9 +212,7 @@ InsetOld * createInset(FuncRequest const & cmd)
|
|||||||
} else if (name == "citation") {
|
} else if (name == "citation") {
|
||||||
InsetCommandParams icp;
|
InsetCommandParams icp;
|
||||||
InsetCommandMailer::string2params(cmd.argument, icp);
|
InsetCommandMailer::string2params(cmd.argument, icp);
|
||||||
InsetCitation * inset = new InsetCitation(icp);
|
return new InsetCitation(icp);
|
||||||
inset->setLoadingBuffer(*bv->buffer(), false);
|
|
||||||
return inset;
|
|
||||||
|
|
||||||
} else if (name == "ert") {
|
} else if (name == "ert") {
|
||||||
InsetERT * inset = new InsetERT(params);
|
InsetERT * inset = new InsetERT(params);
|
||||||
|
@ -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>
|
2003-10-13 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* GraphicsTypes.[Ch] (setDisplayTranslator): removed.
|
* GraphicsTypes.[Ch] (setDisplayTranslator): removed.
|
||||||
|
@ -450,12 +450,15 @@ void PreviewLoader::Impl::startLoading()
|
|||||||
if (pending_.empty() || !pconverter_)
|
if (pending_.empty() || !pconverter_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Only start the process off after the buffer is loaded from file.
|
||||||
|
if (!buffer_.fully_loaded())
|
||||||
|
return;
|
||||||
|
|
||||||
lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl;
|
lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl;
|
||||||
|
|
||||||
// As used by the LaTeX file and by the resulting image files
|
// As used by the LaTeX file and by the resulting image files
|
||||||
string directory = buffer_.temppath();
|
string const directory = buffer_.temppath().empty() ?
|
||||||
if (directory.empty())
|
buffer_.filePath() : buffer_.temppath();
|
||||||
directory = buffer_.filePath();
|
|
||||||
|
|
||||||
string const filename_base(unique_filename(directory));
|
string const filename_base(unique_filename(directory));
|
||||||
|
|
||||||
|
@ -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>
|
2003-10-22 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* render_graphic.[Ch] (statusMessage, readyToDisplay): move out of the
|
* render_graphic.[Ch] (statusMessage, readyToDisplay): move out of the
|
||||||
|
@ -38,51 +38,34 @@ using std::map;
|
|||||||
|
|
||||||
namespace {
|
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 getNatbibLabel(Buffer const & buffer,
|
||||||
string const & citeType, string const & keyList,
|
string const & citeType, string const & keyList,
|
||||||
string const & before, string const & after,
|
string const & before, string const & after,
|
||||||
bool numerical)
|
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;
|
typedef std::map<Buffer const *, biblio::InfoMap> CachedMap;
|
||||||
static CachedMap cached_keys;
|
static CachedMap cached_keys;
|
||||||
|
|
||||||
// Only load the bibkeys once if we're loading up the buffer,
|
// build the keylist
|
||||||
// else load them afresh each time.
|
typedef vector<std::pair<string, string> > InfoType;
|
||||||
map<Buffer const *, bool>::iterator lit = loading_buffer.find(&buffer);
|
InfoType bibkeys;
|
||||||
if (lit == loading_buffer.end())
|
buffer.fillWithBibKeys(bibkeys);
|
||||||
loading_buffer[&buffer] = true;
|
|
||||||
|
|
||||||
bool loadkeys = !loading_buffer[&buffer];
|
InfoType::const_iterator bit = bibkeys.begin();
|
||||||
if (!loadkeys) {
|
InfoType::const_iterator bend = bibkeys.end();
|
||||||
CachedMap::iterator kit = cached_keys.find(&buffer);
|
|
||||||
loadkeys = kit == cached_keys.end();
|
biblio::InfoMap infomap;
|
||||||
|
for (; bit != bend; ++bit) {
|
||||||
|
infomap[bit->first] = bit->second;
|
||||||
}
|
}
|
||||||
|
if (infomap.empty())
|
||||||
|
return string();
|
||||||
|
|
||||||
if (loadkeys) {
|
cached_keys[&buffer] = infomap;
|
||||||
// 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];
|
|
||||||
|
|
||||||
// the natbib citation-styles
|
// the natbib citation-styles
|
||||||
// CITET: author (year)
|
// 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
|
dispatch_result
|
||||||
InsetCitation::priv_dispatch(FuncRequest const & cmd,
|
InsetCitation::priv_dispatch(FuncRequest const & cmd,
|
||||||
idx_type & idx, pos_type & pos)
|
idx_type & idx, pos_type & pos)
|
||||||
{
|
{
|
||||||
switch (cmd.action) {
|
switch (cmd.action) {
|
||||||
case LFUN_INSET_EDIT:
|
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());
|
InsetCommandMailer("citation", *this).showDialog(cmd.view());
|
||||||
return DISPATCHED;
|
return DISPATCHED;
|
||||||
|
|
||||||
|
@ -43,11 +43,6 @@ public:
|
|||||||
dispatch_result localDispatch(FuncRequest const & cmd);
|
dispatch_result localDispatch(FuncRequest const & cmd);
|
||||||
///
|
///
|
||||||
void validate(LaTeXFeatures &) const;
|
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:
|
protected:
|
||||||
///
|
///
|
||||||
virtual
|
virtual
|
||||||
|
Loading…
Reference in New Issue
Block a user