1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-14 06:35:46 +01:00

Move config module to config.jsm.

--HG--
rename : common/content/configbase.js => common/modules/config.jsm
This commit is contained in:
Kris Maglione
2010-12-29 14:49:20 -05:00
parent b8b931b901
commit 7a0c7dacbe
13 changed files with 241 additions and 219 deletions

12
common/bootstrap.js vendored
View File

@@ -99,7 +99,6 @@ FactoryProxy.prototype = {
return this.module;
},
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)
}
@@ -155,18 +154,7 @@ function init() {
for each (let component in components)
component.register();
require(global, "prefs");
require(global, "services");
Cu.import("resource://gre/modules/Services.jsm", global);
services.subscriptLoader.loadSubScript(
url("defaults/preferences/dactyl.js"),
{
pref: function pref(name, val) {
if (prefs.get(name, null) == null)
prefs.set(name, val);
}
});
let manifestText = result.map(function (line) line.join(" ")).join("\n");

View File

@@ -101,14 +101,7 @@ function Dactyl() {
this.pages = {};
Cu.import("resource://dactyl/base.jsm");
require(global, "prefs");
require(global, "util");
["appName", "fileExt", "host", "hostbin", "idName", "name", "version"].forEach(function (pref)
this.__defineGetter__(pref, function () prefs.get("extensions.dactyl." + pref, "dactyl")),
this);
memoize(this, "addonID", function () this.name + "@dactyl.googlecode.com");
}
Dactyl.prototype = {
contractID: "@mozilla.org/network/protocol;1?name=dactyl",

View File

@@ -332,9 +332,9 @@ var Tabs = Module("tabs", {
}
if (focusLeftTab)
tabs.slice(Math.max(0, index + 1 - count), index + 1).forEach(config.removeTab);
tabs.slice(Math.max(0, index + 1 - count), index + 1).forEach(config.closure.removeTab);
else
tabs.slice(index, index + count).forEach(config.removeTab);
tabs.slice(index, index + count).forEach(config.closure.removeTab);
return res;
},

View File

@@ -163,7 +163,7 @@ defineModule.dump = function dump_() {
msg = util.objectToString(msg);
return msg;
}).join(", ");
let name = loaded.services && loaded.prefs && services["dactyl:"] ? services["dactyl:"].name : "dactyl";
let name = loaded.services && loaded.config ? config.name.name : "dactyl";
dump(String.replace(msg, /\n?$/, "\n")
.replace(/^./gm, name + ": $&"));
}
@@ -221,7 +221,7 @@ defineModule("base", {
"keys", "memoize", "octal", "properties", "require", "set", "update",
"values", "withCallerGlobal"
],
use: ["services", "util"]
use: ["config", "services", "util"]
});
function Runnable(self, func, args) {

View File

@@ -6,16 +6,20 @@
// given in the LICENSE.txt file included with this file.
"use strict";
var ConfigBase = Class(ModuleBase, {
try {
Components.utils.import("resource://dactyl/base.jsm");
defineModule("config", {
exports: ["ConfigBase", "Config", "config"],
require: ["highlight", "services", "storage", "util", "template"]
});
var ConfigBase = Class("ConfigBase", {
/**
* Called on dactyl startup to allow for any arbitrary application-specific
* initialization code. Must call superclass's init function.
*/
init: function () {
this.name = services["dactyl:"].name;
this.idName = services["dactyl:"].idName;
this.appName = services["dactyl:"].appName;
this.host = services["dactyl:"].host;
highlight.styleableChrome = this.styleableChrome;
highlight.loadCSS(this.CSS);
@@ -31,22 +35,12 @@ var ConfigBase = Class(ModuleBase, {
}
]]>);
let img = Image();
img.src = this.logo || "chrome://" + this.name + "/content/logo.png";
img.onload = function () {
highlight.loadCSS(<>{"!Logo {"}
display: inline-block;
background: url({img.src});
width: {img.width}px;
height: {img.height}px;
{"}"}</>);
img = null;
};
if (util.haveGecko("2b"))
this.features.push("Gecko2");
},
get addonID() this.name + "@dactyl.googlecode.com",
styleHelp: function () {
if (!this.helpStyled)
for (let k in keys(highlight.loaded))
@@ -55,6 +49,28 @@ var ConfigBase = Class(ModuleBase, {
this.helpCSS = true;
},
Local: function Local(dactyl, modules, window)
let ({modes} = modules) ({
get browser() window.gBrowser,
get tabbrowser() window.gBrowser,
get browserModes() [modes.NORMAL],
/**
* @property {string} The ID of the application's main XUL window.
*/
mainWindowId: window.document.documentElement.id,
/**
* @property {number} The height (px) that is available to the output
* window.
*/
get outputHeight() this.browser.mPanelContainer.boxObject.height,
tabStrip: Class.memoize(function () window.document.getElementById("TabsToolbar") || this.tabbrowser.mTabContainer),
}),
/**
* @property {[["string", "string"]]} A sequence of names and descriptions
* of the autocommands available in this application. Primarily used
@@ -62,11 +78,6 @@ var ConfigBase = Class(ModuleBase, {
*/
autocommands: [],
get browser() window.gBrowser,
get tabbrowser() window.gBrowser,
get browserModes() [modes.NORMAL],
commandContainer: "browser-bottombox",
/**
@@ -118,11 +129,6 @@ var ConfigBase = Class(ModuleBase, {
*/
ignoreKeys: {}, // NOTE: be aware you can't put useful values in here, as "modes.NORMAL" etc. are not defined at this time
/**
* @property {string} The ID of the application's main XUL window.
*/
mainWindowId: window.document.documentElement.id,
/**
* @property {[[]]} An array of application specific mode specifications.
* The values of each mode are passed to modes.addMode during
@@ -136,12 +142,6 @@ var ConfigBase = Class(ModuleBase, {
*/
name: null,
/**
* @property {number} The height (px) that is available to the output
* window.
*/
get outputHeight() this.browser.mPanelContainer.boxObject.height,
/**
* @property {[string]} A list of extra scripts in the dactyl or
* application namespaces which should be loaded before dactyl
@@ -149,8 +149,6 @@ var ConfigBase = Class(ModuleBase, {
*/
scripts: [],
tabStrip: Class.memoize(function () window.document.getElementById("TabsToolbar") || this.tabbrowser.mTabContainer),
/**
* @property {string} The leaf name of any temp files created by
* {@link io.createTempFile}.
@@ -455,4 +453,34 @@ var ConfigBase = Class(ModuleBase, {
]]></>)
});
services.subscriptLoader.loadSubScript("chrome://dactyl/content/config.js", this);
config.INIT = update(Object.create(config.INIT), config.INIT, {
init: function init(dactyl, modules, window) {
init.superapply(this, arguments);
// Hmm...
let config1 = Object.create(config);
let config2 = Object.create(config1);
update(config1, config.Local.superapply(config2, arguments));
update(config2, config.Local.apply(config2, arguments));
modules.config = config2;
modules.config.init();
let img = window.Image();
img.src = this.logo || "chrome://" + this.name + "/content/logo.png";
img.onload = function () {
highlight.loadCSS(<>{"!Logo {"}
display: inline-block;
background: url({img.src});
width: {img.width}px;
height: {img.height}px;
{"}"}</>);
img = null;
};
}
});
} catch(e){ if (isString(e)) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); }
// vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -7,7 +7,7 @@
Components.utils.import("resource://dactyl/base.jsm");
defineModule("overlay", {
exports: ["ModuleBase"],
require: ["highlight", "sanitizer", "services", "template", "util"],
require: ["config", "sanitizer", "services", "util"]
});
/**
@@ -26,7 +26,7 @@ var ModuleBase = Class("ModuleBase", {
var Overlay = Module("Overlay", {
init: function () {
util.overlayWindow("chrome://browser/content/browser.xul", function (window) ({
util.overlayWindow(config.overlayChrome, function (window) ({
init: function (document) {
/**
* @constructor Module
@@ -94,7 +94,7 @@ var Overlay = Module("Overlay", {
return res;
})();
const jsmodules = {};
const jsmodules = { NAME: "jsmodules" };
const modules = update(create(jsmodules), {
jsmodules: jsmodules,
@@ -119,7 +119,7 @@ var Overlay = Module("Overlay", {
}
}
try {
Cu.import("resource://dactyl/" + script + ".jsm", jsmodules);
require(jsmodules, script);
}
catch (e) {
util.dump("Loading script " + script + ":");
@@ -141,15 +141,17 @@ var Overlay = Module("Overlay", {
let prefix = [BASE];
modules.load("util");
modules.load("services");
prefix.unshift("chrome://" + modules.services["dactyl:"].name + "/content/");
["base",
"config",
"util",
"services",
"overlay",
"prefs",
"storage",
"javascript",
"storage"
].forEach(function (name) require(jsmodules, name));
prefix.unshift("chrome://" + config.name + "/content/");
["javascript",
"dactyl",
"modes",
"abbreviations",
@@ -158,8 +160,6 @@ var Overlay = Module("Overlay", {
"commandline",
"commands",
"completion",
"configbase",
"config",
"editor",
"events",
"finder",
@@ -174,7 +174,7 @@ var Overlay = Module("Overlay", {
"template"
].forEach(modules.load);
modules.Config.prototype.scripts.forEach(modules.load);
config.scripts.forEach(modules.load);
},
load: function (document) {
var { modules, Module } = window.dactyl.modules;

View File

@@ -96,7 +96,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
}
};
return template.options(services["dactyl:"].host + " Preferences", prefs.call(this));
return template.options(config.host + " Preferences", prefs.call(this));
},
/**
@@ -332,7 +332,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
completion: function (dactyl, modules) {
modules.completion.preference = function preference(context) {
context.anchored = false;
context.title = [services["dactyl:"].host + " Preference", "Value"];
context.title = [config.host + " Preference", "Value"];
context.keys = { text: function (item) item, description: function (item) prefs.get(item) };
context.completions = prefs.getNames();
};

View File

@@ -158,7 +158,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
append: {
SanitizeDialogPane:
<groupbox orient="horizontal" xmlns={XUL}>
<caption label={services["dactyl:"].appName + " (see :help privacy)"}/>
<caption label={config.appName + " (see :help privacy)"}/>
<grid flex="1">
<columns><column flex="1"/><column flex="1"/></columns>
<rows>{
@@ -183,7 +183,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
{
template.map(ourItems(), function ([item, desc])
<listitem xmlns={XUL} type="checkbox"
label={services["dactyl:"].appName + " " + desc}
label={config.appName + " " + desc}
preference={branch + item}
onsyncfrompreference="return gSanitizePromptDialog.onReadGeneric();"/>)
}

View File

@@ -9,7 +9,7 @@ try {
var global = this;
Components.utils.import("resource://dactyl/base.jsm");
defineModule("services", {
exports: ["AddonManager", "Services", "services"],
exports: ["AddonManager", "services"],
use: ["util"]
});

View File

@@ -62,7 +62,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
addon: Class.memoize(function () {
let addon = services.fuel.storage.get("dactyl.bootstrap", {}).addon;
if (!addon)
addon = AddonManager.getAddonByID(services["dactyl:"].addonID);
addon = AddonManager.getAddonByID(config.addonID);
return addon;
}),