diff --git a/packages/debug/src/browser/debug-preferences.ts b/packages/debug/src/browser/debug-preferences.ts index 5c25ac33dbf8c..3a06847e4bff8 100644 --- a/packages/debug/src/browser/debug-preferences.ts +++ b/packages/debug/src/browser/debug-preferences.ts @@ -44,6 +44,11 @@ export const debugPreferencesSchema: PreferenceSchema = { type: 'boolean', default: false, description: 'Show variable values inline in editor while debugging.' + }, + 'debug.showInStatusBar': { + enum: ['never', 'always', 'onFirstSessionStart'], + description: 'Controls when the debug status bar should be visible.', + default: 'onFirstSessionStart' } } }; @@ -54,6 +59,7 @@ export class DebugConfiguration { 'debug.openDebug': 'neverOpen' | 'openOnSessionStart' | 'openOnFirstSessionStart' | 'openOnDebugBreak'; 'debug.internalConsoleOptions': 'neverOpen' | 'openOnSessionStart' | 'openOnFirstSessionStart'; 'debug.inlineValues': boolean; + 'debug.showInStatusBar': 'never' | 'always' | 'onFirstSessionStart'; } export const DebugPreferences = Symbol('DebugPreferences'); diff --git a/packages/debug/src/browser/debug-prefix-configuration.ts b/packages/debug/src/browser/debug-prefix-configuration.ts index 125f7fa48b66b..d516b2b86cf1c 100644 --- a/packages/debug/src/browser/debug-prefix-configuration.ts +++ b/packages/debug/src/browser/debug-prefix-configuration.ts @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { inject, injectable } from 'inversify'; +import { inject, injectable, postConstruct } from 'inversify'; import { Command, CommandContribution, CommandHandler, CommandRegistry } from '@theia/core/lib/common/command'; import { QuickOpenContribution, QuickOpenHandler, QuickOpenModel, @@ -27,6 +27,8 @@ import { DebugSessionOptions } from './debug-session-options'; import { WorkspaceService } from '@theia/workspace/lib/browser'; import { LabelProvider } from '@theia/core/lib/browser/label-provider'; import URI from '@theia/core/lib/common/uri'; +import { StatusBar, StatusBarAlignment } from '@theia/core/lib/browser'; +import { DebugPreferences } from './debug-preferences'; @injectable() export class DebugPrefixConfiguration implements CommandContribution, CommandHandler, QuickOpenContribution, QuickOpenHandler, QuickOpenModel { @@ -37,6 +39,9 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan @inject(DebugSessionManager) protected readonly debugSessionManager: DebugSessionManager; + @inject(DebugPreferences) + protected readonly preference: DebugPreferences; + @inject(DebugConfigurationManager) protected readonly debugConfigurationManager: DebugConfigurationManager; @@ -49,8 +54,12 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan @inject(LabelProvider) protected readonly labelProvider: LabelProvider; + @inject(StatusBar) + protected readonly statusBar: StatusBar; + readonly prefix = 'debug '; readonly description = 'Debug Configuration'; + readonly statusBarId = 'select-run-debug-statusbar-item'; private readonly command: Command = { id: 'select.debug.configuration', @@ -58,6 +67,21 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan label: 'Select and Start Debugging' }; + @postConstruct() + protected update(): void { + this.handleDebugStatusBarVisibility(); + this.preference.onPreferenceChanged(e => { + if (e.preferenceName === 'debug.showInStatusBar') { + this.handleDebugStatusBarVisibility(); + } + }); + const toDisposeOnStart = this.debugSessionManager.onDidStartDebugSession(() => { + toDisposeOnStart.dispose(); + this.handleDebugStatusBarVisibility(true); + this.debugConfigurationManager.onDidChange(() => this.handleDebugStatusBarVisibility(true)); + }); + } + execute(): void { this.prefixQuickOpenService.open(this.prefix); } @@ -119,4 +143,39 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan this.debugConfigurationManager.current = { ...configuration }; this.commandRegistry.executeCommand(DebugCommands.START.id); } + + /** + * Handle the visibility of the debug status bar. + * @param event the preference change event. + */ + protected handleDebugStatusBarVisibility(started?: boolean): void { + const showInStatusBar = this.preference['debug.showInStatusBar']; + if (showInStatusBar === 'never') { + return this.removeDebugStatusBar(); + } else if (showInStatusBar === 'always' || started) { + return this.updateStatusBar(); + } + } + + /** + * Update the debug status bar element based on the current configuration. + */ + protected updateStatusBar(): void { + const text: string = this.debugConfigurationManager.current + ? this.debugConfigurationManager.current.configuration.name + : ''; + this.statusBar.setElement(this.statusBarId, { + alignment: StatusBarAlignment.LEFT, + text: '$(play) ' + text, + tooltip: this.command.label, + command: this.command.id, + }); + } + + /** + * Remove the debug status bar element. + */ + protected removeDebugStatusBar(): void { + this.statusBar.removeElement(this.statusBarId); + } }