mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Updated API to declarative way for supplying color format.
This commit is contained in:
@@ -492,7 +492,6 @@ export function createApiFactory(
|
||||
CodeLens: extHostTypes.CodeLens,
|
||||
Color: extHostTypes.Color,
|
||||
ColorInfo: extHostTypes.ColorInfo,
|
||||
ColorMode: extHostTypes.ColorMode,
|
||||
EndOfLine: extHostTypes.EndOfLine,
|
||||
CompletionItem: extHostTypes.CompletionItem,
|
||||
CompletionItemKind: extHostTypes.CompletionItemKind,
|
||||
|
||||
@@ -35,7 +35,7 @@ import { IConfigurationData } from 'vs/platform/configuration/common/configurati
|
||||
import { IPickOpenEntry, IPickOptions } from 'vs/platform/quickOpen/common/quickOpen';
|
||||
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
|
||||
import { EndOfLine, TextEditorLineNumbersStyle, ColorMode } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { EndOfLine, TextEditorLineNumbersStyle } from 'vs/workbench/api/node/extHostTypes';
|
||||
|
||||
|
||||
import { TaskSet } from 'vs/workbench/parts/tasks/common/tasks';
|
||||
@@ -453,10 +453,10 @@ export namespace ObjectIdentifier {
|
||||
export abstract class ExtHostHeapServiceShape {
|
||||
$onGarbageCollection(ids: number[]): void { throw ni(); }
|
||||
}
|
||||
|
||||
export interface IColorInfo {
|
||||
color: [number, number, number, number | undefined];
|
||||
mode: ColorMode;
|
||||
format: string | [string, string];
|
||||
availableFormats: (string | [string, string])[];
|
||||
range: IRange;
|
||||
}
|
||||
|
||||
|
||||
@@ -372,9 +372,26 @@ export namespace DocumentLink {
|
||||
|
||||
export namespace DocumentColor {
|
||||
export function from(colorInfo: vscode.ColorInfo): IColorInfo {
|
||||
let format: string | [string, string];
|
||||
if (typeof colorInfo.format === 'string') {
|
||||
format = colorInfo.format;
|
||||
} else {
|
||||
format = [colorInfo.format.opaque, colorInfo.format.transparent];
|
||||
}
|
||||
|
||||
let availableFormats: (string | [string, string])[] = [];
|
||||
colorInfo.availableFormats.forEach(format => {
|
||||
if (typeof format === 'string') {
|
||||
availableFormats.push(format);
|
||||
} else {
|
||||
availableFormats.push([format.opaque, format.transparent]);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
color: [colorInfo.color.red, colorInfo.color.green, colorInfo.color.blue, colorInfo.color.alpha],
|
||||
mode: <number>colorInfo.mode,
|
||||
format: format,
|
||||
availableFormats: availableFormats,
|
||||
range: fromRange(colorInfo.range)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1043,32 +1043,34 @@ export class Color {
|
||||
}
|
||||
}
|
||||
|
||||
export enum ColorMode {
|
||||
RGBA = 0,
|
||||
Hex = 1,
|
||||
HSLA = 2
|
||||
}
|
||||
export type IColorFormat = string | { opaque: string, transparent: string };
|
||||
|
||||
export class ColorInfo {
|
||||
range: Range;
|
||||
|
||||
color: Color;
|
||||
|
||||
mode: ColorMode;
|
||||
format: IColorFormat;
|
||||
|
||||
constructor(range: Range, color: Color, mode: ColorMode) {
|
||||
availableFormats: IColorFormat[];
|
||||
|
||||
constructor(range: Range, color: Color, format: IColorFormat, availableFormats: IColorFormat[]) {
|
||||
if (color && !(color instanceof Color)) {
|
||||
throw illegalArgument('color');
|
||||
}
|
||||
if (mode && !(mode in ColorMode)) {
|
||||
throw illegalArgument('mode');
|
||||
if (format && (typeof format !== 'string') && !format.opaque && !format.transparent && typeof format.opaque !== 'string' && typeof format.transparent !== 'string') {
|
||||
throw illegalArgument('format');
|
||||
}
|
||||
if (availableFormats && !Array.isArray(availableFormats)) {
|
||||
throw illegalArgument('availableFormats');
|
||||
}
|
||||
if (!Range.isRange(range) || range.isEmpty) {
|
||||
throw illegalArgument('range');
|
||||
}
|
||||
this.range = range;
|
||||
this.color = color;
|
||||
this.mode = mode;
|
||||
this.format = format;
|
||||
this.availableFormats = availableFormats;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user