1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 10:17:59 +01:00

Bootstrap cleanup work.

--HG--
branch : bootstrapped
This commit is contained in:
Kris Maglione
2010-12-23 23:27:33 -05:00
parent c396c279c4
commit 33e16f3183
11 changed files with 89 additions and 23 deletions

View File

@@ -152,6 +152,14 @@ const CommandWidgets = Class("CommandWidgets", {
return this.commandbar; return this.commandbar;
} }
}); });
let fontSize = util.computedStyle(document.getElementById(config.mainWindowId)).fontSize;
styles.registerSheet("chrome://dactyl/skin/dactyl.css");
styles.system.add("font-size", "chrome://dactyl/content/buffer.xhtml",
"body { font-size: " + fontSize + "; }");
},
cleanup: function cleanup() {
styles.unregisterSheet("chrome://dactyl/skin/dactyl.css");
}, },
addElement: function (obj) { addElement: function (obj) {
const self = this; const self = this;
@@ -1810,12 +1818,6 @@ const CommandLine = Module("commandline", {
host && (!item.domains || !item.domains.some(function (d) util.isSubdomain(d, host)))); host && (!item.domains || !item.domains.some(function (d) util.isSubdomain(d, host))));
} }
}); });
},
styles: function () {
let fontSize = util.computedStyle(document.getElementById(config.mainWindowId)).fontSize;
styles.registerSheet("chrome://dactyl/skin/dactyl.css");
styles.system.add("font-size", "chrome://dactyl/content/buffer.xhtml",
"body { font-size: " + fontSize + "; }");
} }
}); });

View File

