editorAction.js 913 B

1234567891011121314151617181920212223
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export class InternalEditorAction {
  6. constructor(id, label, alias, precondition, run, contextKeyService) {
  7. this.id = id;
  8. this.label = label;
  9. this.alias = alias;
  10. this._precondition = precondition;
  11. this._run = run;
  12. this._contextKeyService = contextKeyService;
  13. }
  14. isSupported() {
  15. return this._contextKeyService.contextMatchesRules(this._precondition);
  16. }
  17. run() {
  18. if (!this.isSupported()) {
  19. return Promise.resolve(undefined);
  20. }
  21. return this._run();
  22. }
  23. }