]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/config.jsm
Imported Upstream version 1.1+hg7904
[dactyl.git] / common / modules / config.jsm
index d009e1a4ca602024eae72ffccabb8836abaa9c71..dfae6a549bd318de2160b173c988e3cbba39606b 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
 // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
@@ -9,16 +9,19 @@
 let global = this;
 defineModule("config", {
     exports: ["ConfigBase", "Config", "config"],
-    require: ["dom", "io", "protocol", "services", "util", "template"]
+    require: ["io", "protocol", "services"]
 });
 
 lazyRequire("addons", ["AddonManager"]);
 lazyRequire("cache", ["cache"]);
+lazyRequire("dom", ["DOM"]);
 lazyRequire("highlight", ["highlight"]);
 lazyRequire("messages", ["_"]);
 lazyRequire("prefs", ["localPrefs", "prefs"]);
 lazyRequire("storage", ["storage", "File"]);
 lazyRequire("styles", ["Styles"]);
+lazyRequire("template", ["template"]);
+lazyRequire("util", ["util"]);
 
 function AboutHandler() {}
 AboutHandler.prototype = {
@@ -45,19 +48,30 @@ var ConfigBase = Class("ConfigBase", {
      * initialization code. Must call superclass's init function.
      */
     init: function init() {
-        this.loadConfig();
+        if (!config.haveGecko("26"))
+            this.modules.global = this.modules.global.filter(m => m != "downloads"); // FIXME
 
-        this.features.push = deprecated("Set.add", function push(feature) Set.add(this, feature));
-        if (this.haveGecko("2b"))
-            Set.add(this.features, "Gecko2");
+        this.loadConfig();
 
-        JSMLoader.registerFactory(JSMLoader.Factory(AboutHandler));
-        JSMLoader.registerFactory(JSMLoader.Factory(
-            Protocol("dactyl", "{9c8f2530-51c8-4d41-b356-319e0b155c44}",
-                     "resource://dactyl-content/")));
+        util.trapErrors(() => {
+            JSMLoader.registerFactory(JSMLoader.Factory(AboutHandler));
+        });
+        util.withProperErrors(() => {
+            JSMLoader.registerFactory(JSMLoader.Factory(
+                Protocol("dactyl", "{9c8f2530-51c8-4d41-b356-319e0b155c44}",
+                         "resource://dactyl-content/")));
+        });
 
+        this.protocolLoaded = true;
         this.timeout(function () {
-            cache.register("config.dtd", () => util.makeDTD(config.dtd));
+            cache.register("config.dtd", () => util.makeDTD(config.dtd),
+                           true);
+        });
+
+        // FIXME: May not be ready before first window opens.
+        AddonManager.getAddonByID("{972ce4c6-7e08-4474-a285-3208198ce6fd}", a => {
+            if (!a.isActive)
+                config.features.delete("default-theme");
         });
 
         services["dactyl:"].pages["dtd"] = () => [null, cache.get("config.dtd")];
@@ -70,7 +84,7 @@ var ConfigBase = Class("ConfigBase", {
 
     get prefs() localPrefs,
 
-    get has() Set.has(this.features),
+    has: function (feature) this.features.has(feature),
 
     configFiles: [
         "resource://dactyl-common/config.json",
@@ -81,7 +95,7 @@ var ConfigBase = Class("ConfigBase", {
 
     loadConfig: function loadConfig(documentURL) {
 
-        for each (let config in this.configs) {
+        for (let config of this.configs) {
             if (documentURL)
                 config = config.overlays && config.overlays[documentURL] || {};
 
@@ -90,6 +104,9 @@ var ConfigBase = Class("ConfigBase", {
 
                 if (isArray(this[prop]))
                     this[prop] = [].concat(this[prop], value);
+                else if (isinstance(this[prop], ["Set"]))
+                    for (let key of value)
+                        this[prop].add(key);
                 else if (isObject(this[prop])) {
                     if (isArray(value))
                         value = Set(value);
@@ -126,6 +143,7 @@ var ConfigBase = Class("ConfigBase", {
                  "options",
                  "overlay",
                  "prefs",
+                 ["promises", "Promise", "Task", "promises"],
                  "protocol",
                  "sanitizer",
                  "services",
@@ -157,17 +175,6 @@ var ConfigBase = Class("ConfigBase", {
         highlight.loadCSS(this.helpCSS.replace(/__MSG_(.*?)__/g,
                                                (m0, m1) => _(m1)));
 
-        if (!this.haveGecko("2b"))
-            highlight.loadCSS(literal(/*
-                !TabNumber               font-weight: bold; margin: 0px; padding-right: .8ex;
-                !TabIconNumber  {
-                    font-weight: bold;
-                    color: white;
-                    text-align: center;
-                    text-shadow: black -1px 0 1px, black 0 1px 1px, black 1px 0 1px, black 0 -1px 1px;
-                }
-            */));
-
         let hl = highlight.set("Find", "");
         hl.onChange = function () {
             function hex(val) ("#" + util.regexp.iterate(/\d+/g, val)
@@ -246,7 +253,7 @@ var ConfigBase = Class("ConfigBase", {
     bestLocale: function (list) {
         return values([this.appLocale, this.appLocale.replace(/-.*/, ""),
                        "en", "en-US", list[0]])
-            .nth(Set.has(Set(list)), 0);
+            .find(bind("has", RealSet(list)));
     },
 
     /**
@@ -256,7 +263,7 @@ var ConfigBase = Class("ConfigBase", {
         // Horrible hack.
         let res = {};
         function process(manifest) {
-            for each (let line in manifest.split(/\n+/)) {
+            for (let line of manifest.split(/\n+/)) {
                 let match = /^\s*(content|skin|locale|resource)\s+([^\s#]+)\s/.exec(line);
                 if (match)
                     res[match[2]] = true;
@@ -274,7 +281,7 @@ var ConfigBase = Class("ConfigBase", {
                 }
         }
 
-        for each (let dir in ["UChrm", "AChrom"]) {
+        for (let dir of ["UChrm", "AChrom"]) {
             dir = File(services.directory.get(dir, Ci.nsIFile));
             if (dir.exists() && dir.isDirectory())
                 for (let file in dir.iterDirectory())
@@ -401,7 +408,7 @@ var ConfigBase = Class("ConfigBase", {
     dtd: Class.Memoize(function ()
         iter(this.dtdExtra,
              (["dactyl." + k, v] for ([k, v] in iter(config.dtdDactyl))),
-             (["dactyl." + s, config[s]] for each (s in config.dtdStrings)))
+             (["dactyl." + s, config[s]] for (s of config.dtdStrings)))
             .toObject()),
 
     dtdDactyl: memoize({
@@ -458,7 +465,7 @@ var ConfigBase = Class("ConfigBase", {
                     ["menupopup", { id: "viewSidebarMenu", xmlns: "xul" }],
                     ["broadcasterset", { id: "mainBroadcasterSet", xmlns: "xul" }]];
 
-            for each (let [id, [name, key, uri]] in Iterator(this.sidebars)) {
+            for (let [id, [name, key, uri]] in Iterator(this.sidebars)) {
                 append[0].push(
                         ["menuitem", { observes: "pentadactyl-" + id + "Sidebar", label: name,
                                        accesskey: key }]);
@@ -539,7 +546,7 @@ var ConfigBase = Class("ConfigBase", {
      *    dactyl.has(feature) to check for a feature's presence
      *    in this array.
      */
-    features: {},
+    features: RealSet(["default-theme"]),
 
     /**
      * @property {string} The file extension used for command script files.
@@ -586,7 +593,7 @@ config.INIT = update(Object.create(config.INIT), config.INIT, {
     init: function init(dactyl, modules, window) {
         init.superapply(this, arguments);
 
-        let img = window.Image();
+        let img = new window.Image;
         img.src = this.logo || "resource://dactyl-local-content/logo.png";
         img.onload = util.wrapCallback(function () {
             highlight.loadCSS(literal(/*