]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Fix notify icon and context menu.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 11 Jul 2014 11:42:53 +0000 (19:42 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 11 Jul 2014 11:42:53 +0000 (19:42 +0800)
atom.gyp
atom/browser/api/lib/menu-item.coffee
atom/browser/api/lib/menu.coffee
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h

index b471a04d5e86736d97f26e2d209a6a36bee4fe14..2e602e5e9d2687113bd20e7d14c0c774d1a43f34 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
               '-loleacc.lib',
               '-lComdlg32.lib',
               '-lWininet.lib',
-              '<(atom_source_root)/<(libchromiumcontent_library_dir)/chromiumviews.lib',
             ],
           },
           'dependencies': [
index bbac726acce699c97f0dd13f06fc9b3f10189411..64d69881688fac2bad9a6f9a456f0e8bbb2e2f3d 100644 (file)
@@ -44,9 +44,7 @@ class MenuItem
     Object.defineProperty this, name,
       enumerable: true
       get: => v8Util.getHiddenValue this, name
-      set: (val) =>
-        v8Util.setHiddenValue this, name, val
-        @menu?._updateStates()
+      set: (val) => v8Util.setHiddenValue this, name, val
 
   overrideReadOnlyProperty: (name, defaultValue=null) ->
     this[name] ?= defaultValue
index 8a4f15380e352e4c21cb451de581c72e45337c51..f53dc21635b09e9c2f8dc44a5a8beb470dc23b77 100644 (file)
@@ -76,9 +76,6 @@ Menu::insert = (pos, item) ->
             v8Util.setHiddenValue otherItem, 'checked', false
           v8Util.setHiddenValue item, 'checked', true
 
-          # Update states when clicked on Windows.
-          @_updateStates() if process.platform is 'win32'
-
       @insertRadioItem pos, item.commandId, item.label, item.groupId
 
   @setSublabel pos, item.sublabel if item.sublabel?
index 105f223fbbb28f48eb1cb806ed92de5c7fed020c..83cd5a3b190174a8eb7eebb3084083dfc3c5eda4 100644 (file)
@@ -13,6 +13,7 @@
 #include "ui/gfx/icon_util.h"
 #include "ui/gfx/point.h"
 #include "ui/gfx/rect.h"
+#include "ui/views/controls/menu/menu_runner.h"
 
 namespace atom {
 
@@ -60,8 +61,16 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
   if (!SetForegroundWindow(window_))
     return;
 
-  menu_.reset(new Menu2(menu_model_));
-  menu_->RunContextMenuAt(cursor_pos);
+  menu_runner_.reset(new views::MenuRunner(menu_model_));
+  views::MenuRunner::RunResult result = menu_runner_->RunMenuAt(
+      NULL,
+      NULL,
+      gfx::Rect(cursor_pos, gfx::Size()),
+      views::MenuItemView::TOPLEFT,
+      ui::MENU_SOURCE_MOUSE,
+      views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU);
+  if (result == views::MenuRunner::MENU_DELETED)
+    LOG(ERROR) << "Menu deleted when running";
 }
 
 void NotifyIcon::ResetIcon() {
index 51e854b802e2c0f00ded9c264aa08b9ae9ee5a60..b7cdbe229e1a47a77eda14607f62b7c3966fb5e2 100644 (file)
@@ -20,9 +20,12 @@ namespace gfx {
 class Point;
 }
 
+namespace views {
+class MenuRunner;
+}
+
 namespace atom {
 
-class Menu2;
 class NotifyIconHost;
 
 class NotifyIcon : public TrayIcon {
@@ -69,7 +72,7 @@ class NotifyIcon : public TrayIcon {
 
   // The context menu.
   ui::SimpleMenuModel* menu_model_;
-  scoped_ptr<atom::Menu2> menu_;
+  scoped_ptr<views::MenuRunner> menu_runner_;
 
   DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
 };