diff --git a/atom/browser/api/atom_api_menu.cc b/atom/browser/api/atom_api_menu.cc index 996c71739bc..c9cd37522b8 100644 --- a/atom/browser/api/atom_api_menu.cc +++ b/atom/browser/api/atom_api_menu.cc @@ -61,8 +61,10 @@ bool Menu::GetAcceleratorForCommandId(int command_id, return mate::ConvertFromV8(isolate(), val, accelerator); } -void Menu::ExecuteCommand(int command_id, int event_flags) { - execute_command_.Run(command_id); +void Menu::ExecuteCommand(int command_id, int flags) { + execute_command_.Run( + mate::internal::CreateEventFromFlags(isolate(), flags), + command_id); } void Menu::MenuWillShow(ui::SimpleMenuModel* source) { diff --git a/atom/browser/api/atom_api_menu.h b/atom/browser/api/atom_api_menu.h index 9ba4d7a754c..53c6bdaf4ec 100644 --- a/atom/browser/api/atom_api_menu.h +++ b/atom/browser/api/atom_api_menu.h @@ -90,7 +90,7 @@ class Menu : public mate::TrackableObject, base::Callback is_enabled_; base::Callback is_visible_; base::Callback(int)> get_accelerator_; - base::Callback execute_command_; + base::Callback, int)> execute_command_; base::Callback menu_will_show_; DISALLOW_COPY_AND_ASSIGN(Menu); diff --git a/docs/api/menu-item.md b/docs/api/menu-item.md index 13e8317b972..7cb434288b0 100644 --- a/docs/api/menu-item.md +++ b/docs/api/menu-item.md @@ -11,8 +11,8 @@ Create a new `MenuItem` with the following method: ### new MenuItem(options) * `options` Object - * `click` Function - Will be called with `click(menuItem, browserWindow)` when - the menu item is clicked + * `click` Function - Will be called with + `click(menuItem, browserWindow, event)` when the menu item is clicked * `role` String - Define the action of the menu item; when specified the `click` property will be ignored * `type` String - Can be `normal`, `separator`, `submenu`, `checkbox` or diff --git a/lib/browser/api/menu-item.js b/lib/browser/api/menu-item.js index 651de147af1..b0100b7f2ff 100644 --- a/lib/browser/api/menu-item.js +++ b/lib/browser/api/menu-item.js @@ -72,7 +72,7 @@ const MenuItem = (function () { throw new Error('Unknown menu type ' + this.type) } this.commandId = ++nextCommandId - this.click = (focusedWindow) => { + this.click = (event, focusedWindow) => { // Manually flip the checked flags when clicked. if (this.type === 'checkbox' || this.type === 'radio') { this.checked = !this.checked @@ -91,7 +91,7 @@ const MenuItem = (function () { return webContents != null ? webContents[methodName]() : void 0 } } else if (typeof click === 'function') { - return click(this, focusedWindow) + return click(this, focusedWindow, event) } else if (typeof this.selector === 'string' && process.platform === 'darwin') { return Menu.sendActionToFirstResponder(this.selector) } diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index b122fc36cf3..3b108219363 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -114,9 +114,9 @@ Menu.prototype._init = function () { var command = this.commandsMap[commandId] return command != null ? command.icon : undefined }, - executeCommand: (commandId) => { + executeCommand: (event, commandId) => { var command = this.commandsMap[commandId] - return command != null ? command.click(BrowserWindow.getFocusedWindow()) : undefined + return command != null ? command.click(event, BrowserWindow.getFocusedWindow()) : undefined }, menuWillShow: () => { // Make sure radio groups have at least one menu item seleted.