1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 15:48:00 +01:00

Add function completers for services.{get,create}.

This commit is contained in:
Doug Kearns
2009-06-18 22:02:49 +10:00
parent ec8d7686fc
commit 837b17d6c1
2 changed files with 43 additions and 2 deletions

View File

@@ -595,6 +595,9 @@ const liberator = (function () //{{{
/////////////////////////////////////////////////////////////////////////////{{{
registerObserver("load_completion", function () {
completion.setFunctionCompleter(services.get, [function () services.services]);
completion.setFunctionCompleter(services.create, [function () [[c, ""] for (c in services.classes)]]);
completion.dialog = function dialog(context) {
context.title = ["Dialog"];
context.completions = config.dialogs;

View File

@@ -14,7 +14,7 @@ const Cr = Components.results;
const Cu = Components.utils;
/**
* Cached XPCOM services and instances.
* Cached XPCOM services and classes.
*
* @constructor
*/
@@ -22,6 +22,7 @@ function Services()
{
const classes = {};
const services = {};
function create(classes, ifaces, meth)
{
ifaces = Array.concat(ifaces);
@@ -33,22 +34,59 @@ function Services()
}
catch (e) {}
}
const self = {
/* @property {Object} A map of all cached services. */
get services() services,
/* @property {Object} A map of all cached classes. */
get classes() classes,
/**
* Adds a new XPCOM service to the cache.
*
* @param {string} name The service's cache key.
* @param {string} class The class's contract ID.
* @param {nsISupports|nsISupports[]} ifaces The interface or array of
* interfaces implemented by this service.
* @param {string} meth The name of the function used to instanciate
* the service.
*/
add: function (name, class, ifaces, meth)
{
return services[name] = create(class, ifaces, meth);
},
/**
* Adds a new XPCOM class to the cache.
*
* @param {string} name The class's cache key.
* @param {string} class The class's contract ID.
* @param {nsISupports|nsISupports[]} ifaces The interface or array of
* interfaces implemented by this class.
*/
addClass: function (name, class, ifaces)
{
return classes[name] = function () create(class, ifaces, "createInstance");
},
/**
* Returns the cached service with the specified name.
*
* @param {string} name The service's cache key.
*/
get: function (name) services[name],
/**
* Returns a new instance of the cached class with the specified name.
*
* @param {string} name The class's cache key.
*/
create: function (name) classes[name]()
};
self.add("appStartup", "@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup);
self.add("autoCompleteSearch", "@mozilla.org/browser/global-history;2", Ci.nsIAutoCompleteSearch);
//self.add("autoCompleteSearch", "@mozilla.org/autocomplete/search;1?name=songbird-autocomplete", Ci.nsIAutoCompleteSearch);
self.add("browserSearch", "@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService);
self.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService);
self.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=liberator", Ci.nsICommandLineHandler);