From 852e2874b91417d17d8c4dee16608e4612b0235f Mon Sep 17 00:00:00 2001 From: Stefan Schweizer Date: Tue, 21 Apr 2020 11:38:29 +0200 Subject: [PATCH 01/32] removed unused warning button --- src/status.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/status.ts b/src/status.ts index ad454842d..4eddbc8bf 100644 --- a/src/status.ts +++ b/src/status.ts @@ -28,7 +28,6 @@ export class StatusBar implements vscode.Disposable { private readonly _debugButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.25); private readonly _launchTargetNameButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.2); private readonly _testButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.1); - private readonly _warningMessage = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3); private readonly _activeFolderButtonAutoSelectTooltip = localize('active.folder.auto.select.tooltip', 'Active folder'); private readonly _activeFolderButtonTooltip = localize('active.folder.tooltip', 'Select Active folder'); @@ -42,7 +41,6 @@ export class StatusBar implements vscode.Disposable { this._targetButton, this._launchTargetNameButton, this._testButton, - this._warningMessage, ]; for (const item of items) { item.dispose(); @@ -244,13 +242,6 @@ export class StatusBar implements vscode.Disposable { } private _activeKitName: string = ''; - showWarningMessage(msg: string) { - this._warningMessage.color = 'yellow'; - this._warningMessage.text = `$(alert) ${msg}`; - this._warningMessage.show(); - setTimeout(() => this._warningMessage.hide(), 5000); - } - private _hideDebugButton = false; hideDebugButton(shouldHide: boolean = true) { this._hideDebugButton = shouldHide; From b367244cedb017d4725d9ef517776ca0a583c4a1 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer Date: Thu, 23 Apr 2020 14:00:07 +0200 Subject: [PATCH 02/32] statusbar update: now uses classes --- src/extension.ts | 10 +- src/status.ts | 425 +++++++++++++++++++++++++---------------------- 2 files changed, 233 insertions(+), 202 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7b67f6191..6a733b5c2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -58,7 +58,7 @@ type CMakeToolsQueryMapFn = (cmt: CMakeTools) => Thenable { console.assert(this._folders.size === vscode.workspace.workspaceFolders?.length); if (this._folders.size === 1) { @@ -389,7 +389,7 @@ class ExtensionManager implements vscode.Disposable { } else if (!ws) { // When adding a folder but the focus is on somewhere else // Do nothing but make sure we are showing the active folder correctly - this._statusBar.reloadVisibility(); + this._statusBar.update(); } } } @@ -518,14 +518,14 @@ class ExtensionManager implements vscode.Disposable { this._statusBar.setVisible(true); this._statusMessageSub = cmt.onStatusMessageChanged(FireNow, s => this._statusBar.setStatusMessage(s)); this._targetNameSub = cmt.onTargetNameChanged(FireNow, t => { - this._statusBar.targetName = t; + this._statusBar.setBuildTargetName(t); }); this._buildTypeSub = cmt.onBuildTypeChanged(FireNow, bt => this._statusBar.setBuildTypeLabel(bt)); this._launchTargetSub = cmt.onLaunchTargetNameChanged(FireNow, t => { this._statusBar.setLaunchTargetName(t || ''); }); - this._ctestEnabledSub = cmt.onCTestEnabledChanged(FireNow, e => this._statusBar.ctestEnabled = e); - this._testResultsSub = cmt.onTestResultsChanged(FireNow, r => this._statusBar.testResults = r); + this._ctestEnabledSub = cmt.onCTestEnabledChanged(FireNow, e => this._statusBar.setCTestEnabled(e)); + this._testResultsSub = cmt.onTestResultsChanged(FireNow, r => this._statusBar.setTestResults(r)); this._isBusySub = cmt.onIsBusyChanged(FireNow, b => this._statusBar.setIsBusy(b)); this._statusBar.setActiveKitName(cmt.activeKit ? cmt.activeKit.name : ''); } diff --git a/src/status.ts b/src/status.ts index 4eddbc8bf..446a64aeb 100644 --- a/src/status.ts +++ b/src/status.ts @@ -3,248 +3,279 @@ import {BasicTestResults} from '@cmt/ctest'; import * as nls from 'vscode-nls'; import {SpecialKits} from '@cmt/kit'; +// FIXME: Show workspace selection if a folder is added to workspace + nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); -interface Hideable { - show(): void; - hide(): void; -} - -function setVisible(i: Hideable, v: boolean) { - if (v) { - i.show(); - } else { - i.hide(); +type ButtonType = "text" | "short" | "icon" | "hidden"; +abstract class Button { + set command(v:string|null) { this._button.command = v || undefined;} + private _forceHidden:boolean = false; + set forceHidden(v:boolean) { this._forceHidden = v; this.update(); } + constructor(protected readonly priority: number) { + this._button.command = this._button.command; } -} - -export class StatusBar implements vscode.Disposable { - private readonly _activeFolderButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.6); - private readonly _cmakeToolsStatusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.5); - private readonly _kitSelectionButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.45); - private readonly _buildButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.4); - private readonly _targetButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.3); - private readonly _debugButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.25); - private readonly _launchTargetNameButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.2); - private readonly _testButton = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 3.1); - - private readonly _activeFolderButtonAutoSelectTooltip = localize('active.folder.auto.select.tooltip', 'Active folder'); - private readonly _activeFolderButtonTooltip = localize('active.folder.tooltip', 'Select Active folder'); - - dispose() { - const items = [ - this._activeFolderButton, - this._cmakeToolsStatusItem, - this._kitSelectionButton, - this._buildButton, - this._targetButton, - this._launchTargetNameButton, - this._testButton, - ]; - for (const item of items) { - item.dispose(); - } + protected readonly _button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, this.priority); + private _tooltip: string|null = null; + get tooltip() { return this._tooltip; } + set tooltip(v:string|null) { + this._tooltip = v; + this.update(); } - constructor() { - this._activeFolderButton.command = 'cmake.selectActiveFolder'; - this._activeFolderButton.tooltip = this._activeFolderButtonTooltip; - this._activeFolderButton.text = this._activeFolder; - this._cmakeToolsStatusItem.command = 'cmake.setVariant'; - this._cmakeToolsStatusItem.tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); - this._buildButton.command = 'cmake.build'; - this._kitSelectionButton.command = 'cmake.selectKit'; - this._kitSelectionButton.tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); - this._targetButton.command = 'cmake.setDefaultTarget'; - this._targetButton.tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); - this._testButton.command = 'cmake.ctest'; - this._testButton.tooltip = localize('run.ctest.tests.tooltip', 'Run CTest tests'); - this._debugButton.tooltip = localize('launch.debugger.tooltip', 'Launch the debugger for the selected target'); - this._debugButton.command = 'cmake.debugTarget'; - this._launchTargetNameButton.command = 'cmake.selectLaunchTarget'; - this._launchTargetNameButton.tooltip = localize('select.target.tooltip', 'Select the target to launch'); - this._reloadBuildButton(); - this.reloadVisibility(); - } - - reloadVisibility() { - setVisible(this._activeFolderButton, Boolean(this._visible && vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this._activeFolderButton.text)); - const autovis_items = [ - this._cmakeToolsStatusItem, - this._buildButton, - this._kitSelectionButton, - this._targetButton, - this._debugButton, - this._launchTargetNameButton, - ]; - for (const item of autovis_items) { - setVisible(item, this._visible && !!item.text); + private _text: string = ''; + get text() { return this._text; } + set text(v:string) { + this._text = v; + this.update(); + } + dispose() { this._button.dispose(); } + update() { + const visible = this._isVisible(); + if (visible && !this._forceHidden) { + this._button.text = this.getText(); + this._button.tooltip = this.getTooltip() || undefined; + this._button.show(); + }else { + this._button.hide(); } - setVisible(this._debugButton, - this._visible && !this._hideDebugButton && vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined - && !!this._debugButton.text); + return visible; } - /** - * Whether the status bar items are visible - */ - setVisible(v: boolean) { - this._visible = v; - this.reloadVisibility(); + private _isVisible() { + return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; } - private _visible: boolean = true; + protected isVisible() { return true; } + protected getType():ButtonType { return "text"; } - private _reloadStatusButton() { - this._cmakeToolsStatusItem.text = `CMake: ${this._buildTypeLabel}: ${this._statusMessage}`; - this.reloadVisibility(); + getTooltip():string|null { + const type = this.getType(); + switch (type) { + case "hidden": + return null; + case "icon": + return this.getTooltipIcon(); + case "short": + return this.getTooltipShort(); + case "text": + return this.getTooltipNormal(); + } } - - private _reloadDebugButton() { - if (!this._launchTargetNameButton.text) { - this._debugButton.text = '$(bug)'; - this._launchTargetNameButton.hide(); - } else { - this._debugButton.text = `$(bug) ${localize('debug', 'Debug')}`; - if (this._visible) { - this._launchTargetNameButton.show(); - } + getText():string { + const type = this.getType(); + switch (type) { + case "icon": + return this.getTextIcon(); + case "short": + return this.getTextShort(); + default: + return this.getTextNormal(); } - this.reloadVisibility(); } - private _reloadActiveFolderButton() { - this._activeFolderButton.text = this._activeFolder; - this._activeFolderButton.tooltip = this._autoSelectActiveFolder ? this._activeFolderButtonAutoSelectTooltip : this._activeFolderButtonTooltip; - this.reloadVisibility(); - } + protected getTooltipNormal():string|null { return this._tooltip; } + protected getTooltipIcon():string|null { return this.getTooltipNormal(); } + protected getTooltipShort():string|null { return this.getTooltipNormal(); } - private _activeFolder: string = ''; - setActiveFolderName(v: string) { - this._activeFolder = v; - this._reloadActiveFolderButton(); - } + protected getTextNormal():string { return this._text; } + protected getTextIcon():string { return this.getTextNormal(); } + protected getTextShort():string { return this.getTextNormal(); } - private _autoSelectActiveFolder: boolean = false; - setAutoSelectActiveFolder(autoSelectActiveFolder: boolean) { - this._autoSelectActiveFolder = autoSelectActiveFolder; - this._reloadActiveFolderButton(); - } +} - /** - * The build type label. Determined by the active build variant - */ - private _buildTypeLabel: string = localize('unconfigured', 'Unconfigured'); - setBuildTypeLabel(v: string) { - this._buildTypeLabel = v; - this._reloadStatusButton(); - } +class ActiveFolderButton extends Button { + command = "cmake.selectActiveFolder"; + private _autoSelect: boolean = false; + set autoSelect(v:boolean) { this._autoSelect = v; this.update(); } + private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); + private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); - /** - * The message shown in the primary status button. Tells the user what the - * extension is currently up to. - */ - private _statusMessage: string = localize('loading.status', 'Loading...'); - setStatusMessage(v: string) { - this._statusMessage = v; - this._reloadStatusButton(); + protected getTooltipNormal(): string|null { return this._autoSelect?ActiveFolderButton._autoSelectToolTip:ActiveFolderButton._toolTip; } + protected isVisible() { + return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this.getText()); } + protected getType():ButtonType { return 'icon'; } // TODO: settings icon/text + protected getTextIcon(): string { return '$(folder-active)';} + protected getTooltipIcon(): string { return `CMake: ${this.getTooltipNormal()}\n${this.getTextNormal()}`;} +} + +class CMakeStatus extends Button { + command = "cmake.setVariant"; + tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); + + private static _buildTypeLabel: string = localize('unconfigured', 'Unconfigured'); + private static _statusMessage: string = localize('loading.status', 'Loading...'); - /** - * The name of the currently active target to build - */ - private _targetName: string = ''; - public get targetName(): string { return this._targetName; } - public set targetName(v: string) { - this._targetName = v; - this._targetButton.text = `[${v}]`; - this.reloadVisibility(); + set buildTypeLabel(v:string) { CMakeStatus._buildTypeLabel = v; this.update();} + set statusMessage(v:string) { CMakeStatus._statusMessage = v; this.update();} + + protected getType():ButtonType { return 'short'; } // TODO: settings icon/text + protected getTextNormal() { + return `CMake: ${CMakeStatus._buildTypeLabel}: ${CMakeStatus._statusMessage}`; + } + protected getTextShort() { + return `${CMakeStatus._buildTypeLabel}: ${CMakeStatus._statusMessage}`; } +} + +class KitSelection extends Button { + command = 'cmake.selectKit'; + tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); - setLaunchTargetName(v: string) { - this._launchTargetNameButton.text = v; - this._reloadDebugButton(); + protected getType():ButtonType { return 'short'; } // TODO: settings icon/text + protected getTextNormal():string { + const text = this.text; + if (text === SpecialKits.Unspecified) { + return `[${localize('no.active.kit', 'No active kit')}]`; + } + if (text.length===0) { + return localize('no.kit.selected', 'No Kit Selected'); + } + return text; + } + protected getTextShort() { + const len = 10; + let text = this.getTextNormal(); + if (len+3 this._buttons.forEach(btn => btn.dispose()); + update = () => this._buttons.forEach(btn => btn.update()); + setVisible= (v: boolean) => this._buttons.forEach(btn => btn.forceHidden = !v); + + setActiveFolderName = (v: string) => this._activeFolderButton.text = v; + setAutoSelectActiveFolder = (autoSelectActiveFolder: boolean) => this._activeFolderButton.autoSelect = autoSelectActiveFolder; + setBuildTypeLabel = (v: string) => this._cmakeToolsStatusItem.buildTypeLabel = v; + setStatusMessage = (v: string) => this._cmakeToolsStatusItem.statusMessage = v; + setBuildTargetName = (v: string) => this._buildTargetNameButton.text = v; + setLaunchTargetName = (v: string) => this._launchTargetNameButton.text = v; + setCTestEnabled = (v: boolean) => this._testButton.enabled = v; + setTestResults = (v: BasicTestResults|null) => this._testButton.results = v; + setIsBusy = (v:boolean) => this._buildButton.isBusy = v; + setActiveKitName = (v:string) => this._kitSelectionButton.text = v; + hideDebugButton(shouldHide: boolean = true) { - this._hideDebugButton = shouldHide; - this.reloadVisibility(); + if (false) return shouldHide; + // TODO: Find out if this is called... } } \ No newline at end of file From 3ecb255981de3bb65410a4be589b44b514bbc392 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 23 Apr 2020 19:32:07 +0200 Subject: [PATCH 03/32] added settings --- package.json | 90 ++++++++++++++++++++++++++++++++++ src/config.ts | 38 ++++++++++++++ src/extension.ts | 2 +- src/status.ts | 40 ++++++++------- test/unit-tests/config.test.ts | 30 ++++++++++++ 5 files changed, 182 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 648fcb4fc..5f6d48674 100644 --- a/package.json +++ b/package.json @@ -1150,6 +1150,96 @@ ], "scope": "window" }, + "cmake.statusbar.kit.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "short", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.kit.length": { + "type": "integer", + "default": 10, + "scope": "window" + }, + "cmake.statusbar.status.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "short", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.workspace.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.build_target.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.build.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "icon", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.launch_target.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.debug.type": { + "type": "string", + "default": "icon", + "enum": [ + "icon", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.launch.type": { + "type": "string", + "default": "icon", + "enum": [ + "icon", + "hidden" + ], + "scope": "window" + }, + "cmake.statusbar.ctest.type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "hidden" + ], + "scope": "window" + }, + "cmake.revealLog": { "type": "string", "default": "always", diff --git a/src/config.ts b/src/config.ts index 23853aafe..c636215c4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -19,10 +19,43 @@ export type LogLevelKey = 'trace'|'debug'|'info'|'note'|'warning'|'error'|'fatal export type CMakeCommunicationMode = 'legacy'|'serverApi'|'fileApi'|'automatic'; +export type StatusBarButtonType = "text" | "short" | "icon" | "hidden"; + interface HardEnv { [key: string]: string; } +export interface StatusBarConfig { + kit: { + type: StatusBarButtonType; + length: number; + }; + status: { + type: StatusBarButtonType; + }; + workspace: { + type: StatusBarButtonType; + }; + build_target: { + type: StatusBarButtonType; + }; + build: { + type: StatusBarButtonType; + }; + launch_target: { + type: StatusBarButtonType; + }; + debug: { + type: StatusBarButtonType; + }; + launch: { + type: StatusBarButtonType; + }; + ctest: { + type: StatusBarButtonType; + }; +} + export interface ExtensionConfigurationSettings { autoSelectActiveFolder: boolean; cmakePath: string; @@ -64,6 +97,7 @@ export interface ExtensionConfigurationSettings { outputLogEncoding: string; enableTraceLogging: boolean; loggingLevel: LogLevelKey; + statusbar: StatusBarConfig; } type EmittersOf = { @@ -84,6 +118,8 @@ export class ConfigurationReader implements vscode.Disposable { get configData() { return this._configData; } + get statusbar() { return this._configData.statusbar; } + dispose() { if (this._updateSubscription) { this._updateSubscription.dispose(); @@ -286,6 +322,8 @@ export class ConfigurationReader implements vscode.Disposable { outputLogEncoding: new vscode.EventEmitter(), enableTraceLogging: new vscode.EventEmitter(), loggingLevel: new vscode.EventEmitter(), + statusbar: new vscode.EventEmitter() + }; /** diff --git a/src/extension.ts b/src/extension.ts index 6a733b5c2..b57f857e3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -183,7 +183,7 @@ class ExtensionManager implements vscode.Disposable { /** * The status bar controller */ - private readonly _statusBar = new StatusBar(); + private readonly _statusBar = new StatusBar(this._workspaceConfig); // Subscriptions for status bar items: private _statusMessageSub: vscode.Disposable = new DummyDisposable(); private _targetNameSub: vscode.Disposable = new DummyDisposable(); diff --git a/src/status.ts b/src/status.ts index 446a64aeb..f3617ff2d 100644 --- a/src/status.ts +++ b/src/status.ts @@ -2,18 +2,18 @@ import * as vscode from 'vscode'; import {BasicTestResults} from '@cmt/ctest'; import * as nls from 'vscode-nls'; import {SpecialKits} from '@cmt/kit'; +import {StatusBarButtonType as ButtonType, ConfigurationReader } from '@cmt/config'; // FIXME: Show workspace selection if a folder is added to workspace nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); -type ButtonType = "text" | "short" | "icon" | "hidden"; abstract class Button { set command(v:string|null) { this._button.command = v || undefined;} private _forceHidden:boolean = false; set forceHidden(v:boolean) { this._forceHidden = v; this.update(); } - constructor(protected readonly priority: number) { + constructor(protected readonly _config: ConfigurationReader, protected readonly priority: number) { this._button.command = this._button.command; } protected readonly _button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, this.priority); @@ -95,7 +95,7 @@ class ActiveFolderButton extends Button { protected isVisible() { return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this.getText()); } - protected getType():ButtonType { return 'icon'; } // TODO: settings icon/text + protected getType():ButtonType { return this._config.statusbar.workspace.type; } protected getTextIcon(): string { return '$(folder-active)';} protected getTooltipIcon(): string { return `CMake: ${this.getTooltipNormal()}\n${this.getTextNormal()}`;} } @@ -110,7 +110,7 @@ class CMakeStatus extends Button { set buildTypeLabel(v:string) { CMakeStatus._buildTypeLabel = v; this.update();} set statusMessage(v:string) { CMakeStatus._statusMessage = v; this.update();} - protected getType():ButtonType { return 'short'; } // TODO: settings icon/text + protected getType():ButtonType { return this._config.statusbar.status.type; } protected getTextNormal() { return `CMake: ${CMakeStatus._buildTypeLabel}: ${CMakeStatus._statusMessage}`; } @@ -123,7 +123,7 @@ class KitSelection extends Button { command = 'cmake.selectKit'; tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); - protected getType():ButtonType { return 'short'; } // TODO: settings icon/text + protected getType():ButtonType { return this._config.statusbar.kit.type; } protected getTextNormal():string { const text = this.text; if (text === SpecialKits.Unspecified) { @@ -135,7 +135,7 @@ class KitSelection extends Button { return text; } protected getTextShort() { - const len = 10; + const len = this._config.statusbar.kit.length; let text = this.getTextNormal(); if (len+3this.update()); this.update(); } diff --git a/test/unit-tests/config.test.ts b/test/unit-tests/config.test.ts index 71fd43f86..10f0cdc04 100644 --- a/test/unit-tests/config.test.ts +++ b/test/unit-tests/config.test.ts @@ -46,6 +46,36 @@ function createConfig(conf: Partial): Configurat outputLogEncoding: 'auto', enableTraceLogging: false, loggingLevel: 'info', + statusbar: { + kit: { + type: 'text', + length: 10, + }, + status: { + type: 'text', + }, + workspace: { + type: 'text', + }, + build_target: { + type: 'text', + }, + build: { + type: 'text', + }, + launch_target: { + type: 'text', + }, + debug: { + type: 'text', + }, + launch: { + type: 'text', + }, + ctest: { + type: 'text', + } + } }); ret.updatePartial(conf); return ret; From 01b1748de6643d46798c78cae6b9ed9f5cc68727 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 23 Apr 2020 19:45:56 +0200 Subject: [PATCH 04/32] refactoring: readability --- src/status.ts | 225 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 158 insertions(+), 67 deletions(-) diff --git a/src/status.ts b/src/status.ts index f3617ff2d..0720ff507 100644 --- a/src/status.ts +++ b/src/status.ts @@ -10,44 +10,59 @@ nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFo const localize: nls.LocalizeFunc = nls.loadMessageBundle(); abstract class Button { - set command(v:string|null) { this._button.command = v || undefined;} - private _forceHidden:boolean = false; - set forceHidden(v:boolean) { this._forceHidden = v; this.update(); } constructor(protected readonly _config: ConfigurationReader, protected readonly priority: number) { this._button.command = this._button.command; } protected readonly _button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, this.priority); + private _forceHidden:boolean = false; + private _text: string = ''; private _tooltip: string|null = null; - get tooltip() { return this._tooltip; } + + set command(v:string|null) { + this._button.command = v || undefined; + } + + set forceHidden(v:boolean) { + this._forceHidden = v; + this.update(); + } + + get tooltip():string|null { return this._tooltip; } set tooltip(v:string|null) { this._tooltip = v; this.update(); } - private _text: string = ''; - get text() { return this._text; } + get text():string { return this._text; } set text(v:string) { this._text = v; this.update(); } - dispose() { this._button.dispose(); } - update() { + + dispose():void { + this._button.dispose(); + } + update():void { const visible = this._isVisible(); if (visible && !this._forceHidden) { this._button.text = this.getText(); this._button.tooltip = this.getTooltip() || undefined; this._button.show(); - }else { + } else { this._button.hide(); } - return visible; } - private _isVisible() { + private _isVisible():boolean { return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; } - protected isVisible() { return true; } - protected getType():ButtonType { return "text"; } + + protected isVisible():boolean { + return true; + } + protected getType():ButtonType { + return "text"; + } getTooltip():string|null { const type = this.getType(); @@ -76,46 +91,77 @@ abstract class Button { protected getTooltipNormal():string|null { return this._tooltip; } protected getTooltipIcon():string|null { return this.getTooltipNormal(); } - protected getTooltipShort():string|null { return this.getTooltipNormal(); } - - protected getTextNormal():string { return this._text; } - protected getTextIcon():string { return this.getTextNormal(); } - protected getTextShort():string { return this.getTextNormal(); } + protected getTooltipShort():string|null { + return this.getTooltipNormal(); + } + protected getTextNormal():string { + return this._text; + } + protected getTextIcon():string { + return this.getTextNormal(); + } + protected getTextShort():string { + return this.getTextNormal(); + } } class ActiveFolderButton extends Button { command = "cmake.selectActiveFolder"; - private _autoSelect: boolean = false; - set autoSelect(v:boolean) { this._autoSelect = v; this.update(); } + private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); + private _autoSelect: boolean = false; - protected getTooltipNormal(): string|null { return this._autoSelect?ActiveFolderButton._autoSelectToolTip:ActiveFolderButton._toolTip; } - protected isVisible() { + set autoSelect(v:boolean) { + this._autoSelect = v; + this.update(); + } + + protected getTooltipNormal():string|null { + if (this._autoSelect) { + return ActiveFolderButton._autoSelectToolTip; + } + return ActiveFolderButton._toolTip; + } + protected isVisible():boolean { return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this.getText()); } - protected getType():ButtonType { return this._config.statusbar.workspace.type; } - protected getTextIcon(): string { return '$(folder-active)';} - protected getTooltipIcon(): string { return `CMake: ${this.getTooltipNormal()}\n${this.getTextNormal()}`;} + protected getType():ButtonType { + return this._config.statusbar.workspace.type; + } + protected getTextIcon():string { + return '$(folder-active)'; + } + protected getTooltipIcon():string { + return `CMake: ${this.getTooltipNormal()}\n${this.getTextNormal()}`; + } } class CMakeStatus extends Button { command = "cmake.setVariant"; tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); - private static _buildTypeLabel: string = localize('unconfigured', 'Unconfigured'); - private static _statusMessage: string = localize('loading.status', 'Loading...'); + private _buildTypeLabel: string = localize('unconfigured', 'Unconfigured'); + private _statusMessage: string = localize('loading.status', 'Loading...'); - set buildTypeLabel(v:string) { CMakeStatus._buildTypeLabel = v; this.update();} - set statusMessage(v:string) { CMakeStatus._statusMessage = v; this.update();} + set buildTypeLabel(v: string) { + this._buildTypeLabel = v; + this.update(); + } + set statusMessage(v: string) { + this._statusMessage = v; + this.update(); + } - protected getType():ButtonType { return this._config.statusbar.status.type; } + protected getType():ButtonType { + return this._config.statusbar.status.type; + } protected getTextNormal() { - return `CMake: ${CMakeStatus._buildTypeLabel}: ${CMakeStatus._statusMessage}`; + return `CMake: ${this._buildTypeLabel}: ${this._statusMessage}`; } protected getTextShort() { - return `${CMakeStatus._buildTypeLabel}: ${CMakeStatus._statusMessage}`; + return `${this._buildTypeLabel}: ${this._statusMessage}`; } } @@ -123,13 +169,15 @@ class KitSelection extends Button { command = 'cmake.selectKit'; tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); - protected getType():ButtonType { return this._config.statusbar.kit.type; } + protected getType():ButtonType { + return this._config.statusbar.kit.type; + } protected getTextNormal():string { const text = this.text; if (text === SpecialKits.Unspecified) { return `[${localize('no.active.kit', 'No active kit')}]`; } - if (text.length===0) { + if (text.length === 0) { return localize('no.kit.selected', 'No Kit Selected'); } return text; @@ -137,24 +185,34 @@ class KitSelection extends Button { protected getTextShort() { const len = this._config.statusbar.kit.length; let text = this.getTextNormal(); - if (len+3 Date: Thu, 23 Apr 2020 19:50:47 +0200 Subject: [PATCH 05/32] added color setting to ctest button --- src/config.ts | 1 + src/status.ts | 16 ++++++++++++---- test/unit-tests/config.test.ts | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index c636215c4..0ea266db1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -52,6 +52,7 @@ export interface StatusBarConfig { type: StatusBarButtonType; }; ctest: { + color: boolean; type: StatusBarButtonType; }; } diff --git a/src/status.ts b/src/status.ts index 0720ff507..60cdb5aad 100644 --- a/src/status.ts +++ b/src/status.ts @@ -245,6 +245,7 @@ class CTestButton extends Button { private _enabled:boolean = false; private _results: BasicTestResults|null = null; + private _color: string = ''; protected getType():ButtonType { return this._config.statusbar.ctest.type; @@ -254,17 +255,24 @@ class CTestButton extends Button { this._enabled = v; this.update(); } - set results(v:BasicTestResults|null) { this._results = v; - if (!v) { // TODO: check if color is used - this._button.color = ''; + if (!v) { + this._color = ''; } else { - this._button.color = v.passing===v.total?'lightgreen' : 'yellow'; + this._color = v.passing===v.total?'lightgreen' : 'yellow'; } this.update(); } + update() { + super.update(); + if (this._config.statusbar.ctest.color) { + this._button.color = this._color; + } else { + this._button.color = ''; + } + } isVisible() { return this._enabled; } diff --git a/test/unit-tests/config.test.ts b/test/unit-tests/config.test.ts index 10f0cdc04..f59c74363 100644 --- a/test/unit-tests/config.test.ts +++ b/test/unit-tests/config.test.ts @@ -74,6 +74,7 @@ function createConfig(conf: Partial): Configurat }, ctest: { type: 'text', + color: true, } } }); From 91535720c1dc49b807c4ec2ef618b941f7237a39 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Sat, 25 Apr 2020 15:34:07 +0200 Subject: [PATCH 06/32] addressed change requests --- package.json | 205 ++++++++++++++++++++------------- src/config.ts | 46 ++++---- src/status.ts | 108 ++++++++--------- test/unit-tests/config.test.ts | 31 +---- 4 files changed, 207 insertions(+), 183 deletions(-) diff --git a/package.json b/package.json index 9e5e4d1c6..ab7900437 100644 --- a/package.json +++ b/package.json @@ -1205,96 +1205,143 @@ ], "scope": "window" }, - "cmake.statusbar.kit.type": { + "cmake.statusbar.type": { "type": "string", "default": "text", "enum": [ "text", "short", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.kit.length": { - "type": "integer", - "default": 10, - "scope": "window" - }, - "cmake.statusbar.status.type": { - "type": "string", - "default": "text", - "enum": [ - "text", - "short", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.workspace.type": { - "type": "string", - "default": "text", - "enum": [ - "text", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.build_target.type": { - "type": "string", - "default": "text", - "enum": [ - "text", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.build.type": { - "type": "string", - "default": "text", - "enum": [ - "text", - "icon", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.launch_target.type": { - "type": "string", - "default": "text", - "enum": [ - "text", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.debug.type": { - "type": "string", - "default": "icon", - "enum": [ - "icon", - "hidden" - ], - "scope": "window" - }, - "cmake.statusbar.launch.type": { - "type": "string", - "default": "icon", - "enum": [ "icon", "hidden" ], "scope": "window" }, - "cmake.statusbar.ctest.type": { - "type": "string", - "default": "text", - "enum": [ - "text", - "hidden" - ], - "scope": "window" + "cmake.statusbar.advanced": { + "type": "object", + "default": null, + "properties": { + "kit": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text", + "short", + "icon", + "hidden" + ] + }, + "length": { + "type": "integer" + } + } + }, + "status": { + "type": "object", + "properties": { + "type": { + "type": "string", + "default": "text", + "enum": [ + "text", + "short", + "hidden" + ] + } + } + }, + "workspace": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text", + "icon", + "hidden" + ] + } + } + }, + "buildTarget": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text", + "hidden" + ] + } + } + }, + "build": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text", + "icon", + "hidden" + ] + } + } + }, + "launchTarget": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text", + "hidden" + ] + } + } + }, + "debug": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "icon", + "hidden" + ] + } + } + }, + "launch": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "icon", + "hidden" + ] + } + } + }, + "ctest": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text", + "hidden" + ] + }, + "color": { + "type":"boolean" + } + } + } + } }, - "cmake.revealLog": { "type": "string", "default": "always", diff --git a/src/config.ts b/src/config.ts index 0ea266db1..c4165a442 100644 --- a/src/config.ts +++ b/src/config.ts @@ -25,37 +25,41 @@ interface HardEnv { [key: string]: string; } -export interface StatusBarConfig { - kit: { - type: StatusBarButtonType; - length: number; +export interface AdvancedStatusBarConfig { + kit?: { + type?: StatusBarButtonType; + length?: number; }; - status: { - type: StatusBarButtonType; + status?: { + type?: StatusBarButtonType; }; - workspace: { - type: StatusBarButtonType; + workspace?: { + type?: StatusBarButtonType; }; - build_target: { - type: StatusBarButtonType; + buildTarget?: { + type?: StatusBarButtonType; }; - build: { - type: StatusBarButtonType; + build?: { + type?: StatusBarButtonType; }; - launch_target: { - type: StatusBarButtonType; + launchTarget?: { + type?: StatusBarButtonType; }; - debug: { - type: StatusBarButtonType; + debug?: { + type?: StatusBarButtonType; }; - launch: { - type: StatusBarButtonType; + launch?: { + type?: StatusBarButtonType; }; - ctest: { - color: boolean; - type: StatusBarButtonType; + ctest?: { + color?: boolean; + type?: StatusBarButtonType; }; } +export interface StatusBarConfig { + advanced?: AdvancedStatusBarConfig; + type: StatusBarButtonType; +} export interface ExtensionConfigurationSettings { autoSelectActiveFolder: boolean; diff --git a/src/status.ts b/src/status.ts index 60cdb5aad..ce84126cb 100644 --- a/src/status.ts +++ b/src/status.ts @@ -17,6 +17,7 @@ abstract class Button { private _forceHidden:boolean = false; private _text: string = ''; private _tooltip: string|null = null; + readonly settings : string|null = null; set command(v:string|null) { this._button.command = v || undefined; @@ -54,18 +55,24 @@ abstract class Button { } private _isVisible():boolean { - return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; + return this.isVisible() && (this.getType() || this.getDefaultType()) !== "hidden" && this.getText() != ''; } protected isVisible():boolean { return true; } - protected getType():ButtonType { - return "text"; + protected getType():ButtonType | null { + if (this.settings) { + return Object(this._config.statusbar.advanced)[this.settings]?.type || null; + } + return null; + } + protected getDefaultType():ButtonType { + return this._config.statusbar.type; } getTooltip():string|null { - const type = this.getType(); + const type = this.getType() || this.getDefaultType(); switch (type) { case "hidden": return null; @@ -73,12 +80,12 @@ abstract class Button { return this.getTooltipIcon(); case "short": return this.getTooltipShort(); - case "text": + default: return this.getTooltipNormal(); } } getText():string { - const type = this.getType(); + const type = this.getType() || this.getDefaultType(); switch (type) { case "icon": return this.getTextIcon(); @@ -89,24 +96,29 @@ abstract class Button { } } - protected getTooltipNormal():string|null { return this._tooltip; } - protected getTooltipIcon():string|null { return this.getTooltipNormal(); } + protected getTooltipNormal():string|null { + return this._tooltip; + } protected getTooltipShort():string|null { return this.getTooltipNormal(); } + protected getTooltipIcon():string|null { + return this.getTooltipShort(); + } protected getTextNormal():string { return this._text; } - protected getTextIcon():string { - return this.getTextNormal(); - } protected getTextShort():string { return this.getTextNormal(); } + protected getTextIcon():string { + return this.getTextShort(); + } } class ActiveFolderButton extends Button { + settings = 'workspace'; command = "cmake.selectActiveFolder"; private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); @@ -127,9 +139,6 @@ class ActiveFolderButton extends Button { protected isVisible():boolean { return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this.getText()); } - protected getType():ButtonType { - return this._config.statusbar.workspace.type; - } protected getTextIcon():string { return '$(folder-active)'; } @@ -139,6 +148,7 @@ class ActiveFolderButton extends Button { } class CMakeStatus extends Button { + settings = 'status'; command = "cmake.setVariant"; tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); @@ -153,10 +163,6 @@ class CMakeStatus extends Button { this._statusMessage = v; this.update(); } - - protected getType():ButtonType { - return this._config.statusbar.status.type; - } protected getTextNormal() { return `CMake: ${this._buildTypeLabel}: ${this._statusMessage}`; } @@ -166,12 +172,10 @@ class CMakeStatus extends Button { } class KitSelection extends Button { + settings = 'kit'; command = 'cmake.selectKit'; tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); - protected getType():ButtonType { - return this._config.statusbar.kit.type; - } protected getTextNormal():string { const text = this.text; if (text === SpecialKits.Unspecified) { @@ -182,8 +186,11 @@ class KitSelection extends Button { } return text; } + protected getTextIcon(): string { + return `$(tools)`; + } protected getTextShort() { - const len = this._config.statusbar.kit.length; + const len = this._config.statusbar.advanced?.kit?.length || 20; let text = this.getTextNormal(); if (len + 3 < text.length) { text = `${text.substr(0, len)}...`; @@ -193,26 +200,24 @@ class KitSelection extends Button { protected getTooltipShort(): string { return `${this.getTooltipNormal()}\n${this.getTextNormal()}`; } + protected getTooltipIcon(): string { + return `${this.getTooltipNormal()}\n${this.getTextNormal()}`; + } } class BuildTargetSelectionButton extends Button { + settings = 'buildTarget'; command = 'cmake.setDefaultTarget'; tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); protected getTextNormal():string { return `[${this.text}]`; } - protected getType():ButtonType { - return this._config.statusbar.build_target.type; - } } class LaunchTargetSelectionButton extends Button { + settings = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); - - protected getType():ButtonType { - return this._config.statusbar.launch_target.type; - } } class CheckCPPToolsButton extends Button { protected isVisible() { @@ -221,25 +226,22 @@ class CheckCPPToolsButton extends Button { } class DebugButton extends CheckCPPToolsButton { + settings = 'debug'; command = 'cmake.debugTarget'; text = '$(bug)'; tooltip = localize('launch.debugger.tooltip', 'Launch the debugger for the selected target'); - protected getType():ButtonType { - return this._config.statusbar.debug.type; - } } -class LaunchButton extends CheckCPPToolsButton { +class LaunchButton extends Button { + settings = 'launch'; command = 'cmake.launchTarget'; text = '$(play)'; tooltip = localize('launch.tooltip', 'Launch'); - protected getType():ButtonType { - return this._config.statusbar.launch.type; - } } class CTestButton extends Button { private static readonly _default = localize('run.ctest', 'Run CTest'); + settings = 'ctest'; command = 'cmake.ctest'; tooltip = localize('run.ctest.tests.tooltip', 'Run CTest tests'); @@ -247,10 +249,6 @@ class CTestButton extends Button { private _results: BasicTestResults|null = null; private _color: string = ''; - protected getType():ButtonType { - return this._config.statusbar.ctest.type; - } - set enabled(v:boolean) { this._enabled = v; this.update(); @@ -265,9 +263,13 @@ class CTestButton extends Button { this.update(); } + private _isUseColor():boolean { + return this._config.statusbar.advanced?.ctest?.color===false; + } + update() { super.update(); - if (this._config.statusbar.ctest.color) { + if (this._isUseColor()) { this._button.color = this._color; } else { this._button.color = ''; @@ -294,10 +296,11 @@ class CTestButton extends Button { return `$(${icon}) ${testPassingText}`; } } -class BuildButton extends CheckCPPToolsButton { +class BuildButton extends Button { private static readonly _build = localize('build', 'Build'); private static readonly _stop = localize('stop', 'Stop'); + settings = 'build'; command = 'cmake.build'; private _isBusy:boolean = false; @@ -327,24 +330,21 @@ class BuildButton extends CheckCPPToolsButton { isVisible():boolean { return this._isBusy || true; } - protected getType():ButtonType { - return this._config.statusbar.build.type; - } } export class StatusBar implements vscode.Disposable { - private readonly _kitSelectionButton = new KitSelection(this._config, 3.6); - private readonly _cmakeToolsStatusItem = new CMakeStatus(this._config, 3.55); + private readonly _kitSelectionButton = new KitSelection(this._config, 3.45); //3.6 + private readonly _cmakeToolsStatusItem = new CMakeStatus(this._config, 3.5); //3.55 - private readonly _activeFolderButton = new ActiveFolderButton(this._config, 3.5); - private readonly _buildTargetNameButton = new BuildTargetSelectionButton(this._config, 3.45); - private readonly _buildButton:BuildButton = new BuildButton(this._config, 3.4); + private readonly _activeFolderButton = new ActiveFolderButton(this._config, 3.6); // 3.5 + private readonly _buildTargetNameButton = new BuildTargetSelectionButton(this._config, 3.45); // 3.45 + private readonly _buildButton:BuildButton = new BuildButton(this._config, 3.4); //3.4 - private readonly _launchTargetNameButton = new LaunchTargetSelectionButton(this._config, 3.35); - private readonly _debugButton:DebugButton = new DebugButton(this._config, 3.3); - private readonly _runButton = new LaunchButton(this._config, 3.25); + private readonly _launchTargetNameButton = new LaunchTargetSelectionButton(this._config, 3.3); //3.35 + private readonly _debugButton:DebugButton = new DebugButton(this._config, 3.25); //3.3 + private readonly _runButton = new LaunchButton(this._config, 3.2); //3.25 - private readonly _testButton = new CTestButton(this._config, 3.2); + private readonly _testButton = new CTestButton(this._config, 3.1); //3.2 private readonly _buttons: Button[]; diff --git a/test/unit-tests/config.test.ts b/test/unit-tests/config.test.ts index f59c74363..13b6b7410 100644 --- a/test/unit-tests/config.test.ts +++ b/test/unit-tests/config.test.ts @@ -47,35 +47,8 @@ function createConfig(conf: Partial): Configurat enableTraceLogging: false, loggingLevel: 'info', statusbar: { - kit: { - type: 'text', - length: 10, - }, - status: { - type: 'text', - }, - workspace: { - type: 'text', - }, - build_target: { - type: 'text', - }, - build: { - type: 'text', - }, - launch_target: { - type: 'text', - }, - debug: { - type: 'text', - }, - launch: { - type: 'text', - }, - ctest: { - type: 'text', - color: true, - } + advanced: {}, + type: "text" } }); ret.updatePartial(conf); From dbe29912036f91f3e5f45dc1470a7bcfe4a922af Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Sat, 25 Apr 2020 15:52:08 +0200 Subject: [PATCH 07/32] readded hideDebug/LaunchCommand functions to status --- src/extension.ts | 1 + src/status.ts | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index b57f857e3..25f2d47fd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -872,6 +872,7 @@ class ExtensionManager implements vscode.Disposable { async hideLaunchCommand(shouldHide: boolean = true) { // Don't hide command selectLaunchTarget here since the target can still be useful, one example is ${command:cmake.launchTargetPath} in launch.json + this._statusBar.hideLaunchButton(shouldHide); await util.setContextValue(HIDE_LAUNCH_COMMAND_KEY, shouldHide); } diff --git a/src/status.ts b/src/status.ts index ce84126cb..8d99ab59f 100644 --- a/src/status.ts +++ b/src/status.ts @@ -224,18 +224,33 @@ class CheckCPPToolsButton extends Button { return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; } } - class DebugButton extends CheckCPPToolsButton { settings = 'debug'; command = 'cmake.debugTarget'; text = '$(bug)'; tooltip = localize('launch.debugger.tooltip', 'Launch the debugger for the selected target'); + private _hidden: boolean = false; + set hidden(v:boolean) { + this._hidden = v; + this.update(); + } + isVisible() { + return super.isVisible() && !this._hidden; + } } class LaunchButton extends Button { settings = 'launch'; command = 'cmake.launchTarget'; text = '$(play)'; tooltip = localize('launch.tooltip', 'Launch'); + private _hidden: boolean = false; + set hidden(v:boolean) { + this._hidden = v; + this.update(); + } + isVisible() { + return super.isVisible() && !this._hidden; + } } class CTestButton extends Button { @@ -342,7 +357,7 @@ export class StatusBar implements vscode.Disposable { private readonly _launchTargetNameButton = new LaunchTargetSelectionButton(this._config, 3.3); //3.35 private readonly _debugButton:DebugButton = new DebugButton(this._config, 3.25); //3.3 - private readonly _runButton = new LaunchButton(this._config, 3.2); //3.25 + private readonly _launchButton = new LaunchButton(this._config, 3.2); //3.25 private readonly _testButton = new CTestButton(this._config, 3.1); //3.2 @@ -358,7 +373,7 @@ export class StatusBar implements vscode.Disposable { this._debugButton, this._buildButton, this._testButton, - this._runButton + this._launchButton ]; this._config.onChange('statusbar', ()=>this.update()); this.update(); @@ -379,8 +394,6 @@ export class StatusBar implements vscode.Disposable { setIsBusy = (v:boolean) => this._buildButton.isBusy = v; setActiveKitName = (v:string) => this._kitSelectionButton.text = v; - hideDebugButton(shouldHide: boolean = true) { - if (false) return shouldHide; - // TODO: Find out if this is called... - } + hideLaunchButton = (shouldHide: boolean = true) => this._launchButton.hidden = shouldHide; + hideDebugButton = (shouldHide: boolean = true) => this._debugButton.hidden = shouldHide; } \ No newline at end of file From a0c8cd083b971da4e59813ef2ed64a7e7970dd08 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 30 Apr 2020 07:33:00 +0200 Subject: [PATCH 08/32] rename: settings -> settingsName --- src/status.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/status.ts b/src/status.ts index 8d99ab59f..89c5bad7f 100644 --- a/src/status.ts +++ b/src/status.ts @@ -17,7 +17,7 @@ abstract class Button { private _forceHidden:boolean = false; private _text: string = ''; private _tooltip: string|null = null; - readonly settings : string|null = null; + readonly settingsName : string|null = null; set command(v:string|null) { this._button.command = v || undefined; @@ -62,8 +62,8 @@ abstract class Button { return true; } protected getType():ButtonType | null { - if (this.settings) { - return Object(this._config.statusbar.advanced)[this.settings]?.type || null; + if (this.settingsName) { + return Object(this._config.statusbar.advanced)[this.settingsName]?.type || null; } return null; } @@ -118,7 +118,7 @@ abstract class Button { } class ActiveFolderButton extends Button { - settings = 'workspace'; + settingsName = 'workspace'; command = "cmake.selectActiveFolder"; private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); @@ -148,7 +148,7 @@ class ActiveFolderButton extends Button { } class CMakeStatus extends Button { - settings = 'status'; + settingsName = 'status'; command = "cmake.setVariant"; tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); @@ -172,7 +172,7 @@ class CMakeStatus extends Button { } class KitSelection extends Button { - settings = 'kit'; + settingsName = 'kit'; command = 'cmake.selectKit'; tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); @@ -206,7 +206,7 @@ class KitSelection extends Button { } class BuildTargetSelectionButton extends Button { - settings = 'buildTarget'; + settingsName = 'buildTarget'; command = 'cmake.setDefaultTarget'; tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); @@ -215,7 +215,7 @@ class BuildTargetSelectionButton extends Button { } } class LaunchTargetSelectionButton extends Button { - settings = 'launchTarget'; + settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); } @@ -225,7 +225,7 @@ class CheckCPPToolsButton extends Button { } } class DebugButton extends CheckCPPToolsButton { - settings = 'debug'; + settingsName = 'debug'; command = 'cmake.debugTarget'; text = '$(bug)'; tooltip = localize('launch.debugger.tooltip', 'Launch the debugger for the selected target'); @@ -239,7 +239,7 @@ class DebugButton extends CheckCPPToolsButton { } } class LaunchButton extends Button { - settings = 'launch'; + settingsName = 'launch'; command = 'cmake.launchTarget'; text = '$(play)'; tooltip = localize('launch.tooltip', 'Launch'); @@ -256,7 +256,7 @@ class LaunchButton extends Button { class CTestButton extends Button { private static readonly _default = localize('run.ctest', 'Run CTest'); - settings = 'ctest'; + settingsName = 'ctest'; command = 'cmake.ctest'; tooltip = localize('run.ctest.tests.tooltip', 'Run CTest tests'); @@ -315,7 +315,7 @@ class BuildButton extends Button { private static readonly _build = localize('build', 'Build'); private static readonly _stop = localize('stop', 'Stop'); - settings = 'build'; + settingsName = 'build'; command = 'cmake.build'; private _isBusy:boolean = false; From 9523789062dd2ea411783d110c3d23e1280d7f88 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 30 Apr 2020 07:36:31 +0200 Subject: [PATCH 09/32] removed getDefaultType --- src/status.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/status.ts b/src/status.ts index 89c5bad7f..3feaa8f9b 100644 --- a/src/status.ts +++ b/src/status.ts @@ -55,7 +55,7 @@ abstract class Button { } private _isVisible():boolean { - return this.isVisible() && (this.getType() || this.getDefaultType()) !== "hidden" && this.getText() != ''; + return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; } protected isVisible():boolean { @@ -63,16 +63,13 @@ abstract class Button { } protected getType():ButtonType | null { if (this.settingsName) { - return Object(this._config.statusbar.advanced)[this.settingsName]?.type || null; + return Object(this._config.statusbar.advanced)[this.settingsName]?.type || this._config.statusbar.type || null; } - return null; - } - protected getDefaultType():ButtonType { - return this._config.statusbar.type; + return this._config.statusbar.type || null; } getTooltip():string|null { - const type = this.getType() || this.getDefaultType(); + const type = this.getType(); switch (type) { case "hidden": return null; @@ -85,7 +82,7 @@ abstract class Button { } } getText():string { - const type = this.getType() || this.getDefaultType(); + const type = this.getType(); switch (type) { case "icon": return this.getTextIcon(); From 2b5adb250b950c525d46f5c51746419f071c7d22 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 30 Apr 2020 07:39:01 +0200 Subject: [PATCH 10/32] protected getType -> private _getType --- src/status.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/status.ts b/src/status.ts index 3feaa8f9b..42a145714 100644 --- a/src/status.ts +++ b/src/status.ts @@ -55,13 +55,13 @@ abstract class Button { } private _isVisible():boolean { - return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; + return this.isVisible() && this._getType() !== "hidden" && this.getText() != ''; } protected isVisible():boolean { return true; } - protected getType():ButtonType | null { + private _getType():ButtonType | null { if (this.settingsName) { return Object(this._config.statusbar.advanced)[this.settingsName]?.type || this._config.statusbar.type || null; } @@ -69,7 +69,7 @@ abstract class Button { } getTooltip():string|null { - const type = this.getType(); + const type = this._getType(); switch (type) { case "hidden": return null; @@ -82,7 +82,7 @@ abstract class Button { } } getText():string { - const type = this.getType(); + const type = this._getType(); switch (type) { case "icon": return this.getTextIcon(); From 35c438075d285dfc59321c116c3dc35d75da1e89 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 30 Apr 2020 07:42:59 +0200 Subject: [PATCH 11/32] fixed button order --- src/status.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/status.ts b/src/status.ts index 42a145714..13eb3da31 100644 --- a/src/status.ts +++ b/src/status.ts @@ -345,18 +345,19 @@ class BuildButton extends Button { } export class StatusBar implements vscode.Disposable { - private readonly _kitSelectionButton = new KitSelection(this._config, 3.45); //3.6 - private readonly _cmakeToolsStatusItem = new CMakeStatus(this._config, 3.5); //3.55 + private readonly _activeFolderButton = new ActiveFolderButton(this._config, 3.6); - private readonly _activeFolderButton = new ActiveFolderButton(this._config, 3.6); // 3.5 - private readonly _buildTargetNameButton = new BuildTargetSelectionButton(this._config, 3.45); // 3.45 - private readonly _buildButton:BuildButton = new BuildButton(this._config, 3.4); //3.4 + private readonly _cmakeToolsStatusItem = new CMakeStatus(this._config, 3.5); + private readonly _kitSelectionButton = new KitSelection(this._config, 3.4); - private readonly _launchTargetNameButton = new LaunchTargetSelectionButton(this._config, 3.3); //3.35 - private readonly _debugButton:DebugButton = new DebugButton(this._config, 3.25); //3.3 - private readonly _launchButton = new LaunchButton(this._config, 3.2); //3.25 + private readonly _buildButton:BuildButton = new BuildButton(this._config, 3.35); + private readonly _buildTargetNameButton = new BuildTargetSelectionButton(this._config, 3.3); - private readonly _testButton = new CTestButton(this._config, 3.1); //3.2 + private readonly _debugButton:DebugButton = new DebugButton(this._config, 3.22); + private readonly _launchButton = new LaunchButton(this._config, 3.21); + private readonly _launchTargetNameButton = new LaunchTargetSelectionButton(this._config, 3.2); + + private readonly _testButton = new CTestButton(this._config, 3.1); private readonly _buttons: Button[]; From de40098f96280649a2c5edfbe8c843db3880c482 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 30 Apr 2020 07:58:18 +0200 Subject: [PATCH 12/32] typecheck on text length --- src/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status.ts b/src/status.ts index 13eb3da31..183f51da6 100644 --- a/src/status.ts +++ b/src/status.ts @@ -187,7 +187,7 @@ class KitSelection extends Button { return `$(tools)`; } protected getTextShort() { - const len = this._config.statusbar.advanced?.kit?.length || 20; + const len = Number(this._config.statusbar.advanced?.kit?.length) || 20; let text = this.getTextNormal(); if (len + 3 < text.length) { text = `${text.substr(0, len)}...`; From 798e21c6191ade40c56702bba03f0f1a512f7bdd Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 09:03:11 +0200 Subject: [PATCH 13/32] hide Status and targets in icon mode --- src/status.ts | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/status.ts b/src/status.ts index 183f51da6..307b4b408 100644 --- a/src/status.ts +++ b/src/status.ts @@ -55,13 +55,13 @@ abstract class Button { } private _isVisible():boolean { - return this.isVisible() && this._getType() !== "hidden" && this.getText() != ''; + return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; } protected isVisible():boolean { return true; } - private _getType():ButtonType | null { + protected getType():ButtonType | null { if (this.settingsName) { return Object(this._config.statusbar.advanced)[this.settingsName]?.type || this._config.statusbar.type || null; } @@ -69,7 +69,7 @@ abstract class Button { } getTooltip():string|null { - const type = this._getType(); + const type = this.getType(); switch (type) { case "hidden": return null; @@ -82,7 +82,7 @@ abstract class Button { } } getText():string { - const type = this._getType(); + const type = this.getType(); switch (type) { case "icon": return this.getTextIcon(); @@ -114,6 +114,23 @@ abstract class Button { } } +//--------------------------------------------- +//---------------- Helper Class --------------- +//--------------------------------------------- +class CheckCPPToolsButton extends Button { + protected isVisible() { + return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; + } +} +class HideInIconModeButton extends Button { + protected isVisible():boolean { + return this.getType() != 'icon'; + } +} + +//--------------------------------------------- +//---------------- Button Class --------------- +//--------------------------------------------- class ActiveFolderButton extends Button { settingsName = 'workspace'; command = "cmake.selectActiveFolder"; @@ -144,7 +161,7 @@ class ActiveFolderButton extends Button { } } -class CMakeStatus extends Button { +class CMakeStatus extends HideInIconModeButton { settingsName = 'status'; command = "cmake.setVariant"; tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); @@ -202,7 +219,7 @@ class KitSelection extends Button { } } -class BuildTargetSelectionButton extends Button { +class BuildTargetSelectionButton extends HideInIconModeButton { settingsName = 'buildTarget'; command = 'cmake.setDefaultTarget'; tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); @@ -211,16 +228,11 @@ class BuildTargetSelectionButton extends Button { return `[${this.text}]`; } } -class LaunchTargetSelectionButton extends Button { +class LaunchTargetSelectionButton extends HideInIconModeButton { settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); } -class CheckCPPToolsButton extends Button { - protected isVisible() { - return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; - } -} class DebugButton extends CheckCPPToolsButton { settingsName = 'debug'; command = 'cmake.debugTarget'; From 905431d2a9ecb91b53d0e32b08f1829d8c06b753 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 09:04:37 +0200 Subject: [PATCH 14/32] changed loca of Launch button --- src/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status.ts b/src/status.ts index 307b4b408..3d446a54c 100644 --- a/src/status.ts +++ b/src/status.ts @@ -251,7 +251,7 @@ class LaunchButton extends Button { settingsName = 'launch'; command = 'cmake.launchTarget'; text = '$(play)'; - tooltip = localize('launch.tooltip', 'Launch'); + tooltip = localize('launch.tooltip', 'Launch the selected target in the terminal window'); private _hidden: boolean = false; set hidden(v:boolean) { this._hidden = v; From 1f93be77a94eddaf35e8f84bc6c2ce5a5a4ea8e8 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 10:33:04 +0200 Subject: [PATCH 15/32] refactoring for readability added default icon for CTest (beaker) --- src/status.ts | 149 ++++++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 70 deletions(-) diff --git a/src/status.ts b/src/status.ts index 3d446a54c..d178be368 100644 --- a/src/status.ts +++ b/src/status.ts @@ -17,8 +17,13 @@ abstract class Button { private _forceHidden:boolean = false; private _text: string = ''; private _tooltip: string|null = null; + private _icon: string|null = null; readonly settingsName : string|null = null; + set icon(v:string|null) { + this._icon = v?`$(${v})`: null; + } + set command(v:string|null) { this._button.command = v || undefined; } @@ -45,17 +50,22 @@ abstract class Button { } update():void { const visible = this._isVisible(); - if (visible && !this._forceHidden) { - this._button.text = this.getText(); - this._button.tooltip = this.getTooltip() || undefined; - this._button.show(); - } else { + if (!visible || this._forceHidden) { this._button.hide(); + return; } + const text = this.getText(true); + if (text==='') { + this._button.hide(); + return; + } + this._button.text = text; + this._button.tooltip = this.getTooltip() || undefined; + this._button.show(); } private _isVisible():boolean { - return this.isVisible() && this.getType() !== "hidden" && this.getText() != ''; + return this.isVisible() && this.getType() !== "hidden"; } protected isVisible():boolean { @@ -81,23 +91,45 @@ abstract class Button { return this.getTooltipNormal(); } } - getText():string { + getText(icon:boolean=false):string { const type = this.getType(); + let text:string; switch (type) { case "icon": - return this.getTextIcon(); + text = this.getTextIcon(); + break; case "short": - return this.getTextShort(); + text = this.getTextShort(); + break; default: - return this.getTextNormal(); + text = this.getTextNormal(); + break; + } + if (!icon) { + return text; } + if (!this._icon) { + return text; + } + if (text=='') { + return this._icon || ''; + } + return `${this._icon} ${text}`; } protected getTooltipNormal():string|null { return this._tooltip; } protected getTooltipShort():string|null { - return this.getTooltipNormal(); + const tooltip = this.getTooltipNormal(); + const text = this.getTextNormal(); + if (!tooltip && !text) { + return null; + } + if (!tooltip || !text) { + return `CMake: ${tooltip||text}`; + } + return `CMake: ${tooltip}\n${text}`; } protected getTooltipIcon():string|null { return this.getTooltipShort(); @@ -110,7 +142,7 @@ abstract class Button { return this.getTextNormal(); } protected getTextIcon():string { - return this.getTextShort(); + return ''; } } @@ -122,23 +154,19 @@ class CheckCPPToolsButton extends Button { return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; } } -class HideInIconModeButton extends Button { - protected isVisible():boolean { - return this.getType() != 'icon'; - } -} //--------------------------------------------- //---------------- Button Class --------------- //--------------------------------------------- class ActiveFolderButton extends Button { + private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); + private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); + settingsName = 'workspace'; command = "cmake.selectActiveFolder"; + icon = 'folder-active'; - private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); - private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); private _autoSelect: boolean = false; - set autoSelect(v:boolean) { this._autoSelect = v; this.update(); @@ -153,22 +181,15 @@ class ActiveFolderButton extends Button { protected isVisible():boolean { return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this.getText()); } - protected getTextIcon():string { - return '$(folder-active)'; - } - protected getTooltipIcon():string { - return `CMake: ${this.getTooltipNormal()}\n${this.getTextNormal()}`; - } } -class CMakeStatus extends HideInIconModeButton { +class CMakeStatus extends Button { settingsName = 'status'; command = "cmake.setVariant"; tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); private _buildTypeLabel: string = localize('unconfigured', 'Unconfigured'); private _statusMessage: string = localize('loading.status', 'Loading...'); - set buildTypeLabel(v: string) { this._buildTypeLabel = v; this.update(); @@ -186,23 +207,25 @@ class CMakeStatus extends HideInIconModeButton { } class KitSelection extends Button { + private static readonly _noActiveKit = localize('no.active.kit', 'No active kit'); + private static readonly _noKitSelected = localize('no.kit.selected', 'No Kit Selected'); + settingsName = 'kit'; command = 'cmake.selectKit'; + icon = 'tools'; tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); protected getTextNormal():string { const text = this.text; if (text === SpecialKits.Unspecified) { - return `[${localize('no.active.kit', 'No active kit')}]`; + return KitSelection._noActiveKit; } if (text.length === 0) { - return localize('no.kit.selected', 'No Kit Selected'); + return KitSelection._noKitSelected; } return text; } - protected getTextIcon(): string { - return `$(tools)`; - } + protected getTextShort() { const len = Number(this._config.statusbar.advanced?.kit?.length) || 20; let text = this.getTextNormal(); @@ -211,15 +234,9 @@ class KitSelection extends Button { } return text; } - protected getTooltipShort(): string { - return `${this.getTooltipNormal()}\n${this.getTextNormal()}`; - } - protected getTooltipIcon(): string { - return `${this.getTooltipNormal()}\n${this.getTextNormal()}`; - } } -class BuildTargetSelectionButton extends HideInIconModeButton { +class BuildTargetSelectionButton extends Button { settingsName = 'buildTarget'; command = 'cmake.setDefaultTarget'; tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); @@ -228,7 +245,7 @@ class BuildTargetSelectionButton extends HideInIconModeButton { return `[${this.text}]`; } } -class LaunchTargetSelectionButton extends HideInIconModeButton { +class LaunchTargetSelectionButton extends Button { settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); @@ -236,13 +253,15 @@ class LaunchTargetSelectionButton extends HideInIconModeButton { class DebugButton extends CheckCPPToolsButton { settingsName = 'debug'; command = 'cmake.debugTarget'; - text = '$(bug)'; + icon = 'bug'; tooltip = localize('launch.debugger.tooltip', 'Launch the debugger for the selected target'); + private _hidden: boolean = false; set hidden(v:boolean) { this._hidden = v; this.update(); } + isVisible() { return super.isVisible() && !this._hidden; } @@ -250,21 +269,21 @@ class DebugButton extends CheckCPPToolsButton { class LaunchButton extends Button { settingsName = 'launch'; command = 'cmake.launchTarget'; - text = '$(play)'; + icon = 'play'; tooltip = localize('launch.tooltip', 'Launch the selected target in the terminal window'); + private _hidden: boolean = false; set hidden(v:boolean) { this._hidden = v; this.update(); } + isVisible() { return super.isVisible() && !this._hidden; } } class CTestButton extends Button { - private static readonly _default = localize('run.ctest', 'Run CTest'); - settingsName = 'ctest'; command = 'cmake.ctest'; tooltip = localize('run.ctest.tests.tooltip', 'Run CTest tests'); @@ -292,6 +311,12 @@ class CTestButton extends Button { } update() { + if (this._results) { + const {passing, total} = this._results; + this.icon = passing == total? 'check' : 'x'; + } else { + this.icon = 'beaker'; + } super.update(); if (this._isUseColor()) { this._button.color = this._color; @@ -306,18 +331,13 @@ class CTestButton extends Button { protected getTextNormal():string { if (!this._results) { this._button.color = ''; - return CTestButton._default; + return localize('run.ctest', 'Run CTest'); } const {passing, total} = this._results; - const good = passing == total; - let testPassingText: string; if (total == 1) { - testPassingText = localize('test.passing', '{0}/{1} test passing', passing, total); - } else { - testPassingText = localize('tests.passing', '{0}/{1} tests passing', passing, total); + return localize('test.passing', '{0}/{1} test passing', passing, total); } - const icon = good ? 'check' : 'x'; - return `$(${icon}) ${testPassingText}`; + return localize('tests.passing', '{0}/{1} tests passing', passing, total); } } class BuildButton extends Button { @@ -328,28 +348,17 @@ class BuildButton extends Button { command = 'cmake.build'; private _isBusy:boolean = false; - set isBusy(v: boolean) { this._isBusy = v; this._button.command = v ? 'cmake.stop' : 'cmake.build'; - this.update(); + this.text = this._isBusy? BuildButton._stop:BuildButton._build; + // update implicitly called in set text. + // this.update(); } - private _getCurrentText():string { - return this._isBusy?BuildButton._stop:BuildButton._build; - } - private _getCurrentIcon():string { - return this._isBusy?'$(x)':'$(gear)'; - } - - getTextIcon():string { - return this._getCurrentIcon(); - } - getTextNormal():string { - return `${this._getCurrentIcon()} ${this._getCurrentText()}`; - } - getTooltipIcon():string { - return this._getCurrentText(); + update():void { + this.icon = this._isBusy?'x':'gear'; + super.update(); } isVisible():boolean { return this._isBusy || true; From 33b1a73b6a0169066c18c4f378864a01b3254a5f Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 10:33:48 +0200 Subject: [PATCH 16/32] fix: ctest coloring now needs true to use colors --- src/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status.ts b/src/status.ts index d178be368..a0b68373f 100644 --- a/src/status.ts +++ b/src/status.ts @@ -307,7 +307,7 @@ class CTestButton extends Button { } private _isUseColor():boolean { - return this._config.statusbar.advanced?.ctest?.color===false; + return this._config.statusbar.advanced?.ctest?.color===true; } update() { From a93e5090705a5004f3b71942b30cb9f0c3c14386 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 11:15:51 +0200 Subject: [PATCH 17/32] config update: - renamed type to visibility - added toplevel localization --- package.json | 60 +++++++++++++++++++++------------- package.nls.json | 2 ++ src/config.ts | 22 ++++++------- src/status.ts | 20 ++++++------ test/unit-tests/config.test.ts | 2 +- 5 files changed, 61 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index ab7900437..ef072cec6 100644 --- a/package.json +++ b/package.json @@ -1205,12 +1205,13 @@ ], "scope": "window" }, - "cmake.statusbar.type": { + "cmake.statusbar.visibility": { "type": "string", - "default": "text", + "default": "default", + "description": "%cmake-tools.configuration.cmake.statusbar.visibility.description%", "enum": [ - "text", - "short", + "default", + "compact", "icon", "hidden" ], @@ -1219,15 +1220,16 @@ "cmake.statusbar.advanced": { "type": "object", "default": null, + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.description%", "properties": { "kit": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ - "text", - "short", + "default", + "compact", "icon", "hidden" ] @@ -1240,12 +1242,12 @@ "status": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", - "default": "text", "enum": [ - "text", - "short", + "default", + "compact", + "icon", "hidden" ] } @@ -1254,10 +1256,11 @@ "workspace": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ - "text", + "default", + "compact", "icon", "hidden" ] @@ -1267,10 +1270,12 @@ "buildTarget": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ - "text", + "default", + "compact", + "icon", "hidden" ] } @@ -1279,10 +1284,11 @@ "build": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ - "text", + "default", + "compact", "icon", "hidden" ] @@ -1292,10 +1298,12 @@ "launchTarget": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ - "text", + "default", + "compact", + "icon", "hidden" ] } @@ -1304,9 +1312,11 @@ "debug": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ + "default", + "compact", "icon", "hidden" ] @@ -1316,9 +1326,11 @@ "launch": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ + "default", + "compact", "icon", "hidden" ] @@ -1328,10 +1340,12 @@ "ctest": { "type": "object", "properties": { - "type": { + "visibility": { "type": "string", "enum": [ - "text", + "default", + "compact", + "icon", "hidden" ] }, diff --git a/package.nls.json b/package.nls.json index 97eddd8a7..2a13239d7 100644 --- a/package.nls.json +++ b/package.nls.json @@ -106,6 +106,8 @@ "cmake-tools.configuration.cmake.outputLogEncoding.description": "Encoding of the output from external commands (eg.cmake -- build).", "cmake-tools.configuration.cmake.enableTraceLogging.description": "Enable trace logging to file and console (very noisy).", "cmake-tools.configuration.cmake.autoSelectActiveFolder.description": "Select active folder automatically", + "cmake-tools.configuration.cmake.statusbar.visibility.description": "Select default visibility of statusbar buttons (e.g. compact)", + "cmake-tools.configuration.cmake.statusbar.advanced.description": "Change settings of individual statusbar buttons (e.g. visibility). This overwrites the default settings.", "cmake-tools.configuration.views.cmake.folders.description": "Folders", "cmake-tools.configuration.views.cmake.outline.description": "Project Outline" } diff --git a/src/config.ts b/src/config.ts index c4165a442..73539f317 100644 --- a/src/config.ts +++ b/src/config.ts @@ -19,7 +19,7 @@ export type LogLevelKey = 'trace'|'debug'|'info'|'note'|'warning'|'error'|'fatal export type CMakeCommunicationMode = 'legacy'|'serverApi'|'fileApi'|'automatic'; -export type StatusBarButtonType = "text" | "short" | "icon" | "hidden"; +export type StatusBarButtonVisibility = "default" | "compact" | "icon" | "hidden"; interface HardEnv { [key: string]: string; @@ -27,38 +27,38 @@ interface HardEnv { export interface AdvancedStatusBarConfig { kit?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; length?: number; }; status?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; workspace?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; buildTarget?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; build?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; launchTarget?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; debug?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; launch?: { - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; ctest?: { color?: boolean; - type?: StatusBarButtonType; + visibility?: StatusBarButtonVisibility; }; } export interface StatusBarConfig { advanced?: AdvancedStatusBarConfig; - type: StatusBarButtonType; + visibility: StatusBarButtonVisibility; } export interface ExtensionConfigurationSettings { diff --git a/src/status.ts b/src/status.ts index a0b68373f..a613aa798 100644 --- a/src/status.ts +++ b/src/status.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode'; import {BasicTestResults} from '@cmt/ctest'; import * as nls from 'vscode-nls'; import {SpecialKits} from '@cmt/kit'; -import {StatusBarButtonType as ButtonType, ConfigurationReader } from '@cmt/config'; +import {StatusBarButtonVisibility as ButtonVisibility, ConfigurationReader } from '@cmt/config'; // FIXME: Show workspace selection if a folder is added to workspace @@ -65,40 +65,40 @@ abstract class Button { } private _isVisible():boolean { - return this.isVisible() && this.getType() !== "hidden"; + return this.isVisible() && this._getVisibility() !== "hidden"; } protected isVisible():boolean { return true; } - protected getType():ButtonType | null { + private _getVisibility():ButtonVisibility | null { if (this.settingsName) { - return Object(this._config.statusbar.advanced)[this.settingsName]?.type || this._config.statusbar.type || null; + return Object(this._config.statusbar.advanced)[this.settingsName]?.visibility || this._config.statusbar.visibility || null; } - return this._config.statusbar.type || null; + return this._config.statusbar.visibility || null; } getTooltip():string|null { - const type = this.getType(); - switch (type) { + const visibility = this._getVisibility(); + switch (visibility) { case "hidden": return null; case "icon": return this.getTooltipIcon(); - case "short": + case "compact": return this.getTooltipShort(); default: return this.getTooltipNormal(); } } getText(icon:boolean=false):string { - const type = this.getType(); + const type = this._getVisibility(); let text:string; switch (type) { case "icon": text = this.getTextIcon(); break; - case "short": + case "compact": text = this.getTextShort(); break; default: diff --git a/test/unit-tests/config.test.ts b/test/unit-tests/config.test.ts index 13b6b7410..0f48a648b 100644 --- a/test/unit-tests/config.test.ts +++ b/test/unit-tests/config.test.ts @@ -48,7 +48,7 @@ function createConfig(conf: Partial): Configurat loggingLevel: 'info', statusbar: { advanced: {}, - type: "text" + visibility: "default" } }); ret.updatePartial(conf); From a3d6da229d18852f42024822c3bc3f2ea95ae43b Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 11:34:14 +0200 Subject: [PATCH 18/32] added loca and default values to advanced settings --- package.json | 19 ++++++++++++++++--- package.nls.json | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ef072cec6..4c9e0423a 100644 --- a/package.json +++ b/package.json @@ -1219,7 +1219,7 @@ }, "cmake.statusbar.advanced": { "type": "object", - "default": null, + "default": {}, "description": "%cmake-tools.configuration.cmake.statusbar.advanced.description%", "properties": { "kit": { @@ -1227,6 +1227,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1235,7 +1236,9 @@ ] }, "length": { - "type": "integer" + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.length.description%", + "type": "integer", + "default": 20 } } }, @@ -1244,6 +1247,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1258,6 +1262,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1272,6 +1277,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1286,6 +1292,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1300,6 +1307,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1314,6 +1322,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1328,6 +1337,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1342,6 +1352,7 @@ "properties": { "visibility": { "type": "string", + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.visibility.description%", "enum": [ "default", "compact", @@ -1350,7 +1361,9 @@ ] }, "color": { - "type":"boolean" + "type":"boolean", + "default": false, + "description": "%cmake-tools.configuration.cmake.statusbar.advanced.ctest.color.description%" } } } diff --git a/package.nls.json b/package.nls.json index 2a13239d7..d2e0b9b97 100644 --- a/package.nls.json +++ b/package.nls.json @@ -108,6 +108,10 @@ "cmake-tools.configuration.cmake.autoSelectActiveFolder.description": "Select active folder automatically", "cmake-tools.configuration.cmake.statusbar.visibility.description": "Select default visibility of statusbar buttons (e.g. compact)", "cmake-tools.configuration.cmake.statusbar.advanced.description": "Change settings of individual statusbar buttons (e.g. visibility). This overwrites the default settings.", + "cmake-tools.configuration.cmake.statusbar.advanced.visibility.description": "Select visibility (e.g. compact)", + "cmake-tools.configuration.cmake.statusbar.advanced.ctest.color.description": "Change button color dependent on success of tests", + "cmake-tools.configuration.cmake.statusbar.advanced.length.description": "Set maximum length of visible text in compact mode.", + "cmake-tools.configuration.views.cmake.folders.description": "Folders", "cmake-tools.configuration.views.cmake.outline.description": "Project Outline" } From 33e8c8d52ac155a0b55bbf0de75e7f41f5cb6a75 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 11:49:25 +0200 Subject: [PATCH 19/32] added proper typecheck to kit length --- src/status.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/status.ts b/src/status.ts index a613aa798..86532d519 100644 --- a/src/status.ts +++ b/src/status.ts @@ -227,7 +227,10 @@ class KitSelection extends Button { } protected getTextShort() { - const len = Number(this._config.statusbar.advanced?.kit?.length) || 20; + let len = this._config.statusbar.advanced?.kit?.length || 0; + if (!Number.isInteger(len) || len <= 0) { + len = 20; + } let text = this.getTextNormal(); if (len + 3 < text.length) { text = `${text.substr(0, len)}...`; From 8cbef1a037b49dfa0749f5a65e2de6c59e6f0a63 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 4 May 2020 12:12:05 +0200 Subject: [PATCH 20/32] added target tooltip to Build, Launch and Debug added tooltip to BuildTargetName --- src/status.ts | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/status.ts b/src/status.ts index 86532d519..d63934c53 100644 --- a/src/status.ts +++ b/src/status.ts @@ -149,9 +149,18 @@ abstract class Button { //--------------------------------------------- //---------------- Helper Class --------------- //--------------------------------------------- -class CheckCPPToolsButton extends Button { - protected isVisible() { - return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; + +class TargetTooltipButton extends Button { + private _target: string|null = null; + set target(v: string|null) { + this._target = v?`[${v}]`:null; + this.update(); + } + getTooltipNormal() { + if (this.tooltip && this._target) { + return `${this.tooltip}\n${this._target}`; + } + return this._target || this.tooltip || null; } } @@ -252,8 +261,12 @@ class LaunchTargetSelectionButton extends Button { settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); + + protected getTextNormal():string { + return `[${this.text}]`; + } } -class DebugButton extends CheckCPPToolsButton { +class DebugButton extends TargetTooltipButton { settingsName = 'debug'; command = 'cmake.debugTarget'; icon = 'bug'; @@ -266,10 +279,10 @@ class DebugButton extends CheckCPPToolsButton { } isVisible() { - return super.isVisible() && !this._hidden; + return !this._hidden && vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; } } -class LaunchButton extends Button { +class LaunchButton extends TargetTooltipButton { settingsName = 'launch'; command = 'cmake.launchTarget'; icon = 'play'; @@ -343,12 +356,13 @@ class CTestButton extends Button { return localize('tests.passing', '{0}/{1} tests passing', passing, total); } } -class BuildButton extends Button { +class BuildButton extends TargetTooltipButton { private static readonly _build = localize('build', 'Build'); private static readonly _stop = localize('stop', 'Stop'); settingsName = 'build'; command = 'cmake.build'; + tooltip = localize('build.tooltip', 'Build the selected target'); private _isBusy:boolean = false; set isBusy(v: boolean) { @@ -409,8 +423,15 @@ export class StatusBar implements vscode.Disposable { setAutoSelectActiveFolder = (autoSelectActiveFolder: boolean) => this._activeFolderButton.autoSelect = autoSelectActiveFolder; setBuildTypeLabel = (v: string) => this._cmakeToolsStatusItem.buildTypeLabel = v; setStatusMessage = (v: string) => this._cmakeToolsStatusItem.statusMessage = v; - setBuildTargetName = (v: string) => this._buildTargetNameButton.text = v; - setLaunchTargetName = (v: string) => this._launchTargetNameButton.text = v; + setBuildTargetName = (v: string) => { + this._buildTargetNameButton.text = v; + this._buildButton.target = v; + } + setLaunchTargetName = (v: string) => { + this._launchTargetNameButton.text = v; + this._launchButton.target = v; + this._debugButton.target = v; + } setCTestEnabled = (v: boolean) => this._testButton.enabled = v; setTestResults = (v: BasicTestResults|null) => this._testButton.results = v; setIsBusy = (v:boolean) => this._buildButton.isBusy = v; From 226c4e65a614ba8f2f7b489ff516f2dac4d1881b Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 07:46:08 +0200 Subject: [PATCH 21/32] refactoring - fixed access - reordered function to reflect access - renamed member to reflect access --- src/status.ts | 222 +++++++++++++++++++++++--------------------------- 1 file changed, 100 insertions(+), 122 deletions(-) diff --git a/src/status.ts b/src/status.ts index d63934c53..629a39213 100644 --- a/src/status.ts +++ b/src/status.ts @@ -9,23 +9,27 @@ import {StatusBarButtonVisibility as ButtonVisibility, ConfigurationReader } fro nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); +//--------------------------------------------- +//-------------- Helper Functions ------------- +//--------------------------------------------- + +function hasCPPTools():boolean { + return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; +} +//--------------------------------------------- +//---------------- Button Class --------------- +//--------------------------------------------- + abstract class Button { - constructor(protected readonly _config: ConfigurationReader, protected readonly priority: number) { - this._button.command = this._button.command; - } - protected readonly _button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, this.priority); + readonly settingsName : string|null = null; + protected readonly button:vscode.StatusBarItem; private _forceHidden:boolean = false; private _text: string = ''; private _tooltip: string|null = null; private _icon: string|null = null; - readonly settingsName : string|null = null; - - set icon(v:string|null) { - this._icon = v?`$(${v})`: null; - } - set command(v:string|null) { - this._button.command = v || undefined; + constructor(protected readonly config: ConfigurationReader, private readonly _priority: number) { + this.button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, this._priority); } set forceHidden(v:boolean) { @@ -33,52 +37,88 @@ abstract class Button { this.update(); } + get text():string { return this._text; } + set text(v:string) { + this._text = v; + this.update(); + } + get tooltip():string|null { return this._tooltip; } set tooltip(v:string|null) { this._tooltip = v; this.update(); } - get text():string { return this._text; } - set text(v:string) { - this._text = v; - this.update(); + protected set icon(v:string|null) { + this._icon = v?`$(${v})`: null; + } + + protected set command(v:string|null) { + this.button.command = v || undefined; } dispose():void { - this._button.dispose(); + this.button.dispose(); } update():void { const visible = this._isVisible(); if (!visible || this._forceHidden) { - this._button.hide(); + this.button.hide(); return; } - const text = this.getText(true); + const text = this._getText(true); if (text==='') { - this._button.hide(); + this.button.hide(); return; } - this._button.text = text; - this._button.tooltip = this.getTooltip() || undefined; - this._button.show(); + this.button.text = text; + this.button.tooltip = this._getTooltip() || undefined; + this.button.show(); } - private _isVisible():boolean { - return this.isVisible() && this._getVisibility() !== "hidden"; + protected getTextNormal():string { + return this._text; + } + protected getTextShort():string { + return this.getTextNormal(); + } + protected getTextIcon():string { + return ''; + } + + protected getTooltipNormal():string|null { + return this._tooltip; + } + protected getTooltipShort():string|null { + const tooltip = this.getTooltipNormal(); + const text = this.getTextNormal(); + if (!tooltip && !text) { + return null; + } + if (!tooltip || !text) { + return `CMake: ${tooltip||text}`; + } + return `CMake: ${tooltip}\n${text}`; + } + protected getTooltipIcon():string|null { + return this.getTooltipShort(); } protected isVisible():boolean { return true; } + + private _isVisible():boolean { + return this.isVisible() && this._getVisibility() !== "hidden"; + } private _getVisibility():ButtonVisibility | null { if (this.settingsName) { - return Object(this._config.statusbar.advanced)[this.settingsName]?.visibility || this._config.statusbar.visibility || null; + return Object(this.config.statusbar.advanced)[this.settingsName]?.visibility || this.config.statusbar.visibility || null; } - return this._config.statusbar.visibility || null; + return this.config.statusbar.visibility || null; } - getTooltip():string|null { + private _getTooltip():string|null { const visibility = this._getVisibility(); switch (visibility) { case "hidden": @@ -91,7 +131,7 @@ abstract class Button { return this.getTooltipNormal(); } } - getText(icon:boolean=false):string { + private _getText(icon:boolean=false):string { const type = this._getVisibility(); let text:string; switch (type) { @@ -116,57 +156,8 @@ abstract class Button { } return `${this._icon} ${text}`; } - - protected getTooltipNormal():string|null { - return this._tooltip; - } - protected getTooltipShort():string|null { - const tooltip = this.getTooltipNormal(); - const text = this.getTextNormal(); - if (!tooltip && !text) { - return null; - } - if (!tooltip || !text) { - return `CMake: ${tooltip||text}`; - } - return `CMake: ${tooltip}\n${text}`; - } - protected getTooltipIcon():string|null { - return this.getTooltipShort(); - } - - protected getTextNormal():string { - return this._text; - } - protected getTextShort():string { - return this.getTextNormal(); - } - protected getTextIcon():string { - return ''; - } -} - -//--------------------------------------------- -//---------------- Helper Class --------------- -//--------------------------------------------- - -class TargetTooltipButton extends Button { - private _target: string|null = null; - set target(v: string|null) { - this._target = v?`[${v}]`:null; - this.update(); - } - getTooltipNormal() { - if (this.tooltip && this._target) { - return `${this.tooltip}\n${this._target}`; - } - return this._target || this.tooltip || null; - } } -//--------------------------------------------- -//---------------- Button Class --------------- -//--------------------------------------------- class ActiveFolderButton extends Button { private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); @@ -187,31 +178,31 @@ class ActiveFolderButton extends Button { } return ActiveFolderButton._toolTip; } + protected isVisible():boolean { - return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !!this.getText()); + return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1); } } class CMakeStatus extends Button { settingsName = 'status'; command = "cmake.setVariant"; + icon = 'info'; + text: string = localize('unconfigured', 'Unconfigured'); tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); - private _buildTypeLabel: string = localize('unconfigured', 'Unconfigured'); private _statusMessage: string = localize('loading.status', 'Loading...'); - set buildTypeLabel(v: string) { - this._buildTypeLabel = v; - this.update(); - } + set statusMessage(v: string) { this._statusMessage = v; this.update(); } + protected getTextNormal() { - return `CMake: ${this._buildTypeLabel}: ${this._statusMessage}`; + return `CMake: ${this.text}: ${this._statusMessage}`; } protected getTextShort() { - return `${this._buildTypeLabel}: ${this._statusMessage}`; + return `${this.text}: ${this._statusMessage}`; } } @@ -234,9 +225,8 @@ class KitSelection extends Button { } return text; } - protected getTextShort() { - let len = this._config.statusbar.advanced?.kit?.length || 0; + let len = this.config.statusbar.advanced?.kit?.length || 0; if (!Number.isInteger(len) || len <= 0) { len = 20; } @@ -252,21 +242,14 @@ class BuildTargetSelectionButton extends Button { settingsName = 'buildTarget'; command = 'cmake.setDefaultTarget'; tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); - - protected getTextNormal():string { - return `[${this.text}]`; - } } class LaunchTargetSelectionButton extends Button { settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); - - protected getTextNormal():string { - return `[${this.text}]`; - } } -class DebugButton extends TargetTooltipButton { + +class DebugButton extends Button { settingsName = 'debug'; command = 'cmake.debugTarget'; icon = 'bug'; @@ -278,11 +261,11 @@ class DebugButton extends TargetTooltipButton { this.update(); } - isVisible() { - return !this._hidden && vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; + protected isVisible() { + return !this._hidden && hasCPPTools(); } } -class LaunchButton extends TargetTooltipButton { +class LaunchButton extends Button { settingsName = 'launch'; command = 'cmake.launchTarget'; icon = 'play'; @@ -294,7 +277,7 @@ class LaunchButton extends TargetTooltipButton { this.update(); } - isVisible() { + protected isVisible() { return super.isVisible() && !this._hidden; } } @@ -322,10 +305,6 @@ class CTestButton extends Button { this.update(); } - private _isUseColor():boolean { - return this._config.statusbar.advanced?.ctest?.color===true; - } - update() { if (this._results) { const {passing, total} = this._results; @@ -333,20 +312,21 @@ class CTestButton extends Button { } else { this.icon = 'beaker'; } - super.update(); - if (this._isUseColor()) { - this._button.color = this._color; + if (this.config.statusbar.advanced?.ctest?.color===true) { + this.button.color = this._color; } else { - this._button.color = ''; + this.button.color = ''; } + super.update(); } - isVisible() { + + protected isVisible() { return this._enabled; } protected getTextNormal():string { if (!this._results) { - this._button.color = ''; + this.button.color = ''; return localize('run.ctest', 'Run CTest'); } const {passing, total} = this._results; @@ -356,7 +336,8 @@ class CTestButton extends Button { return localize('tests.passing', '{0}/{1} tests passing', passing, total); } } -class BuildButton extends TargetTooltipButton { + +class BuildButton extends Button { private static readonly _build = localize('build', 'Build'); private static readonly _stop = localize('stop', 'Stop'); @@ -365,19 +346,17 @@ class BuildButton extends TargetTooltipButton { tooltip = localize('build.tooltip', 'Build the selected target'); private _isBusy:boolean = false; + set isBusy(v: boolean) { this._isBusy = v; - this._button.command = v ? 'cmake.stop' : 'cmake.build'; + this.button.command = v ? 'cmake.stop' : 'cmake.build'; + this.icon = this._isBusy?'x':'gear'; this.text = this._isBusy? BuildButton._stop:BuildButton._build; // update implicitly called in set text. - // this.update(); + //this.update(); } - update():void { - this.icon = this._isBusy?'x':'gear'; - super.update(); - } - isVisible():boolean { + protected isVisible():boolean { return this._isBusy || true; } } @@ -421,16 +400,15 @@ export class StatusBar implements vscode.Disposable { setActiveFolderName = (v: string) => this._activeFolderButton.text = v; setAutoSelectActiveFolder = (autoSelectActiveFolder: boolean) => this._activeFolderButton.autoSelect = autoSelectActiveFolder; - setBuildTypeLabel = (v: string) => this._cmakeToolsStatusItem.buildTypeLabel = v; + setBuildTypeLabel = (v: string) => this._cmakeToolsStatusItem.text = v; setStatusMessage = (v: string) => this._cmakeToolsStatusItem.statusMessage = v; setBuildTargetName = (v: string) => { + v = `[${v}]`; this._buildTargetNameButton.text = v; - this._buildButton.target = v; } setLaunchTargetName = (v: string) => { + v = v==''?v:`[${v}]`; this._launchTargetNameButton.text = v; - this._launchButton.target = v; - this._debugButton.target = v; } setCTestEnabled = (v: boolean) => this._testButton.enabled = v; setTestResults = (v: BasicTestResults|null) => this._testButton.results = v; From 91e2bec2eb42856abff523a12550d3a7a3d7bfb2 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 07:47:59 +0200 Subject: [PATCH 22/32] improved compact mode of status button --- src/status.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/status.ts b/src/status.ts index 629a39213..222e2024b 100644 --- a/src/status.ts +++ b/src/status.ts @@ -202,7 +202,14 @@ class CMakeStatus extends Button { return `CMake: ${this.text}: ${this._statusMessage}`; } protected getTextShort() { - return `${this.text}: ${this._statusMessage}`; + return this.text; + } + + protected getTooltipNormal():string { + return `${this.tooltip}\n${this.text}: ${this._statusMessage}`; + } + protected getTooltipShort(): string { + return `CMake: ${this.getTooltipNormal()}`; } } From 008cb1391a8da10bf47a4ba5678f206d71b105ca Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 07:49:35 +0200 Subject: [PATCH 23/32] improved launch target selection --- src/status.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/status.ts b/src/status.ts index 222e2024b..51ffaba2e 100644 --- a/src/status.ts +++ b/src/status.ts @@ -254,6 +254,17 @@ class LaunchTargetSelectionButton extends Button { settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); + + protected getTextNormal() { + if (this.text=='') { + return '[-]'; + } + return this.text; + } + + protected getTooltipShort() { + return this.tooltip; + } } class DebugButton extends Button { From 9f6be09c75fbfe683244d5b5e692bdf289978b2e Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 07:50:56 +0200 Subject: [PATCH 24/32] improved compact mode of ctest button --- src/status.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/status.ts b/src/status.ts index 51ffaba2e..0018232e3 100644 --- a/src/status.ts +++ b/src/status.ts @@ -353,6 +353,14 @@ class CTestButton extends Button { } return localize('tests.passing', '{0}/{1} tests passing', passing, total); } + + protected getTextShort(): string { + if (!this._results) { + return '-'; + } + const {passing, total} = this._results; + return `${passing}/${total}`; + } } class BuildButton extends Button { From d8cba033fe33348963400f75335d2747b326e071 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 07:58:13 +0200 Subject: [PATCH 25/32] added target to build, debug and launch buttons --- src/status.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/status.ts b/src/status.ts index 0018232e3..2a2b0808c 100644 --- a/src/status.ts +++ b/src/status.ts @@ -274,10 +274,23 @@ class DebugButton extends Button { tooltip = localize('launch.debugger.tooltip', 'Launch the debugger for the selected target'); private _hidden: boolean = false; + private _target: string|null = null; + set hidden(v:boolean) { this._hidden = v; this.update(); } + set target(v: string|null) { + this._target = v; + this.update(); + } + + protected getTooltipNormal(): string|null { + if (!!this._target) { + return `${this.tooltip}\n${this._target}`; + } + return this.tooltip; + } protected isVisible() { return !this._hidden && hasCPPTools(); @@ -290,10 +303,23 @@ class LaunchButton extends Button { tooltip = localize('launch.tooltip', 'Launch the selected target in the terminal window'); private _hidden: boolean = false; + private _target: string|null = null; + set hidden(v:boolean) { this._hidden = v; this.update(); } + set target(v: string|null) { + this._target = v; + this.update(); + } + + protected getTooltipNormal(): string|null { + if (!!this._target) { + return `${this.tooltip}\n${this._target}`; + } + return this.tooltip; + } protected isVisible() { return super.isVisible() && !this._hidden; @@ -372,6 +398,7 @@ class BuildButton extends Button { tooltip = localize('build.tooltip', 'Build the selected target'); private _isBusy:boolean = false; + private _target: string|null = null; set isBusy(v: boolean) { this._isBusy = v; @@ -381,6 +408,18 @@ class BuildButton extends Button { // update implicitly called in set text. //this.update(); } + set target(v: string|null) { + this._target = v; + this.update(); + } + + protected getTooltipNormal(): string|null { + if (!!this._target) { + return `${this.tooltip}\n${this._target}`; + } + return this.tooltip; + } + protected getTooltipShort = () => this.getTooltipNormal(); protected isVisible():boolean { return this._isBusy || true; @@ -431,10 +470,13 @@ export class StatusBar implements vscode.Disposable { setBuildTargetName = (v: string) => { v = `[${v}]`; this._buildTargetNameButton.text = v; + this._buildButton.target = v; } setLaunchTargetName = (v: string) => { v = v==''?v:`[${v}]`; this._launchTargetNameButton.text = v; + this._launchButton.target = v; + this._debugButton.target = v; } setCTestEnabled = (v: boolean) => this._testButton.enabled = v; setTestResults = (v: BasicTestResults|null) => this._testButton.results = v; From b6a7571fdbd4d1c130cd440b52e5f37f46b74ff8 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 08:06:38 +0200 Subject: [PATCH 26/32] clang-tidy --- src/status.ts | 222 +++++++++++++++++++++----------------------------- 1 file changed, 92 insertions(+), 130 deletions(-) diff --git a/src/status.ts b/src/status.ts index 2a2b0808c..923633b83 100644 --- a/src/status.ts +++ b/src/status.ts @@ -1,29 +1,27 @@ -import * as vscode from 'vscode'; +import {ConfigurationReader, StatusBarButtonVisibility as ButtonVisibility} from '@cmt/config'; import {BasicTestResults} from '@cmt/ctest'; -import * as nls from 'vscode-nls'; import {SpecialKits} from '@cmt/kit'; -import {StatusBarButtonVisibility as ButtonVisibility, ConfigurationReader } from '@cmt/config'; +import * as vscode from 'vscode'; +import * as nls from 'vscode-nls'; // FIXME: Show workspace selection if a folder is added to workspace -nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); +nls.config({messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone})(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); //--------------------------------------------- //-------------- Helper Functions ------------- //--------------------------------------------- -function hasCPPTools():boolean { - return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; -} +function hasCPPTools(): boolean { return vscode.extensions.getExtension('ms-vscode.cpptools') !== undefined; } //--------------------------------------------- //---------------- Button Class --------------- //--------------------------------------------- abstract class Button { - readonly settingsName : string|null = null; - protected readonly button:vscode.StatusBarItem; - private _forceHidden:boolean = false; + readonly settingsName: string|null = null; + protected readonly button: vscode.StatusBarItem; + private _forceHidden: boolean = false; private _text: string = ''; private _tooltip: string|null = null; private _icon: string|null = null; @@ -32,42 +30,36 @@ abstract class Button { this.button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, this._priority); } - set forceHidden(v:boolean) { + set forceHidden(v: boolean) { this._forceHidden = v; this.update(); } - get text():string { return this._text; } - set text(v:string) { + get text(): string { return this._text; } + set text(v: string) { this._text = v; this.update(); } - get tooltip():string|null { return this._tooltip; } - set tooltip(v:string|null) { + get tooltip(): string|null { return this._tooltip; } + set tooltip(v: string|null) { this._tooltip = v; this.update(); } - protected set icon(v:string|null) { - this._icon = v?`$(${v})`: null; - } + protected set icon(v: string|null) { this._icon = v ? `$(${v})` : null; } - protected set command(v:string|null) { - this.button.command = v || undefined; - } + protected set command(v: string|null) { this.button.command = v || undefined; } - dispose():void { - this.button.dispose(); - } - update():void { + dispose(): void { this.button.dispose(); } + update(): void { const visible = this._isVisible(); if (!visible || this._forceHidden) { this.button.hide(); return; } const text = this._getText(true); - if (text==='') { + if (text === '') { this.button.hide(); return; } @@ -76,74 +68,61 @@ abstract class Button { this.button.show(); } - protected getTextNormal():string { - return this._text; - } - protected getTextShort():string { - return this.getTextNormal(); - } - protected getTextIcon():string { - return ''; - } + protected getTextNormal(): string { return this._text; } + protected getTextShort(): string { return this.getTextNormal(); } + protected getTextIcon(): string { return ''; } - protected getTooltipNormal():string|null { - return this._tooltip; - } - protected getTooltipShort():string|null { + protected getTooltipNormal(): string|null { return this._tooltip; } + protected getTooltipShort(): string|null { const tooltip = this.getTooltipNormal(); const text = this.getTextNormal(); if (!tooltip && !text) { return null; } if (!tooltip || !text) { - return `CMake: ${tooltip||text}`; + return `CMake: ${tooltip || text}`; } return `CMake: ${tooltip}\n${text}`; } - protected getTooltipIcon():string|null { - return this.getTooltipShort(); - } + protected getTooltipIcon(): string|null { return this.getTooltipShort(); } - protected isVisible():boolean { - return true; - } + protected isVisible(): boolean { return true; } - private _isVisible():boolean { - return this.isVisible() && this._getVisibility() !== "hidden"; - } - private _getVisibility():ButtonVisibility | null { + private _isVisible(): boolean { return this.isVisible() && this._getVisibility() !== 'hidden'; } + private _getVisibility(): ButtonVisibility|null { if (this.settingsName) { - return Object(this.config.statusbar.advanced)[this.settingsName]?.visibility || this.config.statusbar.visibility || null; + const setting = Object(this.config.statusbar.advanced)[this.settingsName]?.visibility; + return setting || this.config.statusbar.visibility || null; } return this.config.statusbar.visibility || null; } - private _getTooltip():string|null { + private _getTooltip(): string|null { const visibility = this._getVisibility(); switch (visibility) { - case "hidden": - return null; - case "icon": - return this.getTooltipIcon(); - case "compact": - return this.getTooltipShort(); - default: - return this.getTooltipNormal(); + case 'hidden': + return null; + case 'icon': + return this.getTooltipIcon(); + case 'compact': + return this.getTooltipShort(); + default: + return this.getTooltipNormal(); } } - private _getText(icon:boolean=false):string { + private _getText(icon: boolean = false): string { const type = this._getVisibility(); - let text:string; + let text: string; switch (type) { - case "icon": - text = this.getTextIcon(); - break; - case "compact": - text = this.getTextShort(); - break; - default: - text = this.getTextNormal(); - break; + case 'icon': + text = this.getTextIcon(); + break; + case 'compact': + text = this.getTextShort(); + break; + default: + text = this.getTextNormal(); + break; } if (!icon) { return text; @@ -151,7 +130,7 @@ abstract class Button { if (!this._icon) { return text; } - if (text=='') { + if (text == '') { return this._icon || ''; } return `${this._icon} ${text}`; @@ -163,30 +142,30 @@ class ActiveFolderButton extends Button { private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); settingsName = 'workspace'; - command = "cmake.selectActiveFolder"; + command = 'cmake.selectActiveFolder'; icon = 'folder-active'; private _autoSelect: boolean = false; - set autoSelect(v:boolean) { + set autoSelect(v: boolean) { this._autoSelect = v; this.update(); } - protected getTooltipNormal():string|null { + protected getTooltipNormal(): string|null { if (this._autoSelect) { return ActiveFolderButton._autoSelectToolTip; } return ActiveFolderButton._toolTip; } - protected isVisible():boolean { + protected isVisible(): boolean { return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1); } } class CMakeStatus extends Button { settingsName = 'status'; - command = "cmake.setVariant"; + command = 'cmake.setVariant'; icon = 'info'; text: string = localize('unconfigured', 'Unconfigured'); tooltip = localize('click.to.select.variant.tooltip', 'Click to select the current build variant'); @@ -198,19 +177,11 @@ class CMakeStatus extends Button { this.update(); } - protected getTextNormal() { - return `CMake: ${this.text}: ${this._statusMessage}`; - } - protected getTextShort() { - return this.text; - } + protected getTextNormal() { return `CMake: ${this.text}: ${this._statusMessage}`; } + protected getTextShort() { return this.text; } - protected getTooltipNormal():string { - return `${this.tooltip}\n${this.text}: ${this._statusMessage}`; - } - protected getTooltipShort(): string { - return `CMake: ${this.getTooltipNormal()}`; - } + protected getTooltipNormal(): string { return `${this.tooltip}\n${this.text}: ${this._statusMessage}`; } + protected getTooltipShort(): string { return `CMake: ${this.getTooltipNormal()}`; } } class KitSelection extends Button { @@ -222,7 +193,7 @@ class KitSelection extends Button { icon = 'tools'; tooltip = localize('click.to.change.kit.tooltip', 'Click to change the active kit'); - protected getTextNormal():string { + protected getTextNormal(): string { const text = this.text; if (text === SpecialKits.Unspecified) { return KitSelection._noActiveKit; @@ -256,18 +227,16 @@ class LaunchTargetSelectionButton extends Button { tooltip = localize('select.target.tooltip', 'Select the target to launch'); protected getTextNormal() { - if (this.text=='') { + if (this.text == '') { return '[-]'; } return this.text; } - protected getTooltipShort() { - return this.tooltip; - } + protected getTooltipShort() { return this.tooltip; } } -class DebugButton extends Button { +class DebugButton extends Button { settingsName = 'debug'; command = 'cmake.debugTarget'; icon = 'bug'; @@ -276,7 +245,7 @@ class DebugButton extends Button { private _hidden: boolean = false; private _target: string|null = null; - set hidden(v:boolean) { + set hidden(v: boolean) { this._hidden = v; this.update(); } @@ -292,9 +261,7 @@ class DebugButton extends Button { return this.tooltip; } - protected isVisible() { - return !this._hidden && hasCPPTools(); - } + protected isVisible() { return !this._hidden && hasCPPTools(); } } class LaunchButton extends Button { settingsName = 'launch'; @@ -305,7 +272,7 @@ class LaunchButton extends Button { private _hidden: boolean = false; private _target: string|null = null; - set hidden(v:boolean) { + set hidden(v: boolean) { this._hidden = v; this.update(); } @@ -321,9 +288,7 @@ class LaunchButton extends Button { return this.tooltip; } - protected isVisible() { - return super.isVisible() && !this._hidden; - } + protected isVisible() { return super.isVisible() && !this._hidden; } } class CTestButton extends Button { @@ -331,20 +296,20 @@ class CTestButton extends Button { command = 'cmake.ctest'; tooltip = localize('run.ctest.tests.tooltip', 'Run CTest tests'); - private _enabled:boolean = false; + private _enabled: boolean = false; private _results: BasicTestResults|null = null; private _color: string = ''; - set enabled(v:boolean) { + set enabled(v: boolean) { this._enabled = v; this.update(); } - set results(v:BasicTestResults|null) { + set results(v: BasicTestResults|null) { this._results = v; if (!v) { this._color = ''; } else { - this._color = v.passing===v.total?'lightgreen' : 'yellow'; + this._color = v.passing === v.total ? 'lightgreen' : 'yellow'; } this.update(); } @@ -352,11 +317,11 @@ class CTestButton extends Button { update() { if (this._results) { const {passing, total} = this._results; - this.icon = passing == total? 'check' : 'x'; + this.icon = passing == total ? 'check' : 'x'; } else { this.icon = 'beaker'; } - if (this.config.statusbar.advanced?.ctest?.color===true) { + if (this.config.statusbar.advanced?.ctest?.color === true) { this.button.color = this._color; } else { this.button.color = ''; @@ -364,11 +329,9 @@ class CTestButton extends Button { super.update(); } - protected isVisible() { - return this._enabled; - } + protected isVisible() { return this._enabled; } - protected getTextNormal():string { + protected getTextNormal(): string { if (!this._results) { this.button.color = ''; return localize('run.ctest', 'Run CTest'); @@ -397,16 +360,16 @@ class BuildButton extends Button { command = 'cmake.build'; tooltip = localize('build.tooltip', 'Build the selected target'); - private _isBusy:boolean = false; + private _isBusy: boolean = false; private _target: string|null = null; set isBusy(v: boolean) { this._isBusy = v; this.button.command = v ? 'cmake.stop' : 'cmake.build'; - this.icon = this._isBusy?'x':'gear'; - this.text = this._isBusy? BuildButton._stop:BuildButton._build; + this.icon = this._isBusy ? 'x' : 'gear'; + this.text = this._isBusy ? BuildButton._stop : BuildButton._build; // update implicitly called in set text. - //this.update(); + // this.update(); } set target(v: string|null) { this._target = v; @@ -421,9 +384,7 @@ class BuildButton extends Button { } protected getTooltipShort = () => this.getTooltipNormal(); - protected isVisible():boolean { - return this._isBusy || true; - } + protected isVisible(): boolean { return this._isBusy || true; } } export class StatusBar implements vscode.Disposable { @@ -432,10 +393,10 @@ export class StatusBar implements vscode.Disposable { private readonly _cmakeToolsStatusItem = new CMakeStatus(this._config, 3.5); private readonly _kitSelectionButton = new KitSelection(this._config, 3.4); - private readonly _buildButton:BuildButton = new BuildButton(this._config, 3.35); + private readonly _buildButton: BuildButton = new BuildButton(this._config, 3.35); private readonly _buildTargetNameButton = new BuildTargetSelectionButton(this._config, 3.3); - private readonly _debugButton:DebugButton = new DebugButton(this._config, 3.22); + private readonly _debugButton: DebugButton = new DebugButton(this._config, 3.22); private readonly _launchButton = new LaunchButton(this._config, 3.21); private readonly _launchTargetNameButton = new LaunchTargetSelectionButton(this._config, 3.2); @@ -455,33 +416,34 @@ export class StatusBar implements vscode.Disposable { this._testButton, this._launchButton ]; - this._config.onChange('statusbar', ()=>this.update()); + this._config.onChange('statusbar', () => this.update()); this.update(); } dispose = () => this._buttons.forEach(btn => btn.dispose()); update = () => this._buttons.forEach(btn => btn.update()); - setVisible= (v: boolean) => this._buttons.forEach(btn => btn.forceHidden = !v); + setVisible = (v: boolean) => this._buttons.forEach(btn => btn.forceHidden = !v); setActiveFolderName = (v: string) => this._activeFolderButton.text = v; - setAutoSelectActiveFolder = (autoSelectActiveFolder: boolean) => this._activeFolderButton.autoSelect = autoSelectActiveFolder; + setAutoSelectActiveFolder = (autoSelectActiveFolder: boolean) => this._activeFolderButton.autoSelect + = autoSelectActiveFolder; setBuildTypeLabel = (v: string) => this._cmakeToolsStatusItem.text = v; setStatusMessage = (v: string) => this._cmakeToolsStatusItem.statusMessage = v; setBuildTargetName = (v: string) => { v = `[${v}]`; this._buildTargetNameButton.text = v; this._buildButton.target = v; - } + }; setLaunchTargetName = (v: string) => { - v = v==''?v:`[${v}]`; + v = v == '' ? v : `[${v}]`; this._launchTargetNameButton.text = v; this._launchButton.target = v; this._debugButton.target = v; - } + }; setCTestEnabled = (v: boolean) => this._testButton.enabled = v; setTestResults = (v: BasicTestResults|null) => this._testButton.results = v; - setIsBusy = (v:boolean) => this._buildButton.isBusy = v; - setActiveKitName = (v:string) => this._kitSelectionButton.text = v; + setIsBusy = (v: boolean) => this._buildButton.isBusy = v; + setActiveKitName = (v: string) => this._kitSelectionButton.text = v; hideLaunchButton = (shouldHide: boolean = true) => this._launchButton.hidden = shouldHide; hideDebugButton = (shouldHide: boolean = true) => this._debugButton.hidden = shouldHide; From 8209fe8d16fdbbdc6a79987fc801e4217d394570 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Tue, 5 May 2020 08:19:16 +0200 Subject: [PATCH 27/32] added missing type annotations renamed ActiveFolderButton to WorkspaceButton --- src/status.ts | 76 +++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/status.ts b/src/status.ts index 923633b83..ff2de5e3f 100644 --- a/src/status.ts +++ b/src/status.ts @@ -137,7 +137,7 @@ abstract class Button { } } -class ActiveFolderButton extends Button { +class WorkspaceButton extends Button { private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); @@ -153,9 +153,9 @@ class ActiveFolderButton extends Button { protected getTooltipNormal(): string|null { if (this._autoSelect) { - return ActiveFolderButton._autoSelectToolTip; + return WorkspaceButton._autoSelectToolTip; } - return ActiveFolderButton._toolTip; + return WorkspaceButton._toolTip; } protected isVisible(): boolean { @@ -177,11 +177,11 @@ class CMakeStatus extends Button { this.update(); } - protected getTextNormal() { return `CMake: ${this.text}: ${this._statusMessage}`; } - protected getTextShort() { return this.text; } + protected getTextNormal(): string { return `CMake: ${this.text}: ${this._statusMessage}`; } + protected getTextShort(): string { return this.text; } - protected getTooltipNormal(): string { return `${this.tooltip}\n${this.text}: ${this._statusMessage}`; } - protected getTooltipShort(): string { return `CMake: ${this.getTooltipNormal()}`; } + protected getTooltipNormal(): string|null { return `${this.tooltip}\n${this.text}: ${this._statusMessage}`; } + protected getTooltipShort(): string|null { return `CMake: ${this.getTooltipNormal()}`; } } class KitSelection extends Button { @@ -203,7 +203,7 @@ class KitSelection extends Button { } return text; } - protected getTextShort() { + protected getTextShort(): string { let len = this.config.statusbar.advanced?.kit?.length || 0; if (!Number.isInteger(len) || len <= 0) { len = 20; @@ -226,14 +226,14 @@ class LaunchTargetSelectionButton extends Button { command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); - protected getTextNormal() { + protected getTextNormal(): string { if (this.text == '') { return '[-]'; } return this.text; } - protected getTooltipShort() { return this.tooltip; } + protected getTooltipShort(): string|null { return this.tooltip; } } class DebugButton extends Button { @@ -261,7 +261,7 @@ class DebugButton extends Button { return this.tooltip; } - protected isVisible() { return !this._hidden && hasCPPTools(); } + protected isVisible(): boolean { return !this._hidden && hasCPPTools(); } } class LaunchButton extends Button { settingsName = 'launch'; @@ -288,7 +288,7 @@ class LaunchButton extends Button { return this.tooltip; } - protected isVisible() { return super.isVisible() && !this._hidden; } + protected isVisible(): boolean { return super.isVisible() && !this._hidden; } } class CTestButton extends Button { @@ -314,7 +314,7 @@ class CTestButton extends Button { this.update(); } - update() { + update(): void { if (this._results) { const {passing, total} = this._results; this.icon = passing == total ? 'check' : 'x'; @@ -329,7 +329,7 @@ class CTestButton extends Button { super.update(); } - protected isVisible() { return this._enabled; } + protected isVisible(): boolean { return this._enabled; } protected getTextNormal(): string { if (!this._results) { @@ -376,19 +376,21 @@ class BuildButton extends Button { this.update(); } + protected getTextShort(): string { return ''; } + protected getTooltipNormal(): string|null { if (!!this._target) { return `${this.tooltip}\n${this._target}`; } return this.tooltip; } - protected getTooltipShort = () => this.getTooltipNormal(); + protected getTooltipShort(): string|null { return this.getTooltipNormal(); } protected isVisible(): boolean { return this._isBusy || true; } } export class StatusBar implements vscode.Disposable { - private readonly _activeFolderButton = new ActiveFolderButton(this._config, 3.6); + private readonly _workspaceButton = new WorkspaceButton(this._config, 3.6); private readonly _cmakeToolsStatusItem = new CMakeStatus(this._config, 3.5); private readonly _kitSelectionButton = new KitSelection(this._config, 3.4); @@ -406,7 +408,7 @@ export class StatusBar implements vscode.Disposable { constructor(private readonly _config: ConfigurationReader) { this._buttons = [ - this._activeFolderButton, + this._workspaceButton, this._cmakeToolsStatusItem, this._kitSelectionButton, this._buildTargetNameButton, @@ -420,31 +422,33 @@ export class StatusBar implements vscode.Disposable { this.update(); } - dispose = () => this._buttons.forEach(btn => btn.dispose()); - update = () => this._buttons.forEach(btn => btn.update()); - setVisible = (v: boolean) => this._buttons.forEach(btn => btn.forceHidden = !v); + dispose(): void { this._buttons.forEach(btn => btn.dispose()); } + update(): void { this._buttons.forEach(btn => btn.update()); } + + setVisible(v: boolean): void { this._buttons.forEach(btn => btn.forceHidden = !v); } - setActiveFolderName = (v: string) => this._activeFolderButton.text = v; - setAutoSelectActiveFolder = (autoSelectActiveFolder: boolean) => this._activeFolderButton.autoSelect - = autoSelectActiveFolder; - setBuildTypeLabel = (v: string) => this._cmakeToolsStatusItem.text = v; - setStatusMessage = (v: string) => this._cmakeToolsStatusItem.statusMessage = v; - setBuildTargetName = (v: string) => { + setActiveFolderName(v: string): void { this._workspaceButton.text = v; } + setAutoSelectActiveFolder(autoSelectActiveFolder: boolean): void { + this._workspaceButton.autoSelect = autoSelectActiveFolder; + } + setBuildTypeLabel(v: string): void { this._cmakeToolsStatusItem.text = v; } + setStatusMessage(v: string): void { this._cmakeToolsStatusItem.statusMessage = v; } + setBuildTargetName(v: string): void { v = `[${v}]`; this._buildTargetNameButton.text = v; this._buildButton.target = v; - }; - setLaunchTargetName = (v: string) => { + } + setLaunchTargetName(v: string): void { v = v == '' ? v : `[${v}]`; this._launchTargetNameButton.text = v; this._launchButton.target = v; this._debugButton.target = v; - }; - setCTestEnabled = (v: boolean) => this._testButton.enabled = v; - setTestResults = (v: BasicTestResults|null) => this._testButton.results = v; - setIsBusy = (v: boolean) => this._buildButton.isBusy = v; - setActiveKitName = (v: string) => this._kitSelectionButton.text = v; - - hideLaunchButton = (shouldHide: boolean = true) => this._launchButton.hidden = shouldHide; - hideDebugButton = (shouldHide: boolean = true) => this._debugButton.hidden = shouldHide; + } + setCTestEnabled(v: boolean): void { this._testButton.enabled = v; } + setTestResults(v: BasicTestResults|null): void { this._testButton.results = v; } + setIsBusy(v: boolean): void { this._buildButton.isBusy = v; } + setActiveKitName(v: string): void { this._kitSelectionButton.text = v; } + + hideLaunchButton(shouldHide: boolean = true): void { this._launchButton.hidden = shouldHide; } + hideDebugButton(shouldHide: boolean = true): void { this._debugButton.hidden = shouldHide; } } \ No newline at end of file From cfc9ffb561e5173e7a62430d0cb0d40af1454c9c Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Wed, 6 May 2020 08:13:29 +0200 Subject: [PATCH 28/32] loca update --- package.nls.json | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/package.nls.json b/package.nls.json index d2e0b9b97..3e754d4ba 100644 --- a/package.nls.json +++ b/package.nls.json @@ -106,12 +106,11 @@ "cmake-tools.configuration.cmake.outputLogEncoding.description": "Encoding of the output from external commands (eg.cmake -- build).", "cmake-tools.configuration.cmake.enableTraceLogging.description": "Enable trace logging to file and console (very noisy).", "cmake-tools.configuration.cmake.autoSelectActiveFolder.description": "Select active folder automatically", - "cmake-tools.configuration.cmake.statusbar.visibility.description": "Select default visibility of statusbar buttons (e.g. compact)", - "cmake-tools.configuration.cmake.statusbar.advanced.description": "Change settings of individual statusbar buttons (e.g. visibility). This overwrites the default settings.", - "cmake-tools.configuration.cmake.statusbar.advanced.visibility.description": "Select visibility (e.g. compact)", - "cmake-tools.configuration.cmake.statusbar.advanced.ctest.color.description": "Change button color dependent on success of tests", - "cmake-tools.configuration.cmake.statusbar.advanced.length.description": "Set maximum length of visible text in compact mode.", - + "cmake-tools.configuration.cmake.statusbar.visibility.description": "Configures how the extension displays the buttons in the status bar", + "cmake-tools.configuration.cmake.statusbar.advanced.description": "Configures the settings for individual status bar buttons. These settings overwrite the more general 'cmake.statusbar.visibility' setting.", + "cmake-tools.configuration.cmake.statusbar.advanced.visibility.description": "Configures how the extension displays this button in the status bar", + "cmake-tools.configuration.cmake.statusbar.advanced.ctest.color.description": "Enables a change in color for this button depending on test results", + "cmake-tools.configuration.cmake.statusbar.advanced.length.description": "Configures the maximum length of visible text in 'compact' mode.", "cmake-tools.configuration.views.cmake.folders.description": "Folders", "cmake-tools.configuration.views.cmake.outline.description": "Project Outline" } From 4803f5473c0299caeeef366f8876dc111fbceb4f Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Wed, 6 May 2020 08:18:35 +0200 Subject: [PATCH 29/32] tooltip update --- src/status.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/status.ts b/src/status.ts index ff2de5e3f..8640c93be 100644 --- a/src/status.ts +++ b/src/status.ts @@ -256,7 +256,7 @@ class DebugButton extends Button { protected getTooltipNormal(): string|null { if (!!this._target) { - return `${this.tooltip}\n${this._target}`; + return `${this.tooltip}: ${this._target}`; } return this.tooltip; } @@ -283,7 +283,7 @@ class LaunchButton extends Button { protected getTooltipNormal(): string|null { if (!!this._target) { - return `${this.tooltip}\n${this._target}`; + return `${this.tooltip}: ${this._target}`; } return this.tooltip; } @@ -380,7 +380,7 @@ class BuildButton extends Button { protected getTooltipNormal(): string|null { if (!!this._target) { - return `${this.tooltip}\n${this._target}`; + return `${this.tooltip}: ${this._target}`; } return this.tooltip; } From bae00e450612ffc418b011e0e6321c48db000c61 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Thu, 7 May 2020 22:25:19 +0200 Subject: [PATCH 30/32] finalizing for release --- src/status.ts | 86 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/src/status.ts b/src/status.ts index 8640c93be..1699a535e 100644 --- a/src/status.ts +++ b/src/status.ts @@ -4,8 +4,6 @@ import {SpecialKits} from '@cmt/kit'; import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; -// FIXME: Show workspace selection if a folder is added to workspace - nls.config({messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone})(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); @@ -41,6 +39,8 @@ abstract class Button { this.update(); } + get bracketText(): string { return `[${this._text}]`; } + get tooltip(): string|null { return this._tooltip; } set tooltip(v: string|null) { this._tooltip = v; @@ -68,7 +68,12 @@ abstract class Button { this.button.show(); } - protected getTextNormal(): string { return this._text; } + protected getTextNormal(): string { + if (this._text.length > 0) { + return this.bracketText; + } + return ''; + } protected getTextShort(): string { return this.getTextNormal(); } protected getTextIcon(): string { return ''; } @@ -80,13 +85,19 @@ abstract class Button { return null; } if (!tooltip || !text) { - return `CMake: ${tooltip || text}`; + return this.prependCMake(`${tooltip || text}`); } - return `CMake: ${tooltip}\n${text}`; + return this.prependCMake(`${text}\n${tooltip}`); } protected getTooltipIcon(): string|null { return this.getTooltipShort(); } protected isVisible(): boolean { return true; } + protected prependCMake(text: string|null): any { + if (!!text) { + return `CMake: ${text}`; + } + return text; + } private _isVisible(): boolean { return this.isVisible() && this._getVisibility() !== 'hidden'; } private _getVisibility(): ButtonVisibility|null { @@ -138,12 +149,14 @@ abstract class Button { } class WorkspaceButton extends Button { - private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); - private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); + // private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); + // private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); + private static readonly _autoSelectToolTip = localize('active.folder.auto.tooltip', 'auto'); settingsName = 'workspace'; command = 'cmake.selectActiveFolder'; icon = 'folder-active'; + tooltip = localize('click.to.select.workspace.tooltip', 'Click to select the active workspace'); private _autoSelect: boolean = false; set autoSelect(v: boolean) { @@ -153,10 +166,12 @@ class WorkspaceButton extends Button { protected getTooltipNormal(): string|null { if (this._autoSelect) { - return WorkspaceButton._autoSelectToolTip; + return `${this.tooltip} (${WorkspaceButton._autoSelectToolTip})`; } - return WorkspaceButton._toolTip; + return this.tooltip; } + protected getTooltipShort(): string|null { return this.prependCMake(this.getTooltipNormal()); } + protected getTooltipIcon(): string|null { return super.getTooltipShort(); } protected isVisible(): boolean { return Boolean(vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1); @@ -177,11 +192,12 @@ class CMakeStatus extends Button { this.update(); } - protected getTextNormal(): string { return `CMake: ${this.text}: ${this._statusMessage}`; } - protected getTextShort(): string { return this.text; } + protected getTextNormal(): string { return this.prependCMake(`${this.bracketText}: ${this._statusMessage}`); } + protected getTextShort(): string { return this.bracketText; } - protected getTooltipNormal(): string|null { return `${this.tooltip}\n${this.text}: ${this._statusMessage}`; } - protected getTooltipShort(): string|null { return `CMake: ${this.getTooltipNormal()}`; } + protected getTooltipShort(): string|null { + return this.prependCMake(`${this.bracketText} - ${this._statusMessage}\n${this.tooltip}`); + } } class KitSelection extends Button { @@ -201,7 +217,7 @@ class KitSelection extends Button { if (text.length === 0) { return KitSelection._noKitSelected; } - return text; + return this.bracketText; } protected getTextShort(): string { let len = this.config.statusbar.advanced?.kit?.length || 0; @@ -211,29 +227,34 @@ class KitSelection extends Button { let text = this.getTextNormal(); if (len + 3 < text.length) { text = `${text.substr(0, len)}...`; + if (text.startsWith('[')) { + text = `${text}]`; + } } return text; } + + protected getTooltipShort(): string|null { + if (this.getTextNormal() == this.getTextShort()) { + return this.prependCMake(this.getTooltipNormal()); + } + return super.getTooltipShort(); + } } class BuildTargetSelectionButton extends Button { settingsName = 'buildTarget'; command = 'cmake.setDefaultTarget'; tooltip = localize('set.active.target.tooltip', 'Set the active target to build'); + + protected getTooltipShort(): string|null { return this.prependCMake(this.tooltip); } } class LaunchTargetSelectionButton extends Button { settingsName = 'launchTarget'; command = 'cmake.selectLaunchTarget'; tooltip = localize('select.target.tooltip', 'Select the target to launch'); - protected getTextNormal(): string { - if (this.text == '') { - return '[-]'; - } - return this.text; - } - - protected getTooltipShort(): string|null { return this.tooltip; } + protected getTooltipShort(): string|null { return this.prependCMake(this.tooltip); } } class DebugButton extends Button { @@ -256,7 +277,7 @@ class DebugButton extends Button { protected getTooltipNormal(): string|null { if (!!this._target) { - return `${this.tooltip}: ${this._target}`; + return `${this.tooltip}: [${this._target}]`; } return this.tooltip; } @@ -283,7 +304,7 @@ class LaunchButton extends Button { protected getTooltipNormal(): string|null { if (!!this._target) { - return `${this.tooltip}: ${this._target}`; + return `${this.tooltip}: [${this._target}]`; } return this.tooltip; } @@ -345,11 +366,19 @@ class CTestButton extends Button { protected getTextShort(): string { if (!this._results) { - return '-'; + return ''; } const {passing, total} = this._results; return `${passing}/${total}`; } + + protected getTooltipShort(): string|null { return this.prependCMake(this.getTooltipNormal()); } + protected getTooltipIcon() { + if (!!this._results) { + return this.prependCMake(`${this.getTextNormal()}\n${this.getTooltipNormal()}`); + } + return this.getTooltipShort(); + } } class BuildButton extends Button { @@ -376,15 +405,16 @@ class BuildButton extends Button { this.update(); } + protected getTextNormal(): string { return this.text; } protected getTextShort(): string { return ''; } protected getTooltipNormal(): string|null { if (!!this._target) { - return `${this.tooltip}: ${this._target}`; + return `${this.tooltip}: [${this._target}]`; } return this.tooltip; } - protected getTooltipShort(): string|null { return this.getTooltipNormal(); } + protected getTooltipShort(): string|null { return this.prependCMake(this.getTooltipNormal()); } protected isVisible(): boolean { return this._isBusy || true; } } @@ -434,12 +464,10 @@ export class StatusBar implements vscode.Disposable { setBuildTypeLabel(v: string): void { this._cmakeToolsStatusItem.text = v; } setStatusMessage(v: string): void { this._cmakeToolsStatusItem.statusMessage = v; } setBuildTargetName(v: string): void { - v = `[${v}]`; this._buildTargetNameButton.text = v; this._buildButton.target = v; } setLaunchTargetName(v: string): void { - v = v == '' ? v : `[${v}]`; this._launchTargetNameButton.text = v; this._launchButton.target = v; this._debugButton.target = v; From f14d29deb55cd3952dc0c5c135a9e7fbc1cd5406 Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Fri, 8 May 2020 13:08:30 +0200 Subject: [PATCH 31/32] active workspace -> active folder --- src/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status.ts b/src/status.ts index 1699a535e..802b0960f 100644 --- a/src/status.ts +++ b/src/status.ts @@ -156,7 +156,7 @@ class WorkspaceButton extends Button { settingsName = 'workspace'; command = 'cmake.selectActiveFolder'; icon = 'folder-active'; - tooltip = localize('click.to.select.workspace.tooltip', 'Click to select the active workspace'); + tooltip = localize('click.to.select.workspace.tooltip', 'Click to select the active folder'); private _autoSelect: boolean = false; set autoSelect(v: boolean) { From 6d4e4db10ad0ea91a835e7e52170998711c924af Mon Sep 17 00:00:00 2001 From: Stefan Schweizer <18433748+SchweizS@users.noreply.github.com> Date: Mon, 11 May 2020 18:31:07 +0200 Subject: [PATCH 32/32] removed autoSelect note from active folder --- src/status.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/status.ts b/src/status.ts index 802b0960f..855cdc754 100644 --- a/src/status.ts +++ b/src/status.ts @@ -151,23 +151,24 @@ abstract class Button { class WorkspaceButton extends Button { // private static readonly _autoSelectToolTip = localize('active.folder.auto.select.tooltip', 'Active folder'); // private static readonly _toolTip = localize('active.folder.tooltip', 'Select Active folder'); - private static readonly _autoSelectToolTip = localize('active.folder.auto.tooltip', 'auto'); + // private static readonly _autoSelectToolTip = localize('active.folder.auto.tooltip', 'auto'); settingsName = 'workspace'; command = 'cmake.selectActiveFolder'; icon = 'folder-active'; tooltip = localize('click.to.select.workspace.tooltip', 'Click to select the active folder'); - private _autoSelect: boolean = false; + // private _autoSelect: boolean = false; set autoSelect(v: boolean) { - this._autoSelect = v; - this.update(); + if (v) {} + // this._autoSelect = v; + // this.update(); } protected getTooltipNormal(): string|null { - if (this._autoSelect) { - return `${this.tooltip} (${WorkspaceButton._autoSelectToolTip})`; - } + // if (this._autoSelect) { + // return `${this.tooltip} (${WorkspaceButton._autoSelectToolTip})`; + //} return this.tooltip; } protected getTooltipShort(): string|null { return this.prependCMake(this.getTooltipNormal()); }