From b1b349b389f5926accd3d1e72adc255dcf491d2a Mon Sep 17 00:00:00 2001 From: Ian Neal Date: Sun, 27 Jun 2021 03:30:17 +0100 Subject: [PATCH] Bug 1718428 - Tidy up existing plugin code in cZ. r=frg --- suite/chatzilla/js/lib/command-manager.js | 8 +- suite/chatzilla/xul/content/commands.js | 99 +++++++++++------------ suite/chatzilla/xul/content/static.js | 1 + 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/suite/chatzilla/js/lib/command-manager.js b/suite/chatzilla/js/lib/command-manager.js index d159a1cbbd..8cf595fb5d 100644 --- a/suite/chatzilla/js/lib/command-manager.js +++ b/suite/chatzilla/js/lib/command-manager.js @@ -199,8 +199,7 @@ function cmgr_defcmds(cmdary) * @param name The |String| name of the command to define. * @param func A |Function| to call to handle dispatch of the new command. * @param flags Optional. A |Number| indicating any special requirements for the - * command. The |CommandManager| only checks for |CMD_NO_HELP|; - * flags are stored unchanged. + * command. * @param usage Optional. A |String| specifying the arguments to the command. If * not specified, the property string "cmd." + |name| + ".params" * is read from |bundle| or |defaultBundle|. @@ -214,16 +213,13 @@ function cmdmgr_defcmd(name, func, flags, usage, bundle) if (!bundle) bundle = this.defaultBundle; - var helpDefault; + var helpDefault = MSG_NO_HELP; var labelDefault = name; var aliasFor; if (typeof flags != "number") flags = this.defaultFlags; - if (flags & CMD_NO_HELP) - helpDefault = MSG_NO_HELP; - if (typeof usage != "string") usage = getMsgFrom(bundle, "cmd." + name + ".params", null, ""); diff --git a/suite/chatzilla/xul/content/commands.js b/suite/chatzilla/xul/content/commands.js index 138f71ec1a..0a062809f6 100644 --- a/suite/chatzilla/xul/content/commands.js +++ b/suite/chatzilla/xul/content/commands.js @@ -9,7 +9,6 @@ const CMD_NEED_NET = 0x02; const CMD_NEED_SRV = 0x04; const CMD_NEED_CHAN = 0x08; const CMD_NEED_USER = 0x10; -const CMD_NO_HELP = 0x20; function initCommands() { @@ -67,11 +66,11 @@ function initCommands() ["default-charset", cmdCharset, CMD_CONSOLE], ["delete-view", cmdDeleteView, CMD_CONSOLE], ["desc", cmdDesc, CMD_CONSOLE], - ["disable-plugin", cmdAblePlugin, CMD_CONSOLE], + ["disable-plugin", cmdDisablePlugin, CMD_CONSOLE], ["disconnect", cmdDisconnect, CMD_NEED_SRV | CMD_CONSOLE], ["disconnect-all", cmdDisconnectAll, CMD_CONSOLE], ["echo", cmdEcho, CMD_CONSOLE], - ["enable-plugin", cmdAblePlugin, CMD_CONSOLE], + ["enable-plugin", cmdEnablePlugin, CMD_CONSOLE], ["eval", cmdEval, CMD_CONSOLE], ["evalsilent", cmdEval, CMD_CONSOLE], ["except", cmdBanOrExcept, CMD_NEED_CHAN | CMD_CONSOLE], @@ -238,7 +237,7 @@ function initCommands() cmdary.stringBundle = client.defaultBundle; client.commandManager = new CommandManager(client.defaultBundle); - client.commandManager.defaultFlags = CMD_NO_HELP | CMD_CONSOLE; + client.commandManager.defaultFlags = CMD_CONSOLE; client.commandManager.isCommandSatisfied = isCommandSatisfied; client.commandManager.defineCommands(cmdary); @@ -793,69 +792,67 @@ function getToggle (toggle, currentState) * command definitions from here on down. */ -function cmdAblePlugin(e) +function cmdDisablePlugin(e) { - if (e.command.name == "disable-plugin") + if (!e.plugin.enabled) { - if (!e.plugin.enabled) - { - display(getMsg(MSG_IS_DISABLED, e.plugin.id)); - return; - } + display(getMsg(MSG_IS_DISABLED, e.plugin.id)); + return; + } - if (e.plugin.API > 0) - { - if (!e.plugin.disable()) - { - display(getMsg(MSG_CANT_DISABLE, e.plugin.id)); - return; - } - e.plugin.prefs["enabled"] = false; - } - else if (!("disablePlugin" in e.plugin.scope)) + if (e.plugin.API > 0) + { + if (!e.plugin.disable()) { display(getMsg(MSG_CANT_DISABLE, e.plugin.id)); return; } - else - { - e.plugin.scope.disablePlugin(); - } - - display(getMsg(MSG_PLUGIN_DISABLED, e.plugin.id)); - e.plugin.enabled = false; + e.plugin.prefs["enabled"] = false; + } + else if (!("disablePlugin" in e.plugin.scope)) + { + display(getMsg(MSG_CANT_DISABLE, e.plugin.id)); + return; } else { - if (e.plugin.enabled) - { - display(getMsg(MSG_IS_ENABLED, e.plugin.id)); - return; - } + e.plugin.scope.disablePlugin(); + } - if (e.plugin.API > 0) - { - if (!e.plugin.enable()) - { - display(getMsg(MSG_CANT_ENABLE, e.plugin.id)); - e.plugin.prefs["enabled"] = false; - return; - } - e.plugin.prefs["enabled"] = true; - } - else if (!("enablePlugin" in e.plugin.scope)) + display(getMsg(MSG_PLUGIN_DISABLED, e.plugin.id)); + e.plugin.enabled = false; +} + +function cmdEnablePlugin(e) +{ + if (e.plugin.enabled) + { + display(getMsg(MSG_IS_ENABLED, e.plugin.id)); + return; + } + + if (e.plugin.API > 0) + { + if (!e.plugin.enable()) { display(getMsg(MSG_CANT_ENABLE, e.plugin.id)); + e.plugin.prefs["enabled"] = false; return; } - else - { - e.plugin.scope.enablePlugin(); - } - - display(getMsg(MSG_PLUGIN_ENABLED, e.plugin.id)); - e.plugin.enabled = true; + e.plugin.prefs["enabled"] = true; } + else if (!("enablePlugin" in e.plugin.scope)) + { + display(getMsg(MSG_CANT_ENABLE, e.plugin.id)); + return; + } + else + { + e.plugin.scope.enablePlugin(); + } + + display(getMsg(MSG_PLUGIN_ENABLED, e.plugin.id)); + e.plugin.enabled = true; } function cmdBanOrExcept(e) diff --git a/suite/chatzilla/xul/content/static.js b/suite/chatzilla/xul/content/static.js index d452343b70..f64fee40cf 100644 --- a/suite/chatzilla/xul/content/static.js +++ b/suite/chatzilla/xul/content/static.js @@ -3040,6 +3040,7 @@ function cli_installPlugin(name, source) display(getMsg(MSG_INSTALL_PLUGIN_INSTALLING, [source.path, dest.path]), MT_INFO); + var ary; if (source.path.match(/\.(jar|zip)$/i)) { try