colorPickerWidget.ts 1.8 KB
Newer Older
M
Michel Kaporin 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

M
Michel Kaporin 已提交
6
import 'vs/css!./colorpicker';
M
Michel Kaporin 已提交
7
import { ICodeEditor } from "vs/editor/browser/editorBrowser";
M
Michel Kaporin 已提交
8 9
import { Widget } from "vs/base/browser/ui/widget";
import * as dom from 'vs/base/browser/dom';
10
import { onDidChangeZoomLevel } from 'vs/base/browser/browser';
M
Michel Kaporin 已提交
11 12
import { ColorPickerHeader } from "vs/editor/contrib/colorPicker/browser/elements/colorPickerHeader";
import { ColorPickerBody } from "vs/editor/contrib/colorPicker/browser/elements/colorPickerBody";
13
import { ColorPickerModel } from "vs/editor/contrib/colorPicker/browser/colorPickerModel";
M
Michel Kaporin 已提交
14 15
const $ = dom.$;

M
Michel Kaporin 已提交
16
export class ColorPickerWidget extends Widget {
M
Michel Kaporin 已提交
17 18 19
	private static ID = 'editor.contrib.colorPickerWidget';

	private domNode: HTMLElement;
20 21
	public header: ColorPickerHeader;
	public body: ColorPickerBody;
M
Michel Kaporin 已提交
22

M
Michel Kaporin 已提交
23
	public visible: boolean = false;
M
Michel Kaporin 已提交
24

25
	constructor(public model: ColorPickerModel, public editor: ICodeEditor) {
M
Michel Kaporin 已提交
26
		super();
27
		this._register(onDidChangeZoomLevel(() => this.layout()));
M
Michel Kaporin 已提交
28
		this.domNode = $('.editor-widget.colorpicker-widget');
M
Michel Kaporin 已提交
29 30
	}

M
Michel Kaporin 已提交
31
	public layout(): void {
M
Michel Kaporin 已提交
32 33 34 35
		if (this.visible) {
			return;
		}

36
		this.header = new ColorPickerHeader(this, this.model);
M
Cleanup  
Michel Kaporin 已提交
37
		this.body = new ColorPickerBody(this, this.model);
M
Michel Kaporin 已提交
38

M
Michel Kaporin 已提交
39 40 41
		this.visible = true;
	}

M
Michel Kaporin 已提交
42 43
	public layoutSaturationBox(): void {
		this.body.saturationBox.layout();
M
Michel Kaporin 已提交
44
	}
M
Michel Kaporin 已提交
45 46

	public dispose(): void {
M
Michel Kaporin 已提交
47
		this.visible = false;
M
Michel Kaporin 已提交
48 49 50 51 52 53 54 55 56 57 58
		super.dispose();
	}

	public getId(): string {
		return ColorPickerWidget.ID;
	}

	public getDomNode(): HTMLElement {
		return this.domNode;
	}
}