UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

116 lines 4.63 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2017 TypeFox and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.DiffUriLabelProviderContribution = exports.DiffUris = void 0; const tslib_1 = require("tslib"); const inversify_1 = require("inversify"); const uri_1 = require("../common/uri"); const label_provider_1 = require("./label-provider"); const widgets_1 = require("./widgets"); var DiffUris; (function (DiffUris) { DiffUris.DIFF_SCHEME = 'diff'; function encode(left, right, label) { const diffUris = [ left.toString(), right.toString() ]; const diffUriStr = JSON.stringify(diffUris); return new uri_1.default().withScheme(DiffUris.DIFF_SCHEME).withPath(label || '').withQuery(diffUriStr); } DiffUris.encode = encode; function decode(uri) { if (uri.scheme !== DiffUris.DIFF_SCHEME) { throw new Error((`The URI must have scheme "diff". The URI was: ${uri}.`)); } const diffUris = JSON.parse(uri.query); return diffUris.map(s => new uri_1.default(s)); } DiffUris.decode = decode; function isDiffUri(uri) { return uri.scheme === DiffUris.DIFF_SCHEME; } DiffUris.isDiffUri = isDiffUri; })(DiffUris || (exports.DiffUris = DiffUris = {})); let DiffUriLabelProviderContribution = class DiffUriLabelProviderContribution { constructor(labelProvider) { this.labelProvider = labelProvider; } canHandle(element) { if (element instanceof uri_1.default && DiffUris.isDiffUri(element)) { return 20; } return 0; } getLongName(uri) { const label = uri.path.toString(); if (label) { return label; } const [left, right] = DiffUris.decode(uri); const leftLongName = this.labelProvider.getLongName(left); const rightLongName = this.labelProvider.getLongName(right); if (leftLongName === rightLongName) { return leftLongName; } return `${leftLongName}${rightLongName}`; } getName(uri) { const label = uri.path.toString(); if (label) { return label; } const [left, right] = DiffUris.decode(uri); if (left.path.toString() === right.path.toString() && left.query && right.query) { const prefix = left.displayName ? `${left.displayName}: ` : ''; return `${prefix}${left.query}${right.query}`; } else { let title; if (uri.displayName && left.path.toString() !== right.path.toString() && left.displayName !== uri.displayName) { title = `${uri.displayName}: `; } else { title = ''; } const leftLongName = this.labelProvider.getName(left); const rightLongName = this.labelProvider.getName(right); if (leftLongName === rightLongName) { return leftLongName; } return `${title}${leftLongName}${rightLongName}`; } } getIcon(uri) { return (0, widgets_1.codicon)('split-horizontal'); } affects(diffUri, event) { for (const uri of DiffUris.decode(diffUri)) { if (event.affects(uri)) { return true; } } return false; } }; exports.DiffUriLabelProviderContribution = DiffUriLabelProviderContribution; exports.DiffUriLabelProviderContribution = DiffUriLabelProviderContribution = tslib_1.__decorate([ (0, inversify_1.injectable)(), tslib_1.__param(0, (0, inversify_1.inject)(label_provider_1.LabelProvider)), tslib_1.__metadata("design:paramtypes", [label_provider_1.LabelProvider]) ], DiffUriLabelProviderContribution); //# sourceMappingURL=diff-uris.js.map