Make MenuItem's type default to 'submenu' if it has submenu property.
This commit is contained in:
parent
c2f6676c62
commit
e58f115b43
2 changed files with 8 additions and 4 deletions
|
@ -4,8 +4,13 @@ class MenuItem
|
||||||
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
|
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
|
Menu = require 'menu'
|
||||||
|
|
||||||
{click, selector, @type, @label, @sublabel, @accelerator, @enabled, @visible, @checked, @groupId, @submenu} = options
|
{click, selector, @type, @label, @sublabel, @accelerator, @enabled, @visible, @checked, @groupId, @submenu} = options
|
||||||
|
|
||||||
|
@type = 'submenu' if not @type? and @submenu?
|
||||||
|
throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu
|
||||||
|
|
||||||
@type = @type ? 'normal'
|
@type = @type ? 'normal'
|
||||||
@label = @label ? ''
|
@label = @label ? ''
|
||||||
@sublabel = @sublabel ? ''
|
@sublabel = @sublabel ? ''
|
||||||
|
@ -13,13 +18,12 @@ class MenuItem
|
||||||
@visible = @visible ? true
|
@visible = @visible ? true
|
||||||
|
|
||||||
throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1
|
throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1
|
||||||
throw new Error('Invalid menu') if @type is 'submenu' and @submenu?.constructor.name isnt 'Menu'
|
|
||||||
|
|
||||||
@commandId = ++nextCommandId
|
@commandId = ++nextCommandId
|
||||||
@click = ->
|
@click = ->
|
||||||
if typeof click is 'function'
|
if typeof click is 'function'
|
||||||
click()
|
click()
|
||||||
else if typeof selector is 'string'
|
else if typeof selector is 'string'
|
||||||
require('menu').sendActionToFirstResponder selector
|
Menu.sendActionToFirstResponder selector
|
||||||
|
|
||||||
module.exports = MenuItem
|
module.exports = MenuItem
|
||||||
|
|
|
@ -72,8 +72,8 @@ delegate.browserMainParts.preMainMessageLoopRun = function() {
|
||||||
selector: 'arrangeInFront:'
|
selector: 'arrangeInFront:'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
menu.append(new MenuItem({ type: 'submenu', submenu: appleMenu }));
|
menu.append(new MenuItem({ submenu: appleMenu }));
|
||||||
menu.append(new MenuItem({ label: 'Window', type: 'submenu', submenu: windowMenu }));
|
menu.append(new MenuItem({ label: 'Window', submenu: windowMenu }));
|
||||||
|
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue