[Mac] Move the FixMenuTitles hack to MenuController.
This commit is contained in:
parent
22012d41d8
commit
f908619630
3 changed files with 5 additions and 22 deletions
|
@ -26,11 +26,6 @@ class MenuMac : public Menu {
|
||||||
private:
|
private:
|
||||||
friend class Menu;
|
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.
|
// Fake sending an action from the application menu.
|
||||||
static void SendActionToFirstResponder(const std::string& action);
|
static void SendActionToFirstResponder(const std::string& action);
|
||||||
|
|
||||||
|
|
|
@ -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
|
// static
|
||||||
void MenuMac::SendActionToFirstResponder(const std::string& action) {
|
void MenuMac::SendActionToFirstResponder(const std::string& action) {
|
||||||
SEL selector = NSSelectorFromString(base::SysUTF8ToNSString(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(
|
scoped_nsobject<AtomMenuController> menu_controller(
|
||||||
[[AtomMenuController alloc] initWithModel:menu->model_.get()
|
[[AtomMenuController alloc] initWithModel:menu->model_.get()
|
||||||
useWithPopUpButtonCell:NO]);
|
useWithPopUpButtonCell:NO]);
|
||||||
MenuMac::FixMenuTitles([menu_controller menu]);
|
|
||||||
[NSApp setMainMenu:[menu_controller menu]];
|
[NSApp setMainMenu:[menu_controller menu]];
|
||||||
|
|
||||||
// Ensure the menu_controller_ is destroyed after main menu is set.
|
// Ensure the menu_controller_ is destroyed after main menu is set.
|
||||||
|
|
|
@ -159,7 +159,12 @@ int EventFlagsFromNSEvent(NSEvent* event) {
|
||||||
ui::MenuModel* submenuModel = model->GetSubmenuModelAt(index);
|
ui::MenuModel* submenuModel = model->GetSubmenuModelAt(index);
|
||||||
NSMenu* submenu =
|
NSMenu* submenu =
|
||||||
[self menuFromModel:(ui::SimpleMenuModel*)submenuModel];
|
[self menuFromModel:(ui::SimpleMenuModel*)submenuModel];
|
||||||
|
[submenu setTitle:[item title]];
|
||||||
[item setSubmenu:submenu];
|
[item setSubmenu:submenu];
|
||||||
|
|
||||||
|
// Hack to set window menu.
|
||||||
|
if ([[item title] isEqualToString:@"Window"] && [submenu numberOfItems] > 0)
|
||||||
|
[NSApp setWindowsMenu:submenu];
|
||||||
} else {
|
} else {
|
||||||
// The MenuModel works on indexes so we can't just set the command id as the
|
// 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
|
// tag like we do in other menus. Also set the represented object to be
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue