Skip to content

Commit 600ba8e

Browse files
committed
feat: add menuBarService
1 parent 5590dca commit 600ba8e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/services/menuBarService.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { MenuBarEvent, IMenuBar, IMenuBarItem } from 'mo/core/workbench/menuBar';
2+
import { emit } from 'mo/services/eventService';
3+
import { singleton } from 'tsyringe';
4+
5+
@singleton()
6+
export class MenuBarService implements IMenuBar {
7+
data: IMenuBarItem[];
8+
9+
constructor(data: IMenuBarItem[] = []) {
10+
this.data = data;
11+
}
12+
13+
@emit(MenuBarEvent.onClick)
14+
public onClick(event: React.MouseEvent, item: IMenuBarItem) {
15+
console.log('onClick:', this.data);
16+
}
17+
18+
@emit(MenuBarEvent.DataChanged)
19+
public push(data: IMenuBarItem | IMenuBarItem[]) {
20+
if (Array.isArray(data)) {
21+
this.data = this.data.concat(data);
22+
} else {
23+
this.data.push(data);
24+
}
25+
}
26+
27+
public remove(index: number) {
28+
this.data.splice(index, 1);
29+
}
30+
31+
public update() {
32+
// this.data.
33+
}
34+
}

0 commit comments

Comments
 (0)