The Menu object should store items by its index.
This commit is contained in:
parent
c6f18f095e
commit
d4a148ea52
1 changed files with 12 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
EventEmitter = require('events').EventEmitter
|
|
||||||
BrowserWindow = require 'browser-window'
|
BrowserWindow = require 'browser-window'
|
||||||
|
EventEmitter = require('events').EventEmitter
|
||||||
|
IDWeakMap = require 'id-weak-map'
|
||||||
MenuItem = require 'menu-item'
|
MenuItem = require 'menu-item'
|
||||||
|
|
||||||
bindings = process.atomBinding 'menu'
|
bindings = process.atomBinding 'menu'
|
||||||
|
@ -28,15 +29,17 @@ Menu::insert = (pos, item) ->
|
||||||
|
|
||||||
@setSublabel pos, item.sublabel if item.sublabel?
|
@setSublabel pos, item.sublabel if item.sublabel?
|
||||||
|
|
||||||
unless @items?
|
unless @delegate?
|
||||||
@items = {}
|
@commandsMap = {}
|
||||||
|
@items = []
|
||||||
@delegate =
|
@delegate =
|
||||||
isCommandIdChecked: (commandId) => @items[commandId]?.checked
|
isCommandIdChecked: (commandId) => @commandsMap[commandId]?.checked
|
||||||
isCommandIdEnabled: (commandId) => @items[commandId]?.enabled
|
isCommandIdEnabled: (commandId) => @commandsMap[commandId]?.enabled
|
||||||
isCommandIdVisible: (commandId) => @items[commandId]?.visible
|
isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
|
||||||
getAcceleratorForCommandId: (commandId) => @items[commandId]?.accelerator
|
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
|
||||||
executeCommand: (commandId) => @items[commandId]?.click()
|
executeCommand: (commandId) => @commandsMap[commandId]?.click()
|
||||||
@items[item.commandId] = item
|
@items.splice pos, 0, item
|
||||||
|
@commandsMap[item.commandId] = item
|
||||||
|
|
||||||
Menu.setApplicationMenu = (menu) ->
|
Menu.setApplicationMenu = (menu) ->
|
||||||
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
|
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue