styler.ts 10.4 KB
Newer Older
B
Benjamin Pasero 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { ITheme, IThemeService } from 'vs/platform/theme/common/themeService';
9
import { inputBackground, inputForeground, ColorIdentifier, selectForeground, selectBackground, selectBorder, inputBorder, foreground, editorBackground, highContrastBorder, inputActiveOptionBorder, listFocusBackground, listActiveSelectionBackground, listActiveSelectionForeground, listFocusAndSelectionBackground, listFocusAndSelectionForeground, listInactiveFocusBackground, listInactiveSelectionBackground, listHoverBackground, listDropBackground, listHoverOutline, listSelectionOutline, listFocusOutline, listInactiveFocusOutline, pickerGroupBorder, pickerGroupForeground, widgetShadow, infoBorder, infoBackground, warningBorder, warningBackground, errorBorder, errorBackground } from 'vs/platform/theme/common/colorRegistry';
B
Benjamin Pasero 已提交
10
import { IDisposable } from "vs/base/common/lifecycle";
11
import { SIDE_BAR_SECTION_HEADER_BACKGROUND } from "vs/workbench/common/theme";
B
Benjamin Pasero 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

export interface IThemable {
	style(colors: { [name: string]: ColorIdentifier }): void;
}

export function attachStyler(themeService: IThemeService, widget: IThemable, optionsMapping: { [optionsKey: string]: ColorIdentifier }): IDisposable {
	function applyStyles(theme: ITheme): void {
		const styles = Object.create(null);
		for (let key in optionsMapping) {
			styles[key] = theme.getColor(optionsMapping[key]);
		}

		widget.style(styles);
	}

	applyStyles(themeService.getTheme());

	return themeService.onThemeChange(applyStyles);
}

B
Benjamin Pasero 已提交
32 33
export function attachCheckboxStyler(widget: IThemable, themeService: IThemeService, style?: { inputActiveOptionBorderColor?: ColorIdentifier }): IDisposable {
	return attachStyler(themeService, widget, {
34
		inputActiveOptionBorder: (style && style.inputActiveOptionBorderColor) || inputActiveOptionBorder
B
Benjamin Pasero 已提交
35 36 37
	});
}

38 39 40 41 42 43 44 45 46 47 48 49
export function attachInputBoxStyler(widget: IThemable, themeService: IThemeService, style?:
	{
		inputBackground?: ColorIdentifier,
		inputForeground?: ColorIdentifier,
		inputBorder?: ColorIdentifier,
		infoBorder?: ColorIdentifier,
		infoBackground?: ColorIdentifier,
		warningBorder?: ColorIdentifier,
		warningBackground?: ColorIdentifier,
		errorBorder?: ColorIdentifier,
		errorBackground?: ColorIdentifier
	}): IDisposable {
B
Benjamin Pasero 已提交
50 51
	return attachStyler(themeService, widget, {
		inputBackground: (style && style.inputBackground) || inputBackground,
B
Benjamin Pasero 已提交
52
		inputForeground: (style && style.inputForeground) || inputForeground,
53 54 55 56 57 58 59
		inputBorder: (style && style.inputBorder) || inputBorder,
		infoBorder: (style && style.infoBorder) || infoBorder,
		infoBackground: (style && style.infoBackground) || infoBackground,
		warningBorder: (style && style.warningBorder) || warningBorder,
		warningBackground: (style && style.warningBackground) || warningBackground,
		errorBorder: (style && style.errorBorder) || errorBorder,
		errorBackground: (style && style.errorBackground) || errorBackground
B
Benjamin Pasero 已提交
60
	});
61 62
}

B
Benjamin Pasero 已提交
63 64 65 66 67 68
export function attachSelectBoxStyler(widget: IThemable, themeService: IThemeService, style?: { selectBackground?: ColorIdentifier, selectForeground?: ColorIdentifier, selectBorder?: ColorIdentifier }): IDisposable {
	return attachStyler(themeService, widget, {
		selectBackground: (style && style.selectBackground) || selectBackground,
		selectForeground: (style && style.selectForeground) || selectForeground,
		selectBorder: (style && style.selectBorder) || selectBorder
	});
69 70
}

71 72 73 74 75 76 77 78 79 80 81 82 83
export function attachFindInputBoxStyler(widget: IThemable, themeService: IThemeService, style?:
	{
		inputBackground?: ColorIdentifier,
		inputForeground?: ColorIdentifier,
		inputBorder?: ColorIdentifier,
		inputActiveOptionBorder?: ColorIdentifier,
		infoBorder?: ColorIdentifier,
		infoBackground?: ColorIdentifier,
		warningBorder?: ColorIdentifier,
		warningBackground?: ColorIdentifier,
		errorBorder?: ColorIdentifier,
		errorBackground?: ColorIdentifier
	}): IDisposable {
B
Benjamin Pasero 已提交
84 85 86 87
	return attachStyler(themeService, widget, {
		inputBackground: (style && style.inputBackground) || inputBackground,
		inputForeground: (style && style.inputForeground) || inputForeground,
		inputBorder: (style && style.inputBorder) || inputBorder,
88 89 90 91 92 93 94
		inputActiveOptionBorder: (style && style.inputActiveOptionBorder) || inputActiveOptionBorder,
		infoBorder: (style && style.infoBorder) || infoBorder,
		infoBackground: (style && style.infoBackground) || infoBackground,
		warningBorder: (style && style.warningBorder) || warningBorder,
		warningBackground: (style && style.warningBackground) || warningBackground,
		errorBorder: (style && style.errorBorder) || errorBorder,
		errorBackground: (style && style.errorBackground) || errorBackground
B
Benjamin Pasero 已提交
95 96 97
	});
}

B
Benjamin Pasero 已提交
98 99 100 101
export function attachQuickOpenStyler(widget: IThemable, themeService: IThemeService, style?: {
	foreground?: ColorIdentifier,
	background?: ColorIdentifier,
	borderColor?: ColorIdentifier,
102
	widgetShadow?: ColorIdentifier,
B
Benjamin Pasero 已提交
103 104 105
	inputBackground?: ColorIdentifier,
	inputForeground?: ColorIdentifier,
	inputBorder?: ColorIdentifier,
106 107 108 109 110 111
	infoBorder?: ColorIdentifier,
	infoBackground?: ColorIdentifier,
	warningBorder?: ColorIdentifier,
	warningBackground?: ColorIdentifier,
	errorBorder?: ColorIdentifier,
	errorBackground?: ColorIdentifier
112 113
	pickerGroupForeground?: ColorIdentifier,
	pickerGroupBorder?: ColorIdentifier,
B
Benjamin Pasero 已提交
114 115 116 117 118 119 120 121
	listFocusBackground?: ColorIdentifier,
	listActiveSelectionBackground?: ColorIdentifier,
	listActiveSelectionForeground?: ColorIdentifier,
	listFocusAndSelectionBackground?: ColorIdentifier,
	listFocusAndSelectionForeground?: ColorIdentifier,
	listInactiveSelectionBackground?: ColorIdentifier,
	listHoverBackground?: ColorIdentifier,
	listDropBackground?: ColorIdentifier,
122 123 124
	listFocusOutline?: ColorIdentifier,
	listSelectionOutline?: ColorIdentifier,
	listHoverOutline?: ColorIdentifier
B
Benjamin Pasero 已提交
125
}): IDisposable {
126 127 128 129
	return attachStyler(themeService, widget, {
		foreground: (style && style.foreground) || foreground,
		background: (style && style.background) || editorBackground,
		borderColor: style && style.borderColor || highContrastBorder,
130
		widgetShadow: style && style.widgetShadow || widgetShadow,
131 132
		pickerGroupForeground: style && style.pickerGroupForeground || pickerGroupForeground,
		pickerGroupBorder: style && style.pickerGroupBorder || pickerGroupBorder,
133 134
		inputBackground: (style && style.inputBackground) || inputBackground,
		inputForeground: (style && style.inputForeground) || inputForeground,
B
Benjamin Pasero 已提交
135
		inputBorder: (style && style.inputBorder) || inputBorder,
136 137 138 139 140 141
		infoBorder: (style && style.infoBorder) || infoBorder,
		infoBackground: (style && style.infoBackground) || infoBackground,
		warningBorder: (style && style.warningBorder) || warningBorder,
		warningBackground: (style && style.warningBackground) || warningBackground,
		errorBorder: (style && style.errorBorder) || errorBorder,
		errorBackground: (style && style.errorBackground) || errorBackground,
B
Benjamin Pasero 已提交
142 143 144 145 146 147 148 149
		listFocusBackground: (style && style.listFocusBackground) || listFocusBackground,
		listActiveSelectionBackground: (style && style.listActiveSelectionBackground) || listActiveSelectionBackground,
		listActiveSelectionForeground: (style && style.listActiveSelectionForeground) || listActiveSelectionForeground,
		listFocusAndSelectionBackground: (style && style.listFocusAndSelectionBackground) || listFocusAndSelectionBackground,
		listFocusAndSelectionForeground: (style && style.listFocusAndSelectionForeground) || listFocusAndSelectionForeground,
		listInactiveSelectionBackground: (style && style.listInactiveSelectionBackground) || listInactiveSelectionBackground,
		listHoverBackground: (style && style.listHoverBackground) || listHoverBackground,
		listDropBackground: (style && style.listDropBackground) || listDropBackground,
150 151 152
		listFocusOutline: (style && style.listFocusOutline) || listFocusOutline,
		listSelectionOutline: (style && style.listSelectionOutline) || listSelectionOutline,
		listHoverOutline: (style && style.listHoverOutline) || listHoverOutline
B
Benjamin Pasero 已提交
153 154 155 156 157 158 159 160 161
	});
}

