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.UriAwareCommandHandler = void 0;
|
19 | const selection_1 = require("../common/selection");
|
20 | const uri_1 = require("./uri");
|
21 | const types_1 = require("./types");
|
22 | class UriAwareCommandHandler {
|
23 | |
24 |
|
25 |
|
26 | constructor(selectionService, handler, options) {
|
27 | this.selectionService = selectionService;
|
28 | this.handler = handler;
|
29 | this.options = options;
|
30 | }
|
31 | getUri(...args) {
|
32 | const [maybeUriArray] = args;
|
33 | const firstArgIsOK = this.isMulti()
|
34 | ? (0, types_1.isArray)(maybeUriArray, uri => uri instanceof uri_1.default)
|
35 | : maybeUriArray instanceof uri_1.default;
|
36 | if (firstArgIsOK) {
|
37 | return maybeUriArray;
|
38 | }
|
39 | const { selection } = this.selectionService;
|
40 | const uriOrUris = this.isMulti()
|
41 | ? selection_1.UriSelection.getUris(selection)
|
42 | : selection_1.UriSelection.getUri(selection);
|
43 | return uriOrUris;
|
44 | }
|
45 | getArgsWithUri(...args) {
|
46 | const uri = this.getUri(...args);
|
47 | const [maybeUri, ...others] = args;
|
48 | if (uri === maybeUri) {
|
49 | return [maybeUri, ...others];
|
50 | }
|
51 | return [uri, ...args];
|
52 | }
|
53 | execute(...args) {
|
54 | const [uri, ...others] = this.getArgsWithUri(...args);
|
55 | return uri ? this.handler.execute(uri, ...others) : undefined;
|
56 | }
|
57 | isVisible(...args) {
|
58 | const [uri, ...others] = this.getArgsWithUri(...args);
|
59 | if (uri) {
|
60 | if (this.handler.isVisible) {
|
61 | return this.handler.isVisible(uri, ...others);
|
62 | }
|
63 | return true;
|
64 | }
|
65 | return false;
|
66 | }
|
67 | isEnabled(...args) {
|
68 | const [uri, ...others] = this.getArgsWithUri(...args);
|
69 | if (uri) {
|
70 | if (this.handler.isEnabled) {
|
71 | return this.handler.isEnabled(uri, ...others);
|
72 | }
|
73 | return true;
|
74 | }
|
75 | return false;
|
76 | }
|
77 | isMulti() {
|
78 | return this.options && !!this.options.multi;
|
79 | }
|
80 | }
|
81 | exports.UriAwareCommandHandler = UriAwareCommandHandler;
|
82 | (function (UriAwareCommandHandler) {
|
83 | |
84 |
|
85 |
|
86 | function MonoSelect(selectionService, handler) {
|
87 |
|
88 | return new UriAwareCommandHandler(selectionService, handler, { multi: false });
|
89 | }
|
90 | UriAwareCommandHandler.MonoSelect = MonoSelect;
|
91 | |
92 |
|
93 |
|
94 | function MultiSelect(selectionService, handler) {
|
95 |
|
96 | return new UriAwareCommandHandler(selectionService, handler, { multi: true });
|
97 | }
|
98 | UriAwareCommandHandler.MultiSelect = MultiSelect;
|
99 | })(UriAwareCommandHandler = exports.UriAwareCommandHandler || (exports.UriAwareCommandHandler = {}));
|
100 |
|
\ | No newline at end of file |