fix: recentDocuments menu role on macOS (#20398)
This commit is contained in:
parent
2470ef2e91
commit
e543fe702c
1 changed files with 20 additions and 6 deletions
|
@ -126,11 +126,13 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
|
||||||
if (!menu_)
|
if (!menu_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Locate & retain the recent documents menu item
|
||||||
if (!recentDocumentsMenuItem_) {
|
if (!recentDocumentsMenuItem_) {
|
||||||
// Locate & retain the recent documents menu item
|
base::string16 title = base::ASCIIToUTF16("Open Recent");
|
||||||
recentDocumentsMenuItem_.reset(
|
NSString* openTitle = l10n_util::FixUpWindowsStyleLabel(title);
|
||||||
[[[[[NSApp mainMenu] itemWithTitle:@"Electron"] submenu]
|
|
||||||
itemWithTitle:@"Open Recent"] retain]);
|
recentDocumentsMenuItem_.reset([[[[[NSApp mainMenu]
|
||||||
|
itemWithTitle:@"Electron"] submenu] itemWithTitle:openTitle] retain]);
|
||||||
}
|
}
|
||||||
|
|
||||||
model_ = model;
|
model_ = model;
|
||||||
|
@ -193,8 +195,17 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
|
||||||
// Replaces the item's submenu instance with the singleton recent documents
|
// Replaces the item's submenu instance with the singleton recent documents
|
||||||
// menu. Previously replaced menu items will be recovered.
|
// menu. Previously replaced menu items will be recovered.
|
||||||
- (void)replaceSubmenuShowingRecentDocuments:(NSMenuItem*)item {
|
- (void)replaceSubmenuShowingRecentDocuments:(NSMenuItem*)item {
|
||||||
NSMenu* recentDocumentsMenu =
|
NSMenu* recentDocumentsMenu = [recentDocumentsMenuItem_ submenu];
|
||||||
[[[recentDocumentsMenuItem_ submenu] retain] autorelease];
|
if (!recentDocumentsMenu) {
|
||||||
|
base::string16 title = base::ASCIIToUTF16("Clear Menu");
|
||||||
|
NSString* clearTitle = l10n_util::FixUpWindowsStyleLabel(title);
|
||||||
|
recentDocumentsMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
|
||||||
|
[recentDocumentsMenu
|
||||||
|
addItem:[[[NSMenuItem alloc]
|
||||||
|
initWithTitle:clearTitle
|
||||||
|
action:@selector(clearRecentDocuments:)
|
||||||
|
keyEquivalent:@""] autorelease]];
|
||||||
|
}
|
||||||
|
|
||||||
// Remove menu items in recent documents back to swap menu
|
// Remove menu items in recent documents back to swap menu
|
||||||
[self moveMenuItems:recentDocumentsMenu to:recentDocumentsMenuSwap_];
|
[self moveMenuItems:recentDocumentsMenu to:recentDocumentsMenuSwap_];
|
||||||
|
@ -211,6 +222,9 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
|
||||||
// Replace submenu
|
// Replace submenu
|
||||||
[item setSubmenu:recentDocumentsMenu];
|
[item setSubmenu:recentDocumentsMenu];
|
||||||
|
|
||||||
|
DCHECK_EQ([item action], @selector(submenuAction:));
|
||||||
|
DCHECK_EQ([item target], recentDocumentsMenu);
|
||||||
|
|
||||||
// Remember the new menu item that carries the recent documents menu
|
// Remember the new menu item that carries the recent documents menu
|
||||||
recentDocumentsMenuItem_.reset([item retain]);
|
recentDocumentsMenuItem_.reset([item retain]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue