Skip to content

Commit 2066f20

Browse files
committed
Added the tooltip to the right of the toolbar
Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent f556062 commit 2066f20

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,11 @@
5656

5757
.p-Widget.p-TabBar.theia-app-centers.theia-app-bottom .p-TabBar-content-container.ps {
5858
display: none;
59+
}
60+
61+
.arduino-toolbar-tooltip {
62+
margin-left: 10px;
63+
display: flex;
64+
align-items: center;
65+
color: var(--theia-ui-font-color3);
5966
}

arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx

+57-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,57 @@
11
import * as React from 'react';
2-
import { TabBarToolbar, TabBarToolbarRegistry, TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
2+
import { TabBarToolbar, TabBarToolbarRegistry, TabBarToolbarItem, ReactTabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
33
import { LabelParser } from '@theia/core/lib/browser/label-parser';
44
import { CommandRegistry } from '@theia/core/lib/common/command';
55

66
export const ARDUINO_TOOLBAR_ITEM_CLASS = 'arduino-tool-item';
77

8+
export namespace ArduinoToolbarComponent {
9+
export interface Props {
10+
items: (TabBarToolbarItem | ReactTabBarToolbarItem)[],
11+
commands: CommandRegistry,
12+
commandIsEnabled: (id: string) => boolean,
13+
executeCommand: (e: React.MouseEvent<HTMLElement>) => void
14+
}
15+
export interface State {
16+
tootip: string
17+
}
18+
}
19+
export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarComponent.Props, ArduinoToolbarComponent.State> {
20+
21+
constructor(props: ArduinoToolbarComponent.Props) {
22+
super(props);
23+
this.state = {tootip: ''};
24+
}
25+
26+
protected renderItem(item: TabBarToolbarItem): React.ReactNode {
27+
let innerText = '';
28+
const command = this.props.commands.getCommand(item.command);
29+
return <React.Fragment>
30+
<div key={item.id}
31+
className={`${ARDUINO_TOOLBAR_ITEM_CLASS}
32+
${TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM}
33+
${command && this.props.commandIsEnabled(command.id) ? ' enabled' : ''}`} >
34+
<div
35+
id={item.id}
36+
className='arduino-tool-icon'
37+
onClick={this.props.executeCommand}
38+
onMouseOver={() => this.setState({ tootip: item.tooltip || '' })}
39+
onMouseOut={() => this.setState({ tootip: '' })}
40+
title={item.tooltip}>
41+
{innerText}
42+
</div>
43+
</div>
44+
</React.Fragment>;
45+
}
46+
47+
render(): React.ReactNode {
48+
return <React.Fragment>
49+
<div className={'arduino-toolbar-tooltip'}>{this.state.tootip}</div>
50+
{[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())}
51+
</React.Fragment>;
52+
}
53+
}
54+
855
export class ArduinoToolbar extends TabBarToolbar {
956

1057
constructor(
@@ -27,13 +74,14 @@ export class ArduinoToolbar extends TabBarToolbar {
2774
this.update();
2875
}
2976

30-
protected renderItem(item: TabBarToolbarItem): React.ReactNode {
31-
let innerText = '';
32-
const command = this.commands.getCommand(item.command);
33-
return <div key={item.id}
34-
className={`${ARDUINO_TOOLBAR_ITEM_CLASS}
35-
${TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM}${command && this.commandIsEnabled(command.id) ? ' enabled' : ''}`} >
36-
<div id={item.id} className='arduino-tool-icon' onClick={this.executeCommand} title={item.tooltip}>{innerText}</div>
37-
</div>;
77+
protected readonly doCommandIsEnabled = (id: string) => this.commandIsEnabled(id);
78+
protected render(): React.ReactNode {
79+
return <ArduinoToolbarComponent
80+
items={[...this.items.values()]}
81+
commands={this.commands}
82+
commandIsEnabled={this.doCommandIsEnabled}
83+
executeCommand={this.executeCommand}
84+
/>
3885
}
86+
3987
}

arduino-ide-extension/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"noUnusedLocals": true,
99
"strictNullChecks": true,
1010
"experimentalDecorators": true,
11+
"downlevelIteration": true,
1112
"emitDecoratorMetadata": true,
1213
"module": "commonjs",
1314
"moduleResolution": "node",

0 commit comments

Comments
 (0)