clean up menuWillShow

This commit is contained in:
Shelley Vohr 2017-10-23 00:16:35 -04:00
parent 1cd53768ab
commit f9c3123f5f
No known key found for this signature in database
GPG key ID: F13993A75599653C

View file

@ -88,15 +88,15 @@ Menu.prototype._init = function () {
this.items = [] this.items = []
this.delegate = { this.delegate = {
isCommandIdChecked: (commandId) => { isCommandIdChecked: (commandId) => {
var command = this.commandsMap[commandId] const command = this.commandsMap[commandId]
return command != null ? command.checked : undefined return command != null ? command.checked : undefined
}, },
isCommandIdEnabled: (commandId) => { isCommandIdEnabled: (commandId) => {
var command = this.commandsMap[commandId] const command = this.commandsMap[commandId]
return command != null ? command.enabled : undefined return command != null ? command.enabled : undefined
}, },
isCommandIdVisible: (commandId) => { isCommandIdVisible: (commandId) => {
var command = this.commandsMap[commandId] const command = this.commandsMap[commandId]
return command != null ? command.visible : undefined return command != null ? command.visible : undefined
}, },
getAcceleratorForCommandId: (commandId, useDefaultAccelerator) => { getAcceleratorForCommandId: (commandId, useDefaultAccelerator) => {
@ -106,7 +106,7 @@ Menu.prototype._init = function () {
if (useDefaultAccelerator) return command.getDefaultRoleAccelerator() if (useDefaultAccelerator) return command.getDefaultRoleAccelerator()
}, },
getIconForCommandId: (commandId) => { getIconForCommandId: (commandId) => {
var command = this.commandsMap[commandId] const command = this.commandsMap[commandId]
return command != null ? command.icon : undefined return command != null ? command.icon : undefined
}, },
executeCommand: (event, commandId) => { executeCommand: (event, commandId) => {
@ -115,23 +115,17 @@ Menu.prototype._init = function () {
command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents()) command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents())
}, },
menuWillShow: () => { menuWillShow: () => {
// Make sure radio groups have at least one menu item seleted. // Make sure radio groups have at least one menu item selected
var checked, group, id, j, len, radioItem, ref1 for (let id in this.groupsMap) {
ref1 = this.groupsMap const group = this.groupsMap[id]
for (id in ref1) { const checked = false
group = ref1[id] for (let idx = 0; idx < group.length; idx++) {
checked = false const radioItem = group[idx]
for (j = 0, len = group.length; j < len; j++) { if (!radioItem.checked) continue
radioItem = group[j]
if (!radioItem.checked) {
continue
}
checked = true checked = true
break break
} }
if (!checked) { if (!checked) v8Util.setHiddenValue(group[0], 'checked', true)
v8Util.setHiddenValue(group[0], 'checked', true)
}
} }
} }
} }