From 508858358c9f78d6bacbd1dc92564fbfd05da029 Mon Sep 17 00:00:00 2001 From: seantan22 Date: Thu, 14 Jan 2021 15:39:45 -0500 Subject: [PATCH] Add Active Background for Toggled Toolbar Items Fixes [#8312](https://github.com/eclipse-theia/theia/issues/8312) What It Does - Renders toolbar items with a highlighted background if in a toggled state. How To Test 1. Go to View -> Sample Unclosable View 2. Click on the toolbar item (add/plus icon) to toggle and observe that a highlighted background appears behind the toolbar icon. Signed-off-by: seantan22 --- .../sample-unclosable-view-contribution.ts | 2 +- .../src/browser/shell/tab-bar-toolbar.tsx | 35 ++++++++++++++----- packages/core/src/browser/style/tabs.css | 5 +++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/examples/api-samples/src/browser/view/sample-unclosable-view-contribution.ts b/examples/api-samples/src/browser/view/sample-unclosable-view-contribution.ts index fb955d0e5d4da..4220487a59693 100644 --- a/examples/api-samples/src/browser/view/sample-unclosable-view-contribution.ts +++ b/examples/api-samples/src/browser/view/sample-unclosable-view-contribution.ts @@ -78,8 +78,8 @@ export class SampleUnclosableViewContribution extends AbstractViewContribution { bindViewContribution(bind, SampleUnclosableViewContribution); - bind(SampleViewUnclosableView).toSelf(); bind(TabBarToolbarContribution).to(SampleUnclosableViewContribution).inSingletonScope(); + bind(SampleViewUnclosableView).toSelf(); bind(WidgetFactory).toDynamicValue(ctx => ({ id: SampleViewUnclosableView.ID, createWidget: () => ctx.container.get(SampleViewUnclosableView) diff --git a/packages/core/src/browser/shell/tab-bar-toolbar.tsx b/packages/core/src/browser/shell/tab-bar-toolbar.tsx index d10ebe130ee05..6febbb6d7f77b 100644 --- a/packages/core/src/browser/shell/tab-bar-toolbar.tsx +++ b/packages/core/src/browser/shell/tab-bar-toolbar.tsx @@ -129,18 +129,30 @@ export class TabBarToolbar extends ReactWidget { classNames.push(iconClass); } const tooltip = item.tooltip || (command && command.label); -<<<<<<< Updated upstream - return
>>>>>> Stashed changes - onMouseDown={this.onMouseDownEvent} onMouseUp={this.onMouseUpEvent} onMouseOut={this.onMouseUpEvent} > -
{innerText}
+ const toolbarItemClassNames = command ? this.getToolbarItemClassNames(command.id) : ''; + return
+
{innerText} +
; } + protected getToolbarItemClassNames(commandId: string): string { + const classNames = [TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM]; + if (this.commandIsEnabled(commandId)) { + classNames.push('enabled'); + } + if (this.commandIsToggled(commandId)) { + classNames.push('toggled'); + } + return classNames.join(' '); + } + protected renderMore(): React.ReactNode { return !!this.more.size &&
@@ -181,6 +193,10 @@ export class TabBarToolbar extends ReactWidget { return this.commands.isEnabled(command, this.current); } + protected commandIsToggled(command: string): boolean { + return this.commands.isToggled(command, this.current); + } + protected executeCommand = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); @@ -189,6 +205,7 @@ export class TabBarToolbar extends ReactWidget { if (TabBarToolbarItem.is(item)) { this.commands.executeCommand(item.command, this.current); } + this.update(); }; protected onMouseDownEvent = (e: React.MouseEvent) => { diff --git a/packages/core/src/browser/style/tabs.css b/packages/core/src/browser/style/tabs.css index 699e8efb3be8c..80e5c437aa031 100644 --- a/packages/core/src/browser/style/tabs.css +++ b/packages/core/src/browser/style/tabs.css @@ -355,6 +355,11 @@ body.theia-editor-highlightModifiedTabs transform: scale(1.272019649); } +.p-TabBar-toolbar .item.toggled { + border: var(--theia-border-width) var(--theia-inputOption-activeBorder) solid; + background-color: var(--theia-inputOption-activeBackground); +} + .p-TabBar-toolbar .item > div { height: 18px; width: 18px;