From 95626d48a052175195f7967194a44bf2888b180d Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Wed, 15 Jul 2020 15:23:26 -0500 Subject: [PATCH] Add explicit DeepForge.unregisterAction. Fixes #1772 (#1773) --- src/common/globals.js | 4 ++-- .../ForgeActionButton/ForgeActionButton.js | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/common/globals.js b/src/common/globals.js index f5f8e4428..2ba70b71a 100644 --- a/src/common/globals.js +++ b/src/common/globals.js @@ -319,7 +319,7 @@ define([ DeepForge.registerAction = function(name, icon='add', priority=2, action) { if (this._actionButton) { - this._actionButton.addAction({name, icon, priority, action}); + this._actionButton.registerAction({name, icon, priority, action}); } else { this._actions.push(arguments); } @@ -327,7 +327,7 @@ define([ DeepForge.unregisterAction = function(name) { if (this._actionButton) { - this._actionButton.removeAction(name); + this._actionButton.unregisterAction(name); } }; diff --git a/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js b/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js index f6e4af592..33929ee62 100644 --- a/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js +++ b/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js @@ -41,10 +41,11 @@ define([ 'use strict'; var NEW_OPERATION_ID = '__NEW_OPERATION__'; - var ForgeActionButton= function (layoutManager, params) { + var ForgeActionButton = function (layoutManager, params) { PluginButton.call(this, layoutManager, params); this._client = this.client; this._actions = []; + this._registry = []; this._blobClient = new BlobClient({ logger: this.logger.fork('BlobClient') }); @@ -124,7 +125,7 @@ define([ } } - return actions; + return actions.concat(this._registry); }; ForgeActionButton.prototype.getDefinedActionsFor = function(basename, node) { @@ -170,13 +171,17 @@ define([ } }; - ForgeActionButton.prototype.removeAction = function(name, update=true) { - const action = this.buttons[name]; - const index = this._actions.indexOf(action); + ForgeActionButton.prototype.registerAction = function(action, update=true) { + this._registry.push(action); + this.addAction(action, update); + }; + + ForgeActionButton.prototype.unregisterAction = function(name, update=true) { + const index = this._registry.findIndex(action => action.name === name); if (index > -1) { - this._actions.indexOf(action); + this._actions.splice(index, 1); } - delete this.buttons[name]; + if (update) { this.update(); }