gpui: Allow selection of "Services" menu independent of menu title (#34115)
Release Notes: - N/A --- In the same vein as #29538, the "Services" menu on macOS depended on the text being exactly "Services", not allowing for i18n of the menu name. This PR introduces a new menu type called `OsMenu` that defines a special menu that can be populated by the system. Currently, it takes one enum value, `ServicesMenu` that tells the system to populate its contents with the items it would usually populate the "Services" menu with. An example of this being used has been implemented in the `set_menus` example: `cargo run -p gpui --example set_menus` --- Point to consider: In `mac/platform.rs:414` the existing code for setting the "Services" menu remains for backwards compatibility. Should this remain now that this new method exists to set the menu, or should it be removed? --------- Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
094e878ccf
commit
fa3d0aaed4
5 changed files with 89 additions and 12 deletions
|
@ -7,9 +7,9 @@ use super::{
|
|||
use crate::{
|
||||
Action, AnyWindowHandle, BackgroundExecutor, ClipboardEntry, ClipboardItem, ClipboardString,
|
||||
CursorStyle, ForegroundExecutor, Image, ImageFormat, KeyContext, Keymap, MacDispatcher,
|
||||
MacDisplay, MacWindow, Menu, MenuItem, OwnedMenu, PathPromptOptions, Platform, PlatformDisplay,
|
||||
PlatformKeyboardLayout, PlatformTextSystem, PlatformWindow, Result, SemanticVersion, Task,
|
||||
WindowAppearance, WindowParams, hash,
|
||||
MacDisplay, MacWindow, Menu, MenuItem, OsMenu, OwnedMenu, PathPromptOptions, Platform,
|
||||
PlatformDisplay, PlatformKeyboardLayout, PlatformTextSystem, PlatformWindow, Result,
|
||||
SemanticVersion, SystemMenuType, Task, WindowAppearance, WindowParams, hash,
|
||||
};
|
||||
use anyhow::{Context as _, anyhow};
|
||||
use block::ConcreteBlock;
|
||||
|
@ -413,9 +413,20 @@ impl MacPlatform {
|
|||
}
|
||||
item.setSubmenu_(submenu);
|
||||
item.setTitle_(ns_string(&name));
|
||||
if name == "Services" {
|
||||
let app: id = msg_send![APP_CLASS, sharedApplication];
|
||||
app.setServicesMenu_(item);
|
||||
item
|
||||
}
|
||||
MenuItem::SystemMenu(OsMenu { name, menu_type }) => {
|
||||
let item = NSMenuItem::new(nil).autorelease();
|
||||
let submenu = NSMenu::new(nil).autorelease();
|
||||
submenu.setDelegate_(delegate);
|
||||
item.setSubmenu_(submenu);
|
||||
item.setTitle_(ns_string(&name));
|
||||
|
||||
match menu_type {
|
||||
SystemMenuType::Services => {
|
||||
let app: id = msg_send![APP_CLASS, sharedApplication];
|
||||
app.setServicesMenu_(item);
|
||||
}
|
||||
}
|
||||
|
||||
item
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue