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.DiffUriLabelProviderContribution = exports.DiffUris = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const uri_1 = require("../common/uri");
|
22 | const label_provider_1 = require("./label-provider");
|
23 | const widgets_1 = require("./widgets");
|
24 | var DiffUris;
|
25 | (function (DiffUris) {
|
26 | DiffUris.DIFF_SCHEME = 'diff';
|
27 | function encode(left, right, label) {
|
28 | const diffUris = [
|
29 | left.toString(),
|
30 | right.toString()
|
31 | ];
|
32 | const diffUriStr = JSON.stringify(diffUris);
|
33 | return new uri_1.default().withScheme(DiffUris.DIFF_SCHEME).withPath(label || '').withQuery(diffUriStr);
|
34 | }
|
35 | DiffUris.encode = encode;
|
36 | function decode(uri) {
|
37 | if (uri.scheme !== DiffUris.DIFF_SCHEME) {
|
38 | throw new Error((`The URI must have scheme "diff". The URI was: ${uri}.`));
|
39 | }
|
40 | const diffUris = JSON.parse(uri.query);
|
41 | return diffUris.map(s => new uri_1.default(s));
|
42 | }
|
43 | DiffUris.decode = decode;
|
44 | function isDiffUri(uri) {
|
45 | return uri.scheme === DiffUris.DIFF_SCHEME;
|
46 | }
|
47 | DiffUris.isDiffUri = isDiffUri;
|
48 | })(DiffUris = exports.DiffUris || (exports.DiffUris = {}));
|
49 | let DiffUriLabelProviderContribution = class DiffUriLabelProviderContribution {
|
50 | constructor(labelProvider) {
|
51 | this.labelProvider = labelProvider;
|
52 | }
|
53 | canHandle(element) {
|
54 | if (element instanceof uri_1.default && DiffUris.isDiffUri(element)) {
|
55 | return 20;
|
56 | }
|
57 | return 0;
|
58 | }
|
59 | getLongName(uri) {
|
60 | const label = uri.path.toString();
|
61 | if (label) {
|
62 | return label;
|
63 | }
|
64 | const [left, right] = DiffUris.decode(uri);
|
65 | const leftLongName = this.labelProvider.getLongName(left);
|
66 | const rightLongName = this.labelProvider.getLongName(right);
|
67 | if (leftLongName === rightLongName) {
|
68 | return leftLongName;
|
69 | }
|
70 | return `${leftLongName} ⟷ ${rightLongName}`;
|
71 | }
|
72 | getName(uri) {
|
73 | const label = uri.path.toString();
|
74 | if (label) {
|
75 | return label;
|
76 | }
|
77 | const [left, right] = DiffUris.decode(uri);
|
78 | if (left.path.toString() === right.path.toString() && left.query && right.query) {
|
79 | const prefix = left.displayName ? `${left.displayName}: ` : '';
|
80 | return `${prefix}${left.query} ⟷ ${right.query}`;
|
81 | }
|
82 | else {
|
83 | let title;
|
84 | if (uri.displayName && left.path.toString() !== right.path.toString() && left.displayName !== uri.displayName) {
|
85 | title = `${uri.displayName}: `;
|
86 | }
|
87 | else {
|
88 | title = '';
|
89 | }
|
90 | const leftLongName = this.labelProvider.getName(left);
|
91 | const rightLongName = this.labelProvider.getName(right);
|
92 | if (leftLongName === rightLongName) {
|
93 | return leftLongName;
|
94 | }
|
95 | return `${title}${leftLongName} ⟷ ${rightLongName}`;
|
96 | }
|
97 | }
|
98 | getIcon(uri) {
|
99 | return (0, widgets_1.codicon)('split-horizontal');
|
100 | }
|
101 | affects(diffUri, event) {
|
102 | for (const uri of DiffUris.decode(diffUri)) {
|
103 | if (event.affects(uri)) {
|
104 | return true;
|
105 | }
|
106 | }
|
107 | return false;
|
108 | }
|
109 | };
|
110 | DiffUriLabelProviderContribution = (0, tslib_1.__decorate)([
|
111 | (0, inversify_1.injectable)(),
|
112 | (0, tslib_1.__param)(0, (0, inversify_1.inject)(label_provider_1.LabelProvider)),
|
113 | (0, tslib_1.__metadata)("design:paramtypes", [label_provider_1.LabelProvider])
|
114 | ], DiffUriLabelProviderContribution);
|
115 | exports.DiffUriLabelProviderContribution = DiffUriLabelProviderContribution;
|
116 |
|
\ | No newline at end of file |