2013-10-05 06:31:30 +00:00
|
|
|
BrowserWindow = require 'browser-window'
|
|
|
|
|
2013-05-16 11:34:23 +00:00
|
|
|
nextCommandId = 0
|
|
|
|
|
|
|
|
class MenuItem
|
|
|
|
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
|
|
|
|
|
|
|
|
constructor: (options) ->
|
2013-05-16 14:22:33 +00:00
|
|
|
Menu = require 'menu'
|
|
|
|
|
2013-08-15 08:09:34 +00:00
|
|
|
{click, @selector, @type, @label, @sublabel, @accelerator, @enabled, @visible, @checked, @groupId, @submenu} = options
|
2013-05-16 11:34:23 +00:00
|
|
|
|
2013-05-16 14:22:33 +00:00
|
|
|
@type = 'submenu' if not @type? and @submenu?
|
|
|
|
throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu
|
|
|
|
|
2013-05-16 11:34:23 +00:00
|
|
|
@type = @type ? 'normal'
|
|
|
|
@label = @label ? ''
|
|
|
|
@sublabel = @sublabel ? ''
|
2013-08-14 13:59:49 +00:00
|
|
|
@accelerator = @accelerator ? null
|
2013-05-16 12:06:25 +00:00
|
|
|
@enabled = @enabled ? true
|
|
|
|
@visible = @visible ? true
|
2013-08-14 13:59:49 +00:00
|
|
|
@checked = @checked ? false
|
|
|
|
@groupId = @groupId ? null
|
|
|
|
@submenu = @submenu ? null
|
2013-05-16 11:34:23 +00:00
|
|
|
|
|
|
|
throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1
|
|
|
|
|
|
|
|
@commandId = ++nextCommandId
|
2013-08-14 04:51:47 +00:00
|
|
|
@click = =>
|
2013-05-16 12:53:10 +00:00
|
|
|
if typeof click is 'function'
|
2013-10-05 06:31:30 +00:00
|
|
|
click this, BrowserWindow.getFocusedWindow()
|
2013-08-15 09:50:30 +00:00
|
|
|
else if typeof @selector is 'string'
|
|
|
|
Menu.sendActionToFirstResponder @selector
|
2013-05-16 11:34:23 +00:00
|
|
|
|
|
|
|
module.exports = MenuItem
|