export function attachListStyler(widget: IThemable, themeService: IThemeService, style?: {
	listFocusBackground?: ColorIdentifier,
	listActiveSelectionBackground?: ColorIdentifier,
	listActiveSelectionForeground?: ColorIdentifier,
	listFocusAndSelectionBackground?: ColorIdentifier,
	listFocusAndSelectionForeground?: ColorIdentifier,
M
Martin Aeschlimann 已提交
162
	listInactiveFocusBackground?: ColorIdentifier,
B
Benjamin Pasero 已提交
163 164 165
	listInactiveSelectionBackground?: ColorIdentifier,
	listHoverBackground?: ColorIdentifier,
	listDropBackground?: ColorIdentifier,
166 167 168 169
	listFocusOutline?: ColorIdentifier,
	listInactiveFocusOutline?: ColorIdentifier,
	listSelectionOutline?: ColorIdentifier,
	listHoverOutline?: ColorIdentifier,
B
Benjamin Pasero 已提交
170 171 172 173 174 175 176
}): IDisposable {
	return attachStyler(themeService, widget, {
		listFocusBackground: (style && style.listFocusBackground) || listFocusBackground,
		listActiveSelectionBackground: (style && style.listActiveSelectionBackground) || listActiveSelectionBackground,
		listActiveSelectionForeground: (style && style.listActiveSelectionForeground) || listActiveSelectionForeground,
		listFocusAndSelectionBackground: (style && style.listFocusAndSelectionBackground) || listFocusAndSelectionBackground,
		listFocusAndSelectionForeground: (style && style.listFocusAndSelectionForeground) || listFocusAndSelectionForeground,
M
Martin Aeschlimann 已提交
177
		listInactiveFocusBackground: (style && style.listInactiveFocusBackground) || listInactiveFocusBackground,
B
Benjamin Pasero 已提交
178 179 180
		listInactiveSelectionBackground: (style && style.listInactiveSelectionBackground) || listInactiveSelectionBackground,
		listHoverBackground: (style && style.listHoverBackground) || listHoverBackground,
		listDropBackground: (style && style.listDropBackground) || listDropBackground,
181 182 183 184
		listFocusOutline: (style && style.listFocusOutline) || listFocusOutline,
		listInactiveFocusOutline: (style && style.listInactiveFocusOutline) || listInactiveFocusOutline,
		listSelectionOutline: (style && style.listSelectionOutline) || listSelectionOutline,
		listHoverOutline: (style && style.listHoverOutline) || listHoverOutline,
185
	});
186 187 188 189 190 191 192
}

export function attachHeaderViewStyler(widget: IThemable, themeService: IThemeService, style?: { headerBackground?: ColorIdentifier, highContrastBorder?: ColorIdentifier }): IDisposable {
	return attachStyler(themeService, widget, {
		headerBackground: (style && style.headerBackground) || SIDE_BAR_SECTION_HEADER_BACKGROUND,
		headerHighContrastBorder: (style && style.highContrastBorder) || highContrastBorder
	});
B
Benjamin Pasero 已提交
193
}