Read menu item's properties in menu's delegate.

This commit is contained in:
Cheng Zhao 2013-05-16 20:06:25 +08:00
parent 84e721188b
commit 4984f30e48
3 changed files with 16 additions and 10 deletions

View file

@ -13,6 +13,9 @@ Menu::popup = (window) ->
popup.call this, window
Menu::append = (item) ->
@insert @getItemCount(), item
Menu::insert = (pos, item) ->
throw new TypeError('Invalid item') unless item?.constructor is MenuItem
@ -25,12 +28,16 @@ Menu::insert = (pos, item) ->
@setSublabel pos, item.sublabel if item.sublabel?
@items = {} unless @items?
unless @items?
@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
Menu::append = (item) ->
@insert @getItemCount(), item
Menu.setApplicationMenu = (menu) ->
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
bindings.setApplicationMenu menu