Action.js 1.6 KB

12345678910111213141516171819
  1. export default class Action extends Common.Object{constructor(extension){super();this._extension=extension;this._enabled=true;this._toggled=false;}
  2. id(){return this._extension.descriptor()['actionId'];}
  3. extension(){return this._extension;}
  4. execute(){return this._extension.instance().then(handleAction.bind(this));function handleAction(actionDelegate){const actionId=this._extension.descriptor()['actionId'];const delegate=(actionDelegate);return delegate.handleAction(UI.context,actionId);}}
  5. icon(){return this._extension.descriptor()['iconClass']||'';}
  6. toggledIcon(){return this._extension.descriptor()['toggledIconClass']||'';}
  7. toggleWithRedColor(){return!!this._extension.descriptor()['toggleWithRedColor'];}
  8. setEnabled(enabled){if(this._enabled===enabled){return;}
  9. this._enabled=enabled;this.dispatchEventToListeners(Events.Enabled,enabled);}
  10. enabled(){return this._enabled;}
  11. category(){return ls(this._extension.descriptor()['category']||'');}
  12. tags(){return this._extension.descriptor()['tags']||'';}
  13. toggleable(){return!!this._extension.descriptor()['toggleable'];}
  14. title(){let title=this._extension.title()||'';const options=this._extension.descriptor()['options'];if(options){for(const pair of options){if(pair['value']!==this._toggled){title=ls(pair['title']);}}}
  15. return title;}
  16. toggled(){return this._toggled;}
  17. setToggled(toggled){console.assert(this.toggleable(),'Shouldn\'t be toggling an untoggleable action',this.id());if(this._toggled===toggled){return;}
  18. this._toggled=toggled;this.dispatchEventToListeners(Events.Toggled,toggled);}}
  19. const Events={Enabled:Symbol('Enabled'),Toggled:Symbol('Toggled')};self.UI=self.UI||{};UI=UI||{};UI.Action=Action;UI.Action.Events=Events;