mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 01:25:38 -05:00
* Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d * Fix vs unit tests and hygiene issue * Fix strict null check issue
85 lines
3.2 KiB
TypeScript
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);
|
|
}
|
|
}
|