debugViewlet.ts 7.8 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');
62
		this.updateBreakpointsMaxSize();
E
Erich Gamma 已提交
63 64
	}

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

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

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

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

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

		return null;
	}

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

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

106
		if (state === State.Initializing) {
E
Erich Gamma 已提交
107 108 109 110 111
			this.progressRunner = this.progressService.show(true);
		} else {
			this.progressRunner = null;
		}
	}
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

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

export class FocusVariablesViewAction extends Action {

	static ID = 'workbench.debug.action.focusVariablesView';
I
isidor 已提交
140
	static LABEL = nls.localize('debugFocusVariablesView', 'Focus Variables');
I
isidor 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

	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 {

	static ID = 'workbench.debug.action.focusWatchView';
	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 {

	static ID = 'workbench.debug.action.focusCallStackView';
	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 {

	static ID = 'workbench.debug.action.focusBreakpointsView';
	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);
		});
	}
}