]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/addons.jsm
Import 1.0rc1 supporting Firefox up to 11.*
[dactyl.git] / common / modules / addons.jsm
index 6f43950c46b44649bcb836869c4ecddb1ce5335b..c1e4e335514f8627d69e40dd70fdcc58b78ada50 100644 (file)
@@ -3,15 +3,14 @@
 //
 // 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 */
 
 try {
 
 Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("addons", {
     exports: ["AddonManager", "Addons", "Addon", "addons"],
-    require: ["services"],
-    use: ["completion", "config", "io", "messages", "prefs", "template", "util"]
+    require: ["services"]
 }, this);
 
 var callResult = function callResult(method) {
@@ -59,7 +58,6 @@ var updateAddons = Class("UpgradeListener", AddonListener, {
 
     },
     onUpdateAvailable: function (addon, install) {
-        util.dump("onUpdateAvailable");
         this.upgrade.push(addon);
         install.addListener(this);
         install.install();
@@ -76,7 +74,7 @@ var updateAddons = Class("UpgradeListener", AddonListener, {
 
 var actions = {
     delete: {
-        name: "extde[lete]",
+        name: ["extde[lete]", "extrm"],
         description: "Uninstall an extension",
         action: callResult("uninstall"),
         perm: "uninstall"
@@ -111,15 +109,16 @@ 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.flushCache();
             util.timeout(function () {
                 addon.userDisabled = true;
                 addon.userDisabled = false;
             });
         },
         get filter() {
-            let ids = Set(keys(JSON.parse(prefs.get("extensions.bootstrappedAddons", "{}"))));
-            return function ({ item }) !item.userDisabled && Set.has(ids, item.id);
+            return function ({ item }) !item.userDisabled &&
+                !(item.operationsRequiringRestart & (AddonManager.OP_NEEDS_RESTART_ENABLE | AddonManager.OP_NEEDS_RESTART_DISABLE))
         },
         perm: "disable"
     },
@@ -150,7 +149,6 @@ var Addon = Class("Addon", {
             <tr highlight="Addon" key="row" xmlns:dactyl={NS} xmlns={XHTML}>
                 <td highlight="AddonName" key="name"/>
                 <td highlight="AddonVersion" key="version"/>
-                <td highlight="AddonStatus" key="status"/>
                 <td highlight="AddonButtons Buttons">
                     <a highlight="Button" href="javascript:0" key="enable">{_("addon.action.On")}</a>
                     <a highlight="Button" href="javascript:0" key="disable">{_("addon.action.Off")}</a>
@@ -158,6 +156,7 @@ var Addon = Class("Addon", {
                     <a highlight="Button" href="javascript:0" key="update">{_("addon.action.Update")}</a>
                     <a highlight="Button" href="javascript:0" key="options">{_("addon.action.Options")}</a>
                 </td>
+                <td highlight="AddonStatus" key="status"/>
                 <td highlight="AddonDescription" key="description"/>
             </tr>,
             this.list.document, this.nodes);
@@ -225,6 +224,7 @@ var Addon = Class("Addon", {
         this.nodes.version.textContent = this.version;
         update("status", this.statusInfo);
         this.nodes.description.textContent = this.description;
+        DOM(this.nodes.row).attr("active", this.isActive || null);
 
         for (let node in values(this.nodes))
             if (node.update && node.update !== callee)
@@ -278,15 +278,15 @@ var AddonList = Class("AddonList", {
         this.update();
     },
 
-    message: Class.memoize(function () {
+    message: Class.Memoize(function () {
 
         XML.ignoreWhitespace = true;
         util.xmlToDom(<table highlight="Addons" key="list" xmlns={XHTML}>
                         <tr highlight="AddonHead">
                             <td>{_("title.Name")}</td>
                             <td>{_("title.Version")}</td>
-                            <td>{_("title.Status")}</td>
                             <td/>
+                            <td>{_("title.Status")}</td>
                             <td>{_("title.Description")}</td>
                         </tr>
                       </table>, this.document, this.nodes);
@@ -348,7 +348,7 @@ var AddonList = Class("AddonList", {
 });
 
 var Addons = Module("addons", {
-    errors: Class.memoize(function ()
+    errors: Class.Memoize(function ()
             array(["ERROR_NETWORK_FAILURE", "ERROR_INCORRECT_HASH",
                    "ERROR_CORRUPT_FILE", "ERROR_FILE_ACCESS"])
                 .map(function (e) [AddonManager[e], _("AddonManager." + e)])
@@ -425,11 +425,10 @@ var Addons = Module("addons", {
 
                     AddonManager.getAddonsByTypes(args["-types"], dactyl.wrapCallback(function (list) {
                         if (!args.bang || command.bang) {
-                            list = list.filter(function (extension) extension.name == name);
-                            if (list.length == 0)
-                                return void dactyl.echoerr(_("error.invalidArgument", name));
-                            if (!list.every(ok))
-                                return void dactyl.echoerr(_("error.invalidOperation"));
+                            list = list.filter(function (addon) addon.id == name || addon.name == name);
+                            dactyl.assert(list.length, _("error.invalidArgument", name));
+                            dactyl.assert(list.some(ok), _("error.invalidOperation"));
+                            list = list.filter(ok);
                         }
                         if (command.actions)
                             command.actions(list, this.modules);
@@ -440,7 +439,7 @@ var Addons = Module("addons", {
                     argCount: "?", // FIXME: should be "1"
                     bang: true,
                     completer: function (context, args) {
-                        completion.extension(context, args["-types"]);
+                        completion.addon(context, args["-types"]);
                         context.filters.push(function ({ item }) ok(item));
                         if (command.filter)
                             context.filters.push(command.filter);
@@ -478,10 +477,14 @@ var Addons = Module("addons", {
             };
         };
 
-        completion.extension = function extension(context, types) {
-            context.title = ["Extension"];
+        completion.addon = function addon(context, types) {
+            context.title = ["Add-on"];
             context.anchored = false;
-            context.keys = { text: "name", description: "description", icon: "iconURL" },
+            context.keys = {
+                text: function (addon) [addon.name, addon.id],
+                description: "description",
+                icon: "iconURL"
+            };
             context.generate = function () {
                 context.incomplete = true;
                 AddonManager.getAddonsByTypes(types || ["extension"], function (addons) {
@@ -539,7 +542,7 @@ else
                     return "";
                 },
 
-                installLocation: Class.memoize(function () services.extensionManager.getInstallLocation(this.id)),
+                installLocation: Class.Memoize(function () services.extensionManager.getInstallLocation(this.id)),
                 getResourceURI: function getResourceURI(path) {
                     let file = this.installLocation.getItemFile(this.id, path);
                     return services.io.newFileURI(file);