Context menus can now handle different types and commands, as well as submenus

This commit is contained in:
Erik Håkansson
2014-05-10 01:21:43 +02:00
parent 00987f3642
commit 3c8bfb8bc8
2 changed files with 8 additions and 1 deletions

View File

@@ -19,4 +19,6 @@ class ContextMenu
do (item) =>
item.click = =>
global.atomApplication.sendCommandToWindow(item.command, @atomWindow, item.commandOptions)
else if item.submenu
@createClickHandlers(item.submenu)
item

View File

@@ -34,7 +34,10 @@ class ContextMenuManager
add: (name, object, {devMode}={}) ->
for selector, items of object
for label, command of items
@addBySelector(selector, {label, command}, {devMode})
if (typeof command == 'object')
@addBySelector(selector, command, {devMode})
else
@addBySelector(selector, {label, command}, {devMode})
# Registers a command to be displayed when the relevant item is right
# clicked.
@@ -49,6 +52,8 @@ class ContextMenuManager
definitions = if devMode then @devModeDefinitions else @definitions
(definitions[selector] ?= []).push(definition)
# Returns definitions which match the element and devMode.
definitionsForElement: (element, {devMode}={}) ->
definitions = if devMode then @devModeDefinitions else @definitions