+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/menu-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See [`Menu`](menu.md) for examples.
* `type` string (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or
`radio`.
* `label` string (optional)
* `sublabel` string (optional)
* `sublabel` string (optional) _macOS_ - Available in macOS >= 14.4
* `toolTip` string (optional) _macOS_ - Hover text for this menu item.
* `accelerator` [Accelerator](accelerator.md) (optional)
* `icon` ([NativeImage](native-image.md) | string) (optional)
Expand Down
21 changes: 21 additions & 0 deletions docs/api/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,27 @@ name, no matter what label you set. To change it, modify your app bundle's
[About Information Property List Files][AboutInformationPropertyListFiles]
for more information.

### Menu Sublabels

Menu sublabels, or [subtitles](https://developer.apple.com/documentation/appkit/nsmenuitem/subtitle?language=objc), can be added to menu items using the `sublabel` option. Below is an example based on the renderer example above:

```js @ts-expect-error=[12]
// main
ipcMain.on('show-context-menu', (event) => {
const template = [
{
label: 'Menu Item 1',
sublabel: 'Subtitle 1',
click: () => { event.sender.send('context-menu-command', 'menu-item-1') }
},
{ type: 'separator' },
{ label: 'Menu Item 2', sublabel: 'Subtitle 2', type: 'checkbox', checked: true }
]
const menu = Menu.buildFromTemplate(template)
menu.popup({ window: BrowserWindow.fromWebContents(event.sender) })
})
```

## Setting Menu for Specific Browser Window (_Linux_ _Windows_)

The [`setMenu` method][setMenu] of browser windows can set the menu of certain
Expand Down
9 changes: 9 additions & 0 deletions shell/browser/ui/cocoa/electron_menu_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,21 @@ - (NSMenuItem*)menuItemForService:(NSSharingService*)service
- (NSMenuItem*)makeMenuItemForIndex:(NSInteger)index
fromModel:(electron::ElectronMenuModel*)model {
std::u16string label16 = model->GetLabelAt(index);
auto rawSecondaryLabel = model->GetSecondaryLabelAt(index);
NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);

NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:label
action:@selector(itemSelected:)
keyEquivalent:@""];

if (!rawSecondaryLabel.empty()) {
if (@available(macOS 14.4, *)) {
NSString* secondary_label =
l10n_util::FixUpWindowsStyleLabel(rawSecondaryLabel);
item.subtitle = secondary_label;
}
}

// If the menu item has an icon, set it.
ui::ImageModel icon = model->GetIconAt(index);
if (icon.IsImage())
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载