diff --git a/src/ChangeLog b/src/ChangeLog index 1673d16b59..a9c5ca7e6a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2003-10-22 Angus Leeming + + * 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 * text.C: fixed an "oops" in the "is a bit silly" diff --git a/src/buffer.C b/src/buffer.C index d3c34619e5..5fa6624778 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -186,13 +186,19 @@ struct Buffer::Impl string filepath; boost::scoped_ptr 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; } diff --git a/src/buffer.h b/src/buffer.h index ff15795ee4..2128f4db75 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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. diff --git a/src/factory.C b/src/factory.C index ca58000af5..4ca4404d89 100644 --- a/src/factory.C +++ b/src/factory.C @@ -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); diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 51c3cac5d1..f035f32508 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,8 @@ +2003-10-22 Angus Leeming + + * PreviewLoader.C (startLoading): do nothing if the buffer is not yet + loaded. + 2003-10-13 Angus Leeming * GraphicsTypes.[Ch] (setDisplayTranslator): removed. diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 5f541b4467..370b0fd154 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -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)); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 85b0fe096e..630b9a8091 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2003-10-22 Angus Leeming + + * 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 * render_graphic.[Ch] (statusMessage, readyToDisplay): move out of the diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index e696dd2f39..596f29ee31 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -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 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 CachedMap; static CachedMap cached_keys; - // Only load the bibkeys once if we're loading up the buffer, - // else load them afresh each time. - map::iterator lit = loading_buffer.find(&buffer); - if (lit == loading_buffer.end()) - loading_buffer[&buffer] = true; + // build the keylist + typedef vector > 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 > 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; diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 95dbf024b2..925b223db2 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -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