debugViewlet.ts 4.2 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';
S
#27823  
Sandeep Somavarapu 已提交
12
import { ComposedViewsViewlet } from 'vs/workbench/parts/views/browser/views';
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 17 18 19
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
S
#27823  
Sandeep Somavarapu 已提交
20
import { IStorageService } from 'vs/platform/storage/common/storage';
B
Benjamin Pasero 已提交
21
import { IThemeService } from 'vs/platform/theme/common/themeService';
S
#27823  
Sandeep Somavarapu 已提交
22 23
import { ViewLocation } from 'vs/workbench/parts/views/browser/viewsRegistry';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
24
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
I
isidor 已提交
25

S
#27823  
Sandeep Somavarapu 已提交
26
export class DebugViewlet extends ComposedViewsViewlet {
E
Erich Gamma 已提交
27

I
isidor 已提交
28
	private actions: IAction[];
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 41
		@IContextKeyService contextKeyService: IContextKeyService,
		@IContextMenuService contextMenuService: IContextMenuService
E
Erich Gamma 已提交
42
	) {
43
		super(VIEWLET_ID, ViewLocation.Debug, `${VIEWLET_ID}.state`, telemetryService, storageService, instantiationService, themeService, contextService, contextKeyService, contextMenuService);
E
Erich Gamma 已提交
44 45 46

		this.progressRunner = null;

S
#27823  
Sandeep Somavarapu 已提交
47
		this._register(this.debugService.onDidChangeState(state => this.onDebugServiceStateChange(state)));
48 49
	}

S
#27823  
Sandeep Somavarapu 已提交
50 51
	public create(parent: Builder): TPromise<void> {
		return super.create(parent).then(() => DOM.addClass(this.viewletContainer, 'debug-viewlet'));
E
Erich Gamma 已提交
52 53
	}

I
isidor 已提交
54 55
	public focus(): void {
		super.focus();
56

B
Benjamin Pasero 已提交
57
		if (!this.contextService.hasWorkspace()) {
58
			this.views[0].focusBody();
59 60
		}

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

I
isidor 已提交
66
	public getActions(): IAction[] {
E
Erich Gamma 已提交
67
		if (!this.actions) {
68 69
			this.actions = [];
			this.actions.push(this.instantiationService.createInstance(StartAction, StartAction.ID, StartAction.LABEL));
B
Benjamin Pasero 已提交
70
			if (this.contextService.hasWorkspace()) {
71 72
				this.actions.push(this.instantiationService.createInstance(ConfigureAction, ConfigureAction.ID, ConfigureAction.LABEL));
			}
S
#27823  
Sandeep Somavarapu 已提交
73
			this.actions.push(this._register(this.instantiationService.createInstance(ToggleReplAction, ToggleReplAction.ID, ToggleReplAction.LABEL)));
E
Erich Gamma 已提交
74 75 76 77 78
		}

		return this.actions;
	}

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

I
isidor 已提交
83
	public getActionItem(action: IAction): IActionItem {
B
Benjamin Pasero 已提交
84
		if (action.id === StartAction.ID && this.contextService.hasWorkspace()) {
I
isidor 已提交
85
			this.startDebugActionItem = this.instantiationService.createInstance(StartDebugActionItem, null, action);
I
isidor 已提交
86
			return this.startDebugActionItem;
E
Erich Gamma 已提交
87 88 89 90 91
		}

		return null;
	}

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

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