1
1
import * as React from 'react' ;
2
2
import { TabBarToolbar , TabBarToolbarRegistry , TabBarToolbarItem , ReactTabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar' ;
3
- import { LabelParser } from '@theia/core/lib/browser/label-parser' ;
4
3
import { CommandRegistry } from '@theia/core/lib/common/command' ;
4
+ import { ReactWidget } from '@theia/core/lib/browser' ;
5
+ import { LabelParser } from '@theia/core/lib/browser/label-parser' ;
5
6
6
7
export const ARDUINO_TOOLBAR_ITEM_CLASS = 'arduino-tool-item' ;
7
8
@@ -20,7 +21,7 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
20
21
21
22
constructor ( props : ArduinoToolbarComponent . Props ) {
22
23
super ( props ) ;
23
- this . state = { tootip : '' } ;
24
+ this . state = { tootip : '' } ;
24
25
}
25
26
26
27
protected renderItem ( item : TabBarToolbarItem ) : React . ReactNode {
@@ -51,21 +52,33 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
51
52
}
52
53
}
53
54
54
- export class ArduinoToolbar extends TabBarToolbar {
55
+ export class ArduinoToolbar extends ReactWidget {
56
+
57
+ protected items = new Map < string , TabBarToolbarItem | ReactTabBarToolbarItem > ( ) ;
55
58
56
59
constructor (
57
60
protected readonly tabBarToolbarRegistry : TabBarToolbarRegistry ,
58
- commands : CommandRegistry , labelParser : LabelParser
61
+ protected readonly commands : CommandRegistry ,
62
+ protected readonly labelParser : LabelParser
59
63
) {
60
- super ( commands , labelParser ) ;
64
+ super ( ) ;
61
65
this . id = 'arduino-toolbar' ;
66
+ this . addClass ( TabBarToolbar . Styles . TAB_BAR_TOOLBAR ) ;
62
67
this . init ( ) ;
63
68
this . tabBarToolbarRegistry . onDidChange ( ( ) => this . updateToolbar ( ) ) ;
64
69
}
65
70
71
+ protected updateItems ( items : Array < TabBarToolbarItem | ReactTabBarToolbarItem > ) : void {
72
+ this . items . clear ( ) ;
73
+ for ( const item of items . sort ( TabBarToolbarItem . PRIORITY_COMPARATOR ) . reverse ( ) ) {
74
+ this . items . set ( item . id , item ) ;
75
+ }
76
+ this . update ( ) ;
77
+ }
78
+
66
79
protected updateToolbar ( ) : void {
67
80
const items = this ? this . tabBarToolbarRegistry . visibleItems ( this ) : [ ] ;
68
- this . updateItems ( items , this ) ;
81
+ this . updateItems ( items ) ;
69
82
}
70
83
71
84
protected init ( ) : void {
@@ -74,6 +87,10 @@ export class ArduinoToolbar extends TabBarToolbar {
74
87
}
75
88
76
89
protected readonly doCommandIsEnabled = ( id : string ) => this . commandIsEnabled ( id ) ;
90
+ protected commandIsEnabled ( command : string ) : boolean {
91
+ return this . commands . isEnabled ( command , this ) ;
92
+ }
93
+
77
94
protected render ( ) : React . ReactNode {
78
95
return < ArduinoToolbarComponent
79
96
items = { [ ...this . items . values ( ) ] }
@@ -89,5 +106,4 @@ export class ArduinoToolbar extends TabBarToolbar {
89
106
this . commands . executeCommand ( item . command , this , e ) ;
90
107
}
91
108
}
92
-
93
109
}
0 commit comments