Add "event" parameter for "click" handler of MenuItem
This commit is contained in:
parent
e6327fb015
commit
8d08e215b2
5 changed files with 11 additions and 9 deletions
|
@ -61,8 +61,10 @@ bool Menu::GetAcceleratorForCommandId(int command_id,
|
||||||
return mate::ConvertFromV8(isolate(), val, accelerator);
|
return mate::ConvertFromV8(isolate(), val, accelerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::ExecuteCommand(int command_id, int event_flags) {
|
void Menu::ExecuteCommand(int command_id, int flags) {
|
||||||
execute_command_.Run(command_id);
|
execute_command_.Run(
|
||||||
|
mate::internal::CreateEventFromFlags(isolate(), flags),
|
||||||
|
command_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::MenuWillShow(ui::SimpleMenuModel* source) {
|
void Menu::MenuWillShow(ui::SimpleMenuModel* source) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||||
base::Callback<bool(int)> is_enabled_;
|
base::Callback<bool(int)> is_enabled_;
|
||||||
base::Callback<bool(int)> is_visible_;
|
base::Callback<bool(int)> is_visible_;
|
||||||
base::Callback<v8::Local<v8::Value>(int)> get_accelerator_;
|
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_;
|
base::Callback<void()> menu_will_show_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Menu);
|
DISALLOW_COPY_AND_ASSIGN(Menu);
|
||||||
|
|
|
@ -11,8 +11,8 @@ Create a new `MenuItem` with the following method:
|
||||||
### new MenuItem(options)
|
### new MenuItem(options)
|
||||||
|
|
||||||
* `options` Object
|
* `options` Object
|
||||||
* `click` Function - Will be called with `click(menuItem, browserWindow)` when
|
* `click` Function - Will be called with
|
||||||
the menu item is clicked
|
`click(menuItem, browserWindow, event)` when the menu item is clicked
|
||||||
* `role` String - Define the action of the menu item; when specified the
|
* `role` String - Define the action of the menu item; when specified the
|
||||||
`click` property will be ignored
|
`click` property will be ignored
|
||||||
* `type` String - Can be `normal`, `separator`, `submenu`, `checkbox` or
|
* `type` String - Can be `normal`, `separator`, `submenu`, `checkbox` or
|
||||||
|
|
|
@ -72,7 +72,7 @@ const MenuItem = (function () {
|
||||||
throw new Error('Unknown menu type ' + this.type)
|
throw new Error('Unknown menu type ' + this.type)
|
||||||
}
|
}
|
||||||
this.commandId = ++nextCommandId
|
this.commandId = ++nextCommandId
|
||||||
this.click = (focusedWindow) => {
|
this.click = (event, focusedWindow) => {
|
||||||
// Manually flip the checked flags when clicked.
|
// Manually flip the checked flags when clicked.
|
||||||
if (this.type === 'checkbox' || this.type === 'radio') {
|
if (this.type === 'checkbox' || this.type === 'radio') {
|
||||||
this.checked = !this.checked
|
this.checked = !this.checked
|
||||||
|
@ -91,7 +91,7 @@ const MenuItem = (function () {
|
||||||
return webContents != null ? webContents[methodName]() : void 0
|
return webContents != null ? webContents[methodName]() : void 0
|
||||||
}
|
}
|
||||||
} else if (typeof click === 'function') {
|
} else if (typeof click === 'function') {
|
||||||
return click(this, focusedWindow)
|
return click(this, focusedWindow, event)
|
||||||
} else if (typeof this.selector === 'string' && process.platform === 'darwin') {
|
} else if (typeof this.selector === 'string' && process.platform === 'darwin') {
|
||||||
return Menu.sendActionToFirstResponder(this.selector)
|
return Menu.sendActionToFirstResponder(this.selector)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,9 +114,9 @@ Menu.prototype._init = function () {
|
||||||
var command = this.commandsMap[commandId]
|
var command = this.commandsMap[commandId]
|
||||||
return command != null ? command.icon : undefined
|
return command != null ? command.icon : undefined
|
||||||
},
|
},
|
||||||
executeCommand: (commandId) => {
|
executeCommand: (event, commandId) => {
|
||||||
var command = this.commandsMap[commandId]
|
var command = this.commandsMap[commandId]
|
||||||
return command != null ? command.click(BrowserWindow.getFocusedWindow()) : undefined
|
return command != null ? command.click(event, BrowserWindow.getFocusedWindow()) : undefined
|
||||||
},
|
},
|
||||||
menuWillShow: () => {
|
menuWillShow: () => {
|
||||||
// Make sure radio groups have at least one menu item seleted.
|
// Make sure radio groups have at least one menu item seleted.
|
||||||
|
|
Loading…
Reference in a new issue