Convert submenu when non-Menu is passed into MenuItem ctor
This commit is contained in:
parent
f178787737
commit
26ac86c95c
2 changed files with 3 additions and 2 deletions
|
@ -24,8 +24,10 @@ class MenuItem
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
{Menu} = require 'electron'
|
{Menu} = require 'electron'
|
||||||
|
|
||||||
{click, @selector, @type, @role, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked, @submenu} = options
|
{click, @selector, @type, @role, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked} = options
|
||||||
|
|
||||||
|
if options.submenu? and options.submenu.constructor isnt Menu
|
||||||
|
@submenu = Menu.buildFromTemplate options.submenu
|
||||||
@type = 'submenu' if not @type? and @submenu?
|
@type = 'submenu' if not @type? and @submenu?
|
||||||
throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu
|
throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,6 @@ Menu.buildFromTemplate = (template) ->
|
||||||
for item in positionedTemplate
|
for item in positionedTemplate
|
||||||
throw new TypeError('Invalid template for MenuItem') unless typeof item is 'object'
|
throw new TypeError('Invalid template for MenuItem') unless typeof item is 'object'
|
||||||
|
|
||||||
item.submenu = Menu.buildFromTemplate item.submenu if item.submenu?
|
|
||||||
menuItem = new MenuItem(item)
|
menuItem = new MenuItem(item)
|
||||||
menuItem[key] = value for key, value of item when not menuItem[key]?
|
menuItem[key] = value for key, value of item when not menuItem[key]?
|
||||||
menu.append menuItem
|
menu.append menuItem
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue