From: Cheng Zhao Date: Wed, 14 Aug 2013 04:51:47 +0000 (+0800) Subject: When calling menu item's click callback, pass the item object. X-Git-Tag: v0.3.3~10 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=971b72c2b6db74f687914ad1767ed8e934a966ff;p=electron.git When calling menu item's click callback, pass the item object. --- diff --git a/browser/api/lib/menu-item.coffee b/browser/api/lib/menu-item.coffee index 2764a0b4..aeae1f57 100644 --- a/browser/api/lib/menu-item.coffee +++ b/browser/api/lib/menu-item.coffee @@ -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 diff --git a/browser/api/lib/menu.coffee b/browser/api/lib/menu.coffee index d4d2dafb..52c5f242 100644 --- a/browser/api/lib/menu.coffee +++ b/browser/api/lib/menu.coffee @@ -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