]> khamidou — GitHub mirrors - electron.git/commitdiff
Read menu item's properties in menu's delegate.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 16 May 2013 12:06:25 +0000 (20:06 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 16 May 2013 12:06:25 +0000 (20:06 +0800)
browser/api/atom_api_menu.cc
browser/api/lib/menu.coffee
browser/api/lib/menu_item.coffee

index 544ad4339cec570ed726a08d0d1b06215ea7e14c..1bfd271b0283d88c3bde120d832a0ff6c75fcfe8 100644 (file)
@@ -126,11 +126,7 @@ string16 Menu::GetSublabelForCommandId(int command_id) const {
 
 void Menu::ExecuteCommand(int command_id, int event_flags) {
   v8::HandleScope scope;
-  v8::Handle<v8::Value> args[] = {
-    v8::String::New("execute"),
-    v8::Integer::New(command_id)
-  };
-  node::MakeCallback(handle(), "emit", 2, args);
+  CallDelegate(v8::False(), handle(), "executeCommand", command_id);
 }
 
 // static
index 132ad8faaa4c6eb58c62d48403b232a96c9f3f09..013354bbbff1151680fd9f0d23f399783814480b 100644 (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
index d9d801dabcdb9200ebd731e12db2c418ec3c1138..14d65d30e68a1844cde6a3de2e2c41f661516065 100644 (file)
@@ -4,15 +4,18 @@ class MenuItem
   @types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
 
   constructor: (options) ->
-    {@type, @label, @sublabel, @click, @checked, @groupId, @submenu} = options
+    {click, @type, @label, @sublabel, @accelerator, @enabled, @visible, @checked, @groupId, @submenu} = options
 
     @type = @type ? 'normal'
     @label = @label ? ''
     @sublabel = @sublabel ? ''
+    @enabled = @enabled ? true
+    @visible = @visible ? true
 
     throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1
     throw new Error('Invalid menu') if @type is 'submenu' and @submenu?.constructor.name isnt 'Menu'
 
     @commandId = ++nextCommandId
+    @click = -> click() if typeof click is 'function'
 
 module.exports = MenuItem