1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 05:58:03 +01:00

More bootstrap work.

--HG--
branch : bootstrapped
This commit is contained in:
Kris Maglione
2010-12-23 22:35:49 -05:00
parent 909a658338
commit c396c279c4
5 changed files with 51 additions and 20 deletions

View File

@@ -75,7 +75,7 @@ const CommandWidgets = Class("CommandWidgets", {
onblur={_commandline + ".onMultilineInputEvent(event);"}/>
</vbox>
</vbox>
</e4x>.*
</e4x>.elements()
});
this.elements = {};

View File

@@ -13,7 +13,7 @@
*/
const Events = Module("events", {
init: function () {
let _events = "if (window.dactyl &and; dactyl.modules.loaded.events) return dactyl.modules.events"
let _events = "if (window.dactyl && dactyl.modules.loaded.events) return dactyl.modules.events"
util.overlayWindow(window, {
append: <e4x xmlns={XUL}>
<window id={document.documentElement.id}>
@@ -21,11 +21,11 @@ const Events = Module("events", {
from: http://developer.mozilla.org/en/docs/XUL_Tutorial:Updating_Commands !-->
<!-- I don't think we really need this. Kris -->
<commandset id="onPentadactylFocus" commandupdater="true" events="focus"
oncommandupdate="{_events}.onFocusChange(event);"/>
oncommandupdate={_events + ".onFocusChange(event);"}/>
<commandset id="onPentadactylSelect" commandupdater="true" events="select"
oncommandupdate="{_events}.onSelectionChange(event);"/>
oncommandupdate={_events + ".onSelectionChange(event);"}/>
</window>
</e4x>.*
</e4x>.elements()
});
this._fullscreen = window.fullScreen;

View File

@@ -12,7 +12,7 @@ const StatusLine = Module("statusline", {
init: function () {
let _commandline = "if (window.dactyl) return dactyl.modules.commandline";
let append = <e4x xmlns={XUL} xmlns:dactyl={NS}>
let prepend = <e4x xmlns={XUL} xmlns:dactyl={NS}>
<statusbar id="status-bar" dactyl:highlight="StatusLine StatusNormal">
<!-- insertbefore="dactyl.statusBefore;" insertafter="dactyl.statusAfter;" -->
<hbox
@@ -45,12 +45,12 @@ const StatusLine = Module("statusline", {
</statusbar>
</e4x>;
for each (let attr in append..@key)
for each (let attr in prepend..@key)
attr.parent().@id = "dactyl-statusline-field-" + attr;
util.overlayWindow(window, {
objects: this.widgets = { get status() this.container },
append: append.*
prepend: prepend.elements()
});
this._statusLine = document.getElementById("status-bar");

View File

@@ -79,6 +79,11 @@ const Hive = Class("Hive", {
this.names = {};
},
cleanup: function cleanup() {
for (let sheet in values(this.sheets))
sheet.enabled = false;
},
__iterator__: function () Iterator(this.sheets),
get sites() array(this.sheets).map(function (s) s.sites).flatten().uniq().array,
@@ -214,6 +219,11 @@ const Styles = Module("Styles", {
this.system = Hive();
},
cleanup: function cleanup() {
for each (let hive in [this.user, this.system])
hive.cleanup();
},
__iterator__: function () Iterator(this.user.sheets.concat(this.system.sheets)),
_proxy: function (name, args)

View File

@@ -54,6 +54,13 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
this.overlays = {};
},
cleanup: function cleanup() {
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());
},
// FIXME: Only works for Pentadactyl
get activeWindow() services.windowMediator.getMostRecentWindow("navigator:browser"),
dactyl: update(function dactyl(obj) {
@@ -90,12 +97,13 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
let observers = obj.observe;
function register(meth) {
services.observer[meth](obj, "quit-application", true);
services.observer[meth](obj, "dactyl-unload", true);
for (let target in keys(observers))
services.observer[meth](obj, target, true);
}
Class.replaceProperty(obj, "observe",
function (subject, target, data) {
if (target == "quit-application")
if (target == "quit-application" || target == "dactyl-unload")
register("removeObserver");
if (observers[target])
observers[target].call(obj, subject, data);
@@ -908,6 +916,10 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
}
},
_loadOverlay: function _loadOverlay(window, obj) {
let doc = window.document;
if (!doc.dactylOverlayElements)
doc.dactylOverlayElements = [];
function overlay(key, fn) {
if (obj[key]) {
let iterator = Iterator(obj[key]);
@@ -915,9 +927,12 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
iterator = ([elem.@id, elem.*, elem.@*::*] for each (elem in obj[key]));
for (let [elem, xml, attr] in iterator) {
if (elem = window.document.getElementById(elem)) {
fn(elem, util.xmlToDom(xml, window.document, obj.objects));
for each (let attr in attr || [])
if (elem = doc.getElementById(elem)) {
let node = util.xmlToDom(xml, doc, obj.objects);
for (let n in array.iterValues(node.childNodes))
doc.dactylOverlayElements.push(Cu.getWeakReference(n));
fn(elem, node);
for each (let attr in attr || []) // FIXME: Cleanup...
elem.setAttributeNS(attr.namespace(), attr.localName(), attr);
}
}
@@ -929,22 +944,27 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
overlay("append", function (elem, dom) elem.appendChild(dom));
overlay("prepend", function (elem, dom) elem.insertBefore(dom, elem.firstChild));
if (obj.init)
obj.init(window, window.dactylDOMLoaded);
obj.init(window, window.document.dactylDOMLoaded);
if (obj.load)
if (window.document.dactylLoaded)
obj.load(window, window.document.dactylLoaded);
if (doc.dactylLoaded)
obj.load(window, doc.dactylLoaded);
else
window.document.addEventListener("load", wrapCallback(function load(event) {
doc.addEventListener("load", wrapCallback(function load(event) {
if (event.originalTarget === event.target) {
window.document.removeEventListener("load", load.wrapper, true);
window.document.dactylLoaded = event;
doc.removeEventListener("load", load.wrapper, true);
doc.dactylLoaded = event;
obj.load(window, event);
}
}), true);
},
observe: {
"dactyl-cleanup": function () {
for (let module in values(defineModule.modules))
if (module.cleanup)
module.cleanup();
},
"toplevel-window-ready": function (window, data) {
window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) {
if (event.originalTarget === window.document) {
@@ -965,8 +985,9 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
this.overlays[url] = [];
this.overlays[url].push(fn);
}, this);
for (let win in services.windowMediator.getEnumerator(null))
if (win.dactylDOMLoaded)
for (let win in iter(services.windowMediator.getEnumerator(null)))
if (win.document.dactylDOMLoaded)
this._loadOverlays(win);
}
},