UNPKG

4.61 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// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.DiffUriLabelProviderContribution = exports.DiffUris = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const uri_1 = require("../common/uri");
22const label_provider_1 = require("./label-provider");
23const widgets_1 = require("./widgets");
24var 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 = {}));
49let 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};
110DiffUriLabelProviderContribution = (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);
115exports.DiffUriLabelProviderContribution = DiffUriLabelProviderContribution;
116//# sourceMappingURL=diff-uris.js.map
\No newline at end of file