]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/addons.jsm
Import 1.0 supporting Firefox up to 14.*
[dactyl.git] / common / modules / addons.jsm
index c1e4e335514f8627d69e40dd70fdcc58b78ada50..8ea7f8a4a6414a0016ffd0c77f13a9dd9c398d17 100644 (file)
@@ -83,14 +83,14 @@ var actions = {
         name: "exte[nable]",
         description: "Enable an extension",
         action: function (addon) { addon.userDisabled = false; },
-        filter: function ({ item }) item.userDisabled,
+        filter: function (addon) addon.userDisabled,
         perm: "enable"
     },
     disable: {
         name: "extd[isable]",
         description: "Disable an extension",
         action: function (addon) { addon.userDisabled = true; },
-        filter: function ({ item }) !item.userDisabled,
+        filter: function (addon) !addon.userDisabled,
         perm: "disable"
     },
     options: {
@@ -103,7 +103,7 @@ var actions = {
             else
                 this.dactyl.open(addon.optionsURL, { from: "extoptions" });
         },
-        filter: function ({ item }) item.isActive && item.optionsURL
+        filter: function (addon) addon.isActive && addon.optionsURL
     },
     rehash: {
         name: "extr[ehash]",
@@ -117,8 +117,8 @@ var actions = {
             });
         },
         get filter() {
-            return function ({ item }) !item.userDisabled &&
-                !(item.operationsRequiringRestart & (AddonManager.OP_NEEDS_RESTART_ENABLE | AddonManager.OP_NEEDS_RESTART_DISABLE))
+            return function (addon) !addon.userDisabled &&
+                !(addon.operationsRequiringRestart & (AddonManager.OP_NEEDS_RESTART_ENABLE | AddonManager.OP_NEEDS_RESTART_DISABLE))
         },
         perm: "disable"
     },
@@ -170,7 +170,7 @@ var Addon = Class("Addon", {
         let action = actions[cmd];
         if ("perm" in action && !(this.permissions & AddonManager["PERM_CAN_" + action.perm.toUpperCase()]))
             return false;
-        if ("filter" in action && !action.filter({ item: this }))
+        if ("filter" in action && !action.filter(this))
             return false;
         return true;
     },
@@ -356,7 +356,7 @@ var Addons = Module("addons", {
 }, {
 }, {
     commands: function (dactyl, modules, window) {
-        const { CommandOption, commands, completion } = modules;
+        const { CommandOption, commands, completion, io } = modules;
 
         commands.add(["addo[ns]", "ao"],
             "List installed extensions",
@@ -412,7 +412,7 @@ var Addons = Module("addons", {
         // TODO: handle extension dependencies
         values(actions).forEach(function (command) {
             let perm = command.perm && AddonManager["PERM_CAN_" + command.perm.toUpperCase()];
-            function ok(addon) !perm || addon.permissions & perm;
+            function ok(addon) (!perm || addon.permissions & perm) && (!command.filter || command.filter(addon));
 
             commands.add(Array.concat(command.name),
                 command.description,
@@ -430,6 +430,7 @@ var Addons = Module("addons", {
                             dactyl.assert(list.some(ok), _("error.invalidOperation"));
                             list = list.filter(ok);
                         }
+                        dactyl.assert(list.every(ok));
                         if (command.actions)
                             command.actions(list, this.modules);
                         else
@@ -441,8 +442,6 @@ var Addons = Module("addons", {
                     completer: function (context, args) {
                         completion.addon(context, args["-types"]);
                         context.filters.push(function ({ item }) ok(item));
-                        if (command.filter)
-                            context.filters.push(command.filter);
                     },
                     literal: 0,
                     options: [