Fix inproper cleanup of legacy API word processor plugins
This commit is contained in:
parent
b8e0c3f7e4
commit
5b595122b7
|
@ -238,7 +238,8 @@ Zotero.Integration = new function() {
|
||||||
Zotero.debug('Synchronous integration plugin functions are deprecated -- ' +
|
Zotero.debug('Synchronous integration plugin functions are deprecated -- ' +
|
||||||
'update to asynchronous methods');
|
'update to asynchronous methods');
|
||||||
application = Zotero.Integration.LegacyPluginWrapper(application);
|
application = Zotero.Integration.LegacyPluginWrapper(application);
|
||||||
documentPromise = (application.getDocument && docId ? application.getDocument(docId) : application.getActiveDocument());
|
documentPromise = new Zotero.Promise(resolve =>
|
||||||
|
resolve(Zotero.Integration.LegacyPluginWrapper.wrapDocument(documentPromise)));
|
||||||
}
|
}
|
||||||
Zotero.Integration.currentDoc = document = await documentPromise;
|
Zotero.Integration.currentDoc = document = await documentPromise;
|
||||||
|
|
||||||
|
@ -2823,7 +2824,24 @@ Zotero.Integration.Progress = class {
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Integration.LegacyPluginWrapper = function(application) {
|
Zotero.Integration.LegacyPluginWrapper = function(application) {
|
||||||
function wrapField(field) {
|
return {
|
||||||
|
getDocument:
|
||||||
|
async function() {
|
||||||
|
return Zotero.Integration.LegacyPluginWrapper.wrapDocument(
|
||||||
|
application.getDocument.apply(application, arguments))
|
||||||
|
},
|
||||||
|
getActiveDocument:
|
||||||
|
async function() {
|
||||||
|
return Zotero.Integration.LegacyPluginWrapper.wrapDocument(
|
||||||
|
application.getActiveDocument.apply(application, arguments))
|
||||||
|
},
|
||||||
|
primaryFieldType: application.primaryFieldType,
|
||||||
|
secondaryFieldType: application.secondaryFieldType,
|
||||||
|
outputFormat: 'rtf',
|
||||||
|
supportedNotes: ['footnotes', 'endnotes']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Zotero.Integration.LegacyPluginWrapper.wrapField = function (field) {
|
||||||
var wrapped = {rawField: field};
|
var wrapped = {rawField: field};
|
||||||
var fns = ['getNoteIndex', 'setCode', 'getCode', 'setText',
|
var fns = ['getNoteIndex', 'setCode', 'getCode', 'setText',
|
||||||
'getText', 'removeCode', 'delete', 'select'];
|
'getText', 'removeCode', 'delete', 'select'];
|
||||||
|
@ -2837,7 +2855,7 @@ Zotero.Integration.LegacyPluginWrapper = function(application) {
|
||||||
}
|
}
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
function wrapDocument(doc) {
|
Zotero.Integration.LegacyPluginWrapper.wrapDocument = function wrapDocument(doc) {
|
||||||
var wrapped = {};
|
var wrapped = {};
|
||||||
var fns = ['complete', 'cleanup', 'setBibliographyStyle', 'setDocumentData',
|
var fns = ['complete', 'cleanup', 'setBibliographyStyle', 'setDocumentData',
|
||||||
'getDocumentData', 'canInsertField', 'activate', 'displayAlert'];
|
'getDocumentData', 'canInsertField', 'activate', 'displayAlert'];
|
||||||
|
@ -2871,9 +2889,10 @@ Zotero.Integration.LegacyPluginWrapper = function(application) {
|
||||||
while (fieldsEnumerator.hasMoreElements()) {
|
while (fieldsEnumerator.hasMoreElements()) {
|
||||||
let field = fieldsEnumerator.getNext();
|
let field = fieldsEnumerator.getNext();
|
||||||
try {
|
try {
|
||||||
fields.push(wrapField(field.QueryInterface(Components.interfaces.zoteroIntegrationField)));
|
fields.push(Zotero.Integration.LegacyPluginWrapper.wrapField(
|
||||||
|
field.QueryInterface(Components.interfaces.zoteroIntegrationField)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
fields.push(wrapField(field));
|
fields.push(Zotero.Integration.LegacyPluginWrapper.wrapField(field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -2903,7 +2922,7 @@ Zotero.Integration.LegacyPluginWrapper = function(application) {
|
||||||
var fields = [];
|
var fields = [];
|
||||||
if (result.hasMoreElements) {
|
if (result.hasMoreElements) {
|
||||||
while (result.hasMoreElements()) {
|
while (result.hasMoreElements()) {
|
||||||
fields.push(wrapField(result.getNext()));
|
fields.push(Zotero.Integration.LegacyPluginWrapper.wrapField(result.getNext()));
|
||||||
await Zotero.Promise.delay();
|
await Zotero.Promise.delay();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2913,11 +2932,11 @@ Zotero.Integration.LegacyPluginWrapper = function(application) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wrapped.insertField = async function() {
|
wrapped.insertField = async function() {
|
||||||
return wrapField(doc.insertField.apply(doc, arguments));
|
return Zotero.Integration.LegacyPluginWrapper.wrapField(doc.insertField.apply(doc, arguments));
|
||||||
}
|
}
|
||||||
wrapped.cursorInField = async function() {
|
wrapped.cursorInField = async function() {
|
||||||
var result = doc.cursorInField.apply(doc, arguments);
|
var result = doc.cursorInField.apply(doc, arguments);
|
||||||
return !result ? result : wrapField(result);
|
return !result ? result : Zotero.Integration.LegacyPluginWrapper.wrapField(result);
|
||||||
}
|
}
|
||||||
// Should take an arrayOfFields instead of an enumerator
|
// Should take an arrayOfFields instead of an enumerator
|
||||||
wrapped.convert = async function(arrayOfFields) {
|
wrapped.convert = async function(arrayOfFields) {
|
||||||
|
@ -2926,14 +2945,3 @@ Zotero.Integration.LegacyPluginWrapper = function(application) {
|
||||||
}
|
}
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
getDocument:
|
|
||||||
async function() {return wrapDocument(application.getDocument.apply(application, arguments))},
|
|
||||||
getActiveDocument:
|
|
||||||
async function() {return wrapDocument(application.getActiveDocument.apply(application, arguments))},
|
|
||||||
primaryFieldType: application.primaryFieldType,
|
|
||||||
secondaryFieldType: application.secondaryFieldType,
|
|
||||||
outputFormat: 'rtf',
|
|
||||||
supportedNotes: ['footnotes', 'endnotes']
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user