提交 3713e4de 编写于 作者: M Michel Kaporin

Added ColorMode to API.

上级 2c45d350
......@@ -509,4 +509,4 @@ export class Color {
public static readonly cyan = new Color(new RGBA(0, 255, 255, 255));
public static readonly lightgrey = new Color(new RGBA(211, 211, 211, 255));
public static readonly transparent = new Color(new RGBA(0, 0, 0, 0));
}
\ No newline at end of file
}
......@@ -9,7 +9,7 @@ import { MarkedString } from 'vs/base/common/htmlContent';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
import { LanguageId, LanguageIdentifier, ColorMode } from 'vs/editor/common/modes';
import { LineTokens } from 'vs/editor/common/core/lineTokens';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Position, IPosition } from 'vs/editor/common/core/position';
......@@ -62,6 +62,10 @@ export interface IModelDecorationOverviewRulerOptions {
position: OverviewRulerLane;
}
export interface IColorInfo {
color: Color;
mode: ColorMode;
}
/**
* Options for a model decoration.
*/
......@@ -84,9 +88,9 @@ export interface IModelDecorationOptions {
*/
hoverMessage?: MarkedString | MarkedString[];
/**
* Color to render in the color picker.
* Color with mode to render in the color picker.
*/
color?: Color;
colorInfo?: IColorInfo;
/**
* Should the decoration expand to encompass a whole line.
*/
......
......@@ -17,7 +17,6 @@ import { LanguageIdentifier } from 'vs/editor/common/modes';
import { ITextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
import * as textModelEvents from 'vs/editor/common/model/textModelEvents';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { Color } from "vs/base/common/color";
export const ClassName = {
EditorWarningDecoration: 'greensquiggly',
......@@ -896,7 +895,7 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
readonly stickiness: editorCommon.TrackedRangeStickiness;
readonly className: string;
readonly hoverMessage: MarkedString | MarkedString[];
readonly color: Color;
readonly colorInfo: editorCommon.IColorInfo;
readonly glyphMarginHoverMessage: MarkedString | MarkedString[];
readonly isWholeLine: boolean;
readonly showIfCollapsed: boolean;
......@@ -913,7 +912,7 @@ export class ModelDecorationOptions implements editorCommon.IModelDecorationOpti
this.stickiness = options.stickiness || editorCommon.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges;
this.className = options.className ? cleanClassName(options.className) : strings.empty;
this.hoverMessage = options.hoverMessage || [];
this.color = options.color || undefined;
this.colorInfo = options.colorInfo || undefined;
this.glyphMarginHoverMessage = options.glyphMarginHoverMessage || strings.empty;
this.isWholeLine = options.isWholeLine || false;
this.showIfCollapsed = options.showIfCollapsed || false;
......
......@@ -173,7 +173,7 @@ export interface MarkedStringHover {
// TODO@michel documentation
export interface ColorHover {
color: Color;
mode: ColorMode;
/**
* The range to which this hover applies. When missing, the
* editor will use the range at the current position or the
......@@ -678,12 +678,19 @@ export interface LinkProvider {
*/
export interface IColorInfo {
color: Color;
mode: ColorMode;
range: IRange;
}
export enum ColorMode {
RGBA = 0,
Hex = 1,
HSLA = 2
}
/**
* A provider of links.
* A provider of colors.
*/
export interface ColorProvider {
provideColors(model: editorCommon.IReadOnlyModel, token: CancellationToken): IColorInfo[] | Thenable<IColorInfo[]>;
}
......
......@@ -112,7 +112,10 @@ export class ColorPicker implements IEditorContribution {
endColumn: c.range.endColumn
},
options: {
color: c.color
colorInfo: {
color: c.color,
mode: c.mode
}
}
});
}
......
......@@ -5,6 +5,7 @@
import { ColorPickerWidget } from "vs/editor/contrib/colorPicker/browser/colorPickerWidget";
import { Color, RGBA } from "vs/base/common/color";
import { ColorMode } from "vs/editor/common/modes";
export class ColorPickerModel {
......@@ -17,7 +18,7 @@ export class ColorPickerModel {
private _opacity: number;
private _hue: Color;
private _colorModel: ColorModel;
private _colorModel: ColorMode;
private _colorModelIndex: number;
constructor() {
......@@ -32,9 +33,9 @@ export class ColorPickerModel {
this._hue = color;
}
if (this._colorModel === ColorModel.RGBA) {
if (this._colorModel === ColorMode.RGBA) {
this.selectedColorString = color.toRGBA().toString();
} else if (this._colorModel === ColorModel.Hex) {
} else if (this._colorModel === ColorMode.Hex) {
this.selectedColorString = color.toRGBHex();
} else {
this.selectedColorString = color.toHSLA().toString();
......@@ -73,8 +74,8 @@ export class ColorPickerModel {
public set opacity(opacity: number) {
this._opacity = opacity;
if (this._colorModel === ColorModel.Hex) {
this.colorModel = ColorModel.RGBA;
if (this._colorModel === ColorMode.Hex) {
this.colorModel = ColorMode.RGBA;
}
const rgba = this._color.toRGBA();
......@@ -89,7 +90,7 @@ export class ColorPickerModel {
return this._opacity;
}
public set colorModel(model: ColorModel) {
public set colorModel(model: ColorMode) {
this._colorModel = model;
this._colorModelIndex = model;
......@@ -98,7 +99,7 @@ export class ColorPickerModel {
}
}
public get colorModel(): ColorModel {
public get colorModel(): ColorMode {
return this._colorModel;
}
......@@ -110,7 +111,7 @@ export class ColorPickerModel {
}
// Skip hex model if opacity is set
if (this._colorModelIndex === ColorModel.Hex && this._opacity !== 1) {
if (this._colorModelIndex === ColorMode.Hex && this._opacity !== 1) {
this.nextColorModel();
return;
}
......@@ -122,10 +123,4 @@ export class ColorPickerModel {
export class ISaturationState {
public x: number;
public y: number;
}
export enum ColorModel {
RGBA,
Hex,
HSL
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { TPromise } from "vs/base/common/winjs.base";
import { ColorProviderRegistry, IColorInfo } from "vs/editor/common/modes";
import { ColorProviderRegistry, IColorInfo, ColorProvider } from "vs/editor/common/modes";
import { asWinJsPromise } from "vs/base/common/async";
import { onUnexpectedExternalError } from "vs/base/common/errors";
import { IReadOnlyModel } from "vs/editor/common/editorCommon";
......@@ -24,4 +24,8 @@ export function getColors(model: IReadOnlyModel): TPromise<IColorInfo[]> {
return TPromise.join(promises).then(() => {
return colors;
});
}
export function changeMode(provider: ColorProvider, colorInfo: IColorInfo): TPromise<string> {
throw new Error('not implemented');
}
\ No newline at end of file
......@@ -22,9 +22,9 @@ import { HoverOperation, IHoverComputer } from './hoverOperation';
import { ContentHoverWidget } from './hoverWidgets';
import { textToMarkedString, MarkedString } from 'vs/base/common/htmlContent';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
import { Color } from 'vs/base/common/color';
import { ColorPickerModel, ColorModel } from "vs/editor/contrib/colorPicker/browser/colorPickerModel";
import { ColorPickerModel } from "vs/editor/contrib/colorPicker/browser/colorPickerModel";
import { ColorPickerWidget } from "vs/editor/contrib/colorPicker/browser/colorPickerWidget";
import { IColorInfo } from 'vs/editor/common/editorCommon';
class ModesContentComputer implements IHoverComputer<Hover[]> {
......@@ -67,7 +67,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
return [];
}
const hasHoverContent = (contents: MarkedString | MarkedString[] | Color) => {
const hasHoverContent = (contents: MarkedString | MarkedString[] | IColorInfo) => {
return contents && (!Array.isArray(contents) || (<MarkedString[]>contents).length > 0);
};
......@@ -78,7 +78,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1;
const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn;
if (startColumn > this._range.startColumn || this._range.endColumn > endColumn || (!hasHoverContent(d.options.hoverMessage) && !hasHoverContent(d.options.color))) {
if (startColumn > this._range.startColumn || this._range.endColumn > endColumn || (!hasHoverContent(d.options.hoverMessage) && !hasHoverContent(d.options.colorInfo))) {
return null;
}
......@@ -93,9 +93,14 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
}
}
const color = d.options.color;
if (color) {
return { color, range };
const colorInfo = d.options.colorInfo;
if (colorInfo) {
return {
color: colorInfo.color,
mode: colorInfo.mode,
range: range
};
}
return { contents, range };
......@@ -289,7 +294,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
const widget = this._register(new ColorPickerWidget(model, this._editor));
model.widget = widget;
model.originalColor = msg.color.toRGBA().toString();
model.colorModel = ColorModel.RGBA;
model.colorModel = msg.mode;
model.color = msg.color;
this._colorPicker = widget;
......
......@@ -265,6 +265,12 @@ declare module 'vscode' {
static fromHex(hex: string): Color;
}
export enum ColorMode {
RGBA = 0,
Hex = 1, // should we account for 4-byte hex?
HSLA = 2
}
// TODO@Michel
export class ColorInfo {
/**
......@@ -274,13 +280,14 @@ declare module 'vscode' {
color: Color;
constructor(color: Color, range: Range);
}
mode: ColorMode;
constructor(range: Range, color: Color, mode: ColorMode);
}
export interface DocumentColorProvider {
provideDocumentColors(document: TextDocument, token: CancellationToken): ProviderResult<ColorInfo[]>;
// provideColorFormat(colorInfo: ColorInfo): ProviderResult<string>;
provideColorFormat(colorInfo: ColorInfo): ProviderResult<string>;
}
export namespace languages {
......
......@@ -272,10 +272,11 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
this._registrations[handle] = modes.ColorProviderRegistry.register(selector, <modes.ColorProvider>{
provideColors: (model, token) => {
return wireCancellationToken(token, this._proxy.$provideDocumentColors(handle, model.uri))
.then((colors) => {
return colors.map(c => {
.then((colorInfos) => {
return colorInfos.map(c => {
return {
color: Color.fromRGBA(new RGBA(c.color[0], c.color[1], c.color[2], c.color[3] * 255)),
mode: c.mode,
range: c.range
};
});
......
......@@ -492,6 +492,7 @@ 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 } from 'vs/workbench/api/node/extHostTypes';
import { EndOfLine, TextEditorLineNumbersStyle, ColorMode } from 'vs/workbench/api/node/extHostTypes';
import { TaskSet } from 'vs/workbench/parts/tasks/common/tasks';
......@@ -456,6 +456,7 @@ export abstract class ExtHostHeapServiceShape {
export interface IColorInfo {
color: [number, number, number, number | undefined];
mode: ColorMode;
range: IRange;
}
......
......@@ -374,6 +374,7 @@ export namespace DocumentColor {
export function from(colorInfo: vscode.ColorInfo): IColorInfo {
return {
color: [colorInfo.color.red, colorInfo.color.green, colorInfo.color.blue, colorInfo.color.alpha],
mode: <number>colorInfo.mode,
range: fromRange(colorInfo.range)
};
}
......
......@@ -1043,20 +1043,32 @@ export class Color {
}
}
export enum ColorMode {
RGBA = 0,
Hex = 1,
HSLA = 2
}
export class ColorInfo {
range: Range;
color: Color;
constructor(color: Color, range: Range) {
mode: ColorMode;
constructor(range: Range, color: Color, mode: ColorMode) {
if (color && !(color instanceof Color)) {
throw illegalArgument('target');
throw illegalArgument('color');
}
if (mode && !(mode in ColorMode)) {
throw illegalArgument('mode');
}
if (!Range.isRange(range) || range.isEmpty) {
throw illegalArgument('range');
}
this.range = range;
this.color = color;
this.mode = mode;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册