Add Menu.buildFromTemplate API to greatly simplify building menu.
This commit is contained in:
parent
e58f115b43
commit
eec8abf397
2 changed files with 84 additions and 46 deletions
|
@ -44,4 +44,16 @@ Menu.setApplicationMenu = (menu) ->
|
|||
|
||||
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
|
||||
|
||||
Menu.buildFromTemplate = (template) ->
|
||||
throw new TypeError('Invalid template for Menu') unless Array.isArray template
|
||||
|
||||
menu = new Menu
|
||||
for item in template
|
||||
throw new TypeError('Invalid template for MenuItem') unless typeof item is 'object'
|
||||
|
||||
item.submenu = Menu.buildFromTemplate item.submenu if item.submenu?
|
||||
menu.append new MenuItem(item)
|
||||
|
||||
menu
|
||||
|
||||
module.exports = Menu
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue