feat: add menu item role palette and header (#45538)

* feat: add menu item role `palette` and `header`

* adds comments

* refactors new role items to new item types

* docs: custom type

* docs: note types only available on mac 14+

---------

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
This commit is contained in:
Gellert Hegyi 2025-05-23 18:43:49 +02:00 committed by GitHub
commit b9b96a96f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 8 deletions

View file

@ -330,6 +330,17 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
}
}
std::u16string role = model->GetRoleAt(index);
electron::ElectronMenuModel::ItemType type = model->GetTypeAt(index);
std::u16string customType = model->GetCustomTypeAt(index);
// The sectionHeaderWithTitle menu item is only available in macOS 14.0+.
if (@available(macOS 14, *)) {
if (customType == u"header") {
item = [NSMenuItem sectionHeaderWithTitle:label];
}
}
// If the menu item has an icon, set it.
ui::ImageModel icon = model->GetIconAt(index);
if (icon.IsImage())
@ -338,9 +349,6 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
std::u16string toolTip = model->GetToolTipAt(index);
[item setToolTip:base::SysUTF16ToNSString(toolTip)];
std::u16string role = model->GetRoleAt(index);
electron::ElectronMenuModel::ItemType type = model->GetTypeAt(index);
if (role == u"services") {
std::u16string title = u"Services";
NSString* sub_label = l10n_util::FixUpWindowsStyleLabel(title);
@ -372,6 +380,14 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
NSMenu* submenu = MenuHasVisibleItems(submenuModel)
? [self menuFromModel:submenuModel]
: MakeEmptySubmenu();
// NSMenuPresentationStylePalette is only available in macOS 14.0+.
if (@available(macOS 14, *)) {
if (customType == u"palette") {
submenu.presentationStyle = NSMenuPresentationStylePalette;
}
}
[submenu setTitle:[item title]];
[item setSubmenu:submenu];