@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
82 lines • 3.62 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2019 Ericsson 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
// *****************************************************************************
import { __decorate } from "tslib";
import debounce from '../../../shared/lodash.debounce/index.cjs';
import { inject, injectable, named } from 'inversify';
import { ContributionProvider, Emitter } from '../../common/index.js';
import { ColorRegistry } from '../color-registry.js';
import { DecorationsService } from '../decorations-service.js';
import { Navigatable } from '../navigatable-types.js';
export const TabBarDecorator = Symbol('TabBarDecorator');
let TabBarDecoratorService = class TabBarDecoratorService {
constructor() {
this.onDidChangeDecorationsEmitter = new Emitter();
this.onDidChangeDecorations = this.onDidChangeDecorationsEmitter.event;
this.fireDidChangeDecorations = debounce(() => this.onDidChangeDecorationsEmitter.fire(undefined), 150);
}
initialize() {
this.contributions.getContributions().map(decorator => decorator.onDidChangeDecorations(this.fireDidChangeDecorations));
}
/**
* Assign tabs the decorators provided by all the contributions.
* @param {Title<Widget>} title the title
* @returns an array of its decoration data.
*/
getDecorations(title) {
const decorators = this.contributions.getContributions();
const decorations = [];
for (const decorator of decorators) {
decorations.push(...decorator.decorate(title));
}
if (Navigatable.is(title.owner)) {
const resourceUri = title.owner.getResourceUri();
if (resourceUri) {
const serviceDecorations = this.decorationsService.getDecoration(resourceUri, false);
decorations.push(...serviceDecorations.map(d => this.fromDecoration(d)));
}
}
return decorations;
}
fromDecoration(decoration) {
const colorVariable = decoration.colorId && this.colors.toCssVariableName(decoration.colorId);
return {
tailDecorations: [
{
data: decoration.letter ? decoration.letter : '',
fontData: {
color: colorVariable && `var(${colorVariable})`
},
tooltip: decoration.tooltip ? decoration.tooltip : ''
}
]
};
}
};
__decorate([
inject(ContributionProvider),
named(TabBarDecorator)
], TabBarDecoratorService.prototype, "contributions", void 0);
__decorate([
inject(DecorationsService)
], TabBarDecoratorService.prototype, "decorationsService", void 0);
__decorate([
inject(ColorRegistry)
], TabBarDecoratorService.prototype, "colors", void 0);
TabBarDecoratorService = __decorate([
injectable()
], TabBarDecoratorService);
export { TabBarDecoratorService };
//# sourceMappingURL=tab-bar-decorator.js.map