From 6ee437e9bf5a45b5c9172c42e030419e5908d780 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 26 May 2014 09:38:04 +0800 Subject: [PATCH] win: Force menuWillShow to be called when setting window menu. --- atom/browser/api/atom_api_menu.cc | 2 +- atom/browser/api/lib/menu.coffee | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_menu.cc b/atom/browser/api/atom_api_menu.cc index 1971b3a47bc2..2eb1a816adf8 100644 --- a/atom/browser/api/atom_api_menu.cc +++ b/atom/browser/api/atom_api_menu.cc @@ -230,7 +230,7 @@ void Menu::BuildPrototype(v8::Isolate* isolate, .SetMethod("isEnabledAt", &Menu::IsEnabledAt) .SetMethod("isVisibleAt", &Menu::IsVisibleAt) #if defined(OS_WIN) || defined(TOOLKIT_GTK) - .SetMethod("attachToWindow", &Menu::AttachToWindow) + .SetMethod("_attachToWindow", &Menu::AttachToWindow) #endif .SetMethod("_popup", &Menu::Popup); } diff --git a/atom/browser/api/lib/menu.coffee b/atom/browser/api/lib/menu.coffee index a2846db04740..a119d9fdabf1 100644 --- a/atom/browser/api/lib/menu.coffee +++ b/atom/browser/api/lib/menu.coffee @@ -91,18 +91,22 @@ Menu::insert = (pos, item) -> @items.splice pos, 0, item @commandsMap[item.commandId] = item +Menu::attachToWindow = (window) -> + @_callMenuWillShow() if process.platform is 'win32' + @_attachToWindow window + +# Force menuWillShow to be called +Menu::_callMenuWillShow = -> + @delegate?.menuWillShow() + item.submenu._callMenuWillShow() for item in @items when item.submenu? + applicationMenu = null Menu.setApplicationMenu = (menu) -> throw new TypeError('Invalid menu') unless menu?.constructor is Menu applicationMenu = menu # Keep a reference. if process.platform is 'darwin' - # Force menuWillShow to be called - menuWillShow = (menu) -> - menu.delegate?.menuWillShow() - menuWillShow item.submenu for item in menu.items when item.submenu? - menuWillShow menu - + menu._callMenuWillShow() bindings.setApplicationMenu menu else windows = BrowserWindow.getAllWindows()