When calling menu item's click callback, pass the item object.

This commit is contained in:
Cheng Zhao 2013-08-14 12:51:47 +08:00
parent f267a7812f
commit 971b72c2b6
2 changed files with 5 additions and 3 deletions

View file

@ -20,9 +20,9 @@ class MenuItem
throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1
@commandId = ++nextCommandId
@click = ->
@click = =>
if typeof click is 'function'
click()
click.apply this, arguments
else if typeof selector is 'string'
Menu.sendActionToFirstResponder selector

View file

@ -37,7 +37,9 @@ Menu::insert = (pos, item) ->
isCommandIdEnabled: (commandId) => @commandsMap[commandId]?.enabled
isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
executeCommand: (commandId) => @commandsMap[commandId]?.click()
executeCommand: (commandId) =>
activeItem = @commandsMap[commandId]
activeItem.click(activeItem) if activeItem?
@items.splice pos, 0, item
@commandsMap[item.commandId] = item