1
1
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' ;
3
3
import { LabelParser } from '@theia/core/lib/browser/label-parser' ;
4
4
import { CommandRegistry } from '@theia/core/lib/common/command' ;
5
5
6
6
export const ARDUINO_TOOLBAR_ITEM_CLASS = 'arduino-tool-item' ;
7
7
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
+
8
55
export class ArduinoToolbar extends TabBarToolbar {
9
56
10
57
constructor (
@@ -27,13 +74,14 @@ export class ArduinoToolbar extends TabBarToolbar {
27
74
this . update ( ) ;
28
75
}
29
76
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
+ />
38
85
}
86
+
39
87
}
0 commit comments