Add "event" parameter for "click" handler of MenuItem
authorCheng Zhao <zcbenz@gmail.com>
Wed, 22 Jun 2016 02:22:14 +0000 (11:22 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 22 Jun 2016 02:22:14 +0000 (11:22 +0900)
atom/browser/api/atom_api_menu.cc
atom/browser/api/atom_api_menu.h
docs/api/menu-item.md
lib/browser/api/menu-item.js
lib/browser/api/menu.js

index 996c717..c9cd375 100644 (file)
@@ -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) {
index 9ba4d7a..53c6bda 100644 (file)
@@ -90,7 +90,7 @@ class Menu : public mate::TrackableObject<Menu>,
   base::Callback<bool(int)> is_enabled_;
   base::Callback<bool(int)> is_visible_;
   base::Callback<v8::Local<v8::Value>(int)> get_accelerator_;
-  base::Callback<void(int)> execute_command_;
+  base::Callback<void(v8::Local<v8::Value>, int)> execute_command_;
   base::Callback<void()> menu_will_show_;
 
   DISALLOW_COPY_AND_ASSIGN(Menu);
index 13e8317..7cb4342 100644 (file)
@@ -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
index 651de14..b0100b7 100644 (file)
@@ -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)
       }
index b122fc3..3b10821 100644 (file)
@@ -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.