Files
azuredatastudio/src/vs/platform/theme/common/themeService.ts
Karl Burtram dafb780987 Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches

* A few more merges

* Post npm install

* Fix batch of build breaks

* Fix more build breaks

* Fix more build errors

* Fix more build breaks

* Runtime fixes 1

* Get connection dialog working with some todos

* Fix a few packaging issues

* Copy several node_modules to package build to fix loader issues

* Fix breaks from master

* A few more fixes

* Make tests pass

* First pass of license header updates

* Second pass of license header updates

* Fix restore dialog issues

* Remove add additional themes menu items

* fix select box issues where the list doesn't show up

* formatting

* Fix editor dispose issue

* Copy over node modules to correct location on all platforms
2018-04-04 15:27:51 -07:00

135 lines
3.9 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Color } from 'vs/base/common/color';
import { IDisposable } from 'vs/base/common/lifecycle';
import platform = require('vs/platform/registry/common/platform');
import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
import Event, { Emitter } from 'vs/base/common/event';
export const IThemeService = createDecorator<IThemeService>('themeService');
export interface ThemeColor {
id: string;
}
export function themeColorFromId(id: ColorIdentifier) {
return { id };
}
// theme icon
export interface ThemeIcon {
readonly id: string;
}
export const FileThemeIcon = { id: 'file' };
export const FolderThemeIcon = { id: 'folder' };
// base themes
export const DARK: ThemeType = 'dark';
export const LIGHT: ThemeType = 'light';
export const HIGH_CONTRAST: ThemeType = 'hc';
export type ThemeType = 'light' | 'dark' | 'hc';
export function getThemeTypeSelector(type: ThemeType): string {
switch (type) {
case DARK: return 'vs-dark';
case HIGH_CONTRAST: return 'hc-black';
default: return 'vs';
}
}
export interface ITheme {
readonly type: ThemeType;
/**
* Resolves the color of the given color identifer. If the theme does not
* specify the color, the default color is returned unless <code>useDefault</code> is set to false.
* @param color the id of the color
* @param useDefault specifies if the default color should be used. If not set, the default is used.
*/
getColor(color: ColorIdentifier, useDefault?: boolean): Color;
/**
* Returns wheter the theme defines a value for the color. If not, that means the
* default color will be used.
*/
defines(color: ColorIdentifier): boolean;
}
export interface ICssStyleCollector {
addRule(rule: string): void;
}
export interface IThemingParticipant {
(theme: ITheme, collector: ICssStyleCollector): void;
}
export interface IThemeService {
_serviceBrand: any;
getTheme(): ITheme;
/**
* Register a theming participant that is invoked after every theme change.
*/
onThemeChange: Event<ITheme>;
}
// static theming participant
export const Extensions = {
ThemingContribution: 'base.contributions.theming'
};
export interface IThemingRegistry {
/**
* Register a theming participant that is invoked on every theme change.
*/
onThemeChange(participant: IThemingParticipant): IDisposable;
getThemingParticipants(): IThemingParticipant[];
readonly onThemingParticipantAdded: Event<IThemingParticipant>;
}
class ThemingRegistry implements IThemingRegistry {
private themingParticipants: IThemingParticipant[] = [];
private onThemingParticipantAddedEmitter: Emitter<IThemingParticipant>;
constructor() {
this.themingParticipants = [];
this.onThemingParticipantAddedEmitter = new Emitter<IThemingParticipant>();
}
public onThemeChange(participant: IThemingParticipant): IDisposable {
this.themingParticipants.push(participant);
this.onThemingParticipantAddedEmitter.fire(participant);
return {
dispose: () => {
const idx = this.themingParticipants.indexOf(participant);
this.themingParticipants.splice(idx, 1);
}
};
}
public get onThemingParticipantAdded(): Event<IThemingParticipant> {
return this.onThemingParticipantAddedEmitter.event;
}
public getThemingParticipants(): IThemingParticipant[] {
return this.themingParticipants;
}
}
let themingRegistry = new ThemingRegistry();
platform.Registry.add(Extensions.ThemingContribution, themingRegistry);
export function registerThemingParticipant(participant: IThemingParticipant): IDisposable {
return themingRegistry.onThemeChange(participant);
}