1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-26 15:15:46 +01:00

Move DOM and config properties from the util namespace to the DOM and config namespaces, respectively.

This commit is contained in:
Kris Maglione
2011-08-14 23:30:05 -04:00
parent 236a894c89
commit 681af3e618
19 changed files with 719 additions and 594 deletions

View File

@@ -111,7 +111,7 @@ var actions = {
name: "extr[ehash]",
description: "Reload an extension",
action: function (addon) {
util.assert(util.haveGecko("2b"), _("command.notUseful", config.host));
util.assert(config.haveGecko("2b"), _("command.notUseful", config.host));
util.timeout(function () {
addon.userDisabled = true;
addon.userDisabled = false;

View File

@@ -144,6 +144,7 @@ function defineModule(name, params, module) {
use[mod] = use[mod] || [];
use[mod].push(module);
}
module._lastModule = currentModule;
currentModule = module;
module.startTime = Date.now();
}
@@ -190,6 +191,7 @@ function endModule() {
require(mod, currentModule.NAME, "use");
loaded[currentModule.NAME] = 1;
currentModule = currentModule._lastModule;
}
function require(obj, name, from) {
@@ -732,7 +734,7 @@ function Class() {
if (callable(args[0]))
superclass = args.shift();
if (loaded.util && util.haveGecko("6.0a1")) // Bug 657418.
if (loaded.config && config.haveGecko("6.0a1")) // Bug 657418.
var Constructor = function Constructor() {
var self = Object.create(Constructor.prototype, {
constructor: { value: Constructor },

View File

@@ -23,7 +23,7 @@ var ConfigBase = Class("ConfigBase", {
*/
init: function init() {
this.features.push = deprecated("Set.add", function push(feature) Set.add(this, feature));
if (util.haveGecko("2b"))
if (this.haveGecko("2b"))
Set.add(this.features, "Gecko2");
this.timeout(function () {
@@ -40,7 +40,7 @@ var ConfigBase = Class("ConfigBase", {
highlight.loadCSS(this.CSS.replace(/__MSG_(.*?)__/g, function (m0, m1) _(m1)));
highlight.loadCSS(this.helpCSS.replace(/__MSG_(.*?)__/g, function (m0, m1) _(m1)));
if (!util.haveGecko("2b"))
if (!this.haveGecko("2b"))
highlight.loadCSS(<![CDATA[
!TabNumber font-weight: bold; margin: 0px; padding-right: .8ex;
!TabIconNumber {
@@ -60,12 +60,12 @@ var ConfigBase = Class("ConfigBase", {
let elem = services.appShell.hiddenDOMWindow.document.createElement("div");
elem.style.cssText = this.cssText;
let style = util.computedStyle(elem);
let keys = iter(Styles.propertyIter(this.cssText)).map(function (p) p.name).toArray();
let bg = keys.some(function (k) /^background/.test(k));
let fg = keys.indexOf("color") >= 0;
let style = DOM(elem).style;
prefs[bg ? "safeSet" : "safeReset"]("ui.textHighlightBackground", hex(style.backgroundColor));
prefs[fg ? "safeSet" : "safeReset"]("ui.textHighlightForeground", hex(style.color));
};
@@ -148,6 +148,87 @@ var ConfigBase = Class("ConfigBase", {
.nth(function (l) Set.has(langs, l), 0);
},
/**
* A list of all known registered chrome and resource packages.
*/
get chromePackages() {
// Horrible hack.
let res = {};
function process(manifest) {
for each (let line in manifest.split(/\n+/)) {
let match = /^\s*(content|skin|locale|resource)\s+([^\s#]+)\s/.exec(line);
if (match)
res[match[2]] = true;
}
}
function processJar(file) {
let jar = services.ZipReader(file);
if (jar) {
if (jar.hasEntry("chrome.manifest"))
process(File.readStream(jar.getInputStream("chrome.manifest")));
jar.close();
}
}
for each (let dir in ["UChrm", "AChrom"]) {
dir = File(services.directory.get(dir, Ci.nsIFile));
if (dir.exists() && dir.isDirectory())
for (let file in dir.iterDirectory())
if (/\.manifest$/.test(file.leafName))
process(file.read());
dir = File(dir.parent);
if (dir.exists() && dir.isDirectory())
for (let file in dir.iterDirectory())
if (/\.jar$/.test(file.leafName))
processJar(file);
dir = dir.child("extensions");
if (dir.exists() && dir.isDirectory())
for (let ext in dir.iterDirectory()) {
if (/\.xpi$/.test(ext.leafName))
processJar(ext);
else {
if (ext.isFile())
ext = File(ext.read().replace(/\n*$/, ""));
let mf = ext.child("chrome.manifest");
if (mf.exists())
process(mf.read());
}
}
}
return Object.keys(res).sort();
},
/**
* Returns true if the current Gecko runtime is of the given version
* or greater.
*
* @param {string} ver The required version.
* @returns {boolean}
*/
haveGecko: function (ver) services.versionCompare.compare(services.runtime.platformVersion, ver) >= 0,
/** Dactyl's notion of the current operating system platform. */
OS: memoize({
_arch: services.runtime.OS,
/**
* @property {string} The normalised name of the OS. This is one of
* "Windows", "Mac OS X" or "Unix".
*/
get name() this.isWindows ? "Windows" : this.isMacOSX ? "Mac OS X" : "Unix",
/** @property {boolean} True if the OS is Windows. */
get isWindows() this._arch == "WINNT",
/** @property {boolean} True if the OS is Mac OS X. */
get isMacOSX() this._arch == "Darwin",
/** @property {boolean} True if the OS is some other *nix variant. */
get isUnix() !this.isWindows && !this.isMacOSX,
/** @property {RegExp} A RegExp which matches illegal characters in path components. */
get illegalCharacters() this.isWindows ? /[<>:"/\\|?*\x00-\x1f]/g : /\//g,
get pathListSep() this.isWindows ? ";" : ":"
}),
/**
* @property {string} The pathname of the VCS repository clone's root
* directory if the application is running from one via an extension

View File

@@ -403,8 +403,8 @@ var RangeFind = Class("RangeFind", {
focus: function focus() {
if (this.lastRange)
var node = util.evaluateXPath(RangeFind.selectNodePath,
this.lastRange.commonAncestorContainer).snapshotItem(0);
var node = DOM.XPath(RangeFind.selectNodePath,
this.lastRange.commonAncestorContainer).snapshotItem(0);
if (node) {
node.focus();
// Re-highlight collapsed selection
@@ -517,7 +517,7 @@ var RangeFind = Class("RangeFind", {
for (let frame in array.iterValues(win.frames)) {
let range = doc.createRange();
if (util.computedStyle(frame.frameElement).visibility == "visible") {
if (DOM(frame.frameElement).style.visibility == "visible") {
range.selectNode(frame.frameElement);
pushRange(pageStart, RangeFind.endpoint(range, true));
pageStart = RangeFind.endpoint(range, false);

View File

@@ -299,7 +299,7 @@ var IO = Module("io", {
let rcFile1 = dir.child("." + config.name + "rc");
let rcFile2 = dir.child("_" + config.name + "rc");
if (util.OS.isWindows)
if (config.OS.isWindows)
[rcFile1, rcFile2] = [rcFile2, rcFile1];
if (rcFile1.exists() && rcFile1.isFile())
@@ -393,9 +393,9 @@ var IO = Module("io", {
if (bin instanceof File || File.isAbsolutePath(bin))
return this.File(bin);
let dirs = services.environment.get("PATH").split(util.OS.isWindows ? ";" : ":");
let dirs = services.environment.get("PATH").split(config.OS.isWindows ? ";" : ":");
// Windows tries the CWD first TODO: desirable?
if (util.OS.isWindows)
if (config.OS.isWindows)
dirs = [io.cwd].concat(dirs);
for (let [, dir] in Iterator(dirs))
@@ -408,7 +408,7 @@ var IO = Module("io", {
// TODO: couldn't we just palm this off to the start command?
// automatically try to add the executable path extensions on windows
if (util.OS.isWindows) {
if (config.OS.isWindows) {
let extensions = services.environment.get("PATHEXT").split(";");
for (let [, extension] in Iterator(extensions)) {
file = dir.child(bin + extension);
@@ -478,7 +478,7 @@ var IO = Module("io", {
system: function (command, input, callback) {
util.dactyl.echomsg(_("io.callingShell", command), 4);
function escape(str) '"' + String.replace(str, /[\\"$]/g, "\\$&") + '"';
let { shellEscape } = util.closure;
return this.withTempFiles(function (stdin, stdout, cmd) {
if (input instanceof File)
@@ -505,17 +505,17 @@ var IO = Module("io", {
util.assert(shell, _("error.invalid", "'shell'"));
if (isArray(command))
command = command.map(escape).join(" ");
command = command.map(shellEscape).join(" ");
// TODO: implement 'shellredir'
if (util.OS.isWindows && !/sh/.test(shell.leafName)) {
if (config.OS.isWindows && !/sh/.test(shell.leafName)) {
command = "cd /D " + this.cwd.path + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path;
var res = this.run(shell, shcf.split(/\s+/).concat(command), callback ? async : true);
}
else {
cmd.write("cd " + escape(this.cwd.path) + "\n" +
["exec", ">" + escape(stdout.path), "2>&1", "<" + escape(stdin.path),
escape(shell.path), shcf, escape(command)].join(" "));
cmd.write("cd " + shellEscape(this.cwd.path) + "\n" +
["exec", ">" + shellEscape(stdout.path), "2>&1", "<" + shellEscape(stdin.path),
shellEscape(shell.path), shcf, shellEscape(command)].join(" "));
res = this.run("/bin/sh", ["-e", cmd.path], callback ? async : true);
}
@@ -556,7 +556,7 @@ var IO = Module("io", {
const rtpvar = config.idName + "_RUNTIME";
let rtp = services.environment.get(rtpvar);
if (!rtp) {
rtp = "~/" + (util.OS.isWindows ? "" : ".") + config.name;
rtp = "~/" + (config.OS.isWindows ? "" : ".") + config.name;
services.environment.set(rtpvar, rtp);
}
return rtp;
@@ -644,7 +644,7 @@ var IO = Module("io", {
commands.add(["mks[yntax]"],
"Generate a Vim syntax file",
function (args) {
let runtime = util.OS.isWindows ? "~/vimfiles/" : "~/.vim/";
let runtime = config.OS.isWindows ? "~/vimfiles/" : "~/.vim/";
let file = io.File(runtime + "syntax/" + config.name + ".vim");
if (args.length)
file = io.File(args[0]);
@@ -886,7 +886,7 @@ unlet s:cpo_save
completion.environment = function environment(context) {
context.title = ["Environment Variable", "Value"];
context.generate = function ()
io.system(util.OS.isWindows ? "set" : "env")
io.system(config.OS.isWindows ? "set" : "env")
.output.split("\n")
.filter(function (line) line.indexOf("=") > 0)
.map(function (line) line.match(/([^=]+)=(.*)/).slice(1));
@@ -956,7 +956,7 @@ unlet s:cpo_save
completion.shellCommand = function shellCommand(context) {
context.title = ["Shell Command", "Path"];
context.generate = function () {
let dirNames = services.environment.get("PATH").split(util.OS.isWindows ? ";" : ":");
let dirNames = services.environment.get("PATH").split(config.OS.pathListSep);
let commands = [];
for (let [, dirName] in Iterator(dirNames)) {
@@ -987,7 +987,7 @@ unlet s:cpo_save
if (!match.path) {
context.key = match.proto;
context.advance(match.proto.length);
context.generate = function () util.chromePackages.map(function (p) [p, match.proto + p + "/"]);
context.generate = function () config.chromePackages.map(function (p) [p, match.proto + p + "/"]);
}
else if (match.scheme === "chrome") {
context.key = match.prefix;
@@ -1001,7 +1001,7 @@ unlet s:cpo_save
}
if (!match || match.scheme === "resource" && match.path)
if (/^(\.{0,2}|~)\/|^file:/.test(context.filter)
|| util.OS.isWindows && /^[a-z]:/i.test(context.filter)
|| config.OS.isWindows && /^[a-z]:/i.test(context.filter)
|| util.getFile(context.filter)
|| io.isJarURL(context.filter))
completion.file(context, full);
@@ -1030,7 +1030,7 @@ unlet s:cpo_save
const { completion, options } = modules;
var shell, shellcmdflag;
if (util.OS.isWindows) {
if (config.OS.isWindows) {
shell = "cmd.exe";
shellcmdflag = "/c";
}
@@ -1077,7 +1077,7 @@ unlet s:cpo_save
"string", shellcmdflag,
{
getter: function (value) {
if (this.hasChanged || !util.OS.isWindows)
if (this.hasChanged || !config.OS.isWindows)
return value;
return /sh/.test(options["shell"]) ? "-c" : "/c";
}

View File

@@ -8,7 +8,7 @@ try {
Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("overlay", {
exports: ["ModuleBase"],
exports: ["ModuleBase", "overlay"],
require: ["config", "io", "services", "util"]
}, this);
@@ -28,11 +28,13 @@ var ModuleBase = Class("ModuleBase", {
var Overlay = Module("Overlay", {
init: function init() {
let overlay = this;
services["dactyl:"]; // Hack. Force module initialization.
config.loadStyles();
util.overlayWindow(config.overlayChrome, function overlay(window) ({
util.overlayWindow(config.overlayChrome, function _overlay(window) ({
init: function onInit(document) {
/**
* @constructor Module
@@ -308,9 +310,15 @@ var Overlay = Module("Overlay", {
defineModule.loadLog.push("Loaded in " + (Date.now() - start) + "ms");
util.dump(overlay);
overlay.windows = array.uniq(overlay.windows.concat(window), true);
modules.events.listen(window, "unload", function onUnload() {
window.removeEventListener("unload", onUnload.wrapped, false);
overlay.windows = overlay.windows.filter(function (w) w != window);
for each (let mod in modules.moduleList.reverse()) {
mod.stale = true;
@@ -320,7 +328,19 @@ var Overlay = Module("Overlay", {
}, false);
}
}));
}
},
/**
* The most recently active dactyl window.
*/
get activeWindow() this.windows[0],
set activeWindow(win) this.windows = [win].concat(this.windows.filter(function (w) w != win)),
/**
* A list of extant dactyl windows.
*/
windows: Class.memoize(function () [])
});
endModule();

View File

@@ -702,7 +702,7 @@ var Styles = Module("Styles", {
}));
},
completion: function (dactyl, modules, window) {
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
const names = Array.slice(DOM(<div/>, window.document).style);
modules.completion.css = function (context) {
context.title = ["CSS Property"];
context.keys = { text: function (p) p + ":", description: function () "" };

File diff suppressed because it is too large Load Diff