Pump a generator when reading out citations from document to keep UI responsive
This commit is contained in:
parent
49380e39ac
commit
251da6ce50
1 changed files with 77 additions and 66 deletions
|
@ -1010,16 +1010,18 @@ Zotero.Integration.Fields.prototype.updateSession = function(callback) {
|
||||||
if(me._session.reload) {
|
if(me._session.reload) {
|
||||||
//this._session.restoreProcessorState(); TODO doesn't appear to be working properly
|
//this._session.restoreProcessorState(); TODO doesn't appear to be working properly
|
||||||
me._session.updateUpdateIndices();
|
me._session.updateUpdateIndices();
|
||||||
var deleteCitations = me._session.updateCitations();
|
Zotero.pumpGenerator(me._session.updateCitations(function(deleteCitations) {
|
||||||
me._deleteFields = me._deleteFields.concat([i for(i in deleteCitations)]);
|
me._deleteFields = me._deleteFields.concat([i for(i in deleteCitations)]);
|
||||||
me._session.updateIndices = {};
|
me._session.updateIndices = {};
|
||||||
me._session.updateItemIDs = {};
|
me._session.updateItemIDs = {};
|
||||||
me._session.citationText = {};
|
me._session.citationText = {};
|
||||||
me._session.bibliographyHasChanged = false;
|
me._session.bibliographyHasChanged = false;
|
||||||
delete me._session.reload;
|
delete me._session.reload;
|
||||||
|
if(callback) callback(me._session);
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
if(callback) callback(this._session);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(callback) callback(this._session);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1109,7 +1111,13 @@ Zotero.Integration.Fields.prototype._processFields = function(fields, callback,
|
||||||
*/
|
*/
|
||||||
Zotero.Integration.Fields.prototype.updateDocument = function(forceCitations, forceBibliography,
|
Zotero.Integration.Fields.prototype.updateDocument = function(forceCitations, forceBibliography,
|
||||||
ignoreCitationChanges, callback) {
|
ignoreCitationChanges, callback) {
|
||||||
Zotero.pumpGenerator(this._updateDocument(forceCitations, forceBibliography, ignoreCitationChanges, callback));
|
// update citations
|
||||||
|
this._session.updateUpdateIndices(forceCitations);
|
||||||
|
var me = this;
|
||||||
|
var deleteCitations = Zotero.pumpGenerator(this._session.updateCitations(function(deleteCitations) {
|
||||||
|
Zotero.pumpGenerator(me._updateDocument(forceCitations, forceBibliography,
|
||||||
|
ignoreCitationChanges, deleteCitations, callback));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1120,11 +1128,9 @@ Zotero.Integration.Fields.prototype.updateDocument = function(forceCitations, fo
|
||||||
* modified since they were created, instead of showing a warning
|
* modified since they were created, instead of showing a warning
|
||||||
*/
|
*/
|
||||||
Zotero.Integration.Fields.prototype._updateDocument = function(forceCitations, forceBibliography,
|
Zotero.Integration.Fields.prototype._updateDocument = function(forceCitations, forceBibliography,
|
||||||
ignoreCitationChanges, callback) {
|
ignoreCitationChanges, deleteCitations, callback) {
|
||||||
try {
|
try {
|
||||||
// update citations
|
// update citations
|
||||||
this._session.updateUpdateIndices(forceCitations);
|
|
||||||
var deleteCitations = this._session.updateCitations();
|
|
||||||
this._deleteFields = this._deleteFields.concat([i for(i in deleteCitations)]);
|
this._deleteFields = this._deleteFields.concat([i for(i in deleteCitations)]);
|
||||||
|
|
||||||
if(this.progressCallback) {
|
if(this.progressCallback) {
|
||||||
|
@ -2159,64 +2165,69 @@ Zotero.Integration.Session.prototype.formatCitation = function(index, citation)
|
||||||
/**
|
/**
|
||||||
* Updates the list of citations to be serialized to the document
|
* Updates the list of citations to be serialized to the document
|
||||||
*/
|
*/
|
||||||
Zotero.Integration.Session.prototype.updateCitations = function() {
|
Zotero.Integration.Session.prototype.updateCitations = function(callback) {
|
||||||
/*var allUpdatesForced = false;
|
try {
|
||||||
var forcedUpdates = {};
|
/*var allUpdatesForced = false;
|
||||||
if(force) {
|
var forcedUpdates = {};
|
||||||
allUpdatesForced = true;
|
if(force) {
|
||||||
// make sure at least one citation gets updated
|
allUpdatesForced = true;
|
||||||
updateLoop: for each(var indexList in [this.newIndices, this.updateIndices]) {
|
// make sure at least one citation gets updated
|
||||||
for(var i in indexList) {
|
updateLoop: for each(var indexList in [this.newIndices, this.updateIndices]) {
|
||||||
if(!this.citationsByIndex[i].properties.delete) {
|
for(var i in indexList) {
|
||||||
allUpdatesForced = false;
|
if(!this.citationsByIndex[i].properties.delete) {
|
||||||
break updateLoop;
|
allUpdatesForced = false;
|
||||||
|
break updateLoop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(allUpdatesForced) {
|
||||||
|
for(i in this.citationsByIndex) {
|
||||||
|
if(this.citationsByIndex[i] && !this.citationsByIndex[i].properties.delete) {
|
||||||
|
forcedUpdates[i] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if(Zotero.Debug.enabled) {
|
||||||
|
Zotero.debug("Integration: Indices of new citations");
|
||||||
|
Zotero.debug([key for(key in this.newIndices)]);
|
||||||
|
Zotero.debug("Integration: Indices of updated citations");
|
||||||
|
Zotero.debug([key for(key in this.updateIndices)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var deleteCitations = {};
|
||||||
|
for each(var indexList in [this.newIndices, this.updateIndices]) {
|
||||||
|
for(var index in indexList) {
|
||||||
|
index = parseInt(index);
|
||||||
|
|
||||||
|
var citation = this.citationsByIndex[index];
|
||||||
|
if(citation.properties.delete) {
|
||||||
|
deleteCitations[index] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(this.formatCitation(index, citation)) {
|
||||||
|
this.bibliographyHasChanged = true;
|
||||||
|
}
|
||||||
|
if(!this.citationIDs[citation.citationID]) {
|
||||||
|
this.citationIDs[citation.citationID] = citation;
|
||||||
|
}
|
||||||
|
delete this.newIndices[index];
|
||||||
|
yield true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(allUpdatesForced) {
|
/*if(allUpdatesForced) {
|
||||||
for(i in this.citationsByIndex) {
|
this.newIndices = {};
|
||||||
if(this.citationsByIndex[i] && !this.citationsByIndex[i].properties.delete) {
|
this.updateIndices = {};
|
||||||
forcedUpdates[i] = true;
|
}*/
|
||||||
break;
|
|
||||||
}
|
callback(deleteCitations);
|
||||||
}
|
} catch(e) {
|
||||||
}
|
Zotero.Integration.handleError(e, this._doc);
|
||||||
}*/
|
|
||||||
|
|
||||||
if(Zotero.Debug.enabled) {
|
|
||||||
Zotero.debug("Integration: Indices of new citations");
|
|
||||||
Zotero.debug([key for(key in this.newIndices)]);
|
|
||||||
Zotero.debug("Integration: Indices of updated citations");
|
|
||||||
Zotero.debug([key for(key in this.updateIndices)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var deleteCitations = {};
|
|
||||||
for each(var indexList in [this.newIndices, this.updateIndices]) {
|
|
||||||
for(var index in indexList) {
|
|
||||||
index = parseInt(index);
|
|
||||||
|
|
||||||
var citation = this.citationsByIndex[index];
|
|
||||||
if(citation.properties.delete) {
|
|
||||||
deleteCitations[index] = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(this.formatCitation(index, citation)) {
|
|
||||||
this.bibliographyHasChanged = true;
|
|
||||||
}
|
|
||||||
if(!this.citationIDs[citation.citationID]) {
|
|
||||||
this.citationIDs[citation.citationID] = citation;
|
|
||||||
}
|
|
||||||
delete this.newIndices[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if(allUpdatesForced) {
|
|
||||||
this.newIndices = {};
|
|
||||||
this.updateIndices = {};
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return deleteCitations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue