fx115: working autocomplete (#3789)

- autocomplete registration removed from chrome.manifest
- static registration happening in zotero.js
- tweaks to autocomplete methods to implement nsIAutoCompleteSearch based on
https://searchfox.org/mozilla-central/source/toolkit/components/autocomplete/tests/unit/test_378079.js#154
This commit is contained in:
abaevbog 2024-03-03 23:55:32 -05:00 committed by Dan Stillman
parent 8cb0c58b60
commit 349ae52b9c
3 changed files with 22 additions and 10 deletions

View file

@ -63,9 +63,6 @@ locale zotero zh-TW chrome/locale/zh-TW/zotero/
skin zotero default chrome/skin/default/zotero/ skin zotero default chrome/skin/default/zotero/
component {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea} components/zotero-autocomplete.js
contract @mozilla.org/autocomplete/search;1?name=zotero {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea}
# Scaffold # Scaffold
content scaffold chrome/content/scaffold/ content scaffold chrome/content/scaffold/
locale scaffold en-US chrome/locale/en-US/scaffold/ locale scaffold en-US chrome/locale/en-US/scaffold/

View file

@ -674,6 +674,11 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
); );
ZoteroProtocolHandler.init(); ZoteroProtocolHandler.init();
const { ZoteroAutoComplete } = ChromeUtils.import(
`chrome://zotero/content/zotero-autocomplete.js`
);
ZoteroAutoComplete.init();
yield Zotero.Users.init(); yield Zotero.Users.init();
yield Zotero.Libraries.init(); yield Zotero.Libraries.init();

View file

@ -24,6 +24,7 @@
*/ */
const ZOTERO_AC_CID = Components.ID('{06a2ed11-d0a4-4ff0-a56f-a44545eee6ea}'); const ZOTERO_AC_CID = Components.ID('{06a2ed11-d0a4-4ff0-a56f-a44545eee6ea}');
const EXPORTED_SYMBOLS = ['ZoteroAutoComplete'];
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -31,9 +32,7 @@ const Cr = Components.results;
Components.utils.import("resource://gre/modules/ComponentUtils.jsm"); Components.utils.import("resource://gre/modules/ComponentUtils.jsm");
var Zotero = Components.classes["@zotero.org/Zotero;1"] var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs");
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
/* /*
* Implements nsIAutoCompleteSearch * Implements nsIAutoCompleteSearch
@ -340,6 +339,9 @@ ZoteroAutoComplete.prototype.updateResults = function (values, ids, ongoing, res
this._listener.onSearchResult(this, this._result); this._listener.onSearchResult(this, this._result);
} }
ZoteroAutoComplete.prototype.createInstance = function (iid) {
return this.QueryInterface(iid);
};
// FIXME // FIXME
ZoteroAutoComplete.prototype.stopSearch = function(){ ZoteroAutoComplete.prototype.stopSearch = function(){
@ -347,14 +349,22 @@ ZoteroAutoComplete.prototype.stopSearch = function(){
this._cancelled = true; this._cancelled = true;
} }
// Static
ZoteroAutoComplete.init = function () {
let search = new ZoteroAutoComplete();
var name = "@mozilla.org/autocomplete/search;1?name=zotero";
var componentManager = Components.manager.QueryInterface(
Ci.nsIComponentRegistrar
);
componentManager.registerFactory(ZOTERO_AC_CID, "", name, search);
};
// //
// XPCOM goop // XPCOM goop
// //
ZoteroAutoComplete.prototype.classID = ZOTERO_AC_CID; ZoteroAutoComplete.prototype.classID = ZOTERO_AC_CID;
ZoteroAutoComplete.prototype.QueryInterface = ChromeUtils.generateQI([ ZoteroAutoComplete.prototype.QueryInterface = ChromeUtils.generateQI([
Components.interfaces.nsIAutoCompleteSearch, "nsIFactory",
Components.interfaces.nsIAutoCompleteObserver "nsIAutoCompleteSearch"
]); ]);
var NSGetFactory = ComponentUtils.generateNSGetFactory([ZoteroAutoComplete]);