mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-07 01:34:11 +01:00
Automagically generate DTDs. One more step towards dropping the chrome: protocol.
--HG-- rename : common/content/io.js => common/modules/io.jsm
This commit is contained in:
@@ -312,6 +312,10 @@ function properties(obj, prototypes, debugger_) {
|
||||
}
|
||||
|
||||
function deprecated(reason, fn) {
|
||||
if (isObject(fn))
|
||||
return Class.Property(iter(fn).map(function ([k, v]) [k, callable(v) ? deprecated(reason, v) : v])
|
||||
.toObject());
|
||||
|
||||
let name, func = callable(fn) ? fn : function () this[fn].apply(this, arguments);
|
||||
|
||||
function deprecatedMethod() {
|
||||
@@ -708,6 +712,23 @@ function Class() {
|
||||
});
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
if (Cu.getGlobalForObject)
|
||||
Class.objectGlobal = function (caller) {
|
||||
try {
|
||||
return Cu.getGlobalForObject(caller);
|
||||
}
|
||||
catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
else
|
||||
Class.objectGlobal = function (caller) {
|
||||
while (caller.__parent__)
|
||||
caller = caller.__parent__;
|
||||
return caller;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Class.Property
|
||||
* A class which, when assigned to a property in a Class's prototype
|
||||
@@ -870,27 +891,34 @@ function Module(name, prototype) {
|
||||
const module = Class.apply(Class, Array.slice(arguments, 0, init));
|
||||
let instance = module();
|
||||
module.className = name.toLowerCase();
|
||||
instance.INIT = arguments[init] || {};
|
||||
|
||||
instance.INIT = update(Object.create(Module.INIT),
|
||||
arguments[init] || {});
|
||||
|
||||
currentModule[module.className] = instance;
|
||||
defineModule.modules.push(instance);
|
||||
return module;
|
||||
}
|
||||
Module.INIT = {
|
||||
init: function (dactyl, modules, window) {
|
||||
let args = arguments;
|
||||
|
||||
if (Cu.getGlobalForObject)
|
||||
Class.objectGlobal = function (caller) {
|
||||
try {
|
||||
return Cu.getGlobalForObject(caller);
|
||||
let locals = [];
|
||||
for (let local = this.Local; local; local = local.super)
|
||||
locals.push(local);
|
||||
|
||||
if (locals.length) {
|
||||
let module = this, objs = {};
|
||||
for (let i in locals)
|
||||
module = objs[i] = Object.create(module);
|
||||
|
||||
modules[this.constructor.className] = module;
|
||||
locals.reverse().forEach(function (fn, i) update(objs[i], fn.apply(module, args)))
|
||||
module.instance = module;
|
||||
module.init();
|
||||
}
|
||||
catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
else
|
||||
Class.objectGlobal = function (caller) {
|
||||
while (caller.__parent__)
|
||||
caller = caller.__parent__;
|
||||
return caller;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Struct
|
||||
|
||||
@@ -11,7 +11,8 @@ try {
|
||||
Components.utils.import("resource://dactyl/base.jsm");
|
||||
defineModule("config", {
|
||||
exports: ["ConfigBase", "Config", "config"],
|
||||
require: ["highlight", "services", "storage", "util", "template"]
|
||||
require: ["highlight", "services", "storage", "util", "template"],
|
||||
use: ["io"]
|
||||
});
|
||||
|
||||
var ConfigBase = Class("ConfigBase", {
|
||||
@@ -37,9 +38,77 @@ var ConfigBase = Class("ConfigBase", {
|
||||
|
||||
if (util.haveGecko("2b"))
|
||||
this.features.push("Gecko2");
|
||||
|
||||
this.timeout(function () {
|
||||
services["dactyl:"].pages.dtd = function () [null,
|
||||
iter(config.dtdExtra, (["dactyl." + s, config[s]] for each (s in config.dtdStrings)))
|
||||
.map(function ([k, v]) ["<!ENTITY ", k, " '", String.replace(v, /'/g, "'"), "'>"].join(""))
|
||||
.join("\n")]
|
||||
});
|
||||
},
|
||||
|
||||
get addonID() this.name + "@dactyl.googlecode.com",
|
||||
addon: Class.memoize(function () {
|
||||
let addon = services.fuel.storage.get("dactyl.bootstrap", {}).addon;
|
||||
if (!addon)
|
||||
addon = AddonManager.getAddonByID(this.addonID);
|
||||
return addon;
|
||||
}),
|
||||
|
||||
/** @property {string} The Dactyl version string. */
|
||||
version: Class.memoize(function () {
|
||||
if (/pre$/.test(this.addon.version)) {
|
||||
let uri = this.addon.getResourceURI("../.hg");
|
||||
if (uri instanceof Ci.nsIFileURL &&
|
||||
uri.QueryInterface(Ci.nsIFileURL).file.exists() &&
|
||||
io.pathSearch("hg")) {
|
||||
return io.system(["hg", "-R", uri.file.parent.path,
|
||||
"log", "-r.",
|
||||
"--template=hg{rev} ({date|isodate})"]);
|
||||
}
|
||||
}
|
||||
let version = this.addon.version;
|
||||
if ("@DATE" !== "@" + "DATE@")
|
||||
version += " (created: @DATE@)";
|
||||
return version;
|
||||
}),
|
||||
|
||||
// TODO: DTD properties. Cleanup.
|
||||
get home() "http://dactyl.sourceforge.net/",
|
||||
get apphome() this.home + this.name,
|
||||
code: "http://code.google.com/p/dactyl/",
|
||||
get issues() this.home + "bug/" + this.name,
|
||||
get plugins() "http://dactyl.sf.net/" + this.name + "/plugins",
|
||||
get faq() this.home + this.name + "/faq",
|
||||
"list.mailto": Class.memoize(function () config.name + "@googlegroups.com"),
|
||||
"list.href": Class.memoize(function () "http://groups.google.com/group/" + config.name),
|
||||
|
||||
dtdExtra: {
|
||||
"xmlns.dactyl": "http://vimperator.org/namespaces/liberator",
|
||||
"xmlns.html": "http://www.w3.org/1999/xhtml",
|
||||
"xmlns.xul": "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
||||
|
||||
"tag.command-line": '<link topic="command-line">command line</link>',
|
||||
"tag.status-line": '<link topic="status-line">status line</link>',
|
||||
},
|
||||
|
||||
dtdStrings: [
|
||||
"appName",
|
||||
"apphome",
|
||||
"code",
|
||||
"faq",
|
||||
"fileExt",
|
||||
"home",
|
||||
"host",
|
||||
"hostbin",
|
||||
"idName",
|
||||
"issues",
|
||||
"list.href",
|
||||
"list.mailto",
|
||||
"name",
|
||||
"plugins",
|
||||
"version",
|
||||
],
|
||||
|
||||
styleHelp: function styleHelp() {
|
||||
if (!this.helpStyled)
|
||||
@@ -519,15 +588,6 @@ 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);
|
||||
config2.instance = config2;
|
||||
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 () {
|
||||
|
||||
1021
common/modules/io.jsm
Normal file
1021
common/modules/io.jsm
Normal file
File diff suppressed because it is too large
Load Diff
@@ -129,7 +129,9 @@ var Overlay = Module("Overlay", {
|
||||
}
|
||||
},
|
||||
|
||||
newContext: function newContext(proto) {
|
||||
newContext: function newContext(proto, normal) {
|
||||
if (normal)
|
||||
return create(proto);
|
||||
let sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules, wantXrays: false });
|
||||
// Hack:
|
||||
sandbox.Object = jsmodules.Object;
|
||||
|
||||
@@ -69,11 +69,12 @@ var Services = Module("Services", {
|
||||
this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
|
||||
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter);
|
||||
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder);
|
||||
this.addClass("StreamChannel","@mozilla.org/network/input-stream-channel;1",
|
||||
[Ci.nsIChannel, Ci.nsIInputStreamChannel, Ci.nsIRequest], "setURI");
|
||||
this.addClass("InputStream", "@mozilla.org/scriptableinputstream;1", Ci.nsIScriptableInputStream, "init");
|
||||
this.addClass("Persist", "@mozilla.org/embedding/browser/nsWebBrowserPersist;1", Ci.nsIWebBrowserPersist);
|
||||
this.addClass("Pipe", "@mozilla.org/pipe;1", Ci.nsIPipe, "init");
|
||||
this.addClass("Process", "@mozilla.org/process/util;1", Ci.nsIProcess, "init");
|
||||
this.addClass("StreamChannel","@mozilla.org/network/input-stream-channel;1",
|
||||
[Ci.nsIChannel, Ci.nsIInputStreamChannel, Ci.nsIRequest], "setURI");
|
||||
this.addClass("String", "@mozilla.org/supports-string;1", Ci.nsISupportsString, "data");
|
||||
this.addClass("StringStream", "@mozilla.org/io/string-input-stream;1", Ci.nsIStringInputStream, "data");
|
||||
this.addClass("Timer", "@mozilla.org/timer;1", Ci.nsITimer, "initWithCallback");
|
||||
|
||||
@@ -490,6 +490,21 @@ var File = Class("File", {
|
||||
|
||||
defaultEncoding: "UTF-8",
|
||||
|
||||
/**
|
||||
* Expands "~" and environment variables in *path*.
|
||||
*
|
||||
* "~" is expanded to to the value of $HOME. On Windows if this is not
|
||||
* set then the following are tried in order:
|
||||
* $USERPROFILE
|
||||
* ${HOMDRIVE}$HOMEPATH
|
||||
*
|
||||
* The variable notation is $VAR (terminated by a non-word character)
|
||||
* or ${VAR}. %VAR% is also supported on Windows.
|
||||
*
|
||||
* @param {string} path The unexpanded path string.
|
||||
* @param {boolean} relative Whether the path is relative or absolute.
|
||||
* @returns {string}
|
||||
*/
|
||||
expandPath: function (path, relative) {
|
||||
function getenv(name) services.environment.get(name);
|
||||
|
||||
|
||||
@@ -59,13 +59,6 @@ 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(config.addonID);
|
||||
return addon;
|
||||
}),
|
||||
|
||||
// FIXME: Only works for Pentadactyl
|
||||
get activeWindow() services.windowMediator.getMostRecentWindow("navigator:browser"),
|
||||
dactyl: update(function dactyl(obj) {
|
||||
@@ -1203,8 +1196,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
services.fuel.storage.set("dactyl.commandlineArgs", args);
|
||||
this.timeout(function () {
|
||||
this.rehashing = true;
|
||||
this.addon.userDisabled = true;
|
||||
this.addon.userDisabled = false;
|
||||
config.addon.userDisabled = true;
|
||||
config.addon.userDisabled = false;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1508,6 +1501,6 @@ var Math = update(Object.create(GlobalMath), {
|
||||
|
||||
endModule();
|
||||
|
||||
} catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}
|
||||
} 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 ft=javascript:
|
||||
|
||||
Reference in New Issue
Block a user