Skip to content

Commit 4cad068

Browse files
author
Akos Kitta
committed
styled the sketch control.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent bb70562 commit 4cad068

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ContainerModule } from 'inversify';
33
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
44
import { CommandContribution } from '@theia/core/lib/common/command';
55
import { bindViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
6-
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
6+
import { TabBarToolbarContribution, TabBarToolbarFactory } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
77
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
88
import { FrontendApplicationContribution, FrontendApplication as TheiaFrontendApplication } from '@theia/core/lib/browser/frontend-application'
99
import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser/textmate';
@@ -39,7 +39,6 @@ import { MonacoStatusBarContribution } from './theia/monaco/monaco-status-bar-co
3939
import {
4040
ApplicationShell as TheiaApplicationShell,
4141
ShellLayoutRestorer as TheiaShellLayoutRestorer,
42-
KeybindingContribution,
4342
CommonFrontendContribution as TheiaCommonFrontendContribution,
4443
KeybindingRegistry as TheiaKeybindingRegistry
4544
} from '@theia/core/lib/browser';
@@ -113,6 +112,7 @@ import { KeybindingRegistry } from './theia/core/keybindings';
113112
import { WorkspaceCommandContribution } from './theia/workspace/workspace-commands';
114113
import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/workspace/lib/browser/workspace-delete-handler';
115114
import { WorkspaceDeleteHandler } from './theia/workspace/workspace-delete-handler';
115+
import { TabBarToolbar } from './theia/core/tab-bar-toolbar';
116116

117117
const ElementQueries = require('css-element-queries/src/ElementQueries');
118118

@@ -132,7 +132,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
132132
bind(CommandContribution).toService(ArduinoFrontendContribution);
133133
bind(MenuContribution).toService(ArduinoFrontendContribution);
134134
bind(TabBarToolbarContribution).toService(ArduinoFrontendContribution);
135-
bind(KeybindingContribution).toService(ArduinoFrontendContribution);
136135
bind(FrontendApplicationContribution).toService(ArduinoFrontendContribution);
137136
bind(ColorContribution).toService(ArduinoFrontendContribution);
138137

@@ -292,6 +291,11 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
292291
rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope();
293292
rebind(TheiaWorkspaceCommandContribution).to(WorkspaceCommandContribution).inSingletonScope();
294293
rebind(TheiaWorkspaceDeleteHandler).to(WorkspaceDeleteHandler).inSingletonScope();
294+
rebind(TabBarToolbarFactory).toFactory(({ container: parentContainer }) => () => {
295+
const container = parentContainer.createChild();
296+
container.bind(TabBarToolbar).toSelf().inSingletonScope();
297+
return container.get(TabBarToolbar);
298+
});
295299

296300
// Show a disconnected status bar, when the daemon is not available
297301
bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope();

arduino-ide-extension/src/browser/style/main.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@
146146
background-color: var(--theia-arduino-foreground);
147147
}
148148

149-
#arduino-open-sketch-control--toolbar {
150-
background-color: var(--theia-tab-inactiveBackground);
151-
border: 1px solid var(--theia-arduino-toolbar-background);
152-
padding: 2px 0px 2px 9px;
149+
#arduino-open-sketch-control--toolbar--container {
150+
background-color: var(--theia-arduino-toolbar-background);
151+
padding-left: 8px; /* based on pure heuristics */
153152
}
154153

155154
/* Output */
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react';
2+
import { injectable } from 'inversify';
3+
import { LabelIcon } from '@theia/core/lib/browser/label-parser';
4+
import { TabBarToolbar as TheiaTabBarToolbar, TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
5+
6+
@injectable()
7+
export class TabBarToolbar extends TheiaTabBarToolbar {
8+
9+
/**
10+
* Copied over from Theia. Added an ID to the parent of the toolbar item (`--container`).
11+
* CSS3 does not support parent selectors but we want to style the parent of the toolbar item.
12+
*/
13+
protected renderItem(item: TabBarToolbarItem): React.ReactNode {
14+
let innerText = '';
15+
const classNames = [];
16+
if (item.text) {
17+
for (const labelPart of this.labelParser.parse(item.text)) {
18+
if (typeof labelPart !== 'string' && LabelIcon.is(labelPart)) {
19+
const className = `fa fa-${labelPart.name}${labelPart.animation ? ' fa-' + labelPart.animation : ''}`;
20+
classNames.push(...className.split(' '));
21+
} else {
22+
innerText = labelPart;
23+
}
24+
}
25+
}
26+
const command = this.commands.getCommand(item.command);
27+
const iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon || (command && command.iconClass);
28+
if (iconClass) {
29+
classNames.push(iconClass);
30+
}
31+
const tooltip = item.tooltip || (command && command.label);
32+
return <div id={`${item.id}--container`} key={item.id} className={`${TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM}${command && this.commandIsEnabled(command.id) ? ' enabled' : ''}`}
33+
onMouseDown={this.onMouseDownEvent} onMouseUp={this.onMouseUpEvent} onMouseOut={this.onMouseUpEvent} >
34+
<div id={item.id} className={classNames.join(' ')} onClick={this.executeCommand} title={tooltip}>{innerText}</div>
35+
</div>;
36+
}
37+
38+
}

0 commit comments

Comments
 (0)