Files
atom/src/browser/context-menu.coffee
2013-10-11 08:50:09 -07:00

20 lines
669 B
CoffeeScript

Menu = require 'menu'
module.exports =
class ContextMenu
constructor: (template, browserWindow) ->
template = @createClickHandlers(template)
menu = Menu.buildFromTemplate(template)
menu.popup(browserWindow)
# Private: It's necessary to build the event handlers in this process, otherwise
# closures are drug across processes and failed to be garbage collected
# appropriately.
createClickHandlers: (template) ->
for item in template
if item.command
(item.commandOptions ?= {}).contextCommand = true
item.click = do (item) ->
=> global.atomApplication.sendCommand(item.command, item.commandOptions)
item