mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 22:28:00 +01:00
[bootstrap] Changes toward proper reinitialization after disabling.
--HG-- branch : bootstrapped
This commit is contained in:
19
common/bootstrap.js
vendored
19
common/bootstrap.js
vendored
@@ -10,12 +10,13 @@ const Cr = Components.results;
|
||||
|
||||
Cu.import("resource://gre/modules/AddonManager.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const io = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
const resourceProto = io.getProtocolHandler("resource")
|
||||
const resourceProto = Services.io.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||
const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
||||
const manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
const storage = Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);
|
||||
|
||||
function httpGet(url) {
|
||||
let xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
@@ -70,23 +71,27 @@ function FactoryProxy(url, classID) {
|
||||
FactoryProxy.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI(Ci.nsIFactory),
|
||||
register: function () {
|
||||
dump("dactyl: bootstrap: register: " + this.classID + " " + this.contractID + "\n");
|
||||
manager.registerFactory(this.classID,
|
||||
String(this.classID),
|
||||
this.contractID,
|
||||
this);
|
||||
},
|
||||
unregister: function () {
|
||||
dump("dactyl: bootstrap: unregister: " + this.classID + " " + this.contractID + "\n");
|
||||
manager.unregisterFactory(this.classID,
|
||||
this);
|
||||
},
|
||||
get module() {
|
||||
Class.replaceProperty(this, "module", {});
|
||||
Object.defineProperty(this, "module", { value: {}, enumerable: true });
|
||||
Cu.import(this.url, this.module);
|
||||
return this.module;
|
||||
},
|
||||
createInstance: function ()
|
||||
let (factory = this.module.NSGetFactory(this.classID))
|
||||
createInstance: function (iids) {
|
||||
dump("dactyl: bootstrap: createInstance: " + this.classID + " " + this.contractID + " " + iids + "\n");
|
||||
return let (factory = this.module.NSGetFactory(this.classID))
|
||||
factory.createInstance.apply(factory, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
@@ -133,6 +138,10 @@ function init() {
|
||||
}
|
||||
}
|
||||
|
||||
Cc["@dactyl.googlecode.com/base/xpc-interface-shim"].createInstance()
|
||||
|
||||
Services.obs.notifyObservers(null, "dactyl-rehash", null);
|
||||
|
||||
Cu.import("resource://dactyl/base.jsm");
|
||||
require(global, "prefs");
|
||||
require(global, "services");
|
||||
|
||||
@@ -136,7 +136,7 @@ const CommandWidgets = Class("CommandWidgets", {
|
||||
if (this.command && !options.get("guioptions").has("M"))
|
||||
return this.statusbar;
|
||||
let statusElem = this.statusbar.message;
|
||||
if (value && statusElem.editor.rootElement.scrollWidth > statusElem.scrollWidth)
|
||||
if (value && statusElem.inputField.editor.rootElement.scrollWidth > statusElem.scrollWidth)
|
||||
return this.commandbar;
|
||||
return this.activeGroup.mode;
|
||||
}
|
||||
@@ -164,9 +164,12 @@ const CommandWidgets = Class("CommandWidgets", {
|
||||
addElement: function (obj) {
|
||||
const self = this;
|
||||
this.elements[obj.name] = obj;
|
||||
|
||||
function get(id) obj.getElement ? obj.getElement(id) : document.getElementById(id);
|
||||
|
||||
this.active.__defineGetter__(obj.name, function () self.activeGroup[obj.name][obj.name]);
|
||||
this.activeGroup.__defineGetter__(obj.name, function () self.getGroup(obj.name));
|
||||
|
||||
memoize(this.statusbar, obj.name, function () get("dactyl-statusline-field-" + (obj.id || obj.name)));
|
||||
memoize(this.commandbar, obj.name, function () get("dactyl-" + (obj.id || obj.name)));
|
||||
|
||||
|
||||
@@ -38,6 +38,19 @@ const Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
|
||||
};
|
||||
},
|
||||
|
||||
cleanup: function () {
|
||||
delete window.dactyl;
|
||||
delete window.liberator;
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
autocommands.trigger("LeavePre", {});
|
||||
storage.saveAll();
|
||||
dactyl.triggerObserver("shutdown", null);
|
||||
util.dump("All dactyl modules destroyed\n");
|
||||
autocommands.trigger("Leave", {});
|
||||
},
|
||||
|
||||
observe: {
|
||||
"dactyl-cleanup": function () {
|
||||
for (let [, mod] in iter(array(values(modules)).reverse()))
|
||||
@@ -65,20 +78,6 @@ const Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
|
||||
return "unknown";
|
||||
}),
|
||||
|
||||
cleanup: function () {
|
||||
delete window.dactyl;
|
||||
delete window.modules;
|
||||
delete window.liberator;
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
autocommands.trigger("LeavePre", {});
|
||||
storage.saveAll();
|
||||
dactyl.triggerObserver("shutdown", null);
|
||||
util.dump("All dactyl modules destroyed\n");
|
||||
autocommands.trigger("Leave", {});
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {number} The current main mode.
|
||||
* @see modes#mainModes
|
||||
|
||||
@@ -24,7 +24,9 @@ const ModuleBase = Class("ModuleBase", {
|
||||
toString: function () "[module " + this.constructor.className + "]"
|
||||
});
|
||||
|
||||
util.overlayWindow("chrome://browser/content/browser.xul", function (window) ({
|
||||
const Overlay = Module("Overlay", {
|
||||
init: function () {
|
||||
util.overlayWindow("chrome://browser/content/browser.xul", function (window) ({
|
||||
init: function (document) {
|
||||
/**
|
||||
* @constructor Module
|
||||
@@ -253,7 +255,8 @@ util.overlayWindow("chrome://browser/content/browser.xul", function (window) ({
|
||||
mod.destroy();
|
||||
}, false);
|
||||
}
|
||||
}));
|
||||
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -75,6 +75,7 @@ const Services = Module("Services", {
|
||||
if (!this.extensionManager)
|
||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||
},
|
||||
reinit: function () {},
|
||||
|
||||
_create: function (classes, ifaces, meth, init, args) {
|
||||
try {
|
||||
|
||||
@@ -55,10 +55,13 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
},
|
||||
|
||||
cleanup: function cleanup() {
|
||||
for (let win in iter(services.windowMediator.getEnumerator(null)))
|
||||
for (let elem in values(win.document.dactylOverlayElements))
|
||||
for (let win in iter(services.windowMediator.getEnumerator(null))) {
|
||||
for (let elem in values(win.document.dactylOverlayElements || []))
|
||||
if (elem.get() && elem.get().parentNode)
|
||||
elem.get().parentNode.removeChild(elem.get());
|
||||
delete win.document.dactylOverlayElements;
|
||||
delete win.document.dactylOverlays;
|
||||
}
|
||||
},
|
||||
|
||||
// FIXME: Only works for Pentadactyl
|
||||
@@ -962,6 +965,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
|
||||
observe: {
|
||||
"dactyl-cleanup": function () {
|
||||
util.dump("dactyl: util: observe: dactyl-cleanup");
|
||||
// Let window cleanup functions run synchronously before we
|
||||
// destroy modules.
|
||||
util.timeout(function () {
|
||||
@@ -969,6 +973,9 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
if (module.cleanup)
|
||||
module.cleanup();
|
||||
|
||||
services.observer.addObserver(this, "dactyl-rehash", true);
|
||||
|
||||
/*
|
||||
let getOwnPropertyNames = Object.getOwnPropertyNames;
|
||||
for each (let global in defineModule.globals.reverse())
|
||||
for each (let k in getOwnPropertyNames(global))
|
||||
@@ -976,8 +983,17 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
delete global[k];
|
||||
}
|
||||
catch (e) {}
|
||||
*/
|
||||
});
|
||||
},
|
||||
"dactyl-rehash": function () {
|
||||
util.dump("dactyl: util: observe: dactyl-rehash");
|
||||
for (let module in values(defineModule.modules))
|
||||
if (module.reinit)
|
||||
module.reinit();
|
||||
else
|
||||
module.init();
|
||||
},
|
||||
"toplevel-window-ready": function (window, data) {
|
||||
window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) {
|
||||
if (event.originalTarget === window.document) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@namespace dactyl url("http://vimperator.org/namespaces/liberator");
|
||||
@namespace html url("http://www.w3.org/1999/xhtml");
|
||||
@namespace xul uri("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
|
||||
@namespace xul url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
|
||||
|
||||
/* Applied to all content */
|
||||
[dactyl|activeframe] {
|
||||
|
||||
Reference in New Issue
Block a user