diff --git a/src/common/globals.js b/src/common/globals.js index cae27e78f..f5f8e4428 100644 --- a/src/common/globals.js +++ b/src/common/globals.js @@ -21,7 +21,7 @@ define([ _, Q ) { - var DeepForge = {}, + var DeepForge = {_actions: []}, placesTerritoryId, client = WebGMEGlobal.Client, GetOperationCode = _.template(DefaultCodeTpl), @@ -310,6 +310,27 @@ define([ await runArtifactPlugin(IMPORT_PLUGIN, metadata); }; + DeepForge.registerActionButton = function(button) { + DeepForge._actionButton = button; + while (this._actions.length) { + this.registerAction(...this._actions.shift()); + } + }; + + DeepForge.registerAction = function(name, icon='add', priority=2, action) { + if (this._actionButton) { + this._actionButton.addAction({name, icon, priority, action}); + } else { + this._actions.push(arguments); + } + }; + + DeepForge.unregisterAction = function(name) { + if (this._actionButton) { + this._actionButton.removeAction(name); + } + }; + //////////////////// DeepForge prev locations //////////////////// // Update DeepForge on project changed WebGMEGlobal.State.on('change:' + CONSTANTS.STATE_ACTIVE_PROJECT_NAME, diff --git a/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js b/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js index 8fbd07b36..f6e4af592 100644 --- a/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js +++ b/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js @@ -52,6 +52,7 @@ define([ Execute.call(this, this.client, this.logger); this.initializeKeyListener(); this.logger.debug('ctor finished'); + DeepForge.registerActionButton(this); }; // inherit from PanelBaseWithHeader @@ -151,16 +152,36 @@ define([ for (i = this._actions.length; i--;) { delete this.buttons[this._actions[i].name]; } + this._actions = []; // Get node name and look up actions for (i = actions.length; i--;) { - this.buttons[actions[i].name] = actions[i]; + this.addAction(actions[i], false); } - this._actions = actions; this.update(); }; + ForgeActionButton.prototype.addAction = function(action, update=true) { + this.buttons[action.name] = action; + this._actions.push(action); + if (update) { + this.update(); + } + }; + + ForgeActionButton.prototype.removeAction = function(name, update=true) { + const action = this.buttons[name]; + const index = this._actions.indexOf(action); + if (index > -1) { + this._actions.indexOf(action); + } + delete this.buttons[name]; + if (update) { + this.update(); + } + }; + // Helper functions REMOVE! FIXME ForgeActionButton.prototype.addToMetaSheet = function(nodeId, metasheetName) { var root = this.client.getNode(GME_CONSTANTS.PROJECT_ROOT_ID),