Debug status should be IStatusbarEntry

fixes #74455
This commit is contained in:
isidor 2019-06-04 16:52:47 +02:00
parent fc9d770f2d
commit 640e3f1c4d
3 changed files with 52 additions and 80 deletions

View file

@ -4,88 +4,77 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDebugService, State, IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
import { Themable } from 'vs/workbench/common/theme';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
import { IStatusbarEntry, IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
const $ = dom.$;
export class DebugStatus extends Themable implements IStatusbarItem {
private container: HTMLElement;
private statusBarItem: HTMLElement;
private label: OcticonLabel;
export class DebugStatusContribution implements IWorkbenchContribution {
private showInStatusBar: 'never' | 'always' | 'onFirstSessionStart';
private toDispose: IDisposable[] = [];
private entryAccessor: IStatusbarEntryAccessor | undefined;
constructor(
@IQuickOpenService private readonly quickOpenService: IQuickOpenService,
@IDebugService private readonly debugService: IDebugService,
@IThemeService themeService: IThemeService,
@IConfigurationService configurationService: IConfigurationService
@IStatusbarService private readonly statusBarService: IStatusbarService,
@IDebugService readonly debugService: IDebugService,
@IConfigurationService readonly configurationService: IConfigurationService
) {
super(themeService);
this._register(this.debugService.getConfigurationManager().onDidSelectConfiguration(e => {
this.setLabel();
}));
this._register(this.debugService.onDidChangeState(state => {
if (state !== State.Inactive && this.showInStatusBar === 'onFirstSessionStart') {
this.doRender();
} else {
if (this.showInStatusBar !== 'never') {
this.updateStyles();
}
const setShowInStatusBar = () => {
this.showInStatusBar = configurationService.getValue<IDebugConfiguration>('debug').showInStatusBar;
if (this.showInStatusBar === 'always' && !this.entryAccessor) {
this.entryAccessor = this.statusBarService.addEntry(this.entry, StatusbarAlignment.LEFT, 30 /* Low Priority */);
}
};
setShowInStatusBar();
this.toDispose.push(this.debugService.onDidChangeState(state => {
if (state !== State.Inactive && this.showInStatusBar === 'onFirstSessionStart' && !this.entryAccessor) {
this.entryAccessor = this.statusBarService.addEntry(this.entry, StatusbarAlignment.LEFT, 30 /* Low Priority */);
}
}));
this.showInStatusBar = configurationService.getValue<IDebugConfiguration>('debug').showInStatusBar;
this._register(configurationService.onDidChangeConfiguration(e => {
this.toDispose.push(configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('debug.showInStatusBar')) {
this.showInStatusBar = configurationService.getValue<IDebugConfiguration>('debug').showInStatusBar;
if (this.showInStatusBar === 'always') {
this.doRender();
}
if (this.statusBarItem) {
dom.toggleClass(this.statusBarItem, 'hidden', this.showInStatusBar === 'never');
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);
}
}));
}
public render(container: HTMLElement): IDisposable {
this.container = container;
if (this.showInStatusBar === 'always') {
this.doRender();
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);
}
// noop, we render when we decide is best
return this;
return '';
}
private doRender(): void {
if (!this.statusBarItem && this.container) {
this.statusBarItem = dom.append(this.container, $('.debug-statusbar-item'));
this._register(dom.addDisposableListener(this.statusBarItem, 'click', () => this.quickOpenService.show('debug ')));
this.statusBarItem.title = nls.localize('selectAndStartDebug', "Select and start debug configuration");
const a = dom.append(this.statusBarItem, $('a'));
this.label = new OcticonLabel(a);
this.setLabel();
}
this.updateStyles();
private get entry(): IStatusbarEntry {
return {
text: this.getText(),
tooltip: nls.localize('selectAndStartDebug', "Select and start debug configuration"),
command: 'workbench.action.debug.selectandstart'
};
}
private setLabel(): void {
if (this.label && this.statusBarItem) {
const manager = this.debugService.getConfigurationManager();
const name = manager.selectedConfiguration.name || '';
const nameAndLaunchPresent = name && manager.selectedConfiguration.launch;
dom.toggleClass(this.statusBarItem, 'hidden', this.showInStatusBar === 'never' || !nameAndLaunchPresent);
if (nameAndLaunchPresent) {
this.label.text = '$(play) ' + (manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch!.name})` : name);
}
dispose(): void {
if (this.entryAccessor) {
this.entryAccessor.dispose();
}
dispose(this.toDispose);
}
}

View file

@ -110,20 +110,6 @@
box-sizing: border-box;
}
/* Debug status */
.monaco-workbench .part.statusbar > .statusbar-item > .debug-statusbar-item > a {
padding: 0 5px 0 5px;
}
.monaco-workbench .part.statusbar > .statusbar-item > .debug-statusbar-item span.octicon {
text-align: center;
font-size: 14px;
}
.monaco-workbench .part.statusbar .debug-statusbar-item.hidden {
display: none;
}
.monaco-workbench .debug-view-content .monaco-list-row .monaco-tl-contents {
overflow: hidden;
text-overflow: ellipsis;

View file

@ -15,8 +15,6 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'v
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionRegistryExtensions } from 'vs/workbench/common/actions';
import { ShowViewletAction, Extensions as ViewletExtensions, ViewletRegistry, ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { TogglePanelAction, Extensions as PanelExtensions, PanelRegistry, PanelDescriptor } from 'vs/workbench/browser/panel';
import { StatusbarItemDescriptor, IStatusbarRegistry, Extensions as StatusExtensions } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { BreakpointsView } from 'vs/workbench/contrib/debug/browser/breakpointsView';
import { CallStackView } from 'vs/workbench/contrib/debug/browser/callStackView';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
@ -40,7 +38,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { URI } from 'vs/base/common/uri';
import { DebugViewlet } from 'vs/workbench/contrib/debug/browser/debugViewlet';
import { DebugQuickOpenHandler } from 'vs/workbench/contrib/debug/browser/debugQuickOpen';
import { DebugStatus } from 'vs/workbench/contrib/debug/browser/debugStatus';
import { DebugStatusContribution } from 'vs/workbench/contrib/debug/browser/debugStatus';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
@ -258,8 +256,7 @@ configurationRegistry.registerConfiguration({
});
// Register Debug Status
const statusBar = Registry.as<IStatusbarRegistry>(StatusExtensions.Statusbar);
statusBar.registerStatusbarItem(new StatusbarItemDescriptor(DebugStatus, StatusbarAlignment.LEFT, 30 /* Low Priority */));
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DebugStatusContribution, LifecyclePhase.Eventually);
// Debug toolbar