Skip to content

Commit b203e79

Browse files
authored
Register actions for action button. Closes #1741 (#1742)
1 parent 8663343 commit b203e79

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/common/globals.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define([
2121
_,
2222
Q
2323
) {
24-
var DeepForge = {},
24+
var DeepForge = {_actions: []},
2525
placesTerritoryId,
2626
client = WebGMEGlobal.Client,
2727
GetOperationCode = _.template(DefaultCodeTpl),
@@ -310,6 +310,27 @@ define([
310310
await runArtifactPlugin(IMPORT_PLUGIN, metadata);
311311
};
312312

313+
DeepForge.registerActionButton = function(button) {
314+
DeepForge._actionButton = button;
315+
while (this._actions.length) {
316+
this.registerAction(...this._actions.shift());
317+
}
318+
};
319+
320+
DeepForge.registerAction = function(name, icon='add', priority=2, action) {
321+
if (this._actionButton) {
322+
this._actionButton.addAction({name, icon, priority, action});
323+
} else {
324+
this._actions.push(arguments);
325+
}
326+
};
327+
328+
DeepForge.unregisterAction = function(name) {
329+
if (this._actionButton) {
330+
this._actionButton.removeAction(name);
331+
}
332+
};
333+
313334
//////////////////// DeepForge prev locations ////////////////////
314335
// Update DeepForge on project changed
315336
WebGMEGlobal.State.on('change:' + CONSTANTS.STATE_ACTIVE_PROJECT_NAME,

src/visualizers/panels/ForgeActionButton/ForgeActionButton.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ define([
5252
Execute.call(this, this.client, this.logger);
5353
this.initializeKeyListener();
5454
this.logger.debug('ctor finished');
55+
DeepForge.registerActionButton(this);
5556
};
5657

5758
// inherit from PanelBaseWithHeader
@@ -151,16 +152,36 @@ define([
151152
for (i = this._actions.length; i--;) {
152153
delete this.buttons[this._actions[i].name];
153154
}
155+
this._actions = [];
154156

155157
// Get node name and look up actions
156158
for (i = actions.length; i--;) {
157-
this.buttons[actions[i].name] = actions[i];
159+
this.addAction(actions[i], false);
158160
}
159161

160-
this._actions = actions;
161162
this.update();
162163
};
163164

165+
ForgeActionButton.prototype.addAction = function(action, update=true) {
166+
this.buttons[action.name] = action;
167+
this._actions.push(action);
168+
if (update) {
169+
this.update();
170+
}
171+
};
172+
173+
ForgeActionButton.prototype.removeAction = function(name, update=true) {
174+
const action = this.buttons[name];
175+
const index = this._actions.indexOf(action);
176+
if (index > -1) {
177+
this._actions.indexOf(action);
178+
}
179+
delete this.buttons[name];
180+
if (update) {
181+
this.update();
182+
}
183+
};
184+
164185
// Helper functions REMOVE! FIXME
165186
ForgeActionButton.prototype.addToMetaSheet = function(nodeId, metasheetName) {
166187
var root = this.client.getNode(GME_CONSTANTS.PROJECT_ROOT_ID),

0 commit comments

Comments
 (0)