debugViewlet.ts 4.4 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import 'vs/css!./media/debugViewlet';
S
#27823  
Sandeep Somavarapu 已提交
7 8
import { Builder } from 'vs/base/browser/builder';
import * as DOM from 'vs/base/browser/dom';
J
Johannes Rieken 已提交
9
import { TPromise } from 'vs/base/common/winjs.base';
I
isidor 已提交
10 11
import { IAction } from 'vs/base/common/actions';
import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
J
Joao Moreno 已提交
12
import { PersistentViewsViewlet } from 'vs/workbench/browser/parts/views/viewsViewlet';
I
isidor 已提交
13
import { IDebugService, VIEWLET_ID, State } from 'vs/workbench/parts/debug/common/debug';
I
isidor 已提交
14 15
import { StartAction, ToggleReplAction, ConfigureAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { StartDebugActionItem } from 'vs/workbench/parts/debug/browser/debugActionItems';
J
Johannes Rieken 已提交
16
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
S
Sandeep Somavarapu 已提交
17
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
J
Johannes Rieken 已提交
18
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
19
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
20
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
S
#27823  
Sandeep Somavarapu 已提交
21
import { IStorageService } from 'vs/platform/storage/common/storage';
B
Benjamin Pasero 已提交
22
import { IThemeService } from 'vs/platform/theme/common/themeService';
23
import { ViewLocation } from 'vs/workbench/browser/parts/views/viewsRegistry';
S
#27823  
Sandeep Somavarapu 已提交
24
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
25
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
I
isidor 已提交
26

J
Joao Moreno 已提交
27
export class DebugViewlet extends PersistentViewsViewlet {
E
Erich Gamma 已提交
28

I
isidor 已提交
29
	private startDebugActionItem: StartDebugActionItem;
E
Erich Gamma 已提交
30 31 32 33 34 35
	private progressRunner: IProgressRunner;

	constructor(
		@ITelemetryService telemetryService: ITelemetryService,
		@IProgressService private progressService: IProgressService,
		@IDebugService private debugService: IDebugService,
S
#27823  
Sandeep Somavarapu 已提交
36 37 38 39
		@IInstantiationService instantiationService: IInstantiationService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
		@IStorageService storageService: IStorageService,
		@IThemeService themeService: IThemeService,
40
		@IContextKeyService contextKeyService: IContextKeyService,
S
Sandeep Somavarapu 已提交
41 42
		@IContextMenuService contextMenuService: IContextMenuService,
		@IExtensionService extensionService: IExtensionService
E
Erich Gamma 已提交
43
	) {
44
		super(VIEWLET_ID, ViewLocation.Debug, `${VIEWLET_ID}.state`, false, telemetryService, storageService, instantiationService, themeService, contextService, contextKeyService, contextMenuService, extensionService);
E
Erich Gamma 已提交
45 46 47

		this.progressRunner = null;

S
#27823  
Sandeep Somavarapu 已提交
48
		this._register(this.debugService.onDidChangeState(state => this.onDebugServiceStateChange(state)));
49
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateTitleArea()));
50 51
	}

52 53 54 55 56
	async create(parent: Builder): TPromise<void> {
		await super.create(parent);

		const el = parent.getHTMLElement();
		DOM.addClass(el, 'debug-viewlet');
E
Erich Gamma 已提交
57 58
	}

I
isidor 已提交
59 60
	public focus(): void {
		super.focus();
61

I
isidor 已提交
62 63
		if (this.startDebugActionItem) {
			this.startDebugActionItem.focus();
I
isidor 已提交
64 65 66
		}
	}

I
isidor 已提交
67
	public getActions(): IAction[] {
68 69 70 71
		const actions = [];
		actions.push(this.instantiationService.createInstance(StartAction, StartAction.ID, StartAction.LABEL));
		if (this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY) {
			actions.push(this.instantiationService.createInstance(ConfigureAction, ConfigureAction.ID, ConfigureAction.LABEL));
E
Erich Gamma 已提交
72
		}
73 74
		actions.push(this._register(this.instantiationService.createInstance(ToggleReplAction, ToggleReplAction.ID, ToggleReplAction.LABEL)));
		return actions;
E
Erich Gamma 已提交
75 76
	}

S
#27823  
Sandeep Somavarapu 已提交
77 78 79 80
	public getSecondaryActions(): IAction[] {
		return [];
	}

I
isidor 已提交
81
	public getActionItem(action: IAction): IActionItem {
82
		if (action.id === StartAction.ID && this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY) {
I
isidor 已提交
83
			this.startDebugActionItem = this.instantiationService.createInstance(StartDebugActionItem, null, action);
I
isidor 已提交
84
			return this.startDebugActionItem;
E
Erich Gamma 已提交
85 86 87 88 89
		}

		return null;
	}

90
	private onDebugServiceStateChange(state: State): void {
E
Erich Gamma 已提交
91 92 93 94
		if (this.progressRunner) {
			this.progressRunner.done();
		}

95
		if (state === State.Initializing) {
E
Erich Gamma 已提交
96 97 98 99 100 101
			this.progressRunner = this.progressService.show(true);
		} else {
			this.progressRunner = null;
		}
	}
}