1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-28 07:25:47 +01:00

Fix some cleanup issues.

--HG--
branch : bootstrapped
This commit is contained in:
Kris Maglione
2010-12-24 18:32:22 -05:00
parent 2f081bd805
commit d3d60548f1
8 changed files with 176 additions and 138 deletions

View File

@@ -147,6 +147,40 @@ const Buffer = Module("buffer", {
let elem = event.originalTarget;
buffer.viewSource([elem.getAttribute("href"), Number(elem.getAttribute("line"))])
};
this.replaceProgressListener(this.progressListener);
},
cleanup: function () {
for (let prop in properties(this.progressListener))
if (!this.progressListener.__lookupGetter__(prop) &&
!callable(this.progressListener[prop]))
this.origProgressListener[prop] = this.progressListener[prop]
this.replaceProgressListener(this.origProgressListener);
},
replaceProgressListener: function (newListener) {
// I hate this whole hack. --Kris
let obj = window.XULBrowserWindow, getter;
for (let prop in properties(obj))
if ((getter = obj.__lookupGetter__(prop)) && !obj.__lookupSetter__(prop)) {
newListener.__defineGetter__(prop, getter);
delete obj[prop];
}
this.origProgressListener = window.XULBrowserWindow;
try {
config.browser.removeProgressListener(window.XULBrowserWindow);
}
catch (e) {} // Why? --djk
config.browser.addProgressListener(newListener, Ci.nsIWebProgress.NOTIFY_ALL);
window.XULBrowserWindow = newListener;
window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = newListener;
},
destroy: function () {
@@ -1502,26 +1536,6 @@ const Buffer = Module("buffer", {
};
},
events: function () {
try {
config.browser.removeProgressListener(window.XULBrowserWindow);
}
catch (e) {} // Why? --djk
// I hate this whole hack. --Kris
let obj = window.XULBrowserWindow, getter;
for (let p in properties(obj))
if ((getter = obj.__lookupGetter__(p)) && !obj.__lookupSetter__(p)) {
this.progressListener.__defineGetter__(p, getter);
delete obj[p];
}
config.browser.addProgressListener(this.progressListener, Ci.nsIWebProgress.NOTIFY_ALL);
window.XULBrowserWindow = this.progressListener;
window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = this.progressListener;
events.addSessionListener(config.browser, "DOMContentLoaded", this.closure.onDOMContentLoaded, true);
events.addSessionListener(config.browser, "load", this.closure.onPageLoad, true);
events.addSessionListener(config.browser, "scroll", this.closure._updateBufferPosition, false);

View File

@@ -135,9 +135,25 @@ const CommandWidgets = Class("CommandWidgets", {
getGroup: function (value) {
if (this.command && !options.get("guioptions").has("M"))
return this.statusbar;
let statusElem = this.statusbar.message;
if (value && statusElem.inputField.editor.rootElement.scrollWidth > statusElem.scrollWidth)
return this.commandbar;
if (!statusElem.editor) {
util.dump(commandline == window.dactyl.modules.commandline,
window.dactyl.modules.commandline.widgets == this,
commandline.widgets == this);
util.dumpStack();
for (let i=0, e = statusElem; e; e = e.parentNode)
util.dump(i++, e == statusline._statusLine.firstChild,
e == statusline.widgets.container,
e);
util.dump(statusElem == statusline.widgets.message);
util.dump(statusline._statusLine.firstChild == statusline.widgets.container);
}
else {
if (value && statusElem.editor.rootElement.scrollWidth > statusElem.scrollWidth)
return this.commandbar;
}
return this.activeGroup.mode;
}
});
@@ -165,13 +181,13 @@ const CommandWidgets = Class("CommandWidgets", {
const self = this;
this.elements[obj.name] = obj;
function get(id) obj.getElement ? obj.getElement(id) : document.getElementById(id);
function get(prefix, map, id) (obj.getElement || util.identity)(map[id] || document.getElementById(prefix + 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)));
memoize(this.statusbar, obj.name, function () get("dactyl-statusline-field-", statusline.widgets, (obj.id || obj.name)));
memoize(this.commandbar, obj.name, function () get("dactyl-", {}, (obj.id || obj.name)));
if (!(obj.noValue || obj.getValue))
Object.defineProperty(this, obj.name, Modes.boundProperty({
@@ -259,8 +275,7 @@ const CommandWidgets = Class("CommandWidgets", {
multilineInput: Class.memoize(function () document.getElementById("dactyl-multiline-input")),
mowContainer: Class.memoize(function () this.multilineOutput.parentNode)
}, {
getEditor: function (id) {
let elem = document.getElementById(id);
getEditor: function (elem) {
elem.inputField.QueryInterface(Ci.nsIDOMNSEditableElement);
return elem;
}

View File

@@ -53,13 +53,15 @@ const Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
observe: {
"dactyl-cleanup": function () {
for (let [, mod] in iter(array(values(modules)).reverse()))
for (let name in values(Object.getOwnPropertyNames(modules).reverse())) {
let mod = modules[name];
if (mod instanceof ModuleBase) {
if ("cleanup" in mod)
mod.cleanup();
if ("destroy" in mod)
mod.destroy();
}
}
}
},

View File

@@ -10,6 +10,19 @@
const StatusLine = Module("statusline", {
init: function () {
this._statusLine = document.getElementById("status-bar");
this.statusBar = document.getElementById("addon-bar") || this._statusLine;
this.statusBar.collapsed = true; // it is later restored unless the user sets laststatus=0
if (this.statusBar.localName == "toolbar") {
styles.system.add("addon-bar", config.styleableChrome, <css><![CDATA[
#status-bar { margin-top: 0 !important; }
#addon-bar { padding: 0 !important; min-height: 18px !important; }
#addon-bar > statusbar { -moz-box-flex: 1 }
#addon-bar > #addonbar-closebutton { visibility: collapse; }
#addon-bar > xul|toolbarspring { visibility: collapse; }
]]></css>);
}
let _commandline = "if (window.dactyl) return dactyl.modules.commandline";
let prepend = <e4x xmlns={XUL} xmlns:dactyl={NS}>
@@ -21,8 +34,8 @@ const StatusLine = Module("statusline", {
<hbox class="dactyl-container" dactyl:highlight="CmdLine StatusCmdLine">
<label class="plain" key="mode" crop="end" collapsed="true"/>
<stack flex="1" class="dactyl-container" dactyl:highlight="CmdLine StatusCmdLine">
<textbox class="plain" key="url" crop="end" flex="1" readonly="true"/>
<textbox class="plain" key="message" crop="end" flex="1" readonly="true" dactyl:highlight="Normal StatusNormal"/>
<textbox key="url" crop="end" flex="1" readonly="true" class="plain dactyl-status-field-url"/>
<textbox key="message" crop="end" flex="1" readonly="true" class="plain" dactyl:highlight="Normal StatusNormal"/>
</stack>
</hbox>
@@ -45,31 +58,11 @@ const StatusLine = Module("statusline", {
</statusbar>
</e4x>;
for each (let attr in prepend..@key)
attr.parent().@id = "dactyl-statusline-field-" + attr;
util.dump("statusbar: load overlay");
util.overlayWindow(window, {
objects: this.widgets = { get status() this.container },
prepend: prepend.elements()
});
this._statusLine = document.getElementById("status-bar");
this.statusBar = document.getElementById("addon-bar") || this._statusLine;
this.statusBar.collapsed = true; // it is later restored unless the user sets laststatus=0
if (this.statusBar.localName == "toolbar") {
styles.system.add("addon-bar", config.styleableChrome, <css><![CDATA[
#status-bar { margin-top: 0 !important; }
#addon-bar { padding: 0 !important; min-height: 18px !important; }
#addon-bar > statusbar { -moz-box-flex: 1 }
#addon-bar > #addonbar-closebutton { visibility: collapse; }
#addon-bar > xul|toolbarspring { visibility: collapse; }
]]></css>);
let parent = this.widgets.status.parentNode;
parent.removeChild(this.widgets.status);
parent.insertBefore(this.widgets.status, parent.firstChild);
}
},
get visible() !this.statusBar.collapsed && !this.statusBar.hidden,