- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy patharduino-menus.ts
246 lines (225 loc) · 7.47 KB
/
arduino-menus.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import{CommonMenus}from'@theia/core/lib/browser/common-frontend-contribution';
import{
MAIN_MENU_BAR,
MenuModelRegistry,
MenuNode,
MenuPath,
SubMenuOptions,
}from'@theia/core/lib/common/menu';
import{nls}from'@theia/core/lib/common/nls';
import{isOSX}from'@theia/core/lib/common/os';
exportnamespaceArduinoMenus{
// Main menu
// -- File
exportconstFILE__SKETCH_GROUP=[...CommonMenus.FILE,'0_sketch'];
exportconstFILE__PRINT_GROUP=[...CommonMenus.FILE,'1_print'];
// XXX: on macOS, the "Preferences" and "Advanced" group is not under `File`
// The empty path ensures no top level menu is created for the preferences, even if they contains sub menus
exportconstFILE__PREFERENCES_GROUP=[
...(isOSX ? [''] : CommonMenus.FILE),
'2_preferences',
];
exportconstFILE__ADVANCED_GROUP=[
...(isOSX ? [''] : CommonMenus.FILE),
'3_advanced',
];
exportconstFILE__ADVANCED_SUBMENU=[
...FILE__ADVANCED_GROUP,
'0_advanced_sub',
];
exportconstFILE__QUIT_GROUP=[...CommonMenus.FILE,'3_quit'];
// -- File / Open Recent
exportconstFILE__OPEN_RECENT_SUBMENU=[
...FILE__SKETCH_GROUP,
'0_open_recent',
];
// -- File / Sketchbook
exportconstFILE__SKETCHBOOK_SUBMENU=[
...FILE__SKETCH_GROUP,
'1_sketchbook',
];
// -- File / Examples
exportconstFILE__EXAMPLES_SUBMENU=[...FILE__SKETCH_GROUP,'2_examples'];
exportconstEXAMPLES__BUILT_IN_GROUP=[
...FILE__EXAMPLES_SUBMENU,
'0_built_ins',
];
exportconstEXAMPLES__ANY_BOARD_GROUP=[
...FILE__EXAMPLES_SUBMENU,
'1_any_board',
];
exportconstEXAMPLES__CURRENT_BOARD_GROUP=[
...FILE__EXAMPLES_SUBMENU,
'2_current_board',
];
exportconstEXAMPLES__USER_LIBS_GROUP=[
...FILE__EXAMPLES_SUBMENU,
'3_user_libs',
];
// -- Edit
// `Copy`, `Copy to Forum`, `Paste`, etc.
// Note: `1_undo` is the first group from Theia, we start with `2`
exportconstEDIT__TEXT_CONTROL_GROUP=[
...CommonMenus.EDIT,
'2_text_control',
];
// `Comment/Uncomment`, etc.
exportconstEDIT__CODE_CONTROL_GROUP=[
...CommonMenus.EDIT,
'3_code_control',
];
exportconstEDIT__FONT_CONTROL_GROUP=[
...CommonMenus.EDIT,
'4_font_control',
];
exportconstEDIT__FIND_GROUP=[...CommonMenus.EDIT,'5_find'];
// -- Sketch
exportconstSKETCH=[...MAIN_MENU_BAR,'3_sketch'];
exportconstSKETCH__MAIN_GROUP=[...SKETCH,'0_main'];
exportconstSKETCH__UTILS_GROUP=[...SKETCH,'1_utils'];
// -- Tools
exportconstTOOLS=[...MAIN_MENU_BAR,'4_tools'];
// `Auto Format`, `Archive Sketch`, `Manage Libraries...`, `Serial Monitor`, Serial Plotter
exportconstTOOLS__MAIN_GROUP=[...TOOLS,'0_main'];
// `WiFi101 / WiFiNINA Firmware Updater`
exportconstTOOLS__FIRMWARE_UPLOADER_GROUP=[
...TOOLS,
'1_firmware_uploader',
];
// `Board`, `Port`, and `Get Board Info`.
exportconstTOOLS__BOARD_SELECTION_GROUP=[...TOOLS,'2_board_selection'];
// Core settings, such as `Processor` and `Programmers` for the board and `Burn Bootloader`
exportconstTOOLS__BOARD_SETTINGS_GROUP=[...TOOLS,'3_board_settings'];
// `Tool` > `Ports` (always visible https://github.com/arduino/arduino-ide/issues/655)
exportconstTOOLS__PORTS_SUBMENU=[
...ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP,
'2_ports',
];
// -- Help
// `Getting Started`, `Environment`, `Troubleshooting`, etc.
exportconstHELP__MAIN_GROUP=[...CommonMenus.HELP,'0_main'];
// `Find in reference`, `FAQ`, etc.
exportconstHELP__FIND_GROUP=[...CommonMenus.HELP,'1_find'];
// `Advanced Mode`.
// XXX: this will be removed.
exportconstHELP__CONTROL_GROUP=[...CommonMenus.HELP,'2_control'];
// `About` group
// XXX: on macOS, the about group is not under `Help`
exportconstHELP__ABOUT_GROUP=[
...(isOSX ? MAIN_MENU_BAR : CommonMenus.HELP),
'999_about',
];
// ------------
// Context menus
// -- Open
exportconstOPEN_SKETCH__CONTEXT=['arduino-open-sketch--context'];
exportconstOPEN_SKETCH__CONTEXT__OPEN_GROUP=[
...OPEN_SKETCH__CONTEXT,
'0_open',
];
exportconstOPEN_SKETCH__CONTEXT__RECENT_GROUP=[
...OPEN_SKETCH__CONTEXT,
'1_recent',
];
exportconstOPEN_SKETCH__CONTEXT__EXAMPLES_GROUP=[
...OPEN_SKETCH__CONTEXT,
'2_examples',
];
// -- Sketch control
exportconstSKETCH_CONTROL__CONTEXT=['arduino-sketch-control--context'];
// `New Tab`, `Rename`, `Delete`
exportconstSKETCH_CONTROL__CONTEXT__MAIN_GROUP=[
...SKETCH_CONTROL__CONTEXT,
'0_main',
];
// `Previous Tab`, `Next Tab`
exportconstSKETCH_CONTROL__CONTEXT__NAVIGATION_GROUP=[
...SKETCH_CONTROL__CONTEXT,
'1_navigation',
];
// Sketch files opened in editors
exportconstSKETCH_CONTROL__CONTEXT__RESOURCES_GROUP=[
...SKETCH_CONTROL__CONTEXT,
'2_resources',
];
// -- Account
exportconstARDUINO_ACCOUNT__CONTEXT=['arduino-account--context'];
exportconstARDUINO_ACCOUNT__CONTEXT__SIGN_IN_GROUP=[
...ARDUINO_ACCOUNT__CONTEXT,
'0_sign_in',
];
exportconstARDUINO_ACCOUNT__CONTEXT__LEARN_MORE_GROUP=[
...ARDUINO_ACCOUNT__CONTEXT,
'1_learn_more',
];
exportconstARDUINO_ACCOUNT__CONTEXT__GO_TO_GROUP=[
...ARDUINO_ACCOUNT__CONTEXT,
'2_go_to',
];
exportconstARDUINO_ACCOUNT__CONTEXT__SIGN_OUT_GROUP=[
...ARDUINO_ACCOUNT__CONTEXT,
'3_sign_out',
];
// Context menu from the library and boards manager widget
exportconstARDUINO_COMPONENT__CONTEXT=['arduino-component--context'];
exportconstARDUINO_COMPONENT__CONTEXT__INFO_GROUP=[
...ARDUINO_COMPONENT__CONTEXT,
'0_info',
];
exportconstARDUINO_COMPONENT__CONTEXT__ACTION_GROUP=[
...ARDUINO_COMPONENT__CONTEXT,
'1_action',
];
// -- ROOT SSL CERTIFICATES
exportconstROOT_CERTIFICATES__CONTEXT=[
'arduino-root-certificates--context',
];
}
/**
* This is a hack. It removes a submenu with all its children if any.
* Theia cannot dispose submenu entries with a proper API: https://github.com/eclipse-theia/theia/issues/7299
*/
exportfunctionunregisterSubmenu(
menuPath: string[],
menuRegistry: MenuModelRegistry
): void{
if(menuPath.length<2){
thrownewError(
`Expected at least two item as a menu-path. Got ${JSON.stringify(
menuPath
)} instead.`
);
}
consttoRemove=menuPath[menuPath.length-1];
constparentMenuPath=menuPath.slice(0,menuPath.length-1);
// This is unsafe. Calling `getMenu` with a non-existing menu-path will result in a new menu creation.
// https://github.com/eclipse-theia/theia/issues/7300
constparent=menuRegistry.getMenu(parentMenuPath);
constindex=parent.children.findIndex(({ id })=>id===toRemove);
if(index===-1){
thrownewError(
`Could not find menu with menu-path: ${JSON.stringify(menuPath)}.`
);
}
(parent.childrenasArray<MenuNode>).splice(index,1);
}
/**
* Special menu node that is not backed by any commands and is always disabled.
*/
exportclassPlaceholderMenuNodeimplementsMenuNode{
constructor(
protectedreadonlymenuPath: MenuPath,
readonlylabel: string,
protectedoptions: SubMenuOptions={order: '0'}
){}
geticon(): string|undefined{
returnthis.options?.iconClass;
}
getsortString(): string{
returnthis.options?.order||this.label;
}
getid(): string{
return[...this.menuPath,'placeholder'].join('-');
}
}
exportconstexamplesLabel=nls.localize('arduino/examples/menu','Examples');