@@ -10,6 +10,7 @@ import {
10
10
import { exploreActiveItem } from 'mo/model/workbench/explorer/explorer' ;
11
11
import { searchActivityItem } from 'mo/model/workbench/search' ;
12
12
import { searchById } from '../helper' ;
13
+ import { IMenuBarItem } from 'mo/model' ;
13
14
14
15
export interface IActivityBarService extends Component < IActivityBar > {
15
16
showHide ( ) : void ;
@@ -18,6 +19,8 @@ export interface IActivityBarService extends Component<IActivityBar> {
18
19
remove ( id : string ) : void ;
19
20
toggleBar ( id ?: string ) : void ;
20
21
updateContextMenuCheckStatus ( id ?: string ) : void ;
22
+ addConextMenu ( contextMenu : IMenuBarItem | IMenuBarItem [ ] ) : void ;
23
+ removeContextMenu ( id : string ) : void ;
21
24
/**
22
25
* Add click event listener
23
26
* @param callback
@@ -110,6 +113,30 @@ export class ActivityBarService
110
113
} ) ;
111
114
}
112
115
116
+ public addConextMenu ( contextMenu : IMenuBarItem | IMenuBarItem [ ] ) {
117
+ let next = [ ...this . state . contextMenu ! ] ;
118
+ if ( Array . isArray ( contextMenu ) ) {
119
+ next = next ?. concat ( contextMenu ) ;
120
+ } else {
121
+ next ?. push ( contextMenu ) ;
122
+ }
123
+ this . setState ( {
124
+ contextMenu : next ,
125
+ } ) ;
126
+ }
127
+
128
+ public removeContextMenu ( id : string ) {
129
+ const { contextMenu } = this . state ;
130
+ const next = [ ...contextMenu ! ] ;
131
+ const index = next . findIndex ( searchById ( id ) ) ;
132
+ if ( index > - 1 ) {
133
+ next . splice ( index , 1 ) ;
134
+ }
135
+ this . setState ( {
136
+ contextMenu : next ,
137
+ } ) ;
138
+ }
139
+
113
140
// ====== The belows for subscribe activity bar events ======
114
141
public onClick ( callback : Function ) {
115
142
this . subscribe ( ActivityBarEvent . OnClick , callback ) ;
0 commit comments