Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/common/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define([
_,
Q
) {
var DeepForge = {},
var DeepForge = {_actions: []},
placesTerritoryId,
client = WebGMEGlobal.Client,
GetOperationCode = _.template(DefaultCodeTpl),
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 23 additions & 2 deletions src/visualizers/panels/ForgeActionButton/ForgeActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down