Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: add run statusbar item #8134

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/debug/src/browser/debug-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
};
Expand All @@ -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');
Expand Down
62 changes: 61 additions & 1 deletion packages/debug/src/browser/debug-prefix-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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;

Expand All @@ -49,15 +54,34 @@ 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',
category: 'Debug',
label: 'Select and Start Debugging'
};

@postConstruct()
protected initialize(): 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);
}
Expand Down Expand Up @@ -119,4 +143,40 @@ 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
: '';
const icon = '$(play)';
this.statusBar.setElement(this.statusBarId, {
alignment: StatusBarAlignment.LEFT,
text: text.length ? `${icon} ${text}` : icon,
tooltip: this.command.label,
command: this.command.id,
});
}

/**
* Remove the debug status bar element.
*/
protected removeDebugStatusBar(): void {
this.statusBar.removeElement(this.statusBarId);
}
}