ActionRegistry.js 1.2 KB

1234567
  1. export default class ActionRegistry{constructor(){this._actionsById=new Map();this._registerActions();}
  2. _registerActions(){self.runtime.extensions('action').forEach(registerExtension,this);function registerExtension(extension){if(!extension.canInstantiate()){return;}
  3. const actionId=extension.descriptor()['actionId'];console.assert(actionId);console.assert(!this._actionsById.get(actionId));const action=new UI.Action(extension);if(!action.category()||action.title()){this._actionsById.set(actionId,action);}else{console.error(`Category actions require a title for command menu: ${actionId}`);}}}
  4. availableActions(){return this.applicableActions(this._actionsById.keysArray(),UI.context);}
  5. applicableActions(actionIds,context){const extensions=[];actionIds.forEach(function(actionId){const action=this._actionsById.get(actionId);if(action){extensions.push(action.extension());}},this);return context.applicableExtensions(extensions).valuesArray().map(extensionToAction.bind(this));function extensionToAction(extension){return(this.action(extension.descriptor()['actionId']));}}
  6. action(actionId){return this._actionsById.get(actionId)||null;}}
  7. self.UI=self.UI||{};UI=UI||{};UI.ActionRegistry=ActionRegistry;UI.actionRegistry;