未验证 提交 f7c65e63 编写于 作者: M Martin Aeschlimann 提交者: GitHub

Merge pull request #68026 from mjbvz/getColor-ret-undefined

Change `ITheme.getColor` to returned `Color | undefined`
...@@ -46,7 +46,7 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget { ...@@ -46,7 +46,7 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget {
this._domNode.setAttribute('role', 'presentation'); this._domNode.setAttribute('role', 'presentation');
this._domNode.setAttribute('aria-hidden', 'true'); this._domNode.setAttribute('aria-hidden', 'true');
const inputActiveOptionBorderColor = themeService.getTheme().getColor(inputActiveOptionBorder) || undefined; const inputActiveOptionBorderColor = themeService.getTheme().getColor(inputActiveOptionBorder);
this.caseSensitive = this._register(new CaseSensitiveCheckbox({ this.caseSensitive = this._register(new CaseSensitiveCheckbox({
appendTitle: this._keybindingLabelFor(FIND_IDS.ToggleCaseSensitiveCommand), appendTitle: this._keybindingLabelFor(FIND_IDS.ToggleCaseSensitiveCommand),
...@@ -179,7 +179,7 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget { ...@@ -179,7 +179,7 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget {
} }
private _applyTheme(theme: ITheme) { private _applyTheme(theme: ITheme) {
let inputStyles = { inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder) || undefined }; let inputStyles = { inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder) };
this.caseSensitive.style(inputStyles); this.caseSensitive.style(inputStyles);
this.wholeWords.style(inputStyles); this.wholeWords.style(inputStyles);
this.regex.style(inputStyles); this.regex.style(inputStyles);
......
...@@ -530,19 +530,19 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas ...@@ -530,19 +530,19 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private _applyTheme(theme: ITheme) { private _applyTheme(theme: ITheme) {
let inputStyles: IFindInputStyles = { let inputStyles: IFindInputStyles = {
inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder) || undefined, inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder),
inputBackground: theme.getColor(inputBackground) || undefined, inputBackground: theme.getColor(inputBackground),
inputForeground: theme.getColor(inputForeground) || undefined, inputForeground: theme.getColor(inputForeground),
inputBorder: theme.getColor(inputBorder) || undefined, inputBorder: theme.getColor(inputBorder),
inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground) || undefined, inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground),
inputValidationInfoForeground: theme.getColor(inputValidationInfoForeground) || undefined, inputValidationInfoForeground: theme.getColor(inputValidationInfoForeground),
inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder) || undefined, inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder),
inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground) || undefined, inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground),
inputValidationWarningForeground: theme.getColor(inputValidationWarningForeground) || undefined, inputValidationWarningForeground: theme.getColor(inputValidationWarningForeground),
inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder) || undefined, inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder),
inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground) || undefined, inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground),
inputValidationErrorForeground: theme.getColor(inputValidationErrorForeground) || undefined, inputValidationErrorForeground: theme.getColor(inputValidationErrorForeground),
inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder) || undefined, inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder),
}; };
this._findInput.style(inputStyles); this._findInput.style(inputStyles);
this._replaceInputBox.style(inputStyles); this._replaceInputBox.style(inputStyles);
...@@ -1130,7 +1130,7 @@ export class SimpleButton extends Widget { ...@@ -1130,7 +1130,7 @@ export class SimpleButton extends Widget {
// theming // theming
registerThemingParticipant((theme, collector) => { registerThemingParticipant((theme, collector) => {
const addBackgroundColorRule = (selector: string, color: Color | null): void => { const addBackgroundColorRule = (selector: string, color: Color | undefined): void => {
if (color) { if (color) {
collector.addRule(`.monaco-editor ${selector} { background-color: ${color}; }`); collector.addRule(`.monaco-editor ${selector} { background-color: ${color}; }`);
} }
......
...@@ -160,19 +160,19 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -160,19 +160,19 @@ export abstract class SimpleFindWidget extends Widget {
public updateTheme(theme: ITheme): void { public updateTheme(theme: ITheme): void {
const inputStyles: IFindInputStyles = { const inputStyles: IFindInputStyles = {
inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder) || undefined, inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder),
inputBackground: theme.getColor(inputBackground) || undefined, inputBackground: theme.getColor(inputBackground),
inputForeground: theme.getColor(inputForeground) || undefined, inputForeground: theme.getColor(inputForeground),
inputBorder: theme.getColor(inputBorder) || undefined, inputBorder: theme.getColor(inputBorder),
inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground) || undefined, inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground),
inputValidationInfoForeground: theme.getColor(inputValidationInfoForeground) || undefined, inputValidationInfoForeground: theme.getColor(inputValidationInfoForeground),
inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder) || undefined, inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder),
inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground) || undefined, inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground),
inputValidationWarningForeground: theme.getColor(inputValidationWarningForeground) || undefined, inputValidationWarningForeground: theme.getColor(inputValidationWarningForeground),
inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder) || undefined, inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder),
inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground) || undefined, inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground),
inputValidationErrorForeground: theme.getColor(inputValidationErrorForeground) || undefined, inputValidationErrorForeground: theme.getColor(inputValidationErrorForeground),
inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder) || undefined inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder)
}; };
this._findInput.style(inputStyles); this._findInput.style(inputStyles);
} }
......
...@@ -185,7 +185,7 @@ export class MarkerNavigationWidget extends ZoneWidget { ...@@ -185,7 +185,7 @@ export class MarkerNavigationWidget extends ZoneWidget {
} }
private _applyTheme(theme: ITheme) { private _applyTheme(theme: ITheme) {
this._backgroundColor = theme.getColor(editorMarkerNavigationBackground) || undefined; this._backgroundColor = theme.getColor(editorMarkerNavigationBackground);
let colorId = editorMarkerNavigationError; let colorId = editorMarkerNavigationError;
if (this._severity === MarkerSeverity.Warning) { if (this._severity === MarkerSeverity.Warning) {
colorId = editorMarkerNavigationWarning; colorId = editorMarkerNavigationWarning;
......
...@@ -279,8 +279,8 @@ export class ReferenceWidget extends PeekViewWidget { ...@@ -279,8 +279,8 @@ export class ReferenceWidget extends PeekViewWidget {
arrowColor: borderColor, arrowColor: borderColor,
frameColor: borderColor, frameColor: borderColor,
headerBackgroundColor: theme.getColor(peekViewTitleBackground) || Color.transparent, headerBackgroundColor: theme.getColor(peekViewTitleBackground) || Color.transparent,
primaryHeadingColor: theme.getColor(peekViewTitleForeground) || undefined, primaryHeadingColor: theme.getColor(peekViewTitleForeground),
secondaryHeadingColor: theme.getColor(peekViewTitleInfoForeground) || undefined secondaryHeadingColor: theme.getColor(peekViewTitleInfoForeground)
}); });
} }
......
...@@ -28,7 +28,7 @@ class StandaloneTheme implements IStandaloneTheme { ...@@ -28,7 +28,7 @@ class StandaloneTheme implements IStandaloneTheme {
private themeData: IStandaloneThemeData; private themeData: IStandaloneThemeData;
private colors: { [colorId: string]: Color } | null; private colors: { [colorId: string]: Color } | null;
private defaultColors: { [colorId: string]: Color | null; }; private defaultColors: { [colorId: string]: Color | undefined; };
private _tokenTheme: TokenTheme | null; private _tokenTheme: TokenTheme | null;
constructor(name: string, standaloneThemeData: IStandaloneThemeData) { constructor(name: string, standaloneThemeData: IStandaloneThemeData) {
...@@ -77,7 +77,7 @@ class StandaloneTheme implements IStandaloneTheme { ...@@ -77,7 +77,7 @@ class StandaloneTheme implements IStandaloneTheme {
return this.colors; return this.colors;
} }
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | null { public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | undefined {
const color = this.getColors()[colorId]; const color = this.getColors()[colorId];
if (color) { if (color) {
return color; return color;
...@@ -85,10 +85,10 @@ class StandaloneTheme implements IStandaloneTheme { ...@@ -85,10 +85,10 @@ class StandaloneTheme implements IStandaloneTheme {
if (useDefault !== false) { if (useDefault !== false) {
return this.getDefault(colorId); return this.getDefault(colorId);
} }
return null; return undefined;
} }
private getDefault(colorId: ColorIdentifier): Color | null { private getDefault(colorId: ColorIdentifier): Color | undefined {
let color = this.defaultColors[colorId]; let color = this.defaultColors[colorId];
if (color) { if (color) {
return color; return color;
......
...@@ -27,7 +27,7 @@ export interface ColorContribution { ...@@ -27,7 +27,7 @@ export interface ColorContribution {
export interface ColorFunction { export interface ColorFunction {
(theme: ITheme): Color | null; (theme: ITheme): Color | undefined;
} }
export interface ColorDefaults { export interface ColorDefaults {
...@@ -71,7 +71,7 @@ export interface IColorRegistry { ...@@ -71,7 +71,7 @@ export interface IColorRegistry {
/** /**
* Gets the default color of the given id * Gets the default color of the given id
*/ */
resolveDefaultColor(id: ColorIdentifier, theme: ITheme): Color | null; resolveDefaultColor(id: ColorIdentifier, theme: ITheme): Color | undefined;
/** /**
* JSON schema for an object to assign color values to one of the color contributions. * JSON schema for an object to assign color values to one of the color contributions.
...@@ -131,13 +131,13 @@ class ColorRegistry implements IColorRegistry { ...@@ -131,13 +131,13 @@ class ColorRegistry implements IColorRegistry {
return Object.keys(this.colorsById).map(id => this.colorsById[id]); return Object.keys(this.colorsById).map(id => this.colorsById[id]);
} }
public resolveDefaultColor(id: ColorIdentifier, theme: ITheme): Color | null { public resolveDefaultColor(id: ColorIdentifier, theme: ITheme): Color | undefined {
const colorDesc = this.colorsById[id]; const colorDesc = this.colorsById[id];
if (colorDesc && colorDesc.defaults) { if (colorDesc && colorDesc.defaults) {
const colorValue = colorDesc.defaults[theme.type]; const colorValue = colorDesc.defaults[theme.type];
return resolveColorValue(colorValue, theme); return resolveColorValue(colorValue, theme);
} }
return null; return undefined;
} }
public getColorSchema(): IJSONSchema { public getColorSchema(): IJSONSchema {
...@@ -385,7 +385,7 @@ export function darken(colorValue: ColorValue, factor: number): ColorFunction { ...@@ -385,7 +385,7 @@ export function darken(colorValue: ColorValue, factor: number): ColorFunction {
if (color) { if (color) {
return color.darken(factor); return color.darken(factor);
} }
return null; return undefined;
}; };
} }
...@@ -395,7 +395,7 @@ export function lighten(colorValue: ColorValue, factor: number): ColorFunction { ...@@ -395,7 +395,7 @@ export function lighten(colorValue: ColorValue, factor: number): ColorFunction {
if (color) { if (color) {
return color.lighten(factor); return color.lighten(factor);
} }
return null; return undefined;
}; };
} }
...@@ -405,7 +405,7 @@ export function transparent(colorValue: ColorValue, factor: number): ColorFuncti ...@@ -405,7 +405,7 @@ export function transparent(colorValue: ColorValue, factor: number): ColorFuncti
if (color) { if (color) {
return color.transparent(factor); return color.transparent(factor);
} }
return null; return undefined;
}; };
} }
...@@ -417,7 +417,7 @@ export function oneOf(...colorValues: ColorValue[]): ColorFunction { ...@@ -417,7 +417,7 @@ export function oneOf(...colorValues: ColorValue[]): ColorFunction {
return color; return color;
} }
} }
return null; return undefined;
}; };
} }
...@@ -434,7 +434,7 @@ function lessProminent(colorValue: ColorValue, backgroundColorValue: ColorValue, ...@@ -434,7 +434,7 @@ function lessProminent(colorValue: ColorValue, backgroundColorValue: ColorValue,
} }
return from.transparent(factor * transparency); return from.transparent(factor * transparency);
} }
return null; return undefined;
}; };
} }
...@@ -443,9 +443,9 @@ function lessProminent(colorValue: ColorValue, backgroundColorValue: ColorValue, ...@@ -443,9 +443,9 @@ function lessProminent(colorValue: ColorValue, backgroundColorValue: ColorValue,
/** /**
* @param colorValue Resolve a color value in the context of a theme * @param colorValue Resolve a color value in the context of a theme
*/ */
function resolveColorValue(colorValue: ColorValue | null, theme: ITheme): Color | null { function resolveColorValue(colorValue: ColorValue | null, theme: ITheme): Color | undefined {
if (colorValue === null) { if (colorValue === null) {
return null; return undefined;
} else if (typeof colorValue === 'string') { } else if (typeof colorValue === 'string') {
if (colorValue[0] === '#') { if (colorValue[0] === '#') {
return Color.fromHex(colorValue); return Color.fromHex(colorValue);
...@@ -456,7 +456,7 @@ function resolveColorValue(colorValue: ColorValue | null, theme: ITheme): Color ...@@ -456,7 +456,7 @@ function resolveColorValue(colorValue: ColorValue | null, theme: ITheme): Color
} else if (typeof colorValue === 'function') { } else if (typeof colorValue === 'function') {
return colorValue(theme); return colorValue(theme);
} }
return null; return undefined;
} }
export const workbenchColorsSchemaId = 'vscode://schemas/workbench-colors'; export const workbenchColorsSchemaId = 'vscode://schemas/workbench-colors';
......
...@@ -9,7 +9,7 @@ import { IDisposable } from 'vs/base/common/lifecycle'; ...@@ -9,7 +9,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { Color } from 'vs/base/common/color'; import { Color } from 'vs/base/common/color';
import { mixin } from 'vs/base/common/objects'; import { mixin } from 'vs/base/common/objects';
export type styleFn = (colors: { [name: string]: Color | null }) => void; export type styleFn = (colors: { [name: string]: Color | undefined }) => void;
export interface IStyleOverrides { export interface IStyleOverrides {
[color: string]: ColorIdentifier | undefined; [color: string]: ColorIdentifier | undefined;
...@@ -24,7 +24,7 @@ export interface IColorMapping { ...@@ -24,7 +24,7 @@ export interface IColorMapping {
} }
export interface IComputedStyles { export interface IComputedStyles {
[color: string]: Color | null; [color: string]: Color | undefined;
} }
export function computeStyles(theme: ITheme, styleMap: IColorMapping): IComputedStyles { export function computeStyles(theme: ITheme, styleMap: IColorMapping): IComputedStyles {
......
...@@ -52,7 +52,7 @@ export interface ITheme { ...@@ -52,7 +52,7 @@ export interface ITheme {
* @param color the id of the color * @param color the id of the color
* @param useDefault specifies if the default color should be used. If not set, the default is used. * @param useDefault specifies if the default color should be used. If not set, the default is used.
*/ */
getColor(color: ColorIdentifier, useDefault?: boolean): Color | null; getColor(color: ColorIdentifier, useDefault?: boolean): Color | undefined;
/** /**
* Returns whether the theme defines a value for the color. If not, that means the * Returns whether the theme defines a value for the color. If not, that means the
......
...@@ -12,12 +12,12 @@ export class TestTheme implements ITheme { ...@@ -12,12 +12,12 @@ export class TestTheme implements ITheme {
constructor(private colors: { [id: string]: string; } = {}, public type = DARK) { constructor(private colors: { [id: string]: string; } = {}, public type = DARK) {
} }
getColor(color: string, useDefault?: boolean): Color | null { getColor(color: string, useDefault?: boolean): Color | undefined {
let value = this.colors[color]; let value = this.colors[color];
if (value) { if (value) {
return Color.fromHex(value); return Color.fromHex(value);
} }
return null; return undefined;
} }
defines(color: string): boolean { defines(color: string): boolean {
......
...@@ -100,18 +100,18 @@ export class QuickInputBox { ...@@ -100,18 +100,18 @@ export class QuickInputBox {
style(theme: ITheme) { style(theme: ITheme) {
this.inputBox.style({ this.inputBox.style({
inputForeground: theme.getColor(inputForeground) || undefined, inputForeground: theme.getColor(inputForeground),
inputBackground: theme.getColor(inputBackground) || undefined, inputBackground: theme.getColor(inputBackground),
inputBorder: theme.getColor(inputBorder) || undefined, inputBorder: theme.getColor(inputBorder),
inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground) || undefined, inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground),
inputValidationInfoForeground: theme.getColor(inputValidationInfoForeground) || undefined, inputValidationInfoForeground: theme.getColor(inputValidationInfoForeground),
inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder) || undefined, inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder),
inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground) || undefined, inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground),
inputValidationWarningForeground: theme.getColor(inputValidationWarningForeground) || undefined, inputValidationWarningForeground: theme.getColor(inputValidationWarningForeground),
inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder) || undefined, inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder),
inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground) || undefined, inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground),
inputValidationErrorForeground: theme.getColor(inputValidationErrorForeground) || undefined, inputValidationErrorForeground: theme.getColor(inputValidationErrorForeground),
inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder) || undefined, inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder),
}); });
} }
......
...@@ -156,7 +156,7 @@ function getChangeType(change: IChange): ChangeType { ...@@ -156,7 +156,7 @@ function getChangeType(change: IChange): ChangeType {
} }
} }
function getChangeTypeColor(theme: ITheme, changeType: ChangeType): Color | null { function getChangeTypeColor(theme: ITheme, changeType: ChangeType): Color | undefined {
switch (changeType) { switch (changeType) {
case ChangeType.Modify: return theme.getColor(editorGutterModifiedBackground); case ChangeType.Modify: return theme.getColor(editorGutterModifiedBackground);
case ChangeType.Add: return theme.getColor(editorGutterAddedBackground); case ChangeType.Add: return theme.getColor(editorGutterAddedBackground);
...@@ -365,8 +365,8 @@ class DirtyDiffWidget extends PeekViewWidget { ...@@ -365,8 +365,8 @@ class DirtyDiffWidget extends PeekViewWidget {
arrowColor: borderColor, arrowColor: borderColor,
frameColor: borderColor, frameColor: borderColor,
headerBackgroundColor: theme.getColor(peekViewTitleBackground) || Color.transparent, headerBackgroundColor: theme.getColor(peekViewTitleBackground) || Color.transparent,
primaryHeadingColor: theme.getColor(peekViewTitleForeground) || undefined, primaryHeadingColor: theme.getColor(peekViewTitleForeground),
secondaryHeadingColor: theme.getColor(peekViewTitleInfoForeground) || undefined secondaryHeadingColor: theme.getColor(peekViewTitleInfoForeground)
}); });
} }
......
...@@ -57,8 +57,8 @@ export class ColorThemeData implements IColorTheme { ...@@ -57,8 +57,8 @@ export class ColorThemeData implements IColorTheme {
private colorMap: IColorMap = {}; private colorMap: IColorMap = {};
private customColorMap: IColorMap = {}; private customColorMap: IColorMap = {};
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | null { public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | undefined {
let color: Color | null = this.customColorMap[colorId]; let color: Color | undefined = this.customColorMap[colorId];
if (color) { if (color) {
return color; return color;
} }
...@@ -69,7 +69,7 @@ export class ColorThemeData implements IColorTheme { ...@@ -69,7 +69,7 @@ export class ColorThemeData implements IColorTheme {
return color; return color;
} }
public getDefault(colorId: ColorIdentifier): Color | null { public getDefault(colorId: ColorIdentifier): Color | undefined {
return colorRegistry.resolveDefaultColor(colorId, this); return colorRegistry.resolveDefaultColor(colorId, this);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册