1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
27 | return function (target, key) { decorator(target, key, paramIndex); }
|
28 | };
|
29 | Object.defineProperty(exports, "__esModule", { value: true });
|
30 | exports.DefaultOpenerService = exports.open = exports.OpenerService = exports.OpenHandler = void 0;
|
31 | const inversify_1 = require("inversify");
|
32 | const common_1 = require("../common");
|
33 | exports.OpenHandler = Symbol('OpenHandler');
|
34 | exports.OpenerService = Symbol('OpenerService');
|
35 | async function open(openerService, uri, options) {
|
36 | const opener = await openerService.getOpener(uri, options);
|
37 | return opener.open(uri, options);
|
38 | }
|
39 | exports.open = open;
|
40 | let DefaultOpenerService = class DefaultOpenerService {
|
41 | constructor(handlersProvider) {
|
42 | this.handlersProvider = handlersProvider;
|
43 |
|
44 | this.customEditorOpenHandlers = [];
|
45 | this.onDidChangeOpenersEmitter = new common_1.Emitter();
|
46 | this.onDidChangeOpeners = this.onDidChangeOpenersEmitter.event;
|
47 | }
|
48 | addHandler(openHandler) {
|
49 | this.customEditorOpenHandlers.push(openHandler);
|
50 | this.onDidChangeOpenersEmitter.fire();
|
51 | return common_1.Disposable.create(() => {
|
52 | this.customEditorOpenHandlers.splice(this.customEditorOpenHandlers.indexOf(openHandler), 1);
|
53 | this.onDidChangeOpenersEmitter.fire();
|
54 | });
|
55 | }
|
56 | async getOpener(uri, options) {
|
57 | const handlers = await this.prioritize(uri, options);
|
58 | if (handlers.length >= 1) {
|
59 | return handlers[0];
|
60 | }
|
61 | return Promise.reject(new Error(`There is no opener for ${uri}.`));
|
62 | }
|
63 | async getOpeners(uri, options) {
|
64 | return uri ? this.prioritize(uri, options) : this.getHandlers();
|
65 | }
|
66 | async prioritize(uri, options) {
|
67 | const prioritized = await common_1.Prioritizeable.prioritizeAll(this.getHandlers(), async (handler) => {
|
68 | try {
|
69 | return await handler.canHandle(uri, options);
|
70 | }
|
71 | catch {
|
72 | return 0;
|
73 | }
|
74 | });
|
75 | return prioritized.map(p => p.value);
|
76 | }
|
77 | getHandlers() {
|
78 | return [
|
79 | ...this.handlersProvider.getContributions(),
|
80 | ...this.customEditorOpenHandlers
|
81 | ];
|
82 | }
|
83 | };
|
84 | DefaultOpenerService = __decorate([
|
85 | (0, inversify_1.injectable)(),
|
86 | __param(0, (0, inversify_1.inject)(common_1.ContributionProvider)),
|
87 | __param(0, (0, inversify_1.named)(exports.OpenHandler)),
|
88 | __metadata("design:paramtypes", [Object])
|
89 | ], DefaultOpenerService);
|
90 | exports.DefaultOpenerService = DefaultOpenerService;
|
91 |
|
\ | No newline at end of file |