UNPKG

5.43 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17var __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};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26var __param = (this && this.__param) || function (paramIndex, decorator) {
27 return function (target, key) { decorator(target, key, paramIndex); }
28};
29Object.defineProperty(exports, "__esModule", { value: true });
30exports.DiffUriLabelProviderContribution = exports.DiffUris = void 0;
31const inversify_1 = require("inversify");
32const uri_1 = require("../common/uri");
33const label_provider_1 = require("./label-provider");
34const widgets_1 = require("./widgets");
35var 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 = {}));
60let 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};
121DiffUriLabelProviderContribution = __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);
126exports.DiffUriLabelProviderContribution = DiffUriLabelProviderContribution;
127//# sourceMappingURL=diff-uris.js.map
\No newline at end of file