Files
azuredatastudio/src/vs/workbench/contrib/debug/browser/debugStatus.ts
Anthony Dresser 0b7e7ddbf9 Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)
* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
2019-07-15 22:35:46 -07:00

85 lines
3.2 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDebugService, State, IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IStatusbarEntry, IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
export class DebugStatusContribution implements IWorkbenchContribution {
private showInStatusBar: 'never' | 'always' | 'onFirstSessionStart';
private toDispose: IDisposable[] = [];
private entryAccessor: IStatusbarEntryAccessor | undefined;
constructor(
@IStatusbarService private readonly statusBarService: IStatusbarService,
@IDebugService readonly debugService: IDebugService,
@IConfigurationService readonly configurationService: IConfigurationService
) {
const addStatusBarEntry = () => {
this.entryAccessor = this.statusBarService.addEntry(this.entry, 'status.debug', nls.localize('status.debug', "Debug"), StatusbarAlignment.LEFT, 30 /* Low Priority */);
};
const setShowInStatusBar = () => {
this.showInStatusBar = configurationService.getValue<IDebugConfiguration>('debug').showInStatusBar;
if (this.showInStatusBar === 'always' && !this.entryAccessor) {
addStatusBarEntry();
}
};
setShowInStatusBar();
this.toDispose.push(this.debugService.onDidChangeState(state => {
if (state !== State.Inactive && this.showInStatusBar === 'onFirstSessionStart' && !this.entryAccessor) {
addStatusBarEntry();
}
}));
this.toDispose.push(configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('debug.showInStatusBar')) {
setShowInStatusBar();
if (this.entryAccessor && this.showInStatusBar === 'never') {
this.entryAccessor.dispose();
this.entryAccessor = undefined;
}
}
}));
this.toDispose.push(this.debugService.getConfigurationManager().onDidSelectConfiguration(e => {
if (this.entryAccessor) {
this.entryAccessor.update(this.entry);
}
}));
}
private getText(): string {
const manager = this.debugService.getConfigurationManager();
const name = manager.selectedConfiguration.name || '';
const nameAndLaunchPresent = name && manager.selectedConfiguration.launch;
if (nameAndLaunchPresent) {
return '$(play) ' + (manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch!.name})` : name);
}
return '';
}
private get entry(): IStatusbarEntry {
return {
text: this.getText(),
tooltip: nls.localize('selectAndStartDebug', "Select and start debug configuration"),
command: 'workbench.action.debug.selectandstart'
};
}
dispose(): void {
if (this.entryAccessor) {
this.entryAccessor.dispose();
}
dispose(this.toDispose);
}
}