@@ -65,6 +65,7 @@ const ConfigBase = Class(ModuleBase, {
* must be strings as entered via :set. * must be strings as entered via :set.
*/ */
defaults: { guioptions: "rb" }, defaults: { guioptions: "rb" },
cleanups: {},
/** /**
* @property {[["string", "string", "function"]]} An array of * @property {[["string", "string", "function"]]} An array of

View File

@@ -19,7 +19,7 @@ const EVAL_ERROR = "__dactyl_eval_error";
const EVAL_RESULT = "__dactyl_eval_result"; const EVAL_RESULT = "__dactyl_eval_result";
const EVAL_STRING = "__dactyl_eval_string"; const EVAL_STRING = "__dactyl_eval_string";
const Dactyl = Module("dactyl", { const Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
init: function () { init: function () {
window.dactyl = this; window.dactyl = this;
// cheap attempt at compatibility // cheap attempt at compatibility
@@ -30,6 +30,7 @@ const Dactyl = Module("dactyl", {
this.indices = {}; this.indices = {};
this.modules = modules; this.modules = modules;
this.observers = {}; this.observers = {};
util.addObserver(this);
this.commands["dactyl.help"] = function (event) { this.commands["dactyl.help"] = function (event) {
let elem = event.originalTarget; let elem = event.originalTarget;
@@ -37,6 +38,18 @@ const Dactyl = Module("dactyl", {
}; };
}, },
observe: {
"dactyl-cleanup": function () {
for (let [, mod] in iter(array(values(modules)).reverse()))
if (mod instanceof ModuleBase) {
if ("cleanup" in mod)
mod.cleanup();
if ("destroy" in mod)
mod.destroy();
}
}
},
/** @property {string} The name of the current user profile. */ /** @property {string} The name of the current user profile. */
profileName: Class.memoize(function () { profileName: Class.memoize(function () {
// NOTE: services.profile.selectedProfile.name doesn't return // NOTE: services.profile.selectedProfile.name doesn't return
@@ -52,6 +65,12 @@ const Dactyl = Module("dactyl", {
return "unknown"; return "unknown";
}), }),
cleanup: function () {
delete window.dactyl;
delete window.modules;
delete window.liberator;
},
destroy: function () { destroy: function () {
autocommands.trigger("LeavePre", {}); autocommands.trigger("LeavePre", {});
storage.saveAll(); storage.saveAll();
@@ -1315,6 +1334,12 @@ const Dactyl = Module("dactyl", {
options.add(["guioptions", "go"], options.add(["guioptions", "go"],
"Show or hide certain GUI elements like the menu or toolbar", "Show or hide certain GUI elements like the menu or toolbar",
"charlist", config.defaults.guioptions || "", { "charlist", config.defaults.guioptions || "", {
// FIXME: cleanup
cleanupValue: config.cleanups.guioptions ||
"r" + [k for ([k, v] in iter(groups[1].opts))
if (!document.getElementById(v[1][0]).collapsed)].join(""),
completer: function (context) completer: function (context)
array(groups).map(function (g) [[k, v[0]] for ([k, v] in Iterator(g.opts))]).flatten(), array(groups).map(function (g) [[k, v[0]] for ([k, v] in Iterator(g.opts))]).flatten(),
setter: function (value) { setter: function (value) {

View File

@@ -8,8 +8,6 @@
given in the LICENSE.txt file included with this file. given in the LICENSE.txt file included with this file.
--> -->
<?xml-stylesheet href="chrome://dactyl/skin/dactyl.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "dactyl.dtd" [ <!DOCTYPE overlay SYSTEM "dactyl.dtd" [
<!ENTITY dactyl.content "chrome://dactyl/content/"> <!ENTITY dactyl.content "chrome://dactyl/content/">
]> ]>

View File

@@ -281,6 +281,8 @@ const Option = Class("Option", {
*/ */
description: "", description: "",
cleanupValue: null,
/** /**
* @property {function(CompletionContext, Args)} This option's completer. * @property {function(CompletionContext, Args)} This option's completer.
* @see CompletionContext * @see CompletionContext
@@ -637,6 +639,12 @@ const Options = Module("options", {
}, window); }, window);
}, },
cleanup: function cleanup() {
for (let opt in this)
if (opt.cleanupValue != null)
opt.value = opt.parse(opt.cleanupValue);
},
/** @property {Iterator(Option)} @private */ /** @property {Iterator(Option)} @private */
__iterator__: function () __iterator__: function ()
values(this._options.sort(function (a, b) String.localeCompare(a.name, b.name))), values(this._options.sort(function (a, b) String.localeCompare(a.name, b.name))),

View File

@@ -36,6 +36,15 @@ const Tabs = Module("tabs", {
}; };
}, },
cleanup: function cleanup() {
for (let [i, tab] in Iterator(this.allTabs)) {
function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas);
for (let elem in values(["dactyl-tab-icon-number", "dactyl-tab-number"].map(node)))
if (elem)
elem.parentNode.parentNode.removeChild(elem.parentNode);
}
},
_updateTabCount: function () { _updateTabCount: function () {
if (dactyl.has("Gecko2")) if (dactyl.has("Gecko2"))
for (let [i, tab] in Iterator(this.visibleTabs)) { for (let [i, tab] in Iterator(this.visibleTabs)) {
@@ -43,15 +52,15 @@ const Tabs = Module("tabs", {
if (!node("dactyl-tab-number")) { if (!node("dactyl-tab-number")) {
let nodes = {}; let nodes = {};
let dom = util.xmlToDom(<xul xmlns:xul={XUL} xmlns:html={XHTML} let dom = util.xmlToDom(<xul xmlns:xul={XUL} xmlns:html={XHTML}
><xul:hbox highlight="tab-number"><xul:label key="icon" align="center" highlight="TabIconNumber" class="dactyl-tab-number"/></xul:hbox ><xul:hbox highlight="tab-number"><xul:label key="icon" align="center" highlight="TabIconNumber" class="dactyl-tab-icon-number"/></xul:hbox
><xul:hbox highlight="tab-number"><html:div key="label" highlight="TabNumber"/></xul:hbox ><xul:hbox highlight="tab-number"><html:div key="label" highlight="TabNumber" class="dactyl-tab-number"/></xul:hbox
></xul>.*, document, nodes); ></xul>.*, document, nodes);
let img = node("tab-icon-image"); let img = node("tab-icon-image");
img.parentNode.appendChild(dom); img.parentNode.appendChild(dom);
tab.__defineGetter__("ordinal", function () Number(nodes.icon.value)); tab.__defineGetter__("dactylOrdinal", function () Number(nodes.icon.value));
tab.__defineSetter__("ordinal", function (i) nodes.icon.value = nodes.label.textContent = i); tab.__defineSetter__("dactylOrdinal", function (i) nodes.icon.value = nodes.label.textContent = i);
} }
tab.ordinal = i + 1; tab.dactylOrdinal = i + 1;
} }
statusline.updateTabCount(true); statusline.updateTabCount(true);
}, },

View File

@@ -98,6 +98,7 @@ let loaded = {};
let currentModule; let currentModule;
function defineModule(name, params) { function defineModule(name, params) {
let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__; let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__;
defineModule.globals.push(module);
module.NAME = name; module.NAME = name;
module.EXPORTED_SYMBOLS = params.exports || []; module.EXPORTED_SYMBOLS = params.exports || [];
defineModule.loadLog.push("defineModule " + name); defineModule.loadLog.push("defineModule " + name);
@@ -114,6 +115,7 @@ function defineModule(name, params) {
currentModule = module; currentModule = module;
} }
defineModule.globals = [];
defineModule.loadLog = []; defineModule.loadLog = [];
Object.defineProperty(defineModule.loadLog, "push", { Object.defineProperty(defineModule.loadLog, "push", {
value: function (val) { defineModule.dump(val + "\n"); this[this.length] = val; } value: function (val) { defineModule.dump(val + "\n"); this[this.length] = val; }

View File

@@ -42,6 +42,10 @@ const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver),
services.bookmarks.addObserver(this, false); services.bookmarks.addObserver(this, false);
}, },
cleanup: function cleanup() {
services.bookmarks.removeObserver(this);
},
__iterator__: function () (val for ([, val] in Iterator(bookmarkcache.bookmarks))), __iterator__: function () (val for ([, val] in Iterator(bookmarkcache.bookmarks))),
get bookmarks() Class.replaceProperty(this, "bookmarks", this.load()), get bookmarks() Class.replaceProperty(this, "bookmarks", this.load()),

View File

@@ -28,6 +28,10 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
this.restore(); this.restore();
}, },
cleanup: function cleanup() {
this._branch.removeObserver("", this);
},
observe: { observe: {
"nsPref:changed": function (subject, data) { "nsPref:changed": function (subject, data) {
let observers = this._observers[data]; let observers = this._observers[data];

View File

@@ -961,9 +961,21 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
observe: { observe: {
"dactyl-cleanup": function () { "dactyl-cleanup": function () {
for (let module in values(defineModule.modules)) // Let window cleanup functions run synchronously before we
if (module.cleanup) // destroy modules.
module.cleanup(); util.timeout(function () {
for (let module in values(defineModule.modules))
if (module.cleanup)
module.cleanup();
let getOwnPropertyNames = Object.getOwnPropertyNames;
for each (let global in defineModule.globals.reverse())
for each (let k in getOwnPropertyNames(global))
try {
delete global[k];
}
catch (e) {}
});
}, },
"toplevel-window-ready": function (window, data) { "toplevel-window-ready": function (window, data) {
window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) { window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) {
@@ -1141,6 +1153,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
} }
catch (e) { catch (e) {
this.dump(e); this.dump(e);
try { util.dump(e.stack) } catch (e) {}
} }
}, },

View File

@@ -89,8 +89,8 @@ window[dactyl|highlight~=Bell] > * {
} }
[dactyl|highlight~=CmdLine] { [dactyl|highlight~=CmdLine] {
background: inherit; background: inherit !important;
color: inherit; color: inherit !important;
} }
[dactyl|highlight~=CmdLine], [dactyl|highlight~=CmdLine],
[dactyl|highlight~=CmdLine] > [dactyl|highlight~=CmdLine] { [dactyl|highlight~=CmdLine] > [dactyl|highlight~=CmdLine] {
@@ -123,8 +123,8 @@ statusbarpanel {
} }
#dactyl-statusline-field-url { #dactyl-statusline-field-url {
background-color: inherit; background-color: inherit !important;
color: inherit; color: inherit !important;
} }
/* no longer at the window's bottom right corner */ /* no longer at the window's bottom right corner */
@@ -141,8 +141,8 @@ statusbarpanel {
padding: 0px; padding: 0px;
} }
.dactyl-commandline-command { .dactyl-commandline-command {
background-color: inherit; background-color: inherit !important;
color: inherit; color: inherit !important;
margin: 0px; margin: 0px;
} }
.dactyl-commandline-command html|*:focus { .dactyl-commandline-command html|*:focus {