Skip to content

Commit

Permalink
Add explicit DeepForge.unregisterAction. Fixes #1772 (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb authored Jul 15, 2020
1 parent 5a62fea commit 95626d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/common/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ 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);
}
};

DeepForge.unregisterAction = function(name) {
if (this._actionButton) {
this._actionButton.removeAction(name);
this._actionButton.unregisterAction(name);
}
};

Expand Down
19 changes: 12 additions & 7 deletions src/visualizers/panels/ForgeActionButton/ForgeActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
Expand Down Expand Up @@ -124,7 +125,7 @@ define([
}
}

return actions;
return actions.concat(this._registry);
};

ForgeActionButton.prototype.getDefinedActionsFor = function(basename, node) {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 95626d4

Please sign in to comment.