1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.OpenWithService = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const disposable_1 = require("../common/disposable");
|
22 | const nls_1 = require("../common/nls");
|
23 | const quick_input_1 = require("./quick-input");
|
24 | let OpenWithService = class OpenWithService {
|
25 | constructor() {
|
26 | this.handlers = [];
|
27 | }
|
28 | registerHandler(handler) {
|
29 | this.handlers.push(handler);
|
30 | return disposable_1.Disposable.create(() => {
|
31 | const index = this.handlers.indexOf(handler);
|
32 | if (index !== -1) {
|
33 | this.handlers.splice(index, 1);
|
34 | }
|
35 | });
|
36 | }
|
37 | async openWith(uri) {
|
38 | const handlers = this.getHandlers(uri);
|
39 | const result = await this.quickInputService.pick(handlers.map(handler => {
|
40 | var _a;
|
41 | return ({
|
42 | handler: handler,
|
43 | label: (_a = handler.label) !== null && _a !== void 0 ? _a : handler.id,
|
44 | detail: handler.providerName
|
45 | });
|
46 | }), {
|
47 | placeHolder: nls_1.nls.localizeByDefault("Select editor for '{0}'", uri.path.base)
|
48 | });
|
49 | if (result) {
|
50 | return result.handler.open(uri);
|
51 | }
|
52 | }
|
53 | getHandlers(uri) {
|
54 | const map = new Map(this.handlers.map(handler => [handler, handler.canHandle(uri)]));
|
55 | return this.handlers.filter(handler => map.get(handler) > 0).sort((a, b) => map.get(b) - map.get(a));
|
56 | }
|
57 | };
|
58 | (0, tslib_1.__decorate)([
|
59 | (0, inversify_1.inject)(quick_input_1.QuickInputService),
|
60 | (0, tslib_1.__metadata)("design:type", Object)
|
61 | ], OpenWithService.prototype, "quickInputService", void 0);
|
62 | OpenWithService = (0, tslib_1.__decorate)([
|
63 | (0, inversify_1.injectable)()
|
64 | ], OpenWithService);
|
65 | exports.OpenWithService = OpenWithService;
|
66 |
|
\ | No newline at end of file |