Radio menu items should have at least one item checked.

This is to force all platforms to match the same behavior in GTK+.
This commit is contained in:
Cheng Zhao 2014-05-25 15:25:36 +08:00
parent 3921895dd5
commit 6a48568911
5 changed files with 28 additions and 5 deletions

View file

@ -22,7 +22,7 @@ class MenuItem
@checked = @checked ? false
@submenu = @submenu ? null
throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1
throw new Error("Unknown menu type #{@type}") if MenuItem.types.indexOf(@type) is -1
@commandId = ++nextCommandId
@click = =>

View file

@ -26,11 +26,9 @@ generateGroupId = (items, pos) ->
Menu = bindings.Menu
Menu::__proto__ = EventEmitter.prototype
popup = Menu::popup
Menu::popup = (window) ->
throw new TypeError('Invalid window') unless window?.constructor is BrowserWindow
popup.call this, window
@_popup window
Menu::append = (item) ->
@insert @getItemCount(), item
@ -55,6 +53,14 @@ Menu::insert = (pos, item) ->
if activeItem.type in ['checkbox', 'radio']
activeItem.checked = !activeItem.checked
activeItem.click()
menuWillShow: =>
# Make sure radio groups have at least one menu item seleted.
for id, group of @groupsMap
checked = false
for radioItem in group when radioItem.checked
checked = true
break
v8Util.setHiddenValue group[0], 'checked', true unless checked
switch item.type
when 'normal' then @insertItem pos, item.commandId, item.label