Setting a radio menu item should flip other items in the group.
This commit is contained in:
parent
04fbec5120
commit
aa17b3adc2
1 changed files with 14 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
BrowserWindow = require 'browser-window'
|
BrowserWindow = require 'browser-window'
|
||||||
EventEmitter = require('events').EventEmitter
|
EventEmitter = require('events').EventEmitter
|
||||||
MenuItem = require 'menu-item'
|
MenuItem = require 'menu-item'
|
||||||
|
v8Util = process.atomBinding 'v8_util'
|
||||||
|
|
||||||
bindings = process.atomBinding 'menu'
|
bindings = process.atomBinding 'menu'
|
||||||
|
|
||||||
|
@ -51,13 +52,8 @@ Menu::insert = (pos, item) ->
|
||||||
activeItem = @commandsMap[commandId]
|
activeItem = @commandsMap[commandId]
|
||||||
# Manually flip the checked flags when clicked.
|
# Manually flip the checked flags when clicked.
|
||||||
if activeItem?
|
if activeItem?
|
||||||
switch activeItem.type
|
if activeItem.type in ['checkbox', 'radio']
|
||||||
when 'checkbox'
|
activeItem.checked = !activeItem.checked
|
||||||
activeItem.checked = !activeItem.checked
|
|
||||||
when 'radio'
|
|
||||||
for item in @groupsMap[activeItem.groupId]
|
|
||||||
item.checked = false
|
|
||||||
activeItem.checked = true
|
|
||||||
activeItem.click()
|
activeItem.click()
|
||||||
|
|
||||||
switch item.type
|
switch item.type
|
||||||
|
@ -70,6 +66,17 @@ Menu::insert = (pos, item) ->
|
||||||
item.groupId = generateGroupId(@items, pos)
|
item.groupId = generateGroupId(@items, pos)
|
||||||
@groupsMap[item.groupId] ?= []
|
@groupsMap[item.groupId] ?= []
|
||||||
@groupsMap[item.groupId].push item
|
@groupsMap[item.groupId].push item
|
||||||
|
|
||||||
|
# Setting a radio menu item should flip other items in the group.
|
||||||
|
v8Util.setHiddenValue item, 'checked', item.checked
|
||||||
|
Object.defineProperty item, 'checked',
|
||||||
|
enumerable: true
|
||||||
|
get: -> v8Util.getHiddenValue item, 'checked'
|
||||||
|
set: (val) =>
|
||||||
|
for otherItem in @groupsMap[item.groupId]
|
||||||
|
v8Util.setHiddenValue otherItem, 'checked', false
|
||||||
|
v8Util.setHiddenValue item, 'checked', true
|
||||||
|
|
||||||
@insertRadioItem pos, item.commandId, item.label, item.groupId
|
@insertRadioItem pos, item.commandId, item.label, item.groupId
|
||||||
|
|
||||||
@setSublabel pos, item.sublabel if item.sublabel?
|
@setSublabel pos, item.sublabel if item.sublabel?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue