debugViewlet.ts 7.9 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';
I
isidor 已提交
7
import * as nls from 'vs/nls';
S
#27823  
Sandeep Somavarapu 已提交
8
import { Builder } from 'vs/base/browser/builder';
I
isidor 已提交
9
import { Action, IAction } from 'vs/base/common/actions';
S
#27823  
Sandeep Somavarapu 已提交
10
import * as DOM from 'vs/base/browser/dom';
J
Johannes Rieken 已提交
11
import { TPromise } from 'vs/base/common/winjs.base';
I
isidor 已提交
12
import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
13
import { PersistentViewsViewlet, ViewsViewletPanel } from 'vs/workbench/browser/parts/views/viewsViewlet';
I
isidor 已提交
14
import { IDebugService, VIEWLET_ID, State, VARIABLES_VIEW_ID, WATCH_VIEW_ID, CALLSTACK_VIEW_ID, BREAKPOINTS_VIEW_ID } from 'vs/workbench/parts/debug/common/debug';
I
isidor 已提交
15 16
import { StartAction, ToggleReplAction, ConfigureAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { StartDebugActionItem } from 'vs/workbench/parts/debug/browser/debugActionItems';
J
Johannes Rieken 已提交
17
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
S
Sandeep Somavarapu 已提交
18
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
J
Johannes Rieken 已提交
19
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
I
isidor 已提交
20
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
21
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
S
#27823  
Sandeep Somavarapu 已提交
22
import { IStorageService } from 'vs/platform/storage/common/storage';
B
Benjamin Pasero 已提交
23
import { IThemeService } from 'vs/platform/theme/common/themeService';
I
isidor 已提交
24
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
25
import { ViewLocation } from 'vs/workbench/browser/parts/views/viewsRegistry';
S
#27823  
Sandeep Somavarapu 已提交
26
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
27
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
28
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
I
isidor 已提交
29

J
Joao Moreno 已提交
30
export class DebugViewlet extends PersistentViewsViewlet {
E
Erich Gamma 已提交
31

I
isidor 已提交
32
	private startDebugActionItem: StartDebugActionItem;
E
Erich Gamma 已提交
33
	private progressRunner: IProgressRunner;
34 35
	private breakpointView: ViewsViewletPanel;
	private panelListeners = new Map<string, IDisposable>();
E
Erich Gamma 已提交
36 37 38 39 40

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

		this.progressRunner = null;

S
#27823  
Sandeep Somavarapu 已提交
53
		this._register(this.debugService.onDidChangeState(state => this.onDebugServiceStateChange(state)));
54
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateTitleArea()));
55 56
	}

57 58 59 60 61
	async create(parent: Builder): TPromise<void> {
		await super.create(parent);

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

I
isidor 已提交
64 65
	public focus(): void {
		super.focus();
66

I
isidor 已提交
67 68
		if (this.startDebugActionItem) {
			this.startDebugActionItem.focus();
I
isidor 已提交
69 70 71
		}
	}

I
isidor 已提交
72
	public getActions(): IAction[] {
73 74
		const actions = [];
		actions.push(this.instantiationService.createInstance(StartAction, StartAction.ID, StartAction.LABEL));
I
isidor 已提交
75
		actions.push(this.instantiationService.createInstance(ConfigureAction, ConfigureAction.ID, ConfigureAction.LABEL));
76 77
		actions.push(this._register(this.instantiationService.createInstance(ToggleReplAction, ToggleReplAction.ID, ToggleReplAction.LABEL)));
		return actions;
E
Erich Gamma 已提交
78 79
	}

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

I
isidor 已提交
84
	public getActionItem(action: IAction): IActionItem {
I
isidor 已提交
85
		if (action.id === StartAction.ID && !!this.debugService.getConfigurationManager().selectedLaunch) {
I
isidor 已提交
86
			this.startDebugActionItem = this.instantiationService.createInstance(StartDebugActionItem, null, action);
I
isidor 已提交
87
			return this.startDebugActionItem;
E
Erich Gamma 已提交
88 89 90 91 92
		}

		return null;
	}

I
isidor 已提交
93 94 95 96 97 98 99
	public focusView(id: string): void {
		const view = this.getView(id);
		if (view) {
			view.focus();
		}
	}

100
	private onDebugServiceStateChange(state: State): void {
E
Erich Gamma 已提交
101 102 103 104
		if (this.progressRunner) {
			this.progressRunner.done();
		}

105
		if (state === State.Initializing) {
E
Erich Gamma 已提交
106 107 108 109 110
			this.progressRunner = this.progressService.show(true);
		} else {
			this.progressRunner = null;
		}
	}
111 112 113 114 115 116 117

	addPanel(panel: ViewsViewletPanel, size: number, index?: number): void {
		super.addPanel(panel, size, index);

		// attach event listener to
		if (panel.id === BREAKPOINTS_VIEW_ID) {
			this.breakpointView = panel;
I
isidor 已提交
118
			this.updateBreakpointsMaxSize();
119 120 121 122 123 124 125 126 127 128 129 130
		} else {
			this.panelListeners.set(panel.id, panel.onDidChange(() => this.updateBreakpointsMaxSize()));
		}
	}

	removePanel(panel: ViewsViewletPanel): void {
		super.removePanel(panel);
		dispose(this.panelListeners.get(panel.id));
		this.panelListeners.delete(panel.id);
	}

	private updateBreakpointsMaxSize(): void {
I
isidor 已提交
131 132 133 134 135
		if (this.breakpointView) {
			// We need to update the breakpoints view since all other views are collapsed #25384
			const allOtherCollapsed = this.views.every(view => !view.isExpanded() || view === this.breakpointView);
			this.breakpointView.maximumBodySize = allOtherCollapsed ? Number.POSITIVE_INFINITY : this.breakpointView.minimumBodySize;
		}
136
	}
E
Erich Gamma 已提交
137
}
I
isidor 已提交
138 139 140

export class FocusVariablesViewAction extends Action {

141
	static readonly ID = 'workbench.debug.action.focusVariablesView';
I
isidor 已提交
142
	static LABEL = nls.localize('debugFocusVariablesView', 'Focus Variables');
I
isidor 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

	constructor(id: string, label: string,
		@IViewletService private viewletService: IViewletService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		return this.viewletService.openViewlet(VIEWLET_ID).then((viewlet: DebugViewlet) => {
			viewlet.focusView(VARIABLES_VIEW_ID);
		});
	}
}

export class FocusWatchViewAction extends Action {

159
	static readonly ID = 'workbench.debug.action.focusWatchView';
I
isidor 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	static LABEL = nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'debugFocusWatchView' }, 'Focus Watch');

	constructor(id: string, label: string,
		@IViewletService private viewletService: IViewletService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		return this.viewletService.openViewlet(VIEWLET_ID).then((viewlet: DebugViewlet) => {
			viewlet.focusView(WATCH_VIEW_ID);
		});
	}
}

export class FocusCallStackViewAction extends Action {

177
	static readonly ID = 'workbench.debug.action.focusCallStackView';
I
isidor 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
	static LABEL = nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'debugFocusCallStackView' }, 'Focus CallStack');

	constructor(id: string, label: string,
		@IViewletService private viewletService: IViewletService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		return this.viewletService.openViewlet(VIEWLET_ID).then((viewlet: DebugViewlet) => {
			viewlet.focusView(CALLSTACK_VIEW_ID);
		});
	}
}

export class FocusBreakpointsViewAction extends Action {

195
	static readonly ID = 'workbench.debug.action.focusBreakpointsView';
I
isidor 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209
	static LABEL = nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'debugFocusBreakpointsView' }, 'Focus Breakpoints');

	constructor(id: string, label: string,
		@IViewletService private viewletService: IViewletService
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		return this.viewletService.openViewlet(VIEWLET_ID).then((viewlet: DebugViewlet) => {
			viewlet.focusView(BREAKPOINTS_VIEW_ID);
		});
	}
}