From 971b72c2b6db74f687914ad1767ed8e934a966ff Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 14 Aug 2013 12:51:47 +0800 Subject: [PATCH] When calling menu item's click callback, pass the item object. --- browser/api/lib/menu-item.coffee | 4 ++-- browser/api/lib/menu.coffee | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/browser/api/lib/menu-item.coffee b/browser/api/lib/menu-item.coffee index 2764a0b..aeae1f5 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 d4d2daf..52c5f24 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 -- 2.7.4