Introduce openrecent role
- Does not yet accept any options except label--"Clear Menu" can't be modified through exposed node API - If `openrecent` is present across multiple menu items, the last seen will be visible in the main menu due to that it is designed to behave like a singleton
This commit is contained in:
parent
0ba2fa5cba
commit
4da2eb9366
3 changed files with 26 additions and 2 deletions
|
@ -26,6 +26,7 @@ class AtomMenuModel;
|
|||
@protected
|
||||
atom::AtomMenuModel* model_; // weak
|
||||
base::scoped_nsobject<NSMenu> menu_;
|
||||
NSMenuItem* openRecentMenuItem_;
|
||||
BOOL isMenuOpen_;
|
||||
BOOL useDefaultAccelerator_;
|
||||
base::Callback<void()> closeCallback;
|
||||
|
|
|
@ -75,7 +75,10 @@ Role kRolesMap[] = {
|
|||
// while its context menu is still open.
|
||||
[self cancel];
|
||||
|
||||
model_ = nullptr;
|
||||
model_ = nil;
|
||||
|
||||
[openRecentMenuItem_ release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -87,6 +90,13 @@ Role kRolesMap[] = {
|
|||
if (!menu_)
|
||||
return;
|
||||
|
||||
// Retain submenu for recent documents
|
||||
if (!openRecentMenuItem_) {
|
||||
openRecentMenuItem_ = [[[[NSApp mainMenu]
|
||||
itemWithTitle:@"Electron"] submenu] itemWithTitle:@"Open Recent"];
|
||||
[openRecentMenuItem_ retain];
|
||||
}
|
||||
|
||||
model_ = model;
|
||||
[menu_ removeAllItems];
|
||||
|
||||
|
@ -139,6 +149,17 @@ Role kRolesMap[] = {
|
|||
fromModel:(atom::AtomMenuModel*)model {
|
||||
base::string16 label16 = model->GetLabelAt(index);
|
||||
NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);
|
||||
base::string16 role = model->GetRoleAt(index);
|
||||
|
||||
if (role == base::ASCIIToUTF16("openrecent")) {
|
||||
// Special role for recent documents
|
||||
[[openRecentMenuItem_ menu] removeItem:openRecentMenuItem_];
|
||||
[openRecentMenuItem_ setTitle:label];
|
||||
[[openRecentMenuItem_ submenu] setTitle:label];
|
||||
[menu insertItem:openRecentMenuItem_ atIndex:index];
|
||||
return;
|
||||
}
|
||||
|
||||
base::scoped_nsobject<NSMenuItem> item(
|
||||
[[NSMenuItem alloc] initWithTitle:label
|
||||
action:@selector(itemSelected:)
|
||||
|
@ -161,7 +182,6 @@ Role kRolesMap[] = {
|
|||
[item setSubmenu:submenu];
|
||||
|
||||
// Set submenu's role.
|
||||
base::string16 role = model->GetRoleAt(index);
|
||||
if (role == base::ASCIIToUTF16("window") && [submenu numberOfItems])
|
||||
[NSApp setWindowsMenu:submenu];
|
||||
else if (role == base::ASCIIToUTF16("help"))
|
||||
|
|
|
@ -102,6 +102,9 @@ const roles = {
|
|||
services: {
|
||||
label: 'Services'
|
||||
},
|
||||
openrecent: {
|
||||
label: 'Open Recent'
|
||||
},
|
||||
startspeaking: {
|
||||
label: 'Start Speaking'
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue