Updated API to declarative way for supplying color format.

This commit is contained in:
Michel Kaporin
2017-07-25 16:58:49 +02:00
parent 3713e4deea
commit 4bd6bdfe7e
15 changed files with 315 additions and 99 deletions

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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)
};
}

View File

@@ -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;
}
}