Skip to content

Commit 95626d4

Browse files
authored
Add explicit DeepForge.unregisterAction. Fixes #1772 (#1773)
1 parent 5a62fea commit 95626d4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/common/globals.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ define([
319319

320320
DeepForge.registerAction = function(name, icon='add', priority=2, action) {
321321
if (this._actionButton) {
322-
this._actionButton.addAction({name, icon, priority, action});
322+
this._actionButton.registerAction({name, icon, priority, action});
323323
} else {
324324
this._actions.push(arguments);
325325
}
326326
};
327327

328328
DeepForge.unregisterAction = function(name) {
329329
if (this._actionButton) {
330-
this._actionButton.removeAction(name);
330+
this._actionButton.unregisterAction(name);
331331
}
332332
};
333333

src/visualizers/panels/ForgeActionButton/ForgeActionButton.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ define([
4141
'use strict';
4242

4343
var NEW_OPERATION_ID = '__NEW_OPERATION__';
44-
var ForgeActionButton= function (layoutManager, params) {
44+
var ForgeActionButton = function (layoutManager, params) {
4545
PluginButton.call(this, layoutManager, params);
4646
this._client = this.client;
4747
this._actions = [];
48+
this._registry = [];
4849
this._blobClient = new BlobClient({
4950
logger: this.logger.fork('BlobClient')
5051
});
@@ -124,7 +125,7 @@ define([
124125
}
125126
}
126127

127-
return actions;
128+
return actions.concat(this._registry);
128129
};
129130

130131
ForgeActionButton.prototype.getDefinedActionsFor = function(basename, node) {
@@ -170,13 +171,17 @@ define([
170171
}
171172
};
172173

173-
ForgeActionButton.prototype.removeAction = function(name, update=true) {
174-
const action = this.buttons[name];
175-
const index = this._actions.indexOf(action);
174+
ForgeActionButton.prototype.registerAction = function(action, update=true) {
175+
this._registry.push(action);
176+
this.addAction(action, update);
177+
};
178+
179+
ForgeActionButton.prototype.unregisterAction = function(name, update=true) {
180+
const index = this._registry.findIndex(action => action.name === name);
176181
if (index > -1) {
177-
this._actions.indexOf(action);
182+
this._actions.splice(index, 1);
178183
}
179-
delete this.buttons[name];
184+
180185
if (update) {
181186
this.update();
182187
}

0 commit comments

Comments
 (0)