mainThreadStatusBar.ts 1.4 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import {IStatusbarService, StatusbarAlignment as MainThreadStatusBarAlignment} from 'vs/platform/statusbar/common/statusbar';
import {IDisposable} from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
9
import {MainThreadStatusBarShape} from './extHost.protocol';
10

A
Alex Dima 已提交
11
export class MainThreadStatusBar extends MainThreadStatusBarShape {
12 13 14 15 16
	private mapIdToDisposable: { [id: number]: IDisposable };

	constructor(
		@IStatusbarService private statusbarService: IStatusbarService
	) {
A
Alex Dima 已提交
17
		super();
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
		this.mapIdToDisposable = Object.create(null);
	}

	setEntry(id: number, text: string, tooltip: string, command: string, color: string, alignment: MainThreadStatusBarAlignment, priority: number): void {

		// Dispose any old
		this.dispose(id);

		// Add new
		let disposeable = this.statusbarService.addEntry({ text, tooltip, command, color }, alignment, priority);
		this.mapIdToDisposable[id] = disposeable;
	}

	dispose(id: number) {
		let disposeable = this.mapIdToDisposable[id];
		if (disposeable) {
			disposeable.dispose();
		}

		delete this.mapIdToDisposable[id];
	}
}