-
Notifications
You must be signed in to change notification settings - Fork 120
/
activityBar.ts
142 lines (132 loc) · 4.63 KB
/
activityBar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import 'reflect-metadata';
import { Controller } from 'mo/react/controller';
import { container, singleton } from 'tsyringe';
import { MenuBarController, IMenuBarController } from 'mo/controller';
import { IMenuItemProps } from 'mo/components/menu';
import { ActivityBarEvent, IActivityBarItem } from 'mo/model';
import { SelectColorThemeAction } from 'mo/monaco/selectColorThemeAction';
import {
ActivityBarService,
BuiltinService,
IActivityBarService,
IBuiltinService,
ISettingsService,
SettingsService,
} from 'mo/services';
import { CommandQuickAccessViewAction } from 'mo/monaco/quickAccessViewAction';
import { IMonacoService, MonacoService } from 'mo/monaco/monacoService';
import type { UniqueId } from 'mo/common/types';
export interface IActivityBarController extends Partial<Controller> {
/**
* Called when activity bar item is clicked
*/
onClick?: (selectedKey: UniqueId, selectedNode: IActivityBarItem) => void;
/**
* Called when activity bar item which is not global is changed
*/
onChange?: (prevSelected?: UniqueId, nextSelected?: UniqueId) => void;
onContextMenuClick?: (
e: React.MouseEvent,
item: IMenuItemProps | undefined
) => void;
}
@singleton()
export class ActivityBarController
extends Controller
implements IActivityBarController {
private readonly activityBarService: IActivityBarService;
private readonly settingsService: ISettingsService;
private readonly monacoService: IMonacoService;
private readonly menuBarController: IMenuBarController;
private readonly builtinService: IBuiltinService;
constructor() {
super();
this.activityBarService = container.resolve(ActivityBarService);
this.settingsService = container.resolve(SettingsService);
this.monacoService = container.resolve(MonacoService);
this.menuBarController = container.resolve(MenuBarController);
this.builtinService = container.resolve(BuiltinService);
}
public initView() {
const {
activityBarData,
contextMenuData,
} = this.builtinService.getModules();
if (activityBarData) {
this.activityBarService.add(activityBarData);
}
if (contextMenuData) {
this.activityBarService.addContextMenu(contextMenuData);
}
}
public readonly onClick = (
selectedKey: UniqueId,
selctedNode: IActivityBarItem
) => {
this.emit(ActivityBarEvent.OnClick, selectedKey, selctedNode);
};
public readonly onChange = (
prevSelected?: UniqueId,
nextSelected?: UniqueId
) => {
this.emit(ActivityBarEvent.OnChange, prevSelected, nextSelected);
};
private gotoQuickCommand() {
this.monacoService.commandService.executeCommand(
CommandQuickAccessViewAction.ID
);
}
private onSelectColorTheme = () => {
this.monacoService.commandService.executeCommand(
SelectColorThemeAction.ID
);
};
public readonly onContextMenuClick = (
e: React.MouseEvent,
item: IMenuItemProps | undefined
) => {
const contextMenuId = item?.id;
const {
ACTION_QUICK_COMMAND = '',
ACTION_QUICK_ACCESS_SETTINGS = '',
ACTION_SELECT_THEME = '',
CONTEXT_MENU_MENU = '',
CONTEXT_MENU_EXPLORER = '',
CONTEXT_MENU_SEARCH = '',
CONTEXT_MENU_HIDE,
} = this.builtinService.getConstants();
switch (contextMenuId) {
// activityBar contextMenu
case CONTEXT_MENU_MENU: {
this.menuBarController.updateMenuBar!();
this.activityBarService.toggleContextMenuChecked(contextMenuId);
break;
}
case CONTEXT_MENU_EXPLORER:
case CONTEXT_MENU_SEARCH: {
this.activityBarService.toggleBar(contextMenuId);
this.activityBarService.toggleContextMenuChecked(contextMenuId);
break;
}
case CONTEXT_MENU_HIDE: {
this.menuBarController.updateActivityBar!();
break;
}
// manage button contextMenu
case ACTION_QUICK_COMMAND: {
this.gotoQuickCommand();
break;
}
case ACTION_QUICK_ACCESS_SETTINGS: {
this.settingsService.openSettingsInEditor();
break;
}
case ACTION_SELECT_THEME: {
this.onSelectColorTheme();
break;
}
default: {
}
}
};
}