Skip to content

Commit 10411e3

Browse files
zhangtengjinwewoor
authored andcommitted
feat: add addConextMenu removeContextMenu activityServices
add addConextMenu removeContextMenu activityServices
1 parent 0618d12 commit 10411e3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/services/workbench/activityBarService.ts

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { exploreActiveItem } from 'mo/model/workbench/explorer/explorer';
1111
import { searchActivityItem } from 'mo/model/workbench/search';
1212
import { searchById } from '../helper';
13+
import { IMenuBarItem } from 'mo/model';
1314

1415
export interface IActivityBarService extends Component<IActivityBar> {
1516
showHide(): void;
@@ -18,6 +19,8 @@ export interface IActivityBarService extends Component<IActivityBar> {
1819
remove(id: string): void;
1920
toggleBar(id?: string): void;
2021
updateContextMenuCheckStatus(id?: string): void;
22+
addConextMenu(contextMenu: IMenuBarItem | IMenuBarItem[]): void;
23+
removeContextMenu(id: string): void;
2124
/**
2225
* Add click event listener
2326
* @param callback
@@ -110,6 +113,30 @@ export class ActivityBarService
110113
});
111114
}
112115

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+
113140
// ====== The belows for subscribe activity bar events ======
114141
public onClick(callback: Function) {
115142
this.subscribe(ActivityBarEvent.OnClick, callback);

0 commit comments

Comments
 (0)