diff --git a/atom/browser/api/lib/menu.coffee b/atom/browser/api/lib/menu.coffee index 328ce05df642..01008aad7e18 100644 --- a/atom/browser/api/lib/menu.coffee +++ b/atom/browser/api/lib/menu.coffee @@ -30,6 +30,7 @@ Menu::insert = (pos, item) -> unless @delegate? @commandsMap = {} + @groupsMap = {} @items = [] @delegate = isCommandIdChecked: (commandId) => @commandsMap[commandId]?.checked @@ -38,10 +39,22 @@ Menu::insert = (pos, item) -> getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator executeCommand: (commandId) => activeItem = @commandsMap[commandId] - activeItem.click() if activeItem? + if activeItem? + switch activeItem.type + when 'checkbox' + activeItem.checked = !activeItem.checked + when 'radio' + for item in @groupsMap[activeItem.groupId] + item.checked = false + activeItem.checked = true + activeItem.click() @items.splice pos, 0, item @commandsMap[item.commandId] = item + if item.groupId? + @groupsMap[item.groupId] ?= [] + @groupsMap[item.groupId].push item + applicationMenu = null Menu.setApplicationMenu = (menu) -> throw new TypeError('Invalid menu') unless menu?.constructor is Menu