From 4d9c196b6cd1554574fea605bd7660a0b3ab1f8c Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 6 Feb 2011 13:50:00 -0500 Subject: [PATCH 1/3] Fix lost keys when opening command line for the first time. Fix cleanup issue. --- common/content/commandline.js | 16 ++++++++-------- common/content/dactyl.js | 16 ++++++++++------ common/modules/base.jsm | 1 + common/modules/io.jsm | 2 +- common/modules/overlay.jsm | 12 ++++++------ 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/common/content/commandline.js b/common/content/commandline.js index 9898d77a..a61bfa57 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -306,12 +306,6 @@ var CommandWidgets = Class("CommandWidgets", { var CommandMode = Class("CommandMode", { init: function init() { this.keepCommand = userContext.hidden_option_command_afterimage; - - if (this.historyKey) - this.history = CommandLine.History(commandline.widgets.active.command.inputField, this.historyKey, this); - - if (this.complete) - this.completions = CommandLine.Completions(commandline.widgets.active.command.inputField, this); }, open: function (command) { @@ -325,7 +319,13 @@ var CommandMode = Class("CommandMode", { this.widgets.prompt = this.prompt; this.widgets.command = command || ""; - if (this.completions && command && options["autocomplete"].length) + if (this.historyKey) + this.history = CommandLine.History(commandline.widgets.active.command.inputField, this.historyKey, this); + + if (this.complete) + this.completions = CommandLine.Completions(commandline.widgets.active.command.inputField, this); + + if (this.completions && command && options["autocomplete"].length && commandline.commandSession === this) this.completions.complete(true, false); }, @@ -337,7 +337,7 @@ var CommandMode = Class("CommandMode", { enter: function (stack) { commandline.commandSession = this; - if (this.command || stack.pop && commandline.command) { + if (stack.pop && commandline.command) { this.onChange(commandline.command); if (this.completions && stack.pop) this.completions.complete(true, false); diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 90d88c87..b5003ca3 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -61,23 +61,27 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { "dactyl-cleanup": function dactyl_cleanup() { let modules = dactyl.modules; - for (let name in values(Object.getOwnPropertyNames(modules).reverse())) { - let mod = Object.getOwnPropertyDescriptor(modules, name).value; - if (mod instanceof Class) { + let mods = Object.getOwnPropertyNames(modules).reverse() + .map(function (name) Object.getOwnPropertyDescriptor(modules, name).value); + + for (let mod in values(mods)) + if (mod instanceof ModuleBase || mod && mod.isLocalModule) { if ("cleanup" in mod) this.trapErrors(mod.cleanup, mod); if ("destroy" in mod) this.trapErrors(mod.destroy, mod); - if ("INIT" in mod && "cleanup" in mod.INIT) - this.trapErrors(mod.cleanup, mod, dactyl, modules, window); } - } + + for (let mod in values(mods)) + if (mod instanceof Class && "INIT" in mod && "cleanup" in mod.INIT) + this.trapErrors(mod.cleanup, mod, dactyl, modules, window); for (let name in values(Object.getOwnPropertyNames(modules).reverse())) try { delete modules[name]; } catch (e) {} + modules.__proto__ = {}; } }, diff --git a/common/modules/base.jsm b/common/modules/base.jsm index f147ebf1..1b1293bc 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -917,6 +917,7 @@ Module.INIT = { let module = this, objs = {}; for (let i in locals) module = objs[i] = Object.create(module); + module.isLocalModule = true; modules.jsmodules[this.constructor.className] = module; locals.reverse().forEach(function (fn, i) update(objs[i], fn.apply(module, args))) diff --git a/common/modules/io.jsm b/common/modules/io.jsm index bdcdf940..9b5f1492 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -1021,7 +1021,7 @@ unlet s:cpo_save modules.JavaScript.setCompleter([File, File.expandPath], [function (context, obj, args) { context.quote[2] = ""; - completion.file(context, true); + modules.completion.file(context, true); }]); }, diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index 411d7f43..0178e5d2 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -156,11 +156,16 @@ var Overlay = Module("Overlay", { "completion", "config", "downloads", + "finder", + "highlight", + "io", "javascript", "overlay", "prefs", "services", "storage", + "styles", + "template", "util" ].forEach(function (name) defineModule.time("load", name, require, null, jsmodules, name)); @@ -173,17 +178,12 @@ var Overlay = Module("Overlay", { "commands", "editor", "events", - "finder", - "highlight", "hints", - "io", "mappings", "marks", "mow", "options", - "statusline", - "styles", - "template" + "statusline" ].forEach(function (name) defineModule.time("load", name, modules.load, modules, name)); config.scripts.forEach(modules.load); From a1f291a9ec245b8a09fda5904413671c6b163997 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 6 Feb 2011 17:32:42 -0500 Subject: [PATCH 2/3] Move the ACR disabler to common/, pass it an add-on ID. --HG-- rename : pentadactyl/content/disable-acr.jsm => common/content/disable-acr.jsm --- common/bootstrap.js | 12 ++++++++---- {pentadactyl => common}/content/disable-acr.jsm | 13 ++++++++----- common/modules/overlay.jsm | 8 +------- 3 files changed, 17 insertions(+), 16 deletions(-) rename {pentadactyl => common}/content/disable-acr.jsm (90%) diff --git a/common/bootstrap.js b/common/bootstrap.js index 4ab93a0f..467d669d 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -169,9 +169,11 @@ function init() { } try { - module("resource://dactyl-local-content/disable-acr.jsm").init(); + module("resource://dactyl-content/disable-acr.jsm").init(addon.id); + } + catch (e) { + reportError(e); } - catch (e) {} if (JSMLoader && JSMLoader.bump != 3) // Temporary hack Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm", @@ -197,9 +199,11 @@ function shutdown(data, reason) { dump("dactyl: bootstrap: shutdown " + reasonToString(reason) + "\n"); if (reason != APP_SHUTDOWN) { try { - module("resource://dactyl-local-content/disable-acr.jsm").cleanup(); + module("resource://dactyl-content/disable-acr.jsm").init(addon.id); + } + catch (e) { + reportError(e); } - catch (e) {} if ([ADDON_UPGRADE, ADDON_DOWNGRADE, ADDON_UNINSTALL].indexOf(reason) >= 0) Services.obs.notifyObservers(null, "dactyl-purge", null); diff --git a/pentadactyl/content/disable-acr.jsm b/common/content/disable-acr.jsm similarity index 90% rename from pentadactyl/content/disable-acr.jsm rename to common/content/disable-acr.jsm index f5ebe74b..de231635 100644 --- a/pentadactyl/content/disable-acr.jsm +++ b/common/content/disable-acr.jsm @@ -1,7 +1,7 @@ // By Kris Maglione. Public Domain. // Please feel free to copy and use at will. -const ADDON_ID = "pentadactyl@dactyl.googlecode.com"; +var ADDON_ID; const OVERLAY_URLS = [ "about:addons", @@ -18,12 +18,15 @@ function observe(window, topic, url) { if (topic === "chrome-document-global-created") checkDocument(window.document); } -function init(disable) { - Services.obs[disable ? "removeObserver" : "addObserver"](observe, "chrome-document-global-created", false); +function init(id) { + if (id) + ADDON_ID = id; + + Services.obs[id ? "addObserver" : "removeObserver"](observe, "chrome-document-global-created", false); for (let doc in chromeDocuments) - checkDocument(doc, disable); + checkDocument(doc, !id); } -function cleanup() { init(true); } +function cleanup() { init(null); } function checkPopup(event) { let doc = event.originalTarget.ownerDocument; diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index 0178e5d2..b34f60b3 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -249,13 +249,7 @@ var Overlay = Module("Overlay", { defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber); let obj = defineModule.time(module.className, "init", module); - try { - delete modules[module.className]; - modules[module.className] = obj; - } - catch (e) { - Class.replaceProperty(modules, module.className, obj); - } + Class.replaceProperty(modules, module.className, obj); loaded[module.className] = true; frob(module.className); From 00dccddc876f1722042c835a07aeffe8b36b17b5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 6 Feb 2011 17:33:56 -0500 Subject: [PATCH 3/3] Fix stupid typo in last commit. :( --- common/bootstrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/bootstrap.js b/common/bootstrap.js index 467d669d..837a2f39 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -199,7 +199,7 @@ function shutdown(data, reason) { dump("dactyl: bootstrap: shutdown " + reasonToString(reason) + "\n"); if (reason != APP_SHUTDOWN) { try { - module("resource://dactyl-content/disable-acr.jsm").init(addon.id); + module("resource://dactyl-content/disable-acr.jsm").cleanup(); } catch (e) { reportError(e);