Make menu's checked property flipped automatically, fixes #349.
This commit is contained in:
parent
6a071e1b4d
commit
fd99d21c8f
1 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue