faf7280d1f
It's important to bind application menu items to curtain actions of first responder, like 'quit', 'minimize', 'copy' etc. This API gives developers ability to do most of them in javascript.
33 lines
1.2 KiB
CoffeeScript
33 lines
1.2 KiB
CoffeeScript
EventEmitter = require('events').EventEmitter
|
|
BrowserWindow = require 'browser_window'
|
|
|
|
bindings = process.atomBinding 'menu'
|
|
Menu = bindings.Menu
|
|
Menu::__proto__ = EventEmitter.prototype
|
|
|
|
popup = Menu::popup
|
|
Menu::popup = (window) ->
|
|
throw new TypeError('Invalid window') unless window?.constructor is BrowserWindow
|
|
|
|
popup.call this, window
|
|
|
|
insertSubMenu = Menu::insertSubMenu
|
|
Menu::insertSubMenu = (index, command_id, label, submenu) ->
|
|
throw new TypeError('Invalid menu') unless submenu?.constructor is Menu
|
|
|
|
@menus = [] unless Array.isArray @menus
|
|
@menus.push submenu # prevent submenu from getting destroyed
|
|
insertSubMenu.apply this, arguments
|
|
|
|
Menu::appendItem = (args...) -> @insertItem -1, args...
|
|
Menu::appendCheckItem = (args...) -> @insertCheckItem -1, args...
|
|
Menu::appendRadioItem = (args...) -> @insertRadioItem -1, args...
|
|
Menu::appendSeparator = (args...) -> @insertSeparator -1, args...
|
|
Menu::appendSubMenu = (args...) -> @insertSubMenu -1, args...
|
|
|
|
Menu.setApplicationMenu = (menu) ->
|
|
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
|
|
bindings.setApplicationMenu menu
|
|
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
|
|
|
|
module.exports = Menu
|