From: Cheng Zhao Date: Fri, 11 Jul 2014 11:42:53 +0000 (+0800) Subject: win: Fix notify icon and context menu. X-Git-Tag: v0.14.0~1^2~29 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b2afe7b3bf0910df4c7b8ce9f6ceea045f0a404c;p=electron.git win: Fix notify icon and context menu. --- diff --git a/atom.gyp b/atom.gyp index b471a04d..2e602e5e 100644 --- a/atom.gyp +++ b/atom.gyp @@ -439,7 +439,6 @@ '-loleacc.lib', '-lComdlg32.lib', '-lWininet.lib', - '<(atom_source_root)/<(libchromiumcontent_library_dir)/chromiumviews.lib', ], }, 'dependencies': [ diff --git a/atom/browser/api/lib/menu-item.coffee b/atom/browser/api/lib/menu-item.coffee index bbac726a..64d69881 100644 --- a/atom/browser/api/lib/menu-item.coffee +++ b/atom/browser/api/lib/menu-item.coffee @@ -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 diff --git a/atom/browser/api/lib/menu.coffee b/atom/browser/api/lib/menu.coffee index 8a4f1538..f53dc216 100644 --- a/atom/browser/api/lib/menu.coffee +++ b/atom/browser/api/lib/menu.coffee @@ -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? diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 105f223f..83cd5a3b 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -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() { diff --git a/atom/browser/ui/win/notify_icon.h b/atom/browser/ui/win/notify_icon.h index 51e854b8..b7cdbe22 100644 --- a/atom/browser/ui/win/notify_icon.h +++ b/atom/browser/ui/win/notify_icon.h @@ -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 menu_; + scoped_ptr menu_runner_; DISALLOW_COPY_AND_ASSIGN(NotifyIcon); };