2013-05-14 11:24:52 +00:00
|
|
|
EventEmitter = require('events').EventEmitter
|
2013-05-15 11:19:35 +00:00
|
|
|
BrowserWindow = require 'browser_window'
|
2013-05-16 11:34:23 +00:00
|
|
|
MenuItem = require 'menu_item'
|
2013-05-14 11:24:52 +00:00
|
|
|
|
2013-05-16 02:54:37 +00:00
|
|
|
bindings = process.atomBinding 'menu'
|
2013-05-16 11:34:23 +00:00
|
|
|
|
2013-05-16 02:54:37 +00:00
|
|
|
Menu = bindings.Menu
|
2013-05-14 11:24:52 +00:00
|
|
|
Menu::__proto__ = EventEmitter.prototype
|
|
|
|
|
|
|
|
popup = Menu::popup
|
|
|
|
Menu::popup = (window) ->
|
2013-05-15 11:19:35 +00:00
|
|
|
throw new TypeError('Invalid window') unless window?.constructor is BrowserWindow
|
2013-05-14 11:24:52 +00:00
|
|
|
|
|
|
|
popup.call this, window
|
|
|
|
|
2013-05-16 11:34:23 +00:00
|
|
|
Menu::insert = (pos, item) ->
|
|
|
|
throw new TypeError('Invalid item') unless item?.constructor is MenuItem
|
|
|
|
|
|
|
|
switch item.type
|
|
|
|
when 'normal' then @insertItem pos, item.commandId, item.label
|
|
|
|
when 'checkbox' then @insertCheckItem pos, item.commandId, item.label
|
|
|
|
when 'radio' then @insertRadioItem pos, item.commandId, item.label, item.groupId
|
|
|
|
when 'separator' then @insertSeparator pos
|
|
|
|
when 'submenu' then @insertSubMenu pos, item.commandId, item.label, item.submenu
|
2013-05-14 14:17:25 +00:00
|
|
|
|
2013-05-16 11:34:23 +00:00
|
|
|
@setSublabel pos, item.sublabel if item.sublabel?
|
2013-05-14 14:17:25 +00:00
|
|
|
|
2013-05-16 11:34:23 +00:00
|
|
|
@items = {} unless @items?
|
|
|
|
@items[item.commandId] = item
|
|
|
|
|
|
|
|
Menu::append = (item) ->
|
|
|
|
@insert @getItemCount(), item
|
2013-05-14 11:24:52 +00:00
|
|
|
|
2013-05-16 02:54:37 +00:00
|
|
|
Menu.setApplicationMenu = (menu) ->
|
|
|
|
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
|
|
|
|
bindings.setApplicationMenu menu
|
2013-05-16 11:34:23 +00:00
|
|
|
|
2013-05-16 09:25:02 +00:00
|
|
|
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
|
2013-05-16 02:54:37 +00:00
|
|
|
|
2013-05-14 11:24:52 +00:00
|
|
|
module.exports = Menu
|