]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/contexts.jsm
Import r6923 from upstream hg supporting Firefox up to 22.0a1
[dactyl.git] / common / modules / contexts.jsm
index 6d32fb8358074121eb8a7af5e77263e05f19d8a8..c34d2dded318ad56c02ee56b595b86b86768366c 100644 (file)
@@ -1,16 +1,19 @@
-// Copyright (c) 2010-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2010-2012 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.
-/* use strict */
+"use strict";
 
-Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("contexts", {
     exports: ["Contexts", "Group", "contexts"],
     require: ["services", "util"]
-}, this);
+});
 
-this.lazyRequire("overlay", ["overlay"]);
+lazyRequire("commands", ["ArgType", "CommandOption", "commands"]);
+lazyRequire("options", ["Option"]);
+lazyRequire("overlay", ["overlay"]);
+lazyRequire("storage", ["File"]);
+lazyRequire("template", ["template"]);
 
 var Const = function Const(val) Class.Property({ enumerable: true, value: val });
 
@@ -75,10 +78,11 @@ var Group = Class("Group", {
         return update(siteFilter, {
             toString: function () this.filters.join(","),
 
-            toXML: function (modules) let (uri = modules && modules.buffer.uri)
+            toJSONXML: function (modules) let (uri = modules && modules.buffer.uri)
                 template.map(this.filters,
-                             function (f) <span highlight={uri && f(uri) ? "Filter" : ""}>{f}</span>,
-                             <>,</>),
+                             function (f) ["span", { highlight: uri && f(uri) ? "Filter" : "" },
+                                               "toJSONXML" in f ? f.toJSONXML() : String(f)],
+                             ","),
 
             filters: Option.parse.sitelist(patterns)
         });
@@ -374,7 +378,7 @@ var Contexts = Module("contexts", {
            return {
                 __proto__: frame,
                 filename: this.context.file[0] == "[" ? this.context.file
-                                                      : services.io.newFileURI(File(this.context.file)).spec,
+                                                      : File(this.context.file).URI.spec,
                 lineNumber: this.context.line
             };
         return frame;
@@ -480,10 +484,12 @@ var Contexts = Module("contexts", {
     getDocs: function getDocs(context) {
         try {
             if (isinstance(context, ["Sandbox"])) {
-                let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML && INFO.toXMLString()", context);
-                return info && XML(info);
+                let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML ? INFO.toXMLString() : this.INFO", context);
+                return /^</.test(info) ? XML(info) : info;
             }
-            if (typeof context.INFO == "xml")
+            if (DOM.isJSONXML(context.INFO))
+                return context.INFO;
+            if (typeof context.INFO == "xml" && config.haveGecko(null, "14.*"))
                 return context.INFO;
         }
         catch (e) {}
@@ -663,12 +669,12 @@ var Contexts = Module("contexts", {
                     {
                         names: ["-description", "-desc", "-d"],
                         description: "A description of this group",
-                        default: ["User-defined group"],
+                        default: "User-defined group",
                         type: CommandOption.STRING
                     },
                     {
                         names: ["-locations", "-locs", "-loc", "-l"],
-                        description: ["The URLs for which this group should be active"],
+                        description: "The URLs for which this group should be active",
                         default: ["*"],
                         type: CommandOption.LIST
                     },
@@ -794,7 +800,7 @@ var Contexts = Module("contexts", {
             context.keys = {
                 active: function (group) group.filter(uri),
                 text: "name",
-                description: function (g) <>{g.filter.toXML ? g.filter.toXML(modules) + <>&#xa0;</> : ""}{g.description || ""}</>
+                description: function (g) ["", g.filter.toJSONXML ? g.filter.toJSONXML(modules).concat("\u00a0") : "", g.description || ""]
             };
             context.completions = (active === undefined ? contexts.groupList : contexts.initializedGroups(active))
                                     .slice(0, -1);