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