]> khamidou — GitHub mirrors - electron.git/commitdiff
Enable setting icon of menu item
authorCheng Zhao <zcbenz@gmail.com>
Fri, 13 Feb 2015 04:11:50 +0000 (12:11 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 13 Feb 2015 04:11:50 +0000 (12:11 +0800)
atom/browser/api/atom_api_menu.cc
atom/browser/api/atom_api_menu.h
atom/browser/api/lib/menu-item.coffee
atom/browser/api/lib/menu.coffee

index 97049093c01b259ccbbaa4a2bcf72de9a650ae9f..010d0414d9a9046b9c147fcec3b82d4d2c6a8f52 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "atom/browser/native_window.h"
 #include "atom/common/native_mate_converters/accelerator_converter.h"
+#include "atom/common/native_mate_converters/image_converter.h"
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "native_mate/callback.h"
 #include "native_mate/constructor.h"
@@ -103,6 +104,10 @@ void Menu::InsertSubMenuAt(int index,
   model_->InsertSubMenuAt(index, command_id, label, menu->model_.get());
 }
 
+void Menu::SetIcon(int index, const gfx::Image& image) {
+  model_->SetIcon(index, image);
+}
+
 void Menu::SetSublabel(int index, const base::string16& sublabel) {
   model_->SetSublabel(index, sublabel);
 }
@@ -152,6 +157,7 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("insertRadioItem", &Menu::InsertRadioItemAt)
       .SetMethod("insertSeparator", &Menu::InsertSeparatorAt)
       .SetMethod("insertSubMenu", &Menu::InsertSubMenuAt)
+      .SetMethod("setIcon", &Menu::SetIcon)
       .SetMethod("setSublabel", &Menu::SetSublabel)
       .SetMethod("clear", &Menu::Clear)
       .SetMethod("getIndexOfCommandId", &Menu::GetIndexOfCommandId)
index 0c8f28ec7723ac9cf9cebbdef74db4f3117dea71..830c5d0c6465985c2ed9b0b03d8b26ad94c2091b 100644 (file)
@@ -46,9 +46,8 @@ class Menu : public mate::Wrappable,
   bool IsCommandIdChecked(int command_id) const override;
   bool IsCommandIdEnabled(int command_id) const override;
   bool IsCommandIdVisible(int command_id) const override;
-  bool GetAcceleratorForCommandId(
-      int command_id,
-      ui::Accelerator* accelerator) override;
+  bool GetAcceleratorForCommandId(int command_id,
+                                  ui::Accelerator* accelerator) override;
   void ExecuteCommand(int command_id, int event_flags) override;
   void MenuWillShow(ui::SimpleMenuModel* source) override;
 
@@ -73,6 +72,7 @@ class Menu : public mate::Wrappable,
                        int command_id,
                        const base::string16& label,
                        Menu* menu);
+  void SetIcon(int index, const gfx::Image& image);
   void SetSublabel(int index, const base::string16& sublabel);
   void Clear();
   int GetIndexOfCommandId(int command_id);
index 30560e4b7ebd88d36e56e7135e15f6bd16b8207a..d8e896f8ffa1a6ee7c3230bba07d2d69572781ce 100644 (file)
@@ -9,13 +9,14 @@ class MenuItem
   constructor: (options) ->
     Menu = require 'menu'
 
-    {click, @selector, @type, @label, @sublabel, @accelerator, @enabled, @visible, @checked, @submenu} = options
+    {click, @selector, @type, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked, @submenu} = options
 
     @type = 'submenu' if not @type? and @submenu?
     throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu
 
     @overrideReadOnlyProperty 'type', 'normal'
     @overrideReadOnlyProperty 'accelerator'
+    @overrideReadOnlyProperty 'icon'
     @overrideReadOnlyProperty 'submenu'
     @overrideProperty 'label', ''
     @overrideProperty 'sublabel', ''
index bde4e91522dccdcc1ed594e0e2c7a4c66486c3c0..b9ee44e23f5d63147181a3faa94afbf0a509ccb5 100644 (file)
@@ -35,6 +35,7 @@ Menu::_init = ->
     isCommandIdEnabled: (commandId) => @commandsMap[commandId]?.enabled
     isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
     getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
+    getIconForCommandId: (commandId) => @commandsMap[commandId]?.icon
     executeCommand: (commandId) => @commandsMap[commandId]?.click()
     menuWillShow: =>
       # Make sure radio groups have at least one menu item seleted.
@@ -82,6 +83,7 @@ Menu::insert = (pos, item) ->
       @insertRadioItem pos, item.commandId, item.label, item.groupId
 
   @setSublabel pos, item.sublabel if item.sublabel?
+  @setIcon pos, item.icon if item.icon?
 
   # Make menu accessable to items.
   item.overrideReadOnlyProperty 'menu', this