]> khamidou — GitHub mirrors - electron.git/commitdiff
Make menu's checked property flipped automatically, fixes #349.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 25 May 2014 03:30:43 +0000 (11:30 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 25 May 2014 03:32:29 +0000 (11:32 +0800)
atom/browser/api/lib/menu.coffee

index 328ce05df64208f1b3ca8421f47f84be198c4d46..01008aad7e18a2deb50cf732b091e98ef3bfd808 100644 (file)
@@ -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