]> khamidou — GitHub mirrors - electron.git/commitdiff
The Menu object should store items by its index.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 14 Aug 2013 04:03:37 +0000 (12:03 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 14 Aug 2013 04:03:37 +0000 (12:03 +0800)
browser/api/lib/menu.coffee

index d666b2cab6221ff655e709dec4c9f7032b2f4342..d4d2dafbf2a8a25c03ea91c78e648312bd2f0507 100644 (file)
@@ -1,5 +1,6 @@
-EventEmitter = require('events').EventEmitter
 BrowserWindow = require 'browser-window'
+EventEmitter = require('events').EventEmitter
+IDWeakMap = require 'id-weak-map'
 MenuItem = require 'menu-item'
 
 bindings = process.atomBinding 'menu'
@@ -28,15 +29,17 @@ Menu::insert = (pos, item) ->
 
   @setSublabel pos, item.sublabel if item.sublabel?
 
-  unless @items?
-    @items = {}
+  unless @delegate?
+    @commandsMap = {}
+    @items = []
     @delegate =
-      isCommandIdChecked: (commandId) => @items[commandId]?.checked
-      isCommandIdEnabled: (commandId) => @items[commandId]?.enabled
-      isCommandIdVisible: (commandId) => @items[commandId]?.visible
-      getAcceleratorForCommandId: (commandId) => @items[commandId]?.accelerator
-      executeCommand: (commandId) => @items[commandId]?.click()
-  @items[item.commandId] = item
+      isCommandIdChecked: (commandId) => @commandsMap[commandId]?.checked
+      isCommandIdEnabled: (commandId) => @commandsMap[commandId]?.enabled
+      isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
+      getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
+      executeCommand: (commandId) => @commandsMap[commandId]?.click()
+  @items.splice pos, 0, item
+  @commandsMap[item.commandId] = item
 
 Menu.setApplicationMenu = (menu) ->
   throw new TypeError('Invalid menu') unless menu?.constructor is Menu