debugViewlet.ts 8.3 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
Sandeep Somavarapu 已提交
8
import { IAction } from 'vs/base/common/actions';
S
#27823  
Sandeep Somavarapu 已提交
9
import * as DOM from 'vs/base/browser/dom';
I
isidor 已提交
10
import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
S
Sandeep Somavarapu 已提交
11
import { ViewContainerViewlet } from 'vs/workbench/browser/parts/views/viewsViewlet';
12
import { IDebugService, VIEWLET_ID, State, BREAKPOINTS_VIEW_ID, IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
13
import { StartAction, ToggleReplAction, ConfigureAction, SelectAndStartAction, FocusSessionAction } from 'vs/workbench/contrib/debug/browser/debugActions';
14
import { StartDebugActionItem, FocusSessionActionItem } from 'vs/workbench/contrib/debug/browser/debugActionItems';
J
Johannes Rieken 已提交
15
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
16
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
J
Johannes Rieken 已提交
17
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
I
isidor 已提交
18
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
J
Johannes Rieken 已提交
19
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';
22
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
23
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
24
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
I
isidor 已提交
25
import { memoize } from 'vs/base/common/decorators';
26
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
27
import { DebugToolbar } from 'vs/workbench/contrib/debug/browser/debugToolbar';
28
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
29
import { ViewletPanel } from 'vs/workbench/browser/parts/views/panelViewlet';
I
isidor 已提交
30 31 32 33
import { IMenu, MenuId, IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem';
import { INotificationService } from 'vs/platform/notification/common/notification';
I
isidor 已提交
34

S
Sandeep Somavarapu 已提交
35
export class DebugViewlet extends ViewContainerViewlet {
E
Erich Gamma 已提交
36

I
isidor 已提交
37
	private startDebugActionItem: StartDebugActionItem;
E
Erich Gamma 已提交
38
	private progressRunner: IProgressRunner;
39
	private breakpointView: ViewletPanel;
40
	private panelListeners = new Map<string, IDisposable>();
I
isidor 已提交
41
	private debugToolbarMenu: IMenu;
E
Erich Gamma 已提交
42 43

	constructor(
44
		@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
E
Erich Gamma 已提交
45
		@ITelemetryService telemetryService: ITelemetryService,
46 47
		@IProgressService private readonly progressService: IProgressService,
		@IDebugService private readonly debugService: IDebugService,
S
#27823  
Sandeep Somavarapu 已提交
48 49 50 51
		@IInstantiationService instantiationService: IInstantiationService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
		@IStorageService storageService: IStorageService,
		@IThemeService themeService: IThemeService,
S
Sandeep Somavarapu 已提交
52
		@IContextMenuService contextMenuService: IContextMenuService,
53
		@IExtensionService extensionService: IExtensionService,
54
		@IConfigurationService configurationService: IConfigurationService,
55 56
		@IKeybindingService private readonly keybindingService: IKeybindingService,
		@IContextViewService private readonly contextViewService: IContextViewService,
I
isidor 已提交
57 58 59
		@IMenuService private readonly menuService: IMenuService,
		@IContextKeyService private readonly contextKeyService: IContextKeyService,
		@INotificationService private readonly notificationService: INotificationService
E
Erich Gamma 已提交
60
	) {
61
		super(VIEWLET_ID, `${VIEWLET_ID}.state`, false, configurationService, layoutService, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService);
E
Erich Gamma 已提交
62

S
#27823  
Sandeep Somavarapu 已提交
63
		this._register(this.debugService.onDidChangeState(state => this.onDebugServiceStateChange(state)));
64
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateTitleArea()));
65
		this._register(this.configurationService.onDidChangeConfiguration(e => {
I
isidor 已提交
66
			if (e.affectsConfiguration('debug.toolBarLocation')) {
67 68 69
				this.updateTitleArea();
			}
		}));
70 71
	}

I
isidor 已提交
72 73 74
	create(parent: HTMLElement): void {
		super.create(parent);
		DOM.addClass(parent, 'debug-viewlet');
E
Erich Gamma 已提交
75 76
	}

77
	focus(): void {
I
isidor 已提交
78
		super.focus();
79

I
isidor 已提交
80 81
		if (this.startDebugActionItem) {
			this.startDebugActionItem.focus();
I
isidor 已提交
82 83 84
		}
	}

I
isidor 已提交
85
	@memoize
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	private get startAction(): StartAction {
		return this._register(this.instantiationService.createInstance(StartAction, StartAction.ID, StartAction.LABEL));
	}

	@memoize
	private get configureAction(): ConfigureAction {
		return this._register(this.instantiationService.createInstance(ConfigureAction, ConfigureAction.ID, ConfigureAction.LABEL));
	}

	@memoize
	private get toggleReplAction(): ToggleReplAction {
		return this._register(this.instantiationService.createInstance(ToggleReplAction, ToggleReplAction.ID, ToggleReplAction.LABEL));
	}

	@memoize
	private get selectAndStartAction(): SelectAndStartAction {
		return this._register(this.instantiationService.createInstance(SelectAndStartAction, SelectAndStartAction.ID, nls.localize('startAdditionalSession', "Start Additional Session")));
I
isidor 已提交
103 104
	}

105
	getActions(): IAction[] {
106 107 108 109
		if (this.showInitialDebugActions) {
			return [this.startAction, this.configureAction, this.toggleReplAction];
		}

I
isidor 已提交
110 111 112 113
		if (!this.debugToolbarMenu) {
			this.debugToolbarMenu = this.menuService.createMenu(MenuId.DebugToolbar, this.contextKeyService);
			this.toDispose.push(this.debugToolbarMenu);
		}
114
		return DebugToolbar.getActions(this.debugToolbarMenu, this.debugService, this.instantiationService);
115 116
	}

117
	get showInitialDebugActions(): boolean {
118
		const state = this.debugService.state;
I
isidor 已提交
119
		return state === State.Inactive || this.configurationService.getValue<IDebugConfiguration>('debug').toolBarLocation !== 'docked';
E
Erich Gamma 已提交
120 121
	}

122
	getSecondaryActions(): IAction[] {
123 124 125 126 127
		if (this.showInitialDebugActions) {
			return [];
		}

		return [this.selectAndStartAction, this.configureAction, this.toggleReplAction];
S
#27823  
Sandeep Somavarapu 已提交
128 129
	}

I
isidor 已提交
130
	getActionItem(action: IAction): IActionItem | null {
131
		if (action.id === StartAction.ID) {
I
isidor 已提交
132
			this.startDebugActionItem = this.instantiationService.createInstance(StartDebugActionItem, null, action);
I
isidor 已提交
133
			return this.startDebugActionItem;
E
Erich Gamma 已提交
134
		}
135 136 137
		if (action.id === FocusSessionAction.ID) {
			return new FocusSessionActionItem(action, this.debugService, this.themeService, this.contextViewService);
		}
I
isidor 已提交
138 139 140
		if (action instanceof MenuItemAction) {
			return new MenuItemActionItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
		}
E
Erich Gamma 已提交
141 142 143 144

		return null;
	}

145
	focusView(id: string): void {
I
isidor 已提交
146 147 148 149 150 151
		const view = this.getView(id);
		if (view) {
			view.focus();
		}
	}

152
	private onDebugServiceStateChange(state: State): void {
E
Erich Gamma 已提交
153 154 155 156
		if (this.progressRunner) {
			this.progressRunner.done();
		}

157
		if (state === State.Initializing) {
E
Erich Gamma 已提交
158 159
			this.progressRunner = this.progressService.show(true);
		}
160

I
isidor 已提交
161
		if (this.configurationService.getValue<IDebugConfiguration>('debug').toolBarLocation === 'docked') {
162 163
			this.updateTitleArea();
		}
E
Erich Gamma 已提交
164
	}
165

166
	addPanels(panels: { panel: ViewletPanel, size: number, index?: number }[]): void {
S
Sandeep Somavarapu 已提交
167 168 169 170 171 172 173 174 175 176
		super.addPanels(panels);

		for (const { panel } of panels) {
			// attach event listener to
			if (panel.id === BREAKPOINTS_VIEW_ID) {
				this.breakpointView = panel;
				this.updateBreakpointsMaxSize();
			} else {
				this.panelListeners.set(panel.id, panel.onDidChange(() => this.updateBreakpointsMaxSize()));
			}
177 178 179
		}
	}

180
	removePanels(panels: ViewletPanel[]): void {
S
Sandeep Somavarapu 已提交
181 182 183 184 185
		super.removePanels(panels);
		for (const panel of panels) {
			dispose(this.panelListeners.get(panel.id));
			this.panelListeners.delete(panel.id);
		}
186 187 188
	}

	private updateBreakpointsMaxSize(): void {
I
isidor 已提交
189 190
		if (this.breakpointView) {
			// We need to update the breakpoints view since all other views are collapsed #25384
191
			const allOtherCollapsed = this.panels.every(view => !view.isExpanded() || view === this.breakpointView);
I
isidor 已提交
192 193
			this.breakpointView.maximumBodySize = allOtherCollapsed ? Number.POSITIVE_INFINITY : this.breakpointView.minimumBodySize;
		}
194
	}
195
}