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