Skip to content

Commit

Permalink
feat: add addConextMenu removeContextMenu activityServices
Browse files Browse the repository at this point in the history
add addConextMenu removeContextMenu activityServices
  • Loading branch information
zhangtengjin authored and wewoor committed Apr 14, 2021
1 parent 0618d12 commit 10411e3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/services/workbench/activityBarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { exploreActiveItem } from 'mo/model/workbench/explorer/explorer';
import { searchActivityItem } from 'mo/model/workbench/search';
import { searchById } from '../helper';
import { IMenuBarItem } from 'mo/model';

export interface IActivityBarService extends Component<IActivityBar> {
showHide(): void;
Expand All @@ -18,6 +19,8 @@ export interface IActivityBarService extends Component<IActivityBar> {
remove(id: string): void;
toggleBar(id?: string): void;
updateContextMenuCheckStatus(id?: string): void;
addConextMenu(contextMenu: IMenuBarItem | IMenuBarItem[]): void;
removeContextMenu(id: string): void;
/**
* Add click event listener
* @param callback
Expand Down Expand Up @@ -110,6 +113,30 @@ export class ActivityBarService
});
}

public addConextMenu(contextMenu: IMenuBarItem | IMenuBarItem[]) {
let next = [...this.state.contextMenu!];
if (Array.isArray(contextMenu)) {
next = next?.concat(contextMenu);
} else {
next?.push(contextMenu);
}
this.setState({
contextMenu: next,
});
}

public removeContextMenu(id: string) {
const { contextMenu } = this.state;
const next = [...contextMenu!];
const index = next.findIndex(searchById(id));
if (index > -1) {
next.splice(index, 1);
}
this.setState({
contextMenu: next,
});
}

// ====== The belows for subscribe activity bar events ======
public onClick(callback: Function) {
this.subscribe(ActivityBarEvent.OnClick, callback);
Expand Down

0 comments on commit 10411e3

Please sign in to comment.