]> khamidou — GitHub mirrors - electron.git/commitdiff
[Mac] Move the FixMenuTitles hack to MenuController.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 14 Aug 2013 14:33:18 +0000 (22:33 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 14 Aug 2013 14:33:18 +0000 (22:33 +0800)
browser/api/atom_api_menu_mac.h
browser/api/atom_api_menu_mac.mm
browser/ui/atom_menu_controller_mac.mm

index 342f436f5b680a141ef1109de221a10ac6b48556..5f88c9b0e8fac565fe9dbbde02f3f45ed4f4f343 100644 (file)
@@ -26,11 +26,6 @@ class MenuMac : public Menu {
  private:
   friend class Menu;
 
-  // The MenuController doesn't set title for menus, however it's required by
-  // application menu to show submenus correctly, fix it by iterating all
-  // submenus and set their titles.
-  static void FixMenuTitles(NSMenu* menu);
-
   // Fake sending an action from the application menu.
   static void SendActionToFirstResponder(const std::string& action);
 
index 2d40f6b30d274b1be1a2af66ff39cc7fb2d1937d..2ae9f05e9a97d8f049d46f07ca5deb40efc17565 100644 (file)
@@ -62,22 +62,6 @@ void MenuMac::Popup(NativeWindow* native_window) {
   }
 }
 
-// static
-void MenuMac::FixMenuTitles(NSMenu* menu) {
-  int size = [menu numberOfItems];
-  for (int i = 0; i < size; ++i) {
-    NSMenuItem* item = [menu itemAtIndex:i];
-    if ([item hasSubmenu]) {
-      NSString* title = [item title];
-      NSMenu* submenu = [item submenu];
-      [submenu setTitle:title];
-
-      if ([title isEqualToString:@"Window"] && [submenu numberOfItems] > 0)
-        [NSApp setWindowsMenu:submenu];
-    }
-  }
-}
-
 // static
 void MenuMac::SendActionToFirstResponder(const std::string& action) {
   SEL selector = NSSelectorFromString(base::SysUTF8ToNSString(action));
@@ -100,7 +84,6 @@ v8::Handle<v8::Value> Menu::SetApplicationMenu(const v8::Arguments &args) {
   scoped_nsobject<AtomMenuController> menu_controller(
       [[AtomMenuController alloc] initWithModel:menu->model_.get()
                          useWithPopUpButtonCell:NO]);
-  MenuMac::FixMenuTitles([menu_controller menu]);
   [NSApp setMainMenu:[menu_controller menu]];
 
   // Ensure the menu_controller_ is destroyed after main menu is set.
index 8498eb26c18af4c95e9d62f38e6e06c1780cc7b2..ae352a5967b32311c2858bec8643565aa80e848b 100644 (file)
@@ -159,7 +159,12 @@ int EventFlagsFromNSEvent(NSEvent* event) {
     ui::MenuModel* submenuModel = model->GetSubmenuModelAt(index);
     NSMenu* submenu =
         [self menuFromModel:(ui::SimpleMenuModel*)submenuModel];
+    [submenu setTitle:[item title]];
     [item setSubmenu:submenu];
+
+    // Hack to set window menu.
+    if ([[item title] isEqualToString:@"Window"] && [submenu numberOfItems] > 0)
+      [NSApp setWindowsMenu:submenu];
   } else {
     // The MenuModel works on indexes so we can't just set the command id as the
     // tag like we do in other menus. Also set the represented object to be