mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-28 06:59:45 -04:00
Adding support for dynamic menus in extensions.
This commit is contained in:
parent
229cd7a50c
commit
b6bb92d8f6
2 changed files with 42 additions and 15 deletions
src/engine
|
@ -551,22 +551,23 @@ class Runtime extends EventEmitter {
|
|||
*/
|
||||
_buildMenuForScratchBlocks (menuName, menuItems, categoryInfo) {
|
||||
const menuId = this._makeExtensionMenuId(menuName, categoryInfo.id);
|
||||
|
||||
/** @TODO: support dynamic menus when 'menuItems' is a method name string (see extension spec) */
|
||||
if (typeof menuItems === 'string') {
|
||||
throw new Error(`Dynamic extension menus are not yet supported. Menu name: ${menuName}`);
|
||||
}
|
||||
const options = menuItems.map(item => {
|
||||
switch (typeof item) {
|
||||
case 'string':
|
||||
return [item, item];
|
||||
case 'object':
|
||||
return [item.text, item.value];
|
||||
default:
|
||||
throw new Error(`Can't interpret menu item: ${item}`);
|
||||
var options = null;
|
||||
if (typeof menuItems === 'function') {
|
||||
options = function () {
|
||||
return menuItems();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
options = menuItems.map(item => {
|
||||
switch (typeof item) {
|
||||
case 'string':
|
||||
return [item, item];
|
||||
case 'object':
|
||||
return [item.text, item.value];
|
||||
default:
|
||||
throw new Error(`Can't interpret menu item: ${item}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
return {
|
||||
json: {
|
||||
message0: '%1',